OLD | NEW |
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/standalone/android/background_application_loader.h" | 5 #include "mojo/shell/standalone/android/background_application_loader.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 thread_name_(thread_name), | 22 thread_name_(thread_name), |
23 message_loop_created_(true, false) {} | 23 message_loop_created_(true, false) {} |
24 | 24 |
25 BackgroundApplicationLoader::~BackgroundApplicationLoader() { | 25 BackgroundApplicationLoader::~BackgroundApplicationLoader() { |
26 if (thread_) | 26 if (thread_) |
27 thread_->Join(); | 27 thread_->Join(); |
28 } | 28 } |
29 | 29 |
30 void BackgroundApplicationLoader::Load( | 30 void BackgroundApplicationLoader::Load( |
31 const GURL& url, | 31 const GURL& url, |
32 InterfaceRequest<mojom::Application> application_request) { | 32 InterfaceRequest<mojom::ShellClient> request) { |
33 DCHECK(application_request.is_pending()); | 33 DCHECK(request.is_pending()); |
34 if (!thread_) { | 34 if (!thread_) { |
35 // 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 |
36 // result in a new thread like DynamicService{Loader, Runner}. But some | 36 // result in a new thread like DynamicService{Loader, Runner}. But some |
37 // loaders are creating multiple ApplicationImpls (NetworkApplicationLoader) | 37 // loaders are creating multiple ShellConnections (NetworkApplicationLoader) |
38 // 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 |
39 // 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 |
40 // Load calls for now. | 40 // Load calls for now. |
41 thread_.reset(new base::DelegateSimpleThread(this, thread_name_)); | 41 thread_.reset(new base::DelegateSimpleThread(this, thread_name_)); |
42 thread_->Start(); | 42 thread_->Start(); |
43 message_loop_created_.Wait(); | 43 message_loop_created_.Wait(); |
44 DCHECK(task_runner_.get()); | 44 DCHECK(task_runner_.get()); |
45 } | 45 } |
46 | 46 |
47 task_runner_->PostTask( | 47 task_runner_->PostTask( |
48 FROM_HERE, | 48 FROM_HERE, |
49 base::Bind(&BackgroundApplicationLoader::LoadOnBackgroundThread, | 49 base::Bind(&BackgroundApplicationLoader::LoadOnBackgroundThread, |
50 base::Unretained(this), url, | 50 base::Unretained(this), url, base::Passed(&request))); |
51 base::Passed(&application_request))); | |
52 } | 51 } |
53 | 52 |
54 void BackgroundApplicationLoader::Run() { | 53 void BackgroundApplicationLoader::Run() { |
55 base::MessageLoop message_loop(message_loop_type_); | 54 base::MessageLoop message_loop(message_loop_type_); |
56 base::RunLoop loop; | 55 base::RunLoop loop; |
57 task_runner_ = message_loop.task_runner(); | 56 task_runner_ = message_loop.task_runner(); |
58 quit_closure_ = loop.QuitClosure(); | 57 quit_closure_ = loop.QuitClosure(); |
59 message_loop_created_.Signal(); | 58 message_loop_created_.Signal(); |
60 loop.Run(); | 59 loop.Run(); |
61 | 60 |
62 // Destroy |loader_| on the thread it's actually used on. | 61 // Destroy |loader_| on the thread it's actually used on. |
63 loader_.reset(); | 62 loader_.reset(); |
64 } | 63 } |
65 | 64 |
66 void BackgroundApplicationLoader::LoadOnBackgroundThread( | 65 void BackgroundApplicationLoader::LoadOnBackgroundThread( |
67 const GURL& url, | 66 const GURL& url, |
68 InterfaceRequest<mojom::Application> application_request) { | 67 InterfaceRequest<mojom::ShellClient> request) { |
69 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 68 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
70 loader_->Load(url, std::move(application_request)); | 69 loader_->Load(url, std::move(request)); |
71 } | 70 } |
72 | 71 |
73 } // namespace shell | 72 } // namespace shell |
74 } // namespace mojo | 73 } // namespace mojo |
OLD | NEW |