| 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 "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 { | |
| 12 namespace shell { | 11 namespace shell { |
| 13 | 12 |
| 14 BackgroundApplicationLoader::BackgroundApplicationLoader( | 13 BackgroundApplicationLoader::BackgroundApplicationLoader( |
| 15 scoped_ptr<ApplicationLoader> real_loader, | 14 scoped_ptr<ApplicationLoader> real_loader, |
| 16 const std::string& thread_name, | 15 const std::string& thread_name, |
| 17 base::MessageLoop::Type message_loop_type) | 16 base::MessageLoop::Type message_loop_type) |
| 18 : loader_(real_loader.Pass()), | 17 : loader_(real_loader.Pass()), |
| 19 message_loop_type_(message_loop_type), | 18 message_loop_type_(message_loop_type), |
| 20 thread_name_(thread_name), | 19 thread_name_(thread_name), |
| 21 message_loop_created_(true, false) { | 20 message_loop_created_(true, false) { |
| 22 } | 21 } |
| 23 | 22 |
| 24 BackgroundApplicationLoader::~BackgroundApplicationLoader() { | 23 BackgroundApplicationLoader::~BackgroundApplicationLoader() { |
| 25 if (thread_) | 24 if (thread_) |
| 26 thread_->Join(); | 25 thread_->Join(); |
| 27 } | 26 } |
| 28 | 27 |
| 29 void BackgroundApplicationLoader::Load( | 28 void BackgroundApplicationLoader::Load( |
| 30 const GURL& url, | 29 const GURL& url, |
| 31 InterfaceRequest<Application> application_request) { | 30 mojo::InterfaceRequest<mojo::Application> application_request) { |
| 32 DCHECK(application_request.is_pending()); | 31 DCHECK(application_request.is_pending()); |
| 33 if (!thread_) { | 32 if (!thread_) { |
| 34 // TODO(tim): It'd be nice if we could just have each Load call | 33 // 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 | 34 // result in a new thread like DynamicService{Loader, Runner}. But some |
| 36 // loaders are creating multiple ApplicationImpls (NetworkApplicationLoader) | 35 // loaders are creating multiple ApplicationImpls (NetworkApplicationLoader) |
| 37 // sharing a delegate (etc). So we have to keep it single threaded, wait | 36 // 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 | 37 // for the thread to initialize, and post to the TaskRunner for subsequent |
| 39 // Load calls for now. | 38 // Load calls for now. |
| 40 thread_.reset(new base::DelegateSimpleThread(this, thread_name_)); | 39 thread_.reset(new base::DelegateSimpleThread(this, thread_name_)); |
| 41 thread_->Start(); | 40 thread_->Start(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 57 quit_closure_ = loop.QuitClosure(); | 56 quit_closure_ = loop.QuitClosure(); |
| 58 message_loop_created_.Signal(); | 57 message_loop_created_.Signal(); |
| 59 loop.Run(); | 58 loop.Run(); |
| 60 | 59 |
| 61 // Destroy |loader_| on the thread it's actually used on. | 60 // Destroy |loader_| on the thread it's actually used on. |
| 62 loader_.reset(); | 61 loader_.reset(); |
| 63 } | 62 } |
| 64 | 63 |
| 65 void BackgroundApplicationLoader::LoadOnBackgroundThread( | 64 void BackgroundApplicationLoader::LoadOnBackgroundThread( |
| 66 const GURL& url, | 65 const GURL& url, |
| 67 InterfaceRequest<Application> application_request) { | 66 mojo::InterfaceRequest<mojo::Application> application_request) { |
| 68 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 67 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 69 loader_->Load(url, application_request.Pass()); | 68 loader_->Load(url, application_request.Pass()); |
| 70 } | 69 } |
| 71 | 70 |
| 72 } // namespace shell | 71 } // namespace shell |
| 73 } // namespace mojo | |
| OLD | NEW |