diff options
author | ben <ben@chromium.org> | 2015-08-10 12:35:52 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-10 19:36:45 +0000 |
commit | c688d2ebd66cb1fc7d85c478d3858329fbc194b3 (patch) | |
tree | 648e1c33a791d971cd76cfdc595aee6e603682fe | |
parent | 4e9da313512a86d4ace1c211eaf4dc5da6d6f307 (diff) | |
download | chromium_src-c688d2ebd66cb1fc7d85c478d3858329fbc194b3.zip chromium_src-c688d2ebd66cb1fc7d85c478d3858329fbc194b3.tar.gz chromium_src-c688d2ebd66cb1fc7d85c478d3858329fbc194b3.tar.bz2 |
ApplicationImpl cleanup, part 1:
- Remove ctor that does not take a termination closure.
- Terminate()->Quit()
- QuitNow()->private
R=jam@chromium.org
BUG=none
Committed: https://crrev.com/46e34f6bc1c8424c383776e5961094c5df5d563b
Cr-Commit-Position: refs/heads/master@{#341028}
Review URL: https://codereview.chromium.org/1266643003
Cr-Commit-Position: refs/heads/master@{#342676}
-rw-r--r-- | components/filesystem/file_system_app.cc | 2 | ||||
-rw-r--r-- | components/html_viewer/global_state.cc | 2 | ||||
-rw-r--r-- | components/pdf_viewer/pdf_viewer.cc | 2 | ||||
-rw-r--r-- | components/view_manager/view_manager_app.cc | 2 | ||||
-rw-r--r-- | content/public/test/test_mojo_app.cc | 2 | ||||
-rw-r--r-- | device/devices_app/devices_app.cc | 2 | ||||
-rw-r--r-- | mandoline/ui/browser/browser_manager.cc | 2 | ||||
-rw-r--r-- | mojo/application/public/cpp/app_lifetime_helper.h | 2 | ||||
-rw-r--r-- | mojo/application/public/cpp/application_impl.h | 18 | ||||
-rw-r--r-- | mojo/application/public/cpp/lib/app_lifetime_helper.cc | 4 | ||||
-rw-r--r-- | mojo/application/public/cpp/lib/application_impl.cc | 42 |
11 files changed, 41 insertions, 39 deletions
diff --git a/components/filesystem/file_system_app.cc b/components/filesystem/file_system_app.cc index c1e3e16..c42b606 100644 --- a/components/filesystem/file_system_app.cc +++ b/components/filesystem/file_system_app.cc @@ -67,7 +67,7 @@ void FileSystemApp::OnDirectoryConnectionError(DirectoryImpl* directory) { if (in_shutdown_ && client_mapping_.empty()) { // We just cleared the last directory after our shell connection went // away. Time to shut ourselves down. - app_->QuitNow(); + app_->Quit(); } return; diff --git a/components/html_viewer/global_state.cc b/components/html_viewer/global_state.cc index 870c4e7..b91ab73 100644 --- a/components/html_viewer/global_state.cc +++ b/components/html_viewer/global_state.cc @@ -93,7 +93,7 @@ void GlobalState::InitIfNecessary(const gfx::Size& screen_size_in_pixels, if (!resource_loader_.BlockUntilLoaded()) { // Assume on error we're being shut down. - app_->Terminate(); + app_->Quit(); return; } diff --git a/components/pdf_viewer/pdf_viewer.cc b/components/pdf_viewer/pdf_viewer.cc index ad72eb0..f9ba728 100644 --- a/components/pdf_viewer/pdf_viewer.cc +++ b/components/pdf_viewer/pdf_viewer.cc @@ -432,7 +432,7 @@ class PDFView : public mojo::ApplicationDelegate, delete it->second; embedder_for_roots_.erase(it); if (embedder_for_roots_.size() == 0) - app_.Terminate(); + app_.Quit(); } void DrawBitmap(EmbedderData* embedder_data) { diff --git a/components/view_manager/view_manager_app.cc b/components/view_manager/view_manager_app.cc index 4b092ad..5c5e77a 100644 --- a/components/view_manager/view_manager_app.cc +++ b/components/view_manager/view_manager_app.cc @@ -68,7 +68,7 @@ bool ViewManagerApp::ConfigureIncomingConnection( } void ViewManagerApp::OnNoMoreRootConnections() { - app_impl_->Terminate(); + app_impl_->Quit(); } ClientConnection* ViewManagerApp::CreateClientConnectionForEmbedAtView( diff --git a/content/public/test/test_mojo_app.cc b/content/public/test/test_mojo_app.cc index f4fe676..13cb9af 100644 --- a/content/public/test/test_mojo_app.cc +++ b/content/public/test/test_mojo_app.cc @@ -38,7 +38,7 @@ void TestMojoApp::Create(mojo::ApplicationConnection* connection, void TestMojoApp::DoSomething(const DoSomethingCallback& callback) { callback.Run(); DCHECK(app_); - app_->Terminate(); + app_->Quit(); } void TestMojoApp::GetRequestorURL(const GetRequestorURLCallback& callback) { diff --git a/device/devices_app/devices_app.cc b/device/devices_app/devices_app.cc index 1f49170..4501f75 100644 --- a/device/devices_app/devices_app.cc +++ b/device/devices_app/devices_app.cc @@ -156,7 +156,7 @@ void DevicesApp::StartIdleTimer() { // Passing unretained |app_impl_| is safe here because |app_impl_| is // guaranteed to outlive |this|, and the callback is canceled if |this| is // destroyed. - idle_timeout_callback_.Reset(base::Bind(&mojo::ApplicationImpl::Terminate, + idle_timeout_callback_.Reset(base::Bind(&mojo::ApplicationImpl::Quit, base::Unretained(app_impl_))); base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( FROM_HERE, idle_timeout_callback_.callback(), diff --git a/mandoline/ui/browser/browser_manager.cc b/mandoline/ui/browser/browser_manager.cc index 527e265..a4f9c63 100644 --- a/mandoline/ui/browser/browser_manager.cc +++ b/mandoline/ui/browser/browser_manager.cc @@ -67,7 +67,7 @@ void BrowserManager::BrowserClosed(Browser* browser) { DCHECK_GT(browsers_.count(browser), 0u); browsers_.erase(browser); if (browsers_.empty()) - app_->Terminate(); + app_->Quit(); } void BrowserManager::InitUIIfNecessary(Browser* browser, mojo::View* view) { diff --git a/mojo/application/public/cpp/app_lifetime_helper.h b/mojo/application/public/cpp/app_lifetime_helper.h index 93005ef..4322722 100644 --- a/mojo/application/public/cpp/app_lifetime_helper.h +++ b/mojo/application/public/cpp/app_lifetime_helper.h @@ -68,7 +68,7 @@ class AppLifetimeHelper { void Release(); friend ApplicationImpl; - void ApplicationTerminated(); + void OnQuit(); ApplicationImpl* app_; int ref_count_; diff --git a/mojo/application/public/cpp/application_impl.h b/mojo/application/public/cpp/application_impl.h index 9c04013..5d2eb45 100644 --- a/mojo/application/public/cpp/application_impl.h +++ b/mojo/application/public/cpp/application_impl.h @@ -19,6 +19,7 @@ namespace mojo { +// TODO(beng): This comment is hilariously out of date. // Utility class for communicating with the Shell, and providing Services // to clients. // @@ -59,8 +60,8 @@ class ApplicationImpl : public Application { ApplicationImpl(ApplicationDelegate* delegate, InterfaceRequest<Application> request); // Constructs an ApplicationImpl with a custom termination closure. This - // closure is invoked on Terminate() instead of the default behavior of - // quitting the current MessageLoop. + // closure is invoked on Quit() instead of the default behavior of quitting + // the current base::MessageLoop. ApplicationImpl(ApplicationDelegate* delegate, InterfaceRequest<Application> request, const Closure& termination_closure); @@ -113,12 +114,9 @@ class ApplicationImpl : public Application { void UnbindConnections(InterfaceRequest<Application>* application_request, ShellPtr* shell); - // Quits the main run loop for this application. It first checks with the - // shell to ensure there are no outstanding service requests. - void Terminate(); - - // Quits without waiting to check with the shell. - void QuitNow(); + // Initiate shutdown of this application. This may involve a round trip to the + // Shell to ensure there are no inbound service requests. + void Quit(); private: // Application implementation. @@ -133,6 +131,10 @@ class ApplicationImpl : public Application { void ClearConnections(); + // Called from Quit() when there is no Shell connection, or asynchronously + // from Quit() once the Shell has OK'ed shutdown. + void QuitNow(); + typedef std::vector<internal::ServiceRegistry*> ServiceRegistryList; ServiceRegistryList incoming_service_registries_; diff --git a/mojo/application/public/cpp/lib/app_lifetime_helper.cc b/mojo/application/public/cpp/lib/app_lifetime_helper.cc index 4d12339..74c7ee8 100644 --- a/mojo/application/public/cpp/lib/app_lifetime_helper.cc +++ b/mojo/application/public/cpp/lib/app_lifetime_helper.cc @@ -83,11 +83,11 @@ void AppLifetimeHelper::AddRef() { void AppLifetimeHelper::Release() { if (!--ref_count_) { if (app_) - app_->Terminate(); + app_->Quit(); } } -void AppLifetimeHelper::ApplicationTerminated() { +void AppLifetimeHelper::OnQuit() { app_ = nullptr; } diff --git a/mojo/application/public/cpp/lib/application_impl.cc b/mojo/application/public/cpp/lib/application_impl.cc index edfeed2..f24429b 100644 --- a/mojo/application/public/cpp/lib/application_impl.cc +++ b/mojo/application/public/cpp/lib/application_impl.cc @@ -55,25 +55,11 @@ ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, in_destructor_(false), weak_factory_(this) {} -void ApplicationImpl::ClearConnections() { - // Copy the ServiceRegistryLists because they will be mutated by - // ApplicationConnection::CloseConnection. - ServiceRegistryList incoming_service_registries(incoming_service_registries_); - for (internal::ServiceRegistry* registry : incoming_service_registries) - registry->CloseConnection(); - DCHECK(incoming_service_registries_.empty()); - - ServiceRegistryList outgoing_service_registries(outgoing_service_registries_); - for (internal::ServiceRegistry* registry : outgoing_service_registries) - registry->CloseConnection(); - DCHECK(outgoing_service_registries_.empty()); -} - ApplicationImpl::~ApplicationImpl() { DCHECK(!in_destructor_); in_destructor_ = true; ClearConnections(); - app_lifetime_helper_.ApplicationTerminated(); + app_lifetime_helper_.OnQuit(); } ApplicationConnection* ApplicationImpl::ConnectToApplication( @@ -140,7 +126,7 @@ void ApplicationImpl::UnbindConnections( shell->Bind(shell_.PassInterface()); } -void ApplicationImpl::Terminate() { +void ApplicationImpl::Quit() { // We can't quit immediately, since there could be in-flight requests from the // shell. So check with it first. if (shell_) { @@ -151,11 +137,6 @@ void ApplicationImpl::Terminate() { } } -void ApplicationImpl::QuitNow() { - delegate_->Quit(); - termination_closure_.Run(); -} - void ApplicationImpl::AcceptConnection( const String& requestor_url, InterfaceRequest<ServiceProvider> services, @@ -201,4 +182,23 @@ void ApplicationImpl::OnConnectionError() { shell_ = nullptr; } +void ApplicationImpl::ClearConnections() { + // Copy the ServiceRegistryLists because they will be mutated by + // ApplicationConnection::CloseConnection. + ServiceRegistryList incoming_service_registries(incoming_service_registries_); + for (internal::ServiceRegistry* registry : incoming_service_registries) + registry->CloseConnection(); + DCHECK(incoming_service_registries_.empty()); + + ServiceRegistryList outgoing_service_registries(outgoing_service_registries_); + for (internal::ServiceRegistry* registry : outgoing_service_registries) + registry->CloseConnection(); + DCHECK(outgoing_service_registries_.empty()); +} + +void ApplicationImpl::QuitNow() { + delegate_->Quit(); + termination_closure_.Run(); +} + } // namespace mojo |