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