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

Unified Diff: mojo/shell/ui_service_loader_android.cc

Issue 399663002: Have mojo_shell run in its custom thread on android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 5 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
« no previous file with comments | « mojo/shell/ui_service_loader_android.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/ui_service_loader_android.cc
diff --git a/mojo/shell/ui_service_loader_android.cc b/mojo/shell/ui_service_loader_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3960858c2f73ad165f980c1ebd6799c3e802d4ad
--- /dev/null
+++ b/mojo/shell/ui_service_loader_android.cc
@@ -0,0 +1,89 @@
+// 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/shell/ui_service_loader_android.h"
+
+#include "base/bind.h"
+#include "mojo/service_manager/service_manager.h"
+#include "mojo/shell/context.h"
+
+namespace mojo {
+
+class UIServiceLoader::UILoader {
+ public:
+ explicit UILoader(ServiceLoader* loader) : loader_(loader) {}
+ ~UILoader() {}
+
+ 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:
+ ServiceLoader* loader_; // Owned by UIServiceLoader
+
+ DISALLOW_COPY_AND_ASSIGN(UILoader);
+};
+
+UIServiceLoader::UIServiceLoader(scoped_ptr<ServiceLoader> real_loader,
+ shell::Context* context)
+ : loader_(real_loader.Pass()), context_(context) {
+}
+
+UIServiceLoader::~UIServiceLoader() {
+ context_->ui_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&UIServiceLoader::ShutdownOnUIThread, base::Unretained(this)));
+}
+
+void UIServiceLoader::LoadService(ServiceManager* manager,
+ const GURL& url,
+ ScopedMessagePipeHandle shell_handle) {
+ context_->ui_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &UIServiceLoader::LoadServiceOnUIThread,
+ base::Unretained(this),
+ manager,
+ url,
+ base::Owned(new ScopedMessagePipeHandle(shell_handle.Pass()))));
+}
+
+void UIServiceLoader::OnServiceError(ServiceManager* manager, const GURL& url) {
+ context_->ui_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&UIServiceLoader::OnServiceErrorOnUIThread,
+ base::Unretained(this),
+ manager,
+ url));
+}
+
+void UIServiceLoader::LoadServiceOnUIThread(
+ ServiceManager* manager,
+ const GURL& url,
+ ScopedMessagePipeHandle* shell_handle) {
+ if (!ui_loader_)
+ ui_loader_ = new UILoader(loader_.get());
+ ui_loader_->LoadService(manager, url, shell_handle->Pass());
+}
+
+void UIServiceLoader::OnServiceErrorOnUIThread(ServiceManager* manager,
+ const GURL& url) {
+ if (!ui_loader_)
+ ui_loader_ = new UILoader(loader_.get());
+ ui_loader_->OnServiceError(manager, url);
+}
+
+void UIServiceLoader::ShutdownOnUIThread() {
+ delete ui_loader_;
+ // Destroy |loader_| on the thread it's actually used on.
+ loader_.reset();
+}
+
+} // namespace mojo
« no previous file with comments | « mojo/shell/ui_service_loader_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698