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/service_manager/background_shell_service_loader.h" | 5 #include "mojo/service_manager/background_shell_service_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 "mojo/service_manager/service_manager.h" | 9 #include "mojo/service_manager/service_manager.h" |
10 | 10 |
11 namespace mojo { | 11 namespace mojo { |
12 | 12 |
13 class BackgroundShellServiceLoader::BackgroundLoader { | 13 class BackgroundShellServiceLoader::BackgroundLoader { |
14 public: | 14 public: |
15 explicit BackgroundLoader(ServiceLoader* loader) : loader_(loader) {} | 15 explicit BackgroundLoader(ServiceLoader* loader) : loader_(loader) {} |
16 ~BackgroundLoader() {} | 16 ~BackgroundLoader() {} |
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 BackgroundShellServiceLoader | 31 ServiceLoader* loader_; // Owned by BackgroundShellServiceLoader |
30 | 32 |
31 DISALLOW_COPY_AND_ASSIGN(BackgroundLoader); | 33 DISALLOW_COPY_AND_ASSIGN(BackgroundLoader); |
(...skipping 15 matching lines...) Expand all Loading... |
47 if (thread_) { | 49 if (thread_) { |
48 if (quit_on_shutdown_) | 50 if (quit_on_shutdown_) |
49 task_runner_->PostTask(FROM_HERE, quit_closure_); | 51 task_runner_->PostTask(FROM_HERE, quit_closure_); |
50 thread_->Join(); | 52 thread_->Join(); |
51 } | 53 } |
52 } | 54 } |
53 | 55 |
54 void BackgroundShellServiceLoader::LoadService( | 56 void BackgroundShellServiceLoader::LoadService( |
55 ServiceManager* manager, | 57 ServiceManager* manager, |
56 const GURL& url, | 58 const GURL& url, |
57 ScopedMessagePipeHandle shell_handle) { | 59 scoped_refptr<LoadServiceCallbacks> callbacks) { |
| 60 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); |
| 61 if (!shell_handle.is_valid()) |
| 62 return; |
| 63 |
58 if (!thread_) { | 64 if (!thread_) { |
59 // TODO(tim): It'd be nice if we could just have each LoadService call | 65 // TODO(tim): It'd be nice if we could just have each LoadService call |
60 // result in a new thread like DynamicService{Loader, Runner}. But some | 66 // result in a new thread like DynamicService{Loader, Runner}. But some |
61 // loaders are creating multiple ApplicationImpls (NetworkServiceLoader) | 67 // loaders are creating multiple ApplicationImpls (NetworkServiceLoader) |
62 // sharing a delegate (etc). So we have to keep it single threaded, wait | 68 // sharing a delegate (etc). So we have to keep it single threaded, wait |
63 // for the thread to initialize, and post to the TaskRunner for subsequent | 69 // for the thread to initialize, and post to the TaskRunner for subsequent |
64 // LoadService calls for now. | 70 // LoadService calls for now. |
65 thread_.reset(new base::DelegateSimpleThread(this, thread_name_)); | 71 thread_.reset(new base::DelegateSimpleThread(this, thread_name_)); |
66 thread_->Start(); | 72 thread_->Start(); |
67 message_loop_created_.Wait(); | 73 message_loop_created_.Wait(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 115 |
110 void BackgroundShellServiceLoader::OnServiceErrorOnBackgroundThread( | 116 void BackgroundShellServiceLoader::OnServiceErrorOnBackgroundThread( |
111 ServiceManager* manager, const GURL& url) { | 117 ServiceManager* manager, const GURL& url) { |
112 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 118 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
113 if (!background_loader_) | 119 if (!background_loader_) |
114 background_loader_ = new BackgroundLoader(loader_.get()); | 120 background_loader_ = new BackgroundLoader(loader_.get()); |
115 background_loader_->OnServiceError(manager, url); | 121 background_loader_->OnServiceError(manager, url); |
116 } | 122 } |
117 | 123 |
118 } // namespace mojo | 124 } // namespace mojo |
OLD | NEW |