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

Side by Side Diff: mojo/shell/ui_service_loader_android.cc

Issue 423963004: First cut at "content handling" support in Mojo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: blech 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/shell/ui_service_loader_android.h" 5 #include "mojo/shell/ui_service_loader_android.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "mojo/service_manager/service_manager.h" 8 #include "mojo/service_manager/service_manager.h"
9 #include "mojo/shell/context.h" 9 #include "mojo/shell/context.h"
10 10
11 namespace mojo { 11 namespace mojo {
12 12
13 class UIServiceLoader::UILoader { 13 class UIServiceLoader::UILoader {
14 public: 14 public:
15 explicit UILoader(ServiceLoader* loader) : loader_(loader) {} 15 explicit UILoader(ServiceLoader* loader) : loader_(loader) {}
16 ~UILoader() {} 16 ~UILoader() {}
17 17
18 void LoadService(ServiceManager* manager, 18 void LoadService(ServiceManager* manager,
19 const GURL& url, 19 const GURL& url,
20 ScopedMessagePipeHandle shell_handle) { 20 ScopedMessagePipeHandle shell_handle) {
21 loader_->LoadService(manager, url, shell_handle.Pass()); 21 scoped_refptr<LoadServiceCallbacks> callbacks(
22 new ServiceLoader::SimpleLoadServiceCallbacks(shell_handle.Pass()));
23 loader_->LoadService(manager, url, callbacks);
22 } 24 }
23 25
24 void OnServiceError(ServiceManager* manager, const GURL& url) { 26 void OnServiceError(ServiceManager* manager, const GURL& url) {
25 loader_->OnServiceError(manager, url); 27 loader_->OnServiceError(manager, url);
26 } 28 }
27 29
28 private: 30 private:
29 ServiceLoader* loader_; // Owned by UIServiceLoader 31 ServiceLoader* loader_; // Owned by UIServiceLoader
30 32
31 DISALLOW_COPY_AND_ASSIGN(UILoader); 33 DISALLOW_COPY_AND_ASSIGN(UILoader);
32 }; 34 };
33 35
34 UIServiceLoader::UIServiceLoader(scoped_ptr<ServiceLoader> real_loader, 36 UIServiceLoader::UIServiceLoader(scoped_ptr<ServiceLoader> real_loader,
35 shell::Context* context) 37 shell::Context* context)
36 : loader_(real_loader.Pass()), context_(context) { 38 : loader_(real_loader.Pass()), context_(context) {
37 } 39 }
38 40
39 UIServiceLoader::~UIServiceLoader() { 41 UIServiceLoader::~UIServiceLoader() {
40 context_->ui_loop()->PostTask( 42 context_->ui_loop()->PostTask(
41 FROM_HERE, 43 FROM_HERE,
42 base::Bind(&UIServiceLoader::ShutdownOnUIThread, base::Unretained(this))); 44 base::Bind(&UIServiceLoader::ShutdownOnUIThread, base::Unretained(this)));
43 } 45 }
44 46
45 void UIServiceLoader::LoadService(ServiceManager* manager, 47 void UIServiceLoader::LoadService(
46 const GURL& url, 48 ServiceManager* manager,
47 ScopedMessagePipeHandle shell_handle) { 49 const GURL& url,
50 scoped_refptr<LoadServiceCallbacks> callbacks) {
51 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication();
52 if (!shell_handle.is_valid())
53 return;
48 context_->ui_loop()->PostTask( 54 context_->ui_loop()->PostTask(
49 FROM_HERE, 55 FROM_HERE,
50 base::Bind( 56 base::Bind(
51 &UIServiceLoader::LoadServiceOnUIThread, 57 &UIServiceLoader::LoadServiceOnUIThread,
52 base::Unretained(this), 58 base::Unretained(this),
53 manager, 59 manager,
54 url, 60 url,
55 base::Owned(new ScopedMessagePipeHandle(shell_handle.Pass())))); 61 shell_handle.Pass()));
56 } 62 }
57 63
58 void UIServiceLoader::OnServiceError(ServiceManager* manager, const GURL& url) { 64 void UIServiceLoader::OnServiceError(ServiceManager* manager, const GURL& url) {
59 context_->ui_loop()->PostTask( 65 context_->ui_loop()->PostTask(
60 FROM_HERE, 66 FROM_HERE,
61 base::Bind(&UIServiceLoader::OnServiceErrorOnUIThread, 67 base::Bind(&UIServiceLoader::OnServiceErrorOnUIThread,
62 base::Unretained(this), 68 base::Unretained(this),
63 manager, 69 manager,
64 url)); 70 url));
65 } 71 }
66 72
67 void UIServiceLoader::LoadServiceOnUIThread( 73 void UIServiceLoader::LoadServiceOnUIThread(
68 ServiceManager* manager, 74 ServiceManager* manager,
69 const GURL& url, 75 const GURL& url,
70 ScopedMessagePipeHandle* shell_handle) { 76 ScopedMessagePipeHandle shell_handle) {
71 if (!ui_loader_) 77 if (!ui_loader_)
72 ui_loader_ = new UILoader(loader_.get()); 78 ui_loader_ = new UILoader(loader_.get());
73 ui_loader_->LoadService(manager, url, shell_handle->Pass()); 79 ui_loader_->LoadService(manager, url, shell_handle.Pass());
74 } 80 }
75 81
76 void UIServiceLoader::OnServiceErrorOnUIThread(ServiceManager* manager, 82 void UIServiceLoader::OnServiceErrorOnUIThread(ServiceManager* manager,
77 const GURL& url) { 83 const GURL& url) {
78 if (!ui_loader_) 84 if (!ui_loader_)
79 ui_loader_ = new UILoader(loader_.get()); 85 ui_loader_ = new UILoader(loader_.get());
80 ui_loader_->OnServiceError(manager, url); 86 ui_loader_->OnServiceError(manager, url);
81 } 87 }
82 88
83 void UIServiceLoader::ShutdownOnUIThread() { 89 void UIServiceLoader::ShutdownOnUIThread() {
84 delete ui_loader_; 90 delete ui_loader_;
85 // Destroy |loader_| on the thread it's actually used on. 91 // Destroy |loader_| on the thread it's actually used on.
86 loader_.reset(); 92 loader_.reset();
87 } 93 }
88 94
89 } // namespace mojo 95 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698