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 <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/barrier_closure.h" | 12 #include "base/barrier_closure.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
18 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 18 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
19 #include "content/browser/service_worker/service_worker_context_core.h" | 19 #include "content/browser/service_worker/service_worker_context_core.h" |
20 #include "content/browser/service_worker/service_worker_context_observer.h" | 20 #include "content/browser/service_worker/service_worker_context_observer.h" |
21 #include "content/browser/service_worker/service_worker_process_manager.h" | 21 #include "content/browser/service_worker/service_worker_process_manager.h" |
22 #include "content/browser/service_worker/service_worker_quota_client.h" | 22 #include "content/browser/service_worker/service_worker_quota_client.h" |
23 #include "content/browser/service_worker/service_worker_request_handler.h" | 23 #include "content/browser/service_worker/service_worker_request_handler.h" |
| 24 #include "content/browser/storage_partition_impl.h" |
24 #include "content/public/browser/browser_context.h" | 25 #include "content/public/browser/browser_context.h" |
25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/service_worker_context.h" | 27 #include "content/public/browser/service_worker_context.h" |
27 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
28 #include "net/url_request/url_request_context_getter.h" | 29 #include "net/url_request/url_request_context_getter.h" |
29 #include "storage/browser/blob/blob_storage_context.h" | 30 #include "storage/browser/blob/blob_storage_context.h" |
30 #include "storage/browser/quota/quota_manager_proxy.h" | 31 #include "storage/browser/quota/quota_manager_proxy.h" |
31 #include "storage/browser/quota/special_storage_policy.h" | 32 #include "storage/browser/quota/special_storage_policy.h" |
32 | 33 |
33 namespace content { | 34 namespace content { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 if (!handler || !handler->context()) | 67 if (!handler || !handler->context()) |
67 return nullptr; | 68 return nullptr; |
68 return handler->context()->wrapper_; | 69 return handler->context()->wrapper_; |
69 } | 70 } |
70 | 71 |
71 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( | 72 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( |
72 BrowserContext* browser_context) | 73 BrowserContext* browser_context) |
73 : observer_list_( | 74 : observer_list_( |
74 new ObserverListThreadSafe<ServiceWorkerContextObserver>()), | 75 new ObserverListThreadSafe<ServiceWorkerContextObserver>()), |
75 process_manager_(new ServiceWorkerProcessManager(browser_context)), | 76 process_manager_(new ServiceWorkerProcessManager(browser_context)), |
76 is_incognito_(false) { | 77 is_incognito_(false), |
| 78 storage_partition_(nullptr) { |
| 79 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
77 } | 80 } |
78 | 81 |
79 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() { | 82 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() { |
80 } | 83 } |
81 | 84 |
82 void ServiceWorkerContextWrapper::Init( | 85 void ServiceWorkerContextWrapper::Init( |
83 const base::FilePath& user_data_directory, | 86 const base::FilePath& user_data_directory, |
84 storage::QuotaManagerProxy* quota_manager_proxy, | 87 storage::QuotaManagerProxy* quota_manager_proxy, |
85 storage::SpecialStoragePolicy* special_storage_policy) { | 88 storage::SpecialStoragePolicy* special_storage_policy) { |
| 89 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 90 |
86 is_incognito_ = user_data_directory.empty(); | 91 is_incognito_ = user_data_directory.empty(); |
87 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | 92 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); |
88 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager( | 93 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager( |
89 new ServiceWorkerDatabaseTaskManagerImpl(pool)); | 94 new ServiceWorkerDatabaseTaskManagerImpl(pool)); |
90 scoped_refptr<base::SingleThreadTaskRunner> disk_cache_thread = | 95 scoped_refptr<base::SingleThreadTaskRunner> disk_cache_thread = |
91 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE); | 96 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE); |
92 scoped_refptr<base::SequencedTaskRunner> cache_task_runner = | 97 scoped_refptr<base::SequencedTaskRunner> cache_task_runner = |
93 pool->GetSequencedTaskRunnerWithShutdownBehavior( | 98 pool->GetSequencedTaskRunnerWithShutdownBehavior( |
94 BrowserThread::GetBlockingPool()->GetSequenceToken(), | 99 BrowserThread::GetBlockingPool()->GetSequenceToken(), |
95 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 100 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
96 InitInternal(user_data_directory, | 101 InitInternal(user_data_directory, |
97 cache_task_runner, | 102 cache_task_runner, |
98 database_task_manager.Pass(), | 103 database_task_manager.Pass(), |
99 disk_cache_thread, | 104 disk_cache_thread, |
100 quota_manager_proxy, | 105 quota_manager_proxy, |
101 special_storage_policy); | 106 special_storage_policy); |
102 } | 107 } |
103 | 108 |
104 void ServiceWorkerContextWrapper::Shutdown() { | 109 void ServiceWorkerContextWrapper::Shutdown() { |
105 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 110 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 111 |
| 112 storage_partition_ = nullptr; |
106 process_manager_->Shutdown(); | 113 process_manager_->Shutdown(); |
107 BrowserThread::PostTask( | 114 BrowserThread::PostTask( |
108 BrowserThread::IO, | 115 BrowserThread::IO, |
109 FROM_HERE, | 116 FROM_HERE, |
110 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); | 117 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); |
111 } | 118 } |
112 | 119 |
113 void ServiceWorkerContextWrapper::DeleteAndStartOver() { | 120 void ServiceWorkerContextWrapper::DeleteAndStartOver() { |
114 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 121 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
115 context_core_->DeleteAndStartOver( | 122 context_core_->DeleteAndStartOver( |
116 base::Bind(&ServiceWorkerContextWrapper::DidDeleteAndStartOver, this)); | 123 base::Bind(&ServiceWorkerContextWrapper::DidDeleteAndStartOver, this)); |
117 } | 124 } |
118 | 125 |
119 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 126 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
120 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 127 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
121 return context_core_.get(); | 128 return context_core_.get(); |
122 } | 129 } |
123 | 130 |
| 131 StoragePartitionImpl* ServiceWorkerContextWrapper::storage_partition() const { |
| 132 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 133 return storage_partition_; |
| 134 } |
| 135 |
| 136 void ServiceWorkerContextWrapper::set_storage_partition( |
| 137 StoragePartitionImpl* storage_partition) { |
| 138 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 139 storage_partition_ = storage_partition; |
| 140 } |
| 141 |
124 static void FinishRegistrationOnIO( | 142 static void FinishRegistrationOnIO( |
125 const ServiceWorkerContext::ResultCallback& continuation, | 143 const ServiceWorkerContext::ResultCallback& continuation, |
126 ServiceWorkerStatusCode status, | 144 ServiceWorkerStatusCode status, |
127 int64 registration_id) { | 145 int64 registration_id) { |
128 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 146 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
129 BrowserThread::PostTask( | 147 BrowserThread::PostTask( |
130 BrowserThread::UI, | 148 BrowserThread::UI, |
131 FROM_HERE, | 149 FROM_HERE, |
132 base::Bind(continuation, status == SERVICE_WORKER_OK)); | 150 base::Bind(continuation, status == SERVICE_WORKER_OK)); |
133 } | 151 } |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 context_core_.reset(); | 377 context_core_.reset(); |
360 return; | 378 return; |
361 } | 379 } |
362 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 380 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
363 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 381 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
364 | 382 |
365 observer_list_->Notify(&ServiceWorkerContextObserver::OnStorageWiped); | 383 observer_list_->Notify(&ServiceWorkerContextObserver::OnStorageWiped); |
366 } | 384 } |
367 | 385 |
368 } // namespace content | 386 } // namespace content |
OLD | NEW |