OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_context_wrapper.h" | 5 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
9 #include "content/browser/service_worker/service_worker_context_core.h" | 9 #include "content/browser/service_worker/service_worker_context_core.h" |
10 #include "content/browser/service_worker/service_worker_context_observer.h" | 10 #include "content/browser/service_worker/service_worker_context_observer.h" |
11 #include "content/browser/service_worker/service_worker_process_manager.h" | 11 #include "content/browser/service_worker/service_worker_process_manager.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "webkit/browser/quota/quota_manager_proxy.h" | 13 #include "webkit/browser/quota/quota_manager_proxy.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( | 17 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( |
18 BrowserContext* browser_context) | 18 BrowserContext* browser_context) |
19 : observer_list_( | 19 : observer_list_( |
20 new ObserverListThreadSafe<ServiceWorkerContextObserver>()), | 20 new ObserverListThreadSafe<ServiceWorkerContextObserver>()), |
21 process_manager_(new ServiceWorkerProcessManager(browser_context)) { | 21 browser_context_(browser_context) { |
22 } | 22 } |
23 | 23 |
24 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() { | 24 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() { |
25 } | 25 } |
26 | 26 |
27 void ServiceWorkerContextWrapper::Init( | 27 void ServiceWorkerContextWrapper::Init( |
28 const base::FilePath& user_data_directory, | 28 const base::FilePath& user_data_directory, |
29 quota::QuotaManagerProxy* quota_manager_proxy) { | 29 quota::QuotaManagerProxy* quota_manager_proxy) { |
30 scoped_refptr<base::SequencedTaskRunner> database_task_runner = | 30 scoped_refptr<base::SequencedTaskRunner> database_task_runner = |
31 BrowserThread::GetBlockingPool()-> | 31 BrowserThread::GetBlockingPool()-> |
32 GetSequencedTaskRunnerWithShutdownBehavior( | 32 GetSequencedTaskRunnerWithShutdownBehavior( |
33 BrowserThread::GetBlockingPool()->GetSequenceToken(), | 33 BrowserThread::GetBlockingPool()->GetSequenceToken(), |
34 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 34 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
35 scoped_refptr<base::MessageLoopProxy> disk_cache_thread = | 35 scoped_refptr<base::MessageLoopProxy> disk_cache_thread = |
36 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE); | 36 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE); |
37 InitInternal(user_data_directory, database_task_runner, | 37 InitInternal(user_data_directory, database_task_runner, |
38 disk_cache_thread, quota_manager_proxy); | 38 disk_cache_thread, quota_manager_proxy); |
39 } | 39 } |
40 | 40 |
41 void ServiceWorkerContextWrapper::Shutdown() { | 41 void ServiceWorkerContextWrapper::Shutdown() { |
42 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 42 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
43 process_manager_->Shutdown(); | 43 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
44 BrowserThread::PostTask( | 44 browser_context_ = NULL; |
45 BrowserThread::IO, | 45 BrowserThread::PostTask( |
46 FROM_HERE, | 46 BrowserThread::IO, FROM_HERE, |
47 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); | 47 base::Bind(&ServiceWorkerContextWrapper::Shutdown, this)); |
| 48 return; |
| 49 } |
| 50 // Breaks the reference cycle through ServiceWorkerProcessManager. |
| 51 context_core_.reset(); |
48 } | 52 } |
49 | 53 |
50 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 54 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
51 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 55 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
52 return context_core_.get(); | 56 return context_core_.get(); |
53 } | 57 } |
54 | 58 |
55 static void FinishRegistrationOnIO( | 59 static void FinishRegistrationOnIO( |
56 const ServiceWorkerContext::ResultCallback& continuation, | 60 const ServiceWorkerContext::ResultCallback& continuation, |
57 ServiceWorkerStatusCode status, | 61 ServiceWorkerStatusCode status, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 FROM_HERE, | 142 FROM_HERE, |
139 base::Bind(&ServiceWorkerContextWrapper::InitInternal, | 143 base::Bind(&ServiceWorkerContextWrapper::InitInternal, |
140 this, | 144 this, |
141 user_data_directory, | 145 user_data_directory, |
142 make_scoped_refptr(database_task_runner), | 146 make_scoped_refptr(database_task_runner), |
143 make_scoped_refptr(disk_cache_thread), | 147 make_scoped_refptr(disk_cache_thread), |
144 make_scoped_refptr(quota_manager_proxy))); | 148 make_scoped_refptr(quota_manager_proxy))); |
145 return; | 149 return; |
146 } | 150 } |
147 DCHECK(!context_core_); | 151 DCHECK(!context_core_); |
148 context_core_.reset(new ServiceWorkerContextCore(user_data_directory, | 152 context_core_.reset(new ServiceWorkerContextCore( |
149 database_task_runner, | 153 user_data_directory, |
150 disk_cache_thread, | 154 database_task_runner, |
151 quota_manager_proxy, | 155 disk_cache_thread, |
152 observer_list_, | 156 quota_manager_proxy, |
153 this)); | 157 observer_list_, |
154 } | 158 make_scoped_ptr(new ServiceWorkerProcessManager(this)))); |
155 | |
156 void ServiceWorkerContextWrapper::ShutdownOnIO() { | |
157 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
158 context_core_.reset(); | |
159 } | 159 } |
160 | 160 |
161 } // namespace content | 161 } // namespace content |
OLD | NEW |