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

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

Issue 672813002: [ServiceWorker] Added size deltas and total size computation for QuotaM. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed last comment Created 6 years, 1 month 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 8
9 #include "base/barrier_closure.h" 9 #include "base/barrier_closure.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/threading/sequenced_worker_pool.h" 12 #include "base/threading/sequenced_worker_pool.h"
13 #include "content/browser/fileapi/chrome_blob_storage_context.h" 13 #include "content/browser/fileapi/chrome_blob_storage_context.h"
14 #include "content/browser/service_worker/service_worker_context_core.h" 14 #include "content/browser/service_worker/service_worker_context_core.h"
15 #include "content/browser/service_worker/service_worker_context_observer.h" 15 #include "content/browser/service_worker/service_worker_context_observer.h"
16 #include "content/browser/service_worker/service_worker_process_manager.h" 16 #include "content/browser/service_worker/service_worker_process_manager.h"
17 #include "content/browser/service_worker/service_worker_quota_client.h" 17 #include "content/browser/service_worker/service_worker_quota_client.h"
18 #include "content/public/browser/browser_context.h" 18 #include "content/public/browser/browser_context.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "net/url_request/url_request_context_getter.h" 20 #include "net/url_request/url_request_context_getter.h"
21 #include "storage/browser/blob/blob_storage_context.h" 21 #include "storage/browser/blob/blob_storage_context.h"
22 #include "storage/browser/quota/quota_manager_proxy.h" 22 #include "storage/browser/quota/quota_manager_proxy.h"
23 #include "storage/browser/quota/special_storage_policy.h" 23 #include "storage/browser/quota/special_storage_policy.h"
24 24
25 namespace content { 25 namespace content {
26 namespace {
27
28 size_t GetUsageIfValid(const ServiceWorkerVersionInfo& version_info) {
29 return version_info.version_id != kInvalidServiceWorkerVersionId
30 ? version_info.resources_total_size_bytes
31 : 0;
32 }
33
34 size_t GetTotalUsageForRegistrationInfo(
35 const ServiceWorkerRegistrationInfo& registration_info) {
36 return GetUsageIfValid(registration_info.active_version) +
37 GetUsageIfValid(registration_info.waiting_version) +
38 GetUsageIfValid(registration_info.installing_version);
michaeln 2014/10/30 01:32:27 Like we chatted about, going with a model where th
dmurph 2014/10/30 22:06:16 Done.
39 }
40
41 } // namespace
26 42
27 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( 43 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper(
28 BrowserContext* browser_context) 44 BrowserContext* browser_context)
29 : observer_list_( 45 : observer_list_(
30 new ObserverListThreadSafe<ServiceWorkerContextObserver>()), 46 new ObserverListThreadSafe<ServiceWorkerContextObserver>()),
31 process_manager_(new ServiceWorkerProcessManager(browser_context)), 47 process_manager_(new ServiceWorkerProcessManager(browser_context)),
32 is_incognito_(false) { 48 is_incognito_(false) {
33 } 49 }
34 50
35 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() { 51 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 callback)); 193 callback));
178 } 194 }
179 195
180 void ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins( 196 void ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins(
181 const GetUsageInfoCallback& callback, 197 const GetUsageInfoCallback& callback,
182 const std::vector<ServiceWorkerRegistrationInfo>& registrations) { 198 const std::vector<ServiceWorkerRegistrationInfo>& registrations) {
183 DCHECK_CURRENTLY_ON(BrowserThread::IO); 199 DCHECK_CURRENTLY_ON(BrowserThread::IO);
184 std::vector<ServiceWorkerUsageInfo> usage_infos; 200 std::vector<ServiceWorkerUsageInfo> usage_infos;
185 201
186 std::map<GURL, ServiceWorkerUsageInfo> origins; 202 std::map<GURL, ServiceWorkerUsageInfo> origins;
187 for (std::vector<ServiceWorkerRegistrationInfo>::const_iterator it = 203 for (const auto& registration_info : registrations) {
188 registrations.begin();
189 it != registrations.end();
190 ++it) {
191 const ServiceWorkerRegistrationInfo& registration_info = *it;
192 GURL origin = registration_info.pattern.GetOrigin(); 204 GURL origin = registration_info.pattern.GetOrigin();
193 205
194 ServiceWorkerUsageInfo& usage_info = origins[origin]; 206 ServiceWorkerUsageInfo& usage_info = origins[origin];
195 if (usage_info.origin.is_empty()) 207 if (usage_info.origin.is_empty())
196 usage_info.origin = origin; 208 usage_info.origin = origin;
197 usage_info.scopes.push_back(registration_info.pattern); 209 usage_info.scopes.push_back(registration_info.pattern);
210 usage_info.total_size_bytes +=
211 GetTotalUsageForRegistrationInfo(registration_info);
198 } 212 }
199 213
200 for (std::map<GURL, ServiceWorkerUsageInfo>::const_iterator it = 214 for (const auto& origin_info_pair : origins) {
201 origins.begin(); 215 usage_infos.push_back(origin_info_pair.second);
202 it != origins.end();
203 ++it) {
204 usage_infos.push_back(it->second);
205 } 216 }
206
207 callback.Run(usage_infos); 217 callback.Run(usage_infos);
208 } 218 }
209 219
210 namespace { 220 namespace {
211 void StatusCodeToBoolCallbackAdapter( 221 void StatusCodeToBoolCallbackAdapter(
212 const ServiceWorkerContext::ResultCallback& callback, 222 const ServiceWorkerContext::ResultCallback& callback,
213 ServiceWorkerStatusCode code) { 223 ServiceWorkerStatusCode code) {
214 callback.Run(code == ServiceWorkerStatusCode::SERVICE_WORKER_OK); 224 callback.Run(code == ServiceWorkerStatusCode::SERVICE_WORKER_OK);
215 } 225 }
216 226
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 DCHECK_CURRENTLY_ON(BrowserThread::IO); 315 DCHECK_CURRENTLY_ON(BrowserThread::IO);
306 if (status != SERVICE_WORKER_OK) { 316 if (status != SERVICE_WORKER_OK) {
307 context_core_.reset(); 317 context_core_.reset();
308 return; 318 return;
309 } 319 }
310 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); 320 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this));
311 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; 321 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully.";
312 } 322 }
313 323
314 } // namespace content 324 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698