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

Side by Side Diff: shell/android/background_application_loader.cc

Issue 868463008: Remove Client relationship between mojo.Shell/mojo.Application (Closed) Base URL: git@github.com:domokit/mojo.git@app_impl_init
Patch Set: fix android Created 5 years, 10 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
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 "shell/android/background_application_loader.h" 5 #include "shell/android/background_application_loader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "shell/application_manager/application_manager.h" 9 #include "shell/application_manager/application_manager.h"
10 10
11 namespace mojo { 11 namespace mojo {
12 12
13 BackgroundApplicationLoader::BackgroundApplicationLoader( 13 BackgroundApplicationLoader::BackgroundApplicationLoader(
14 scoped_ptr<ApplicationLoader> real_loader, 14 scoped_ptr<ApplicationLoader> real_loader,
15 const std::string& thread_name, 15 const std::string& thread_name,
16 base::MessageLoop::Type message_loop_type) 16 base::MessageLoop::Type message_loop_type)
17 : loader_(real_loader.Pass()), 17 : loader_(real_loader.Pass()),
18 message_loop_type_(message_loop_type), 18 message_loop_type_(message_loop_type),
19 thread_name_(thread_name), 19 thread_name_(thread_name),
20 message_loop_created_(true, false) { 20 message_loop_created_(true, false) {
21 } 21 }
22 22
23 BackgroundApplicationLoader::~BackgroundApplicationLoader() { 23 BackgroundApplicationLoader::~BackgroundApplicationLoader() {
24 if (thread_) 24 if (thread_)
25 thread_->Join(); 25 thread_->Join();
26 } 26 }
27 27
28 void BackgroundApplicationLoader::Load(ApplicationManager* manager, 28 void BackgroundApplicationLoader::Load(
29 const GURL& url, 29 ApplicationManager* manager,
30 ShellPtr shell, 30 const GURL& url,
31 LoadCallback callback) { 31 InterfaceRequest<Application> application_request,
32 DCHECK(shell); 32 LoadCallback callback) {
33 DCHECK(application_request.is_pending());
33 if (!thread_) { 34 if (!thread_) {
34 // TODO(tim): It'd be nice if we could just have each Load call 35 // TODO(tim): It'd be nice if we could just have each Load call
35 // result in a new thread like DynamicService{Loader, Runner}. But some 36 // result in a new thread like DynamicService{Loader, Runner}. But some
36 // loaders are creating multiple ApplicationImpls (NetworkApplicationLoader) 37 // loaders are creating multiple ApplicationImpls (NetworkApplicationLoader)
37 // sharing a delegate (etc). So we have to keep it single threaded, wait 38 // sharing a delegate (etc). So we have to keep it single threaded, wait
38 // for the thread to initialize, and post to the TaskRunner for subsequent 39 // for the thread to initialize, and post to the TaskRunner for subsequent
39 // Load calls for now. 40 // Load calls for now.
40 thread_.reset(new base::DelegateSimpleThread(this, thread_name_)); 41 thread_.reset(new base::DelegateSimpleThread(this, thread_name_));
41 thread_->Start(); 42 thread_->Start();
42 message_loop_created_.Wait(); 43 message_loop_created_.Wait();
43 DCHECK(task_runner_.get()); 44 DCHECK(task_runner_.get());
44 } 45 }
45 46
46 task_runner_->PostTask( 47 task_runner_->PostTask(
47 FROM_HERE, 48 FROM_HERE,
48 base::Bind(&BackgroundApplicationLoader::LoadOnBackgroundThread, 49 base::Bind(&BackgroundApplicationLoader::LoadOnBackgroundThread,
49 base::Unretained(this), manager, url, base::Passed(&shell))); 50 base::Unretained(this), manager, url,
51 base::Passed(&application_request)));
50 } 52 }
51 53
52 void BackgroundApplicationLoader::OnApplicationError( 54 void BackgroundApplicationLoader::OnApplicationError(
53 ApplicationManager* manager, 55 ApplicationManager* manager,
54 const GURL& url) { 56 const GURL& url) {
55 task_runner_->PostTask( 57 task_runner_->PostTask(
56 FROM_HERE, 58 FROM_HERE,
57 base::Bind( 59 base::Bind(
58 &BackgroundApplicationLoader::OnApplicationErrorOnBackgroundThread, 60 &BackgroundApplicationLoader::OnApplicationErrorOnBackgroundThread,
59 base::Unretained(this), manager, url)); 61 base::Unretained(this), manager, url));
60 } 62 }
61 63
62 void BackgroundApplicationLoader::Run() { 64 void BackgroundApplicationLoader::Run() {
63 base::MessageLoop message_loop(message_loop_type_); 65 base::MessageLoop message_loop(message_loop_type_);
64 base::RunLoop loop; 66 base::RunLoop loop;
65 task_runner_ = message_loop.task_runner(); 67 task_runner_ = message_loop.task_runner();
66 quit_closure_ = loop.QuitClosure(); 68 quit_closure_ = loop.QuitClosure();
67 message_loop_created_.Signal(); 69 message_loop_created_.Signal();
68 loop.Run(); 70 loop.Run();
69 71
70 // Destroy |loader_| on the thread it's actually used on. 72 // Destroy |loader_| on the thread it's actually used on.
71 loader_.reset(); 73 loader_.reset();
72 } 74 }
73 75
74 void BackgroundApplicationLoader::LoadOnBackgroundThread( 76 void BackgroundApplicationLoader::LoadOnBackgroundThread(
75 ApplicationManager* manager, 77 ApplicationManager* manager,
76 const GURL& url, 78 const GURL& url,
77 ShellPtr shell) { 79 InterfaceRequest<Application> application_request) {
78 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 80 DCHECK(task_runner_->RunsTasksOnCurrentThread());
79 loader_->Load(manager, url, shell.Pass(), SimpleLoadCallback()); 81 loader_->Load(manager, url, application_request.Pass(), SimpleLoadCallback());
80 } 82 }
81 83
82 void BackgroundApplicationLoader::OnApplicationErrorOnBackgroundThread( 84 void BackgroundApplicationLoader::OnApplicationErrorOnBackgroundThread(
83 ApplicationManager* manager, 85 ApplicationManager* manager,
84 const GURL& url) { 86 const GURL& url) {
85 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 87 DCHECK(task_runner_->RunsTasksOnCurrentThread());
86 loader_->OnApplicationError(manager, url); 88 loader_->OnApplicationError(manager, url);
87 } 89 }
88 90
89 } // namespace mojo 91 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698