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/dynamic_service_loader.h" | 5 #include "mojo/shell/dynamic_service_loader.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "mojo/shell/context.h" | 9 #include "mojo/shell/context.h" |
10 #include "mojo/shell/keep_alive.h" | 10 #include "mojo/shell/keep_alive.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 return std::string(); | 27 return std::string(); |
28 #endif | 28 #endif |
29 } | 29 } |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 class DynamicServiceLoader::LoadContext : public mojo::shell::Loader::Delegate { | 33 class DynamicServiceLoader::LoadContext : public mojo::shell::Loader::Delegate { |
34 public: | 34 public: |
35 LoadContext(DynamicServiceLoader* loader, | 35 LoadContext(DynamicServiceLoader* loader, |
36 const GURL& url, | 36 const GURL& url, |
37 ScopedShellHandle service_handle, | 37 ScopedMessagePipeHandle service_handle, |
38 scoped_ptr<DynamicServiceRunner> runner) | 38 scoped_ptr<DynamicServiceRunner> runner) |
39 : loader_(loader), | 39 : loader_(loader), |
40 url_(url), | 40 url_(url), |
41 service_handle_(service_handle.Pass()), | 41 service_handle_(service_handle.Pass()), |
42 runner_(runner.Pass()), | 42 runner_(runner.Pass()), |
43 keep_alive_(loader->context_) { | 43 keep_alive_(loader->context_) { |
44 GURL url_to_load; | 44 GURL url_to_load; |
45 | 45 |
46 if (url.SchemeIs("mojo")) { | 46 if (url.SchemeIs("mojo")) { |
47 std::string origin = | 47 std::string origin = |
(...skipping 24 matching lines...) Expand all Loading... |
72 runner_->Start( | 72 runner_->Start( |
73 app_path, | 73 app_path, |
74 service_handle_.Pass(), | 74 service_handle_.Pass(), |
75 base::Bind(&DynamicServiceLoader::AppCompleted, | 75 base::Bind(&DynamicServiceLoader::AppCompleted, |
76 base::Unretained(loader_), url_)); | 76 base::Unretained(loader_), url_)); |
77 } | 77 } |
78 | 78 |
79 DynamicServiceLoader* const loader_; | 79 DynamicServiceLoader* const loader_; |
80 const GURL url_; | 80 const GURL url_; |
81 scoped_ptr<mojo::shell::Loader::Job> request_; | 81 scoped_ptr<mojo::shell::Loader::Job> request_; |
82 ScopedShellHandle service_handle_; | 82 ScopedMessagePipeHandle service_handle_; |
83 scoped_ptr<DynamicServiceRunner> runner_; | 83 scoped_ptr<DynamicServiceRunner> runner_; |
84 KeepAlive keep_alive_; | 84 KeepAlive keep_alive_; |
85 | 85 |
86 DISALLOW_COPY_AND_ASSIGN(LoadContext); | 86 DISALLOW_COPY_AND_ASSIGN(LoadContext); |
87 }; | 87 }; |
88 | 88 |
89 DynamicServiceLoader::DynamicServiceLoader( | 89 DynamicServiceLoader::DynamicServiceLoader( |
90 Context* context, | 90 Context* context, |
91 scoped_ptr<DynamicServiceRunnerFactory> runner_factory) | 91 scoped_ptr<DynamicServiceRunnerFactory> runner_factory) |
92 : context_(context), | 92 : context_(context), |
93 runner_factory_(runner_factory.Pass()) { | 93 runner_factory_(runner_factory.Pass()) { |
94 } | 94 } |
95 | 95 |
96 DynamicServiceLoader::~DynamicServiceLoader() { | 96 DynamicServiceLoader::~DynamicServiceLoader() { |
97 DCHECK(url_to_load_context_.empty()); | 97 DCHECK(url_to_load_context_.empty()); |
98 } | 98 } |
99 | 99 |
100 void DynamicServiceLoader::LoadService(ServiceManager* manager, | 100 void DynamicServiceLoader::LoadService(ServiceManager* manager, |
101 const GURL& url, | 101 const GURL& url, |
102 ScopedShellHandle service_handle) { | 102 ScopedMessagePipeHandle service_handle) { |
103 DCHECK(url_to_load_context_.find(url) == url_to_load_context_.end()); | 103 DCHECK(url_to_load_context_.find(url) == url_to_load_context_.end()); |
104 url_to_load_context_[url] = new LoadContext( | 104 url_to_load_context_[url] = new LoadContext( |
105 this, url, service_handle.Pass(), runner_factory_->Create(context_)); | 105 this, url, service_handle.Pass(), runner_factory_->Create(context_)); |
106 } | 106 } |
107 | 107 |
108 void DynamicServiceLoader::OnServiceError(ServiceManager* manager, | 108 void DynamicServiceLoader::OnServiceError(ServiceManager* manager, |
109 const GURL& url) { | 109 const GURL& url) { |
110 } | 110 } |
111 | 111 |
112 void DynamicServiceLoader::AppCompleted(const GURL& url) { | 112 void DynamicServiceLoader::AppCompleted(const GURL& url) { |
113 DCHECK(context_->task_runners()->ui_runner()->BelongsToCurrentThread()); | 113 DCHECK(context_->task_runners()->ui_runner()->BelongsToCurrentThread()); |
114 DVLOG(2) << "App completed (url: " << url << ")"; | 114 DVLOG(2) << "App completed (url: " << url << ")"; |
115 | 115 |
116 LoadContextMap::iterator it = url_to_load_context_.find(url); | 116 LoadContextMap::iterator it = url_to_load_context_.find(url); |
117 DCHECK(it != url_to_load_context_.end()) << url; | 117 DCHECK(it != url_to_load_context_.end()) << url; |
118 | 118 |
119 LoadContext* doomed = it->second; | 119 LoadContext* doomed = it->second; |
120 url_to_load_context_.erase(it); | 120 url_to_load_context_.erase(it); |
121 | 121 |
122 delete doomed; | 122 delete doomed; |
123 } | 123 } |
124 | 124 |
125 } // namespace shell | 125 } // namespace shell |
126 } // namespace mojo | 126 } // namespace mojo |
OLD | NEW |