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

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

Issue 2390953002: ServiceWorker: Remove an unused origin_filter param for cleanup (Closed)
Patch Set: slightly revert renaming for consistency Created 4 years, 2 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
« no previous file with comments | « content/browser/service_worker/service_worker_storage.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_storage.h" 5 #include "content/browser/service_worker/service_worker_storage.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 } 344 }
345 DCHECK_EQ(INITIALIZED, state_); 345 DCHECK_EQ(INITIALIZED, state_);
346 346
347 RegistrationList* registrations = new RegistrationList; 347 RegistrationList* registrations = new RegistrationList;
348 std::vector<ResourceList>* resource_lists = new std::vector<ResourceList>; 348 std::vector<ResourceList>* resource_lists = new std::vector<ResourceList>;
349 PostTaskAndReplyWithResult( 349 PostTaskAndReplyWithResult(
350 database_task_manager_->GetTaskRunner(), FROM_HERE, 350 database_task_manager_->GetTaskRunner(), FROM_HERE,
351 base::Bind(&ServiceWorkerDatabase::GetRegistrationsForOrigin, 351 base::Bind(&ServiceWorkerDatabase::GetRegistrationsForOrigin,
352 base::Unretained(database_.get()), origin, registrations, 352 base::Unretained(database_.get()), origin, registrations,
353 resource_lists), 353 resource_lists),
354 base::Bind(&ServiceWorkerStorage::DidGetRegistrations, 354 base::Bind(&ServiceWorkerStorage::DidGetRegistrationsForOrigin,
355 weak_factory_.GetWeakPtr(), callback, 355 weak_factory_.GetWeakPtr(), callback,
356 base::Owned(registrations), base::Owned(resource_lists), 356 base::Owned(registrations), base::Owned(resource_lists),
357 origin)); 357 origin));
358 } 358 }
359 359
360 void ServiceWorkerStorage::GetAllRegistrationsInfos( 360 void ServiceWorkerStorage::GetAllRegistrationsInfos(
361 const GetRegistrationsInfosCallback& callback) { 361 const GetRegistrationsInfosCallback& callback) {
362 if (!LazyInitialize( 362 if (!LazyInitialize(
363 base::Bind(&ServiceWorkerStorage::GetAllRegistrationsInfos, 363 base::Bind(&ServiceWorkerStorage::GetAllRegistrationsInfos,
364 weak_factory_.GetWeakPtr(), callback))) { 364 weak_factory_.GetWeakPtr(), callback))) {
365 if (state_ != INITIALIZING) { 365 if (state_ != INITIALIZING) {
366 RunSoon(FROM_HERE, 366 RunSoon(FROM_HERE,
367 base::Bind(callback, SERVICE_WORKER_ERROR_ABORT, 367 base::Bind(callback, SERVICE_WORKER_ERROR_ABORT,
368 std::vector<ServiceWorkerRegistrationInfo>())); 368 std::vector<ServiceWorkerRegistrationInfo>()));
369 } 369 }
370 return; 370 return;
371 } 371 }
372 DCHECK_EQ(INITIALIZED, state_); 372 DCHECK_EQ(INITIALIZED, state_);
373 373
374 RegistrationList* registrations = new RegistrationList; 374 RegistrationList* registrations = new RegistrationList;
375 PostTaskAndReplyWithResult( 375 PostTaskAndReplyWithResult(
376 database_task_manager_->GetTaskRunner(), FROM_HERE, 376 database_task_manager_->GetTaskRunner(), FROM_HERE,
377 base::Bind(&ServiceWorkerDatabase::GetAllRegistrations, 377 base::Bind(&ServiceWorkerDatabase::GetAllRegistrations,
378 base::Unretained(database_.get()), registrations), 378 base::Unretained(database_.get()), registrations),
379 base::Bind(&ServiceWorkerStorage::DidGetRegistrationsInfos, 379 base::Bind(&ServiceWorkerStorage::DidGetAllRegistrationsInfos,
380 weak_factory_.GetWeakPtr(), callback, 380 weak_factory_.GetWeakPtr(), callback,
381 base::Owned(registrations), GURL())); 381 base::Owned(registrations)));
382 } 382 }
383 383
384 void ServiceWorkerStorage::StoreRegistration( 384 void ServiceWorkerStorage::StoreRegistration(
385 ServiceWorkerRegistration* registration, 385 ServiceWorkerRegistration* registration,
386 ServiceWorkerVersion* version, 386 ServiceWorkerVersion* version,
387 const StatusCallback& callback) { 387 const StatusCallback& callback) {
388 DCHECK(registration); 388 DCHECK(registration);
389 DCHECK(version); 389 DCHECK(version);
390 390
391 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_; 391 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_;
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 void ServiceWorkerStorage::ReturnFoundRegistration( 973 void ServiceWorkerStorage::ReturnFoundRegistration(
974 const FindRegistrationCallback& callback, 974 const FindRegistrationCallback& callback,
975 const ServiceWorkerDatabase::RegistrationData& data, 975 const ServiceWorkerDatabase::RegistrationData& data,
976 const ResourceList& resources) { 976 const ResourceList& resources) {
977 DCHECK(!resources.empty()); 977 DCHECK(!resources.empty());
978 scoped_refptr<ServiceWorkerRegistration> registration = 978 scoped_refptr<ServiceWorkerRegistration> registration =
979 GetOrCreateRegistration(data, resources); 979 GetOrCreateRegistration(data, resources);
980 CompleteFindNow(std::move(registration), SERVICE_WORKER_OK, callback); 980 CompleteFindNow(std::move(registration), SERVICE_WORKER_OK, callback);
981 } 981 }
982 982
983 void ServiceWorkerStorage::DidGetRegistrations( 983 void ServiceWorkerStorage::DidGetRegistrationsForOrigin(
984 const GetRegistrationsCallback& callback, 984 const GetRegistrationsCallback& callback,
985 RegistrationList* registration_data_list, 985 RegistrationList* registration_data_list,
986 std::vector<ResourceList>* resources_list, 986 std::vector<ResourceList>* resources_list,
987 const GURL& origin_filter, 987 const GURL& origin_filter,
988 ServiceWorkerDatabase::Status status) { 988 ServiceWorkerDatabase::Status status) {
989 DCHECK(registration_data_list); 989 DCHECK(registration_data_list);
990 DCHECK(resources_list); 990 DCHECK(resources_list);
991 DCHECK(origin_filter.is_valid());
991 992
992 if (status != ServiceWorkerDatabase::STATUS_OK && 993 if (status != ServiceWorkerDatabase::STATUS_OK &&
993 status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { 994 status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) {
994 ScheduleDeleteAndStartOver(); 995 ScheduleDeleteAndStartOver();
995 callback.Run(DatabaseStatusToStatusCode(status), 996 callback.Run(DatabaseStatusToStatusCode(status),
996 std::vector<scoped_refptr<ServiceWorkerRegistration>>()); 997 std::vector<scoped_refptr<ServiceWorkerRegistration>>());
997 return; 998 return;
998 } 999 }
999 1000
1000 // Add all stored registrations. 1001 // Add all stored registrations.
1001 std::set<int64_t> registration_ids; 1002 std::set<int64_t> registration_ids;
1002 std::vector<scoped_refptr<ServiceWorkerRegistration>> registrations; 1003 std::vector<scoped_refptr<ServiceWorkerRegistration>> registrations;
1003 size_t index = 0; 1004 size_t index = 0;
1004 for (const auto& registration_data : *registration_data_list) { 1005 for (const auto& registration_data : *registration_data_list) {
1005 registration_ids.insert(registration_data.registration_id); 1006 registration_ids.insert(registration_data.registration_id);
1006 registrations.push_back(GetOrCreateRegistration( 1007 registrations.push_back(GetOrCreateRegistration(
1007 registration_data, resources_list->at(index++))); 1008 registration_data, resources_list->at(index++)));
1008 } 1009 }
1009 1010
1010 // Add unstored registrations that are being installed. 1011 // Add unstored registrations that are being installed.
1011 for (const auto& registration : installing_registrations_) { 1012 for (const auto& registration : installing_registrations_) {
1012 if ((!origin_filter.is_valid() || 1013 if (registration.second->pattern().GetOrigin() != origin_filter)
1013 registration.second->pattern().GetOrigin() == origin_filter) && 1014 continue;
1014 registration_ids.insert(registration.first).second) { 1015 if (registration_ids.insert(registration.first).second)
1015 registrations.push_back(registration.second); 1016 registrations.push_back(registration.second);
1016 }
1017 } 1017 }
1018 1018
1019 callback.Run(SERVICE_WORKER_OK, std::move(registrations)); 1019 callback.Run(SERVICE_WORKER_OK, std::move(registrations));
1020 } 1020 }
1021 1021
1022 void ServiceWorkerStorage::DidGetRegistrationsInfos( 1022 void ServiceWorkerStorage::DidGetAllRegistrationsInfos(
1023 const GetRegistrationsInfosCallback& callback, 1023 const GetRegistrationsInfosCallback& callback,
1024 RegistrationList* registration_data_list, 1024 RegistrationList* registration_data_list,
1025 const GURL& origin_filter,
1026 ServiceWorkerDatabase::Status status) { 1025 ServiceWorkerDatabase::Status status) {
1027 DCHECK(registration_data_list); 1026 DCHECK(registration_data_list);
1028 if (status != ServiceWorkerDatabase::STATUS_OK && 1027 if (status != ServiceWorkerDatabase::STATUS_OK &&
1029 status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { 1028 status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) {
1030 ScheduleDeleteAndStartOver(); 1029 ScheduleDeleteAndStartOver();
1031 callback.Run(DatabaseStatusToStatusCode(status), 1030 callback.Run(DatabaseStatusToStatusCode(status),
1032 std::vector<ServiceWorkerRegistrationInfo>()); 1031 std::vector<ServiceWorkerRegistrationInfo>());
1033 return; 1032 return;
1034 } 1033 }
1035 1034
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 info.waiting_version.fetch_handler_existence = 1079 info.waiting_version.fetch_handler_existence =
1081 registration_data.has_fetch_handler 1080 registration_data.has_fetch_handler
1082 ? ServiceWorkerVersion::FetchHandlerExistence::EXISTS 1081 ? ServiceWorkerVersion::FetchHandlerExistence::EXISTS
1083 : ServiceWorkerVersion::FetchHandlerExistence::DOES_NOT_EXIST; 1082 : ServiceWorkerVersion::FetchHandlerExistence::DOES_NOT_EXIST;
1084 } 1083 }
1085 infos.push_back(info); 1084 infos.push_back(info);
1086 } 1085 }
1087 1086
1088 // Add unstored registrations that are being installed. 1087 // Add unstored registrations that are being installed.
1089 for (const auto& registration : installing_registrations_) { 1088 for (const auto& registration : installing_registrations_) {
1090 if ((!origin_filter.is_valid() || 1089 if (pushed_registrations.insert(registration.first).second)
1091 registration.second->pattern().GetOrigin() == origin_filter) &&
1092 pushed_registrations.insert(registration.first).second) {
1093 infos.push_back(registration.second->GetInfo()); 1090 infos.push_back(registration.second->GetInfo());
1094 }
1095 } 1091 }
1096 1092
1097 callback.Run(SERVICE_WORKER_OK, infos); 1093 callback.Run(SERVICE_WORKER_OK, infos);
1098 } 1094 }
1099 1095
1100 void ServiceWorkerStorage::DidStoreRegistration( 1096 void ServiceWorkerStorage::DidStoreRegistration(
1101 const StatusCallback& callback, 1097 const StatusCallback& callback,
1102 const ServiceWorkerDatabase::RegistrationData& new_version, 1098 const ServiceWorkerDatabase::RegistrationData& new_version,
1103 const GURL& origin, 1099 const GURL& origin,
1104 const ServiceWorkerDatabase::RegistrationData& deleted_version, 1100 const ServiceWorkerDatabase::RegistrationData& deleted_version,
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 callback.Run(SERVICE_WORKER_ERROR_FAILED); 1781 callback.Run(SERVICE_WORKER_ERROR_FAILED);
1786 return; 1782 return;
1787 } 1783 }
1788 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; 1784 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully.";
1789 ServiceWorkerMetrics::RecordDeleteAndStartOverResult( 1785 ServiceWorkerMetrics::RecordDeleteAndStartOverResult(
1790 ServiceWorkerMetrics::DELETE_OK); 1786 ServiceWorkerMetrics::DELETE_OK);
1791 callback.Run(SERVICE_WORKER_OK); 1787 callback.Run(SERVICE_WORKER_OK);
1792 } 1788 }
1793 1789
1794 } // namespace content 1790 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_storage.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698