Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Unified Diff: mojo/service_manager/background_service_loader.cc

Issue 437493002: mojo: allow BackgroundServiceLoader-loaded apps to Quit themselves. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/service_manager/background_service_loader.cc
diff --git a/mojo/service_manager/background_service_loader.cc b/mojo/service_manager/background_service_loader.cc
deleted file mode 100644
index 8c60a2cc00696df313e989933dcf63d6875d480f..0000000000000000000000000000000000000000
--- a/mojo/service_manager/background_service_loader.cc
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/service_manager/background_service_loader.h"
-
-#include "base/bind.h"
-#include "mojo/service_manager/service_manager.h"
-
-namespace mojo {
-
-class BackgroundServiceLoader::BackgroundLoader {
- public:
- explicit BackgroundLoader(ServiceLoader* loader) : loader_(loader) {}
- ~BackgroundLoader() {}
-
- void LoadService(ServiceManager* manager,
- const GURL& url,
- ScopedMessagePipeHandle shell_handle) {
- loader_->LoadService(manager, url, shell_handle.Pass());
- }
-
- void OnServiceError(ServiceManager* manager, const GURL& url) {
- loader_->OnServiceError(manager, url);
- }
-
- private:
- base::MessageLoop::Type message_loop_type_;
- ServiceLoader* loader_; // Owned by BackgroundServiceLoader
-
- DISALLOW_COPY_AND_ASSIGN(BackgroundLoader);
-};
-
-BackgroundServiceLoader::BackgroundServiceLoader(
- scoped_ptr<ServiceLoader> real_loader,
- const char* thread_name,
- base::MessageLoop::Type message_loop_type)
- : loader_(real_loader.Pass()),
- thread_(thread_name),
- message_loop_type_(message_loop_type),
- background_loader_(NULL) {
-}
-
-BackgroundServiceLoader::~BackgroundServiceLoader() {
- if (thread_.IsRunning()) {
- thread_.message_loop()->PostTask(
- FROM_HERE,
- base::Bind(&BackgroundServiceLoader::ShutdownOnBackgroundThread,
- base::Unretained(this)));
- }
- thread_.Stop();
-}
-
-void BackgroundServiceLoader::LoadService(
- ServiceManager* manager,
- const GURL& url,
- ScopedMessagePipeHandle shell_handle) {
- const int kDefaultStackSize = 0;
- if (!thread_.IsRunning()) {
- thread_.StartWithOptions(
- base::Thread::Options(message_loop_type_, kDefaultStackSize));
- }
- thread_.message_loop()->PostTask(
- FROM_HERE,
- base::Bind(&BackgroundServiceLoader::LoadServiceOnBackgroundThread,
- base::Unretained(this), manager, url,
- base::Owned(
- new ScopedMessagePipeHandle(shell_handle.Pass()))));
-}
-
-void BackgroundServiceLoader::OnServiceError(ServiceManager* manager,
- const GURL& url) {
- if (!thread_.IsRunning())
- thread_.Start();
- thread_.message_loop()->PostTask(
- FROM_HERE,
- base::Bind(&BackgroundServiceLoader::OnServiceErrorOnBackgroundThread,
- base::Unretained(this), manager, url));
-}
-
-void BackgroundServiceLoader::LoadServiceOnBackgroundThread(
- ServiceManager* manager,
- const GURL& url,
- ScopedMessagePipeHandle* shell_handle) {
- if (!background_loader_)
- background_loader_ = new BackgroundLoader(loader_.get());
- background_loader_->LoadService(
- manager, url, shell_handle->Pass());
-}
-
-void BackgroundServiceLoader::OnServiceErrorOnBackgroundThread(
- ServiceManager* manager,
- const GURL& url) {
- if (!background_loader_)
- background_loader_ = new BackgroundLoader(loader_.get());
- background_loader_->OnServiceError(manager, url);
-}
-
-void BackgroundServiceLoader::ShutdownOnBackgroundThread() {
- delete background_loader_;
- // Destroy |loader_| on the thread it's actually used on.
- loader_.reset();
-}
-
-} // namespace mojo
« no previous file with comments | « mojo/service_manager/background_service_loader.h ('k') | mojo/service_manager/background_shell_service_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698