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 "content/browser/service_worker/service_worker_process_manager.h" | 5 #include "content/browser/service_worker/service_worker_process_manager.h" |
6 | 6 |
7 #include "content/browser/renderer_host/render_process_host_impl.h" | 7 #include "content/browser/renderer_host/render_process_host_impl.h" |
8 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 8 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "content/public/browser/site_instance.h" | 10 #include "content/public/browser/site_instance.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 } | 28 } |
29 | 29 |
30 ServiceWorkerProcessManager::ProcessInfo::ProcessInfo(int process_id) | 30 ServiceWorkerProcessManager::ProcessInfo::ProcessInfo(int process_id) |
31 : process_id(process_id) { | 31 : process_id(process_id) { |
32 } | 32 } |
33 | 33 |
34 ServiceWorkerProcessManager::ProcessInfo::~ProcessInfo() { | 34 ServiceWorkerProcessManager::ProcessInfo::~ProcessInfo() { |
35 } | 35 } |
36 | 36 |
37 ServiceWorkerProcessManager::ServiceWorkerProcessManager( | 37 ServiceWorkerProcessManager::ServiceWorkerProcessManager( |
38 BrowserContext* browser_context) | 38 ServiceWorkerContextWrapper* context_wrapper) |
39 : browser_context_(browser_context), | 39 : context_wrapper_(context_wrapper), |
40 process_id_for_test_(-1), | 40 process_id_for_test_(-1), |
41 weak_this_factory_(this), | 41 weak_this_factory_(this), |
42 weak_this_(weak_this_factory_.GetWeakPtr()) { | 42 weak_this_(weak_this_factory_.GetWeakPtr()) { |
43 } | 43 } |
44 | 44 |
45 ServiceWorkerProcessManager::~ServiceWorkerProcessManager() { | 45 ServiceWorkerProcessManager::~ServiceWorkerProcessManager() { |
46 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 46 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
47 DCHECK(browser_context_ == NULL) | |
48 << "Call Shutdown() before destroying |this|, so that racing method " | |
49 << "invocations don't use a destroyed BrowserContext."; | |
50 } | |
51 | |
52 void ServiceWorkerProcessManager::Shutdown() { | |
53 browser_context_ = NULL; | |
54 } | 47 } |
55 | 48 |
56 void ServiceWorkerProcessManager::AllocateWorkerProcess( | 49 void ServiceWorkerProcessManager::AllocateWorkerProcess( |
57 int embedded_worker_id, | 50 int embedded_worker_id, |
58 const std::vector<int>& process_ids, | 51 const std::vector<int>& process_ids, |
59 const GURL& script_url, | 52 const GURL& script_url, |
60 const base::Callback<void(ServiceWorkerStatusCode, int process_id)>& | 53 const base::Callback<void(ServiceWorkerStatusCode, int process_id)>& |
61 callback) { | 54 callback) { |
62 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 55 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
63 BrowserThread::PostTask( | 56 BrowserThread::PostTask( |
(...skipping 27 matching lines...) Expand all Loading... |
91 if (IncrementWorkerRefCountByPid(*it)) { | 84 if (IncrementWorkerRefCountByPid(*it)) { |
92 instance_info_.insert( | 85 instance_info_.insert( |
93 std::make_pair(embedded_worker_id, ProcessInfo(*it))); | 86 std::make_pair(embedded_worker_id, ProcessInfo(*it))); |
94 BrowserThread::PostTask(BrowserThread::IO, | 87 BrowserThread::PostTask(BrowserThread::IO, |
95 FROM_HERE, | 88 FROM_HERE, |
96 base::Bind(callback, SERVICE_WORKER_OK, *it)); | 89 base::Bind(callback, SERVICE_WORKER_OK, *it)); |
97 return; | 90 return; |
98 } | 91 } |
99 } | 92 } |
100 | 93 |
101 if (!browser_context_) { | 94 if (!context_wrapper_->browser_context_) { |
102 // Shutdown has started. | 95 // Shutdown has started. |
103 BrowserThread::PostTask( | 96 BrowserThread::PostTask( |
104 BrowserThread::IO, | 97 BrowserThread::IO, |
105 FROM_HERE, | 98 FROM_HERE, |
106 base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED, -1)); | 99 base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED, -1)); |
107 return; | 100 return; |
108 } | 101 } |
109 // No existing processes available; start a new one. | 102 // No existing processes available; start a new one. |
110 scoped_refptr<SiteInstance> site_instance = | 103 scoped_refptr<SiteInstance> site_instance = SiteInstance::CreateForURL( |
111 SiteInstance::CreateForURL(browser_context_, script_url); | 104 context_wrapper_->browser_context_, script_url); |
112 RenderProcessHost* rph = site_instance->GetProcess(); | 105 RenderProcessHost* rph = site_instance->GetProcess(); |
113 // This Init() call posts a task to the IO thread that adds the RPH's | 106 // This Init() call posts a task to the IO thread that adds the RPH's |
114 // ServiceWorkerDispatcherHost to the | 107 // ServiceWorkerDispatcherHost to the |
115 // EmbeddedWorkerRegistry::process_sender_map_. | 108 // EmbeddedWorkerRegistry::process_sender_map_. |
116 if (!rph->Init()) { | 109 if (!rph->Init()) { |
117 LOG(ERROR) << "Couldn't start a new process!"; | 110 LOG(ERROR) << "Couldn't start a new process!"; |
118 BrowserThread::PostTask( | 111 BrowserThread::PostTask( |
119 BrowserThread::IO, | 112 BrowserThread::IO, |
120 FROM_HERE, | 113 FROM_HERE, |
121 base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED, -1)); | 114 base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED, -1)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 namespace base { | 164 namespace base { |
172 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the | 165 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the |
173 // member WeakPtr to safely guard the object's lifetime when used on that | 166 // member WeakPtr to safely guard the object's lifetime when used on that |
174 // thread. | 167 // thread. |
175 void DefaultDeleter<content::ServiceWorkerProcessManager>::operator()( | 168 void DefaultDeleter<content::ServiceWorkerProcessManager>::operator()( |
176 content::ServiceWorkerProcessManager* ptr) const { | 169 content::ServiceWorkerProcessManager* ptr) const { |
177 content::BrowserThread::DeleteSoon( | 170 content::BrowserThread::DeleteSoon( |
178 content::BrowserThread::UI, FROM_HERE, ptr); | 171 content::BrowserThread::UI, FROM_HERE, ptr); |
179 } | 172 } |
180 } // namespace base | 173 } // namespace base |
OLD | NEW |