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 | 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" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 callback)); | 177 callback)); |
178 } | 178 } |
179 | 179 |
180 void ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins( | 180 void ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins( |
181 const GetUsageInfoCallback& callback, | 181 const GetUsageInfoCallback& callback, |
182 const std::vector<ServiceWorkerRegistrationInfo>& registrations) { | 182 const std::vector<ServiceWorkerRegistrationInfo>& registrations) { |
183 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 183 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
184 std::vector<ServiceWorkerUsageInfo> usage_infos; | 184 std::vector<ServiceWorkerUsageInfo> usage_infos; |
185 | 185 |
186 std::map<GURL, ServiceWorkerUsageInfo> origins; | 186 std::map<GURL, ServiceWorkerUsageInfo> origins; |
187 for (std::vector<ServiceWorkerRegistrationInfo>::const_iterator it = | 187 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(); | 188 GURL origin = registration_info.pattern.GetOrigin(); |
193 | 189 |
194 ServiceWorkerUsageInfo& usage_info = origins[origin]; | 190 ServiceWorkerUsageInfo& usage_info = origins[origin]; |
195 if (usage_info.origin.is_empty()) | 191 if (usage_info.origin.is_empty()) |
196 usage_info.origin = origin; | 192 usage_info.origin = origin; |
197 usage_info.scopes.push_back(registration_info.pattern); | 193 usage_info.scopes.push_back(registration_info.pattern); |
| 194 usage_info.total_size_bytes += |
| 195 registration_info.active_version_total_size_bytes; |
198 } | 196 } |
199 | 197 |
200 for (std::map<GURL, ServiceWorkerUsageInfo>::const_iterator it = | 198 for (const auto& origin_info_pair : origins) { |
201 origins.begin(); | 199 usage_infos.push_back(origin_info_pair.second); |
202 it != origins.end(); | |
203 ++it) { | |
204 usage_infos.push_back(it->second); | |
205 } | 200 } |
206 | |
207 callback.Run(usage_infos); | 201 callback.Run(usage_infos); |
208 } | 202 } |
209 | 203 |
210 namespace { | 204 namespace { |
211 void StatusCodeToBoolCallbackAdapter( | 205 void StatusCodeToBoolCallbackAdapter( |
212 const ServiceWorkerContext::ResultCallback& callback, | 206 const ServiceWorkerContext::ResultCallback& callback, |
213 ServiceWorkerStatusCode code) { | 207 ServiceWorkerStatusCode code) { |
214 callback.Run(code == ServiceWorkerStatusCode::SERVICE_WORKER_OK); | 208 callback.Run(code == ServiceWorkerStatusCode::SERVICE_WORKER_OK); |
215 } | 209 } |
216 | 210 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 299 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
306 if (status != SERVICE_WORKER_OK) { | 300 if (status != SERVICE_WORKER_OK) { |
307 context_core_.reset(); | 301 context_core_.reset(); |
308 return; | 302 return; |
309 } | 303 } |
310 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 304 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
311 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 305 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
312 } | 306 } |
313 | 307 |
314 } // namespace content | 308 } // namespace content |
OLD | NEW |