From 142c5dc5ecfb84a35dc966845e774646b8cd6e8b Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 27 Jan 2016 01:05:47 -0800 Subject: [PATCH] Remove almost all uses of base::scoped_ptr We now use std::unique_ptr more consistently. --- sky/shell/gpu/direct/rasterizer_direct.cc | 10 +++++----- sky/shell/gpu/mojo/rasterizer_mojo.cc | 11 ++++++----- sky/shell/platform/android/platform_view_android.cc | 6 +++--- sky/shell/platform/android/platform_view_android.h | 4 ++-- sky/shell/platform/android/sky_main.cc | 2 +- sky/shell/platform/android/update_service_android.cc | 2 +- sky/shell/platform/android/update_service_android.h | 4 ++-- sky/shell/platform/ios/sky_surface.mm | 2 +- sky/shell/platform/mac/platform_mac.mm | 2 +- sky/shell/platform/mac/sky_window.mm | 2 +- sky/shell/platform/mojo/sky_application_impl.h | 2 +- sky/shell/rasterizer.h | 3 +-- sky/shell/shell.cc | 2 +- sky/shell/shell.h | 7 +++---- sky/shell/shell_view.cc | 12 ++---------- sky/shell/shell_view.h | 9 +++++---- sky/shell/testing/test_runner.h | 3 ++- sky/shell/ui/animator.cc | 4 ++-- sky/shell/ui/engine.h | 5 ++--- 19 files changed, 42 insertions(+), 50 deletions(-) diff --git a/sky/shell/gpu/direct/rasterizer_direct.cc b/sky/shell/gpu/direct/rasterizer_direct.cc index 01a07c4a7..6833365d0 100644 --- a/sky/shell/gpu/direct/rasterizer_direct.cc +++ b/sky/shell/gpu/direct/rasterizer_direct.cc @@ -27,8 +27,8 @@ namespace shell { static const double kOneFrameDuration = 1e3 / 60.0; -scoped_ptr Rasterizer::Create() { - return make_scoped_ptr(new RasterizerDirect()); +std::unique_ptr Rasterizer::Create() { + return std::unique_ptr(new RasterizerDirect()); } RasterizerDirect::RasterizerDirect() @@ -67,14 +67,14 @@ void RasterizerDirect::Draw(uint64_t layer_tree_ptr, const DrawCallback& callback) { TRACE_EVENT0("flutter", "RasterizerDirect::Draw"); + std::unique_ptr layer_tree( + reinterpret_cast(layer_tree_ptr)); + if (!surface_) { callback.Run(); return; } - scoped_ptr layer_tree( - reinterpret_cast(layer_tree_ptr)); - gfx::Size size(layer_tree->frame_size().width(), layer_tree->frame_size().height()); diff --git a/sky/shell/gpu/mojo/rasterizer_mojo.cc b/sky/shell/gpu/mojo/rasterizer_mojo.cc index e05b71b01..77f12b23d 100644 --- a/sky/shell/gpu/mojo/rasterizer_mojo.cc +++ b/sky/shell/gpu/mojo/rasterizer_mojo.cc @@ -20,8 +20,8 @@ void ContextLostThunk(void* closure) { } // namespace -scoped_ptr Rasterizer::Create() { - return make_scoped_ptr(new RasterizerMojo()); +std::unique_ptr Rasterizer::Create() { + return std::unique_ptr(new RasterizerMojo()); } RasterizerMojo::RasterizerMojo() : binding_(this), weak_factory_(this) { @@ -46,14 +46,15 @@ void RasterizerMojo::ConnectToRasterizer ( void RasterizerMojo::Draw(uint64_t layer_tree_ptr, const DrawCallback& callback) { TRACE_EVENT0("flutter", "RasterizerMojo::Draw"); + + std::unique_ptr layer_tree( + reinterpret_cast(layer_tree_ptr)); + if (!MGLGetCurrentContext()) { callback.Run(); return; } - scoped_ptr layer_tree( - reinterpret_cast(layer_tree_ptr)); - if (layer_tree->frame_size().isEmpty()) { callback.Run(); return; diff --git a/sky/shell/platform/android/platform_view_android.cc b/sky/shell/platform/android/platform_view_android.cc index 79a3038bb..ddb29eace 100644 --- a/sky/shell/platform/android/platform_view_android.cc +++ b/sky/shell/platform/android/platform_view_android.cc @@ -21,7 +21,7 @@ namespace shell { static jlong Attach(JNIEnv* env, jclass clazz, jint skyEngineHandle) { ShellView* shell_view = new ShellView(Shell::Shared()); auto view = static_cast(shell_view->view()); - view->SetShellView(make_scoped_ptr(shell_view)); + view->SetShellView(std::unique_ptr(shell_view)); view->ConnectToEngine( mojo::MakeRequest(mojo::ScopedMessagePipeHandle( mojo::MessagePipeHandle(skyEngineHandle)))); @@ -70,9 +70,9 @@ void PlatformViewAndroid::SurfaceDestroyed(JNIEnv* env, jobject obj) { ReleaseWindow(); } -void PlatformViewAndroid::SetShellView(scoped_ptr shell_view) { +void PlatformViewAndroid::SetShellView(std::unique_ptr shell_view) { DCHECK(!shell_view_); - shell_view_ = shell_view.Pass(); + shell_view_ = std::move(shell_view); } void PlatformViewAndroid::ReleaseWindow() { diff --git a/sky/shell/platform/android/platform_view_android.h b/sky/shell/platform/android/platform_view_android.h index fb9ee40dc..2a49f8565 100644 --- a/sky/shell/platform/android/platform_view_android.h +++ b/sky/shell/platform/android/platform_view_android.h @@ -25,7 +25,7 @@ class PlatformViewAndroid : public PlatformView { void SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface); void SurfaceDestroyed(JNIEnv* env, jobject obj); - void SetShellView(scoped_ptr shell_view); + void SetShellView(std::unique_ptr shell_view); private: void ReleaseWindow(); @@ -34,7 +34,7 @@ class PlatformViewAndroid : public PlatformView { // lifetime is controlled by the Android view hierarchy, we flip around the // ownership and have the shell_view owned by Java. We reset this pointer in // |Detach|, which will eventually cause |~PlatformViewAndroid|. - scoped_ptr shell_view_; + std::unique_ptr shell_view_; gfx::AcceleratedWidget window_; DISALLOW_COPY_AND_ASSIGN(PlatformViewAndroid); diff --git a/sky/shell/platform/android/sky_main.cc b/sky/shell/platform/android/sky_main.cc index 731030a1b..2678c3f7e 100644 --- a/sky/shell/platform/android/sky_main.cc +++ b/sky/shell/platform/android/sky_main.cc @@ -31,7 +31,7 @@ namespace shell { namespace { -LazyInstance> g_java_message_loop = +LazyInstance> g_java_message_loop = LAZY_INSTANCE_INITIALIZER; void InitializeLogging() { diff --git a/sky/shell/platform/android/update_service_android.cc b/sky/shell/platform/android/update_service_android.cc index b74c85ec6..5e7febe08 100644 --- a/sky/shell/platform/android/update_service_android.cc +++ b/sky/shell/platform/android/update_service_android.cc @@ -15,7 +15,7 @@ namespace sky { namespace shell { static jlong CheckForUpdates(JNIEnv* env, jobject jcaller) { - scoped_ptr task(new UpdateTaskAndroid(env, jcaller)); + std::unique_ptr task(new UpdateTaskAndroid(env, jcaller)); task->Start(); return reinterpret_cast(task.release()); } diff --git a/sky/shell/platform/android/update_service_android.h b/sky/shell/platform/android/update_service_android.h index 56a8c14e4..a5c223ac1 100644 --- a/sky/shell/platform/android/update_service_android.h +++ b/sky/shell/platform/android/update_service_android.h @@ -6,9 +6,9 @@ #define SKY_SHELL_ANDROID_UPDATE_SERVICE_ANDROID_H_ #include +#include #include "base/android/scoped_java_ref.h" -#include "base/memory/scoped_ptr.h" #include "sky/engine/public/sky/sky_headless.h" namespace sky { @@ -31,7 +31,7 @@ class UpdateTaskAndroid : public blink::SkyHeadless::Client { // SkyHeadless::Client: void DidCreateIsolate(Dart_Isolate isolate) override; - scoped_ptr headless_; + std::unique_ptr headless_; base::android::ScopedJavaGlobalRef update_service_; }; diff --git a/sky/shell/platform/ios/sky_surface.mm b/sky/shell/platform/ios/sky_surface.mm index eca893a64..df891cc1a 100644 --- a/sky/shell/platform/ios/sky_surface.mm +++ b/sky/shell/platform/ios/sky_surface.mm @@ -91,7 +91,7 @@ class TouchMapper { CGPoint _lastScrollTranslation; sky::SkyEnginePtr _sky_engine; - scoped_ptr _shell_view; + std::unique_ptr _shell_view; TouchMapper _touch_mapper; } diff --git a/sky/shell/platform/mac/platform_mac.mm b/sky/shell/platform/mac/platform_mac.mm index 147661d5b..845a371be 100644 --- a/sky/shell/platform/mac/platform_mac.mm +++ b/sky/shell/platform/mac/platform_mac.mm @@ -72,7 +72,7 @@ int PlatformMacMain(int argc, // marker that can be used as a reference for startup. TRACE_EVENT_INSTANT0("flutter", "main", TRACE_EVENT_SCOPE_PROCESS); - scoped_ptr message_loop(new base::MessageLoopForUI()); + std::unique_ptr message_loop(new base::MessageLoopForUI()); #if TARGET_OS_IPHONE // One cannot start the message loop on the platform main thread. Instead, diff --git a/sky/shell/platform/mac/sky_window.mm b/sky/shell/platform/mac/sky_window.mm index 0b6dfb2fc..49a92507b 100644 --- a/sky/shell/platform/mac/sky_window.mm +++ b/sky/shell/platform/mac/sky_window.mm @@ -45,7 +45,7 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(NSEventPhase phase) @implementation SkyWindow { sky::SkyEnginePtr _sky_engine; - scoped_ptr _shell_view; + std::unique_ptr _shell_view; } @synthesize renderSurface = _renderSurface; diff --git a/sky/shell/platform/mojo/sky_application_impl.h b/sky/shell/platform/mojo/sky_application_impl.h index 07236882e..ccefe7697 100644 --- a/sky/shell/platform/mojo/sky_application_impl.h +++ b/sky/shell/platform/mojo/sky_application_impl.h @@ -45,7 +45,7 @@ class SkyApplicationImpl : public mojo::Application { mojo::URLResponsePtr initial_response_; mojo::ShellPtr shell_; mojo::asset_bundle::AssetBundlePtr bundle_; - scoped_ptr shell_view_; + std::unique_ptr shell_view_; }; } // namespace shell diff --git a/sky/shell/rasterizer.h b/sky/shell/rasterizer.h index ab48423b1..e713fedb6 100644 --- a/sky/shell/rasterizer.h +++ b/sky/shell/rasterizer.h @@ -8,7 +8,6 @@ #include #include "base/callback.h" -#include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "mojo/public/cpp/bindings/binding.h" #include "flow/layer_tree.h" @@ -25,7 +24,7 @@ class Rasterizer : public rasterizer::Rasterizer { virtual base::WeakPtr<::sky::shell::Rasterizer> GetWeakRasterizerPtr() = 0; // Implemented by each GPU backend. - static scoped_ptr Create(); + static std::unique_ptr Create(); }; } // namespace shell diff --git a/sky/shell/shell.cc b/sky/shell/shell.cc index f1e99507a..1ffb669f3 100644 --- a/sky/shell/shell.cc +++ b/sky/shell/shell.cc @@ -37,7 +37,7 @@ class NonDiscardableMemory : public base::DiscardableMemory { void* data() const override { return data_.get(); } private: - scoped_ptr data_; + std::unique_ptr data_; }; class NonDiscardableMemoryAllocator : public base::DiscardableMemoryAllocator { diff --git a/sky/shell/shell.h b/sky/shell/shell.h index ede37ae43..e4f7da9f9 100644 --- a/sky/shell/shell.h +++ b/sky/shell/shell.h @@ -7,7 +7,6 @@ #include "base/macros.h" #include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" #include "base/threading/thread.h" #include "sky/shell/tracing_controller.h" @@ -46,9 +45,9 @@ class Shell { void InitGPU(const base::Thread::Options& options); void InitUI(const base::Thread::Options& options); - scoped_ptr gpu_thread_; - scoped_ptr ui_thread_; - scoped_ptr io_thread_; + std::unique_ptr gpu_thread_; + std::unique_ptr ui_thread_; + std::unique_ptr io_thread_; scoped_refptr gpu_task_runner_; scoped_refptr ui_task_runner_; diff --git a/sky/shell/shell_view.cc b/sky/shell/shell_view.cc index 8674893fb..e190a8346 100644 --- a/sky/shell/shell_view.cc +++ b/sky/shell/shell_view.cc @@ -14,12 +14,6 @@ namespace sky { namespace shell { -namespace { - -template -void Drop(scoped_ptr ptr) { } - -} // namespace ShellView::ShellView(Shell& shell) : shell_(shell) { @@ -30,10 +24,8 @@ ShellView::ShellView(Shell& shell) ShellView::~ShellView() { view_ = nullptr; - shell_.gpu_task_runner()->PostTask(FROM_HERE, - base::Bind(&Drop, base::Passed(&rasterizer_))); - shell_.ui_task_runner()->PostTask(FROM_HERE, - base::Bind(&Drop, base::Passed(&engine_))); + shell_.gpu_task_runner()->DeleteSoon(FROM_HERE, rasterizer_.release()); + shell_.ui_task_runner()->DeleteSoon(FROM_HERE, engine_.release()); } void ShellView::CreateEngine() { diff --git a/sky/shell/shell_view.h b/sky/shell/shell_view.h index 5d2a47a84..712011281 100644 --- a/sky/shell/shell_view.h +++ b/sky/shell/shell_view.h @@ -5,9 +5,10 @@ #ifndef SKY_SHELL_SHELL_VIEW_H_ #define SKY_SHELL_SHELL_VIEW_H_ +#include + #include "base/files/file_path.h" #include "base/macros.h" -#include "base/memory/scoped_ptr.h" #include "mojo/public/cpp/system/data_pipe.h" namespace sky { @@ -29,9 +30,9 @@ class ShellView { void CreatePlatformView(); Shell& shell_; - scoped_ptr view_; - scoped_ptr rasterizer_; - scoped_ptr engine_; + std::unique_ptr view_; + std::unique_ptr rasterizer_; + std::unique_ptr engine_; DISALLOW_COPY_AND_ASSIGN(ShellView); }; diff --git a/sky/shell/testing/test_runner.h b/sky/shell/testing/test_runner.h index 4d0b71923..fbb27a6ce 100644 --- a/sky/shell/testing/test_runner.h +++ b/sky/shell/testing/test_runner.h @@ -5,6 +5,7 @@ #ifndef SKY_SHELL_TESTING_TEST_RUNNER_H_ #define SKY_SHELL_TESTING_TEST_RUNNER_H_ +#include #include #include "base/macros.h" @@ -32,7 +33,7 @@ class TestRunner { TestRunner(); ~TestRunner(); - scoped_ptr shell_view_; + std::unique_ptr shell_view_; SkyEnginePtr sky_engine_; base::WeakPtrFactory weak_ptr_factory_; diff --git a/sky/shell/ui/animator.cc b/sky/shell/ui/animator.cc index 357fda85f..3a2962ff2 100644 --- a/sky/shell/ui/animator.cc +++ b/sky/shell/ui/animator.cc @@ -83,14 +83,14 @@ void Animator::BeginFrame(int64_t time_stamp) { base::TimeTicks frame_time = time_stamp ? base::TimeTicks::FromInternalValue(time_stamp) : base::TimeTicks::Now(); - scoped_ptr layer_tree = - make_scoped_ptr(engine_->BeginFrame(frame_time).release()); + std::unique_ptr layer_tree = engine_->BeginFrame(frame_time); if (!layer_tree) { OnFrameComplete(); return; } + // TODO(abarth): Doesn't this leak if OnFrameComplete never runs? rasterizer_->Draw(reinterpret_cast(layer_tree.release()), base::Bind(&Animator::OnFrameComplete, weak_factory_.GetWeakPtr())); } diff --git a/sky/shell/ui/engine.h b/sky/shell/ui/engine.h index a3b809e93..de9c8342b 100644 --- a/sky/shell/ui/engine.h +++ b/sky/shell/ui/engine.h @@ -7,7 +7,6 @@ #include "base/files/file_path.h" #include "base/macros.h" -#include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/single_thread_task_runner.h" #include "mojo/public/cpp/bindings/binding.h" @@ -87,11 +86,11 @@ class Engine : public UIDelegate, void StartAnimatorIfPossible(); Config config_; - scoped_ptr animator_; + std::unique_ptr animator_; ServicesDataPtr services_; mojo::asset_bundle::AssetBundlePtr root_bundle_; - scoped_ptr dart_library_provider_; + std::unique_ptr dart_library_provider_; std::unique_ptr sky_view_; gfx::Size physical_size_;