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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/shell/ui_service_loader_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/shell/ui_service_loader_android.h"
6
7 #include "base/bind.h"
8 #include "mojo/service_manager/service_manager.h"
9 #include "mojo/shell/context.h"
10
11 namespace mojo {
12
13 class UIServiceLoader::UILoader {
14 public:
15 explicit UILoader(ServiceLoader* loader) : loader_(loader) {}
16 ~UILoader() {}
17
18 void LoadService(ServiceManager* manager,
19 const GURL& url,
20 ScopedMessagePipeHandle shell_handle) {
21 loader_->LoadService(manager, url, shell_handle.Pass());
22 }
23
24 void OnServiceError(ServiceManager* manager, const GURL& url) {
25 loader_->OnServiceError(manager, url);
26 }
27
28 private:
29 ServiceLoader* loader_; // Owned by UIServiceLoader
30
31 DISALLOW_COPY_AND_ASSIGN(UILoader);
32 };
33
34 UIServiceLoader::UIServiceLoader(scoped_ptr<ServiceLoader> real_loader,
35 shell::Context* context)
36 : loader_(real_loader.Pass()), context_(context) {
37 }
38
39 UIServiceLoader::~UIServiceLoader() {
40 context_->ui_loop()->PostTask(
41 FROM_HERE,
42 base::Bind(&UIServiceLoader::ShutdownOnUIThread, base::Unretained(this)));
43 }
44
45 void UIServiceLoader::LoadService(ServiceManager* manager,
46 const GURL& url,
47 ScopedMessagePipeHandle shell_handle) {
48 context_->ui_loop()->PostTask(
49 FROM_HERE,
50 base::Bind(
51 &UIServiceLoader::LoadServiceOnUIThread,
52 base::Unretained(this),
53 manager,
54 url,
55 base::Owned(new ScopedMessagePipeHandle(shell_handle.Pass()))));
56 }
57
58 void UIServiceLoader::OnServiceError(ServiceManager* manager, const GURL& url) {
59 context_->ui_loop()->PostTask(
60 FROM_HERE,
61 base::Bind(&UIServiceLoader::OnServiceErrorOnUIThread,
62 base::Unretained(this),
63 manager,
64 url));
65 }
66
67 void UIServiceLoader::LoadServiceOnUIThread(
68 ServiceManager* manager,
69 const GURL& url,
70 ScopedMessagePipeHandle* shell_handle) {
71 if (!ui_loader_)
72 ui_loader_ = new UILoader(loader_.get());
73 ui_loader_->LoadService(manager, url, shell_handle->Pass());
74 }
75
76 void UIServiceLoader::OnServiceErrorOnUIThread(ServiceManager* manager,
77 const GURL& url) {
78 if (!ui_loader_)
79 ui_loader_ = new UILoader(loader_.get());
80 ui_loader_->OnServiceError(manager, url);
81 }
82
83 void UIServiceLoader::ShutdownOnUIThread() {
84 delete ui_loader_;
85 // Destroy |loader_| on the thread it's actually used on.
86 loader_.reset();
87 }
88
89 } // namespace mojo
OLDNEW
« 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