Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: content/browser/service_worker/service_worker_context_wrapper.cc

Issue 852463002: Keep track of ServiceWorkerContext's BrowserContext and expose it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@nullptr
Patch Set: review comments Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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) {
michaeln 2015/01/14 23:36:47 ooops, wait, please initialize storage_partition_(
78 DCHECK_CURRENTLY_ON(BrowserThread::UI);
77 } 79 }
78 80
79 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() { 81 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() {
80 } 82 }
81 83
82 void ServiceWorkerContextWrapper::Init( 84 void ServiceWorkerContextWrapper::Init(
83 const base::FilePath& user_data_directory, 85 const base::FilePath& user_data_directory,
84 storage::QuotaManagerProxy* quota_manager_proxy, 86 storage::QuotaManagerProxy* quota_manager_proxy,
85 storage::SpecialStoragePolicy* special_storage_policy) { 87 storage::SpecialStoragePolicy* special_storage_policy) {
88 DCHECK_CURRENTLY_ON(BrowserThread::UI);
89
86 is_incognito_ = user_data_directory.empty(); 90 is_incognito_ = user_data_directory.empty();
87 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); 91 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool();
88 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager( 92 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager(
89 new ServiceWorkerDatabaseTaskManagerImpl(pool)); 93 new ServiceWorkerDatabaseTaskManagerImpl(pool));
90 scoped_refptr<base::SingleThreadTaskRunner> disk_cache_thread = 94 scoped_refptr<base::SingleThreadTaskRunner> disk_cache_thread =
91 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE); 95 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE);
92 scoped_refptr<base::SequencedTaskRunner> cache_task_runner = 96 scoped_refptr<base::SequencedTaskRunner> cache_task_runner =
93 pool->GetSequencedTaskRunnerWithShutdownBehavior( 97 pool->GetSequencedTaskRunnerWithShutdownBehavior(
94 BrowserThread::GetBlockingPool()->GetSequenceToken(), 98 BrowserThread::GetBlockingPool()->GetSequenceToken(),
95 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 99 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
96 InitInternal(user_data_directory, 100 InitInternal(user_data_directory,
97 cache_task_runner, 101 cache_task_runner,
98 database_task_manager.Pass(), 102 database_task_manager.Pass(),
99 disk_cache_thread, 103 disk_cache_thread,
100 quota_manager_proxy, 104 quota_manager_proxy,
101 special_storage_policy); 105 special_storage_policy);
102 } 106 }
103 107
104 void ServiceWorkerContextWrapper::Shutdown() { 108 void ServiceWorkerContextWrapper::Shutdown() {
105 DCHECK_CURRENTLY_ON(BrowserThread::UI); 109 DCHECK_CURRENTLY_ON(BrowserThread::UI);
110
111 storage_partition_ = nullptr;
106 process_manager_->Shutdown(); 112 process_manager_->Shutdown();
107 BrowserThread::PostTask( 113 BrowserThread::PostTask(
108 BrowserThread::IO, 114 BrowserThread::IO,
109 FROM_HERE, 115 FROM_HERE,
110 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); 116 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this));
111 } 117 }
112 118
113 void ServiceWorkerContextWrapper::DeleteAndStartOver() { 119 void ServiceWorkerContextWrapper::DeleteAndStartOver() {
114 DCHECK_CURRENTLY_ON(BrowserThread::IO); 120 DCHECK_CURRENTLY_ON(BrowserThread::IO);
115 context_core_->DeleteAndStartOver( 121 context_core_->DeleteAndStartOver(
116 base::Bind(&ServiceWorkerContextWrapper::DidDeleteAndStartOver, this)); 122 base::Bind(&ServiceWorkerContextWrapper::DidDeleteAndStartOver, this));
117 } 123 }
118 124
119 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { 125 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() {
120 DCHECK_CURRENTLY_ON(BrowserThread::IO); 126 DCHECK_CURRENTLY_ON(BrowserThread::IO);
121 return context_core_.get(); 127 return context_core_.get();
122 } 128 }
123 129
130 StoragePartitionImpl* ServiceWorkerContextWrapper::storage_partition() const {
131 DCHECK_CURRENTLY_ON(BrowserThread::UI);
132 return storage_partition_;
133 }
134
135 void ServiceWorkerContextWrapper::set_storage_partition(
136 StoragePartitionImpl* storage_partition) {
137 DCHECK_CURRENTLY_ON(BrowserThread::UI);
138 storage_partition_ = storage_partition;
139 }
140
124 static void FinishRegistrationOnIO( 141 static void FinishRegistrationOnIO(
125 const ServiceWorkerContext::ResultCallback& continuation, 142 const ServiceWorkerContext::ResultCallback& continuation,
126 ServiceWorkerStatusCode status, 143 ServiceWorkerStatusCode status,
127 int64 registration_id) { 144 int64 registration_id) {
128 DCHECK_CURRENTLY_ON(BrowserThread::IO); 145 DCHECK_CURRENTLY_ON(BrowserThread::IO);
129 BrowserThread::PostTask( 146 BrowserThread::PostTask(
130 BrowserThread::UI, 147 BrowserThread::UI,
131 FROM_HERE, 148 FROM_HERE,
132 base::Bind(continuation, status == SERVICE_WORKER_OK)); 149 base::Bind(continuation, status == SERVICE_WORKER_OK));
133 } 150 }
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 context_core_.reset(); 376 context_core_.reset();
360 return; 377 return;
361 } 378 }
362 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); 379 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this));
363 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; 380 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully.";
364 381
365 observer_list_->Notify(&ServiceWorkerContextObserver::OnStorageWiped); 382 observer_list_->Notify(&ServiceWorkerContextObserver::OnStorageWiped);
366 } 383 }
367 384
368 } // namespace content 385 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_context_wrapper.h ('k') | content/browser/storage_partition_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698