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

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

Issue 741453002: Make sure that Content Handled application can be connected multiple times. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fix sky Created 6 years, 1 month 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
« no previous file with comments | « mojo/shell/ui_application_loader_android.h ('k') | mojo/shell/view_manager_loader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_application_loader_android.h" 5 #include "mojo/shell/ui_application_loader_android.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "mojo/application_manager/application_manager.h" 8 #include "mojo/application_manager/application_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 UIApplicationLoader::UILoader {
14 public:
15 explicit UILoader(ApplicationLoader* loader) : loader_(loader) {}
16 ~UILoader() {}
17
18 void Load(ApplicationManager* manager,
19 const GURL& url,
20 ScopedMessagePipeHandle shell_handle) {
21 scoped_refptr<LoadCallbacks> callbacks(
22 new ApplicationLoader::SimpleLoadCallbacks(shell_handle.Pass()));
23 loader_->Load(manager, url, callbacks);
24 }
25
26 void OnApplicationError(ApplicationManager* manager, const GURL& url) {
27 loader_->OnApplicationError(manager, url);
28 }
29
30 private:
31 ApplicationLoader* loader_; // Owned by UIApplicationLoader
32
33 DISALLOW_COPY_AND_ASSIGN(UILoader);
34 };
35
36 UIApplicationLoader::UIApplicationLoader( 13 UIApplicationLoader::UIApplicationLoader(
37 scoped_ptr<ApplicationLoader> real_loader, 14 scoped_ptr<ApplicationLoader> real_loader,
38 shell::Context* context) 15 shell::Context* context)
39 : loader_(real_loader.Pass()), context_(context) { 16 : loader_(real_loader.Pass()), context_(context) {
40 } 17 }
41 18
42 UIApplicationLoader::~UIApplicationLoader() { 19 UIApplicationLoader::~UIApplicationLoader() {
43 context_->ui_loop()->PostTask( 20 context_->ui_loop()->PostTask(
44 FROM_HERE, 21 FROM_HERE,
45 base::Bind(&UIApplicationLoader::ShutdownOnUIThread, 22 base::Bind(&UIApplicationLoader::ShutdownOnUIThread,
46 base::Unretained(this))); 23 base::Unretained(this)));
47 } 24 }
48 25
49 void UIApplicationLoader::Load(ApplicationManager* manager, 26 void UIApplicationLoader::Load(ApplicationManager* manager,
50 const GURL& url, 27 const GURL& url,
51 scoped_refptr<LoadCallbacks> callbacks) { 28 ScopedMessagePipeHandle shell_handle,
52 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); 29 LoadCallback callback) {
53 if (!shell_handle.is_valid()) 30 DCHECK(shell_handle.is_valid());
54 return;
55 context_->ui_loop()->PostTask( 31 context_->ui_loop()->PostTask(
56 FROM_HERE, 32 FROM_HERE,
57 base::Bind( 33 base::Bind(&UIApplicationLoader::LoadOnUIThread, base::Unretained(this),
58 &UIApplicationLoader::LoadOnUIThread, 34 manager, url, base::Passed(&shell_handle)));
59 base::Unretained(this),
60 manager,
61 url,
62 base::Owned(new ScopedMessagePipeHandle(shell_handle.Pass()))));
63 } 35 }
64 36
65 void UIApplicationLoader::OnApplicationError(ApplicationManager* manager, 37 void UIApplicationLoader::OnApplicationError(ApplicationManager* manager,
66 const GURL& url) { 38 const GURL& url) {
67 context_->ui_loop()->PostTask( 39 context_->ui_loop()->PostTask(
68 FROM_HERE, 40 FROM_HERE,
69 base::Bind(&UIApplicationLoader::OnApplicationErrorOnUIThread, 41 base::Bind(&UIApplicationLoader::OnApplicationErrorOnUIThread,
70 base::Unretained(this), 42 base::Unretained(this),
71 manager, 43 manager,
72 url)); 44 url));
73 } 45 }
74 46
75 void UIApplicationLoader::LoadOnUIThread( 47 void UIApplicationLoader::LoadOnUIThread(ApplicationManager* manager,
76 ApplicationManager* manager, 48 const GURL& url,
77 const GURL& url, 49 ScopedMessagePipeHandle shell_handle) {
78 ScopedMessagePipeHandle* shell_handle) { 50 loader_->Load(manager, url, shell_handle.Pass(), SimpleLoadCallback());
79 if (!ui_loader_)
80 ui_loader_ = new UILoader(loader_.get());
81 ui_loader_->Load(manager, url, shell_handle->Pass());
82 } 51 }
83 52
84 void UIApplicationLoader::OnApplicationErrorOnUIThread( 53 void UIApplicationLoader::OnApplicationErrorOnUIThread(
85 ApplicationManager* manager, 54 ApplicationManager* manager,
86 const GURL& url) { 55 const GURL& url) {
87 if (!ui_loader_) 56 loader_->OnApplicationError(manager, url);
88 ui_loader_ = new UILoader(loader_.get());
89 ui_loader_->OnApplicationError(manager, url);
90 } 57 }
91 58
92 void UIApplicationLoader::ShutdownOnUIThread() { 59 void UIApplicationLoader::ShutdownOnUIThread() {
93 delete ui_loader_;
94 // Destroy |loader_| on the thread it's actually used on. 60 // Destroy |loader_| on the thread it's actually used on.
95 loader_.reset(); 61 loader_.reset();
96 } 62 }
97 63
98 } // namespace mojo 64 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/ui_application_loader_android.h ('k') | mojo/shell/view_manager_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698