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 browser_context_(browser_context) { | 21 process_manager_(new ServiceWorkerProcessManager(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 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 42 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
43 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 43 process_manager_->Shutdown(); |
44 browser_context_ = NULL; | 44 BrowserThread::PostTask( |
45 BrowserThread::PostTask( | 45 BrowserThread::IO, |
46 BrowserThread::IO, FROM_HERE, | 46 FROM_HERE, |
47 base::Bind(&ServiceWorkerContextWrapper::Shutdown, this)); | 47 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); |
48 return; | |
49 } | |
50 // Breaks the reference cycle through ServiceWorkerProcessManager. | |
51 context_core_.reset(); | |
52 } | 48 } |
53 | 49 |
54 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 50 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
55 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 51 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
56 return context_core_.get(); | 52 return context_core_.get(); |
57 } | 53 } |
58 | 54 |
59 static void FinishRegistrationOnIO( | 55 static void FinishRegistrationOnIO( |
60 const ServiceWorkerContext::ResultCallback& continuation, | 56 const ServiceWorkerContext::ResultCallback& continuation, |
61 ServiceWorkerStatusCode status, | 57 ServiceWorkerStatusCode status, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 FROM_HERE, | 138 FROM_HERE, |
143 base::Bind(&ServiceWorkerContextWrapper::InitInternal, | 139 base::Bind(&ServiceWorkerContextWrapper::InitInternal, |
144 this, | 140 this, |
145 user_data_directory, | 141 user_data_directory, |
146 make_scoped_refptr(database_task_runner), | 142 make_scoped_refptr(database_task_runner), |
147 make_scoped_refptr(disk_cache_thread), | 143 make_scoped_refptr(disk_cache_thread), |
148 make_scoped_refptr(quota_manager_proxy))); | 144 make_scoped_refptr(quota_manager_proxy))); |
149 return; | 145 return; |
150 } | 146 } |
151 DCHECK(!context_core_); | 147 DCHECK(!context_core_); |
152 context_core_.reset(new ServiceWorkerContextCore( | 148 context_core_.reset(new ServiceWorkerContextCore(user_data_directory, |
153 user_data_directory, | 149 database_task_runner, |
154 database_task_runner, | 150 disk_cache_thread, |
155 disk_cache_thread, | 151 quota_manager_proxy, |
156 quota_manager_proxy, | 152 observer_list_, |
157 observer_list_, | 153 this)); |
158 make_scoped_ptr(new ServiceWorkerProcessManager(this)))); | 154 } |
| 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 |