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

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

Issue 2181553003: Stop passing const-reference of SWRegistration in all GetRegistrationsCallbacks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use std::move Created 4 years, 5 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_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 21 matching lines...) Expand all
32 namespace content { 32 namespace content {
33 33
34 namespace { 34 namespace {
35 35
36 void RunSoon(const tracked_objects::Location& from_here, 36 void RunSoon(const tracked_objects::Location& from_here,
37 const base::Closure& closure) { 37 const base::Closure& closure) {
38 base::ThreadTaskRunnerHandle::Get()->PostTask(from_here, closure); 38 base::ThreadTaskRunnerHandle::Get()->PostTask(from_here, closure);
39 } 39 }
40 40
41 void CompleteFindNow( 41 void CompleteFindNow(
42 const scoped_refptr<ServiceWorkerRegistration>& registration, 42 scoped_refptr<ServiceWorkerRegistration> registration,
43 ServiceWorkerStatusCode status, 43 ServiceWorkerStatusCode status,
44 const ServiceWorkerStorage::FindRegistrationCallback& callback) { 44 const ServiceWorkerStorage::FindRegistrationCallback& callback) {
45 if (registration && registration->is_deleted()) { 45 if (registration && registration->is_deleted()) {
46 // It's past the point of no return and no longer findable. 46 // It's past the point of no return and no longer findable.
47 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND, nullptr); 47 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND, nullptr);
48 return; 48 return;
49 } 49 }
50 callback.Run(status, registration); 50 callback.Run(status, std::move(registration));
51 } 51 }
52 52
53 void CompleteFindSoon( 53 void CompleteFindSoon(
54 const tracked_objects::Location& from_here, 54 const tracked_objects::Location& from_here,
55 const scoped_refptr<ServiceWorkerRegistration>& registration, 55 scoped_refptr<ServiceWorkerRegistration> registration,
56 ServiceWorkerStatusCode status, 56 ServiceWorkerStatusCode status,
57 const ServiceWorkerStorage::FindRegistrationCallback& callback) { 57 const ServiceWorkerStorage::FindRegistrationCallback& callback) {
58 RunSoon(from_here, 58 RunSoon(from_here, base::Bind(&CompleteFindNow, std::move(registration),
59 base::Bind(&CompleteFindNow, registration, status, callback)); 59 status, callback));
60 } 60 }
61 61
62 const base::FilePath::CharType kDatabaseName[] = 62 const base::FilePath::CharType kDatabaseName[] =
63 FILE_PATH_LITERAL("Database"); 63 FILE_PATH_LITERAL("Database");
64 const base::FilePath::CharType kDiskCacheName[] = 64 const base::FilePath::CharType kDiskCacheName[] =
65 FILE_PATH_LITERAL("ScriptCache"); 65 FILE_PATH_LITERAL("ScriptCache");
66 66
67 const int kMaxMemDiskCacheSize = 10 * 1024 * 1024; 67 const int kMaxMemDiskCacheSize = 10 * 1024 * 1024;
68 const int kMaxDiskCacheSize = 250 * 1024 * 1024; 68 const int kMaxDiskCacheSize = 250 * 1024 * 1024;
69 69
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 FindInstallingRegistrationForDocument(document_url); 160 FindInstallingRegistrationForDocument(document_url);
161 ServiceWorkerStatusCode status = installing_registration 161 ServiceWorkerStatusCode status = installing_registration
162 ? SERVICE_WORKER_OK 162 ? SERVICE_WORKER_OK
163 : SERVICE_WORKER_ERROR_NOT_FOUND; 163 : SERVICE_WORKER_ERROR_NOT_FOUND;
164 TRACE_EVENT_INSTANT2( 164 TRACE_EVENT_INSTANT2(
165 "ServiceWorker", 165 "ServiceWorker",
166 "ServiceWorkerStorage::FindRegistrationForDocument:CheckInstalling", 166 "ServiceWorkerStorage::FindRegistrationForDocument:CheckInstalling",
167 TRACE_EVENT_SCOPE_THREAD, 167 TRACE_EVENT_SCOPE_THREAD,
168 "URL", document_url.spec(), 168 "URL", document_url.spec(),
169 "Status", ServiceWorkerStatusToString(status)); 169 "Status", ServiceWorkerStatusToString(status));
170 CompleteFindNow(installing_registration, 170 CompleteFindNow(std::move(installing_registration), status, callback);
171 status,
172 callback);
173 return; 171 return;
174 } 172 }
175 173
176 // To connect this TRACE_EVENT with the callback, TimeTicks is used for 174 // To connect this TRACE_EVENT with the callback, TimeTicks is used for
177 // callback id. 175 // callback id.
178 int64_t callback_id = base::TimeTicks::Now().ToInternalValue(); 176 int64_t callback_id = base::TimeTicks::Now().ToInternalValue();
179 TRACE_EVENT_ASYNC_BEGIN1( 177 TRACE_EVENT_ASYNC_BEGIN1(
180 "ServiceWorker", 178 "ServiceWorker",
181 "ServiceWorkerStorage::FindRegistrationForDocument", 179 "ServiceWorkerStorage::FindRegistrationForDocument",
182 callback_id, 180 callback_id,
(...skipping 24 matching lines...) Expand all
207 } 205 }
208 return; 206 return;
209 } 207 }
210 DCHECK_EQ(INITIALIZED, state_); 208 DCHECK_EQ(INITIALIZED, state_);
211 209
212 // See if there are any stored registrations for the origin. 210 // See if there are any stored registrations for the origin.
213 if (!ContainsKey(registered_origins_, scope.GetOrigin())) { 211 if (!ContainsKey(registered_origins_, scope.GetOrigin())) {
214 // Look for something currently being installed. 212 // Look for something currently being installed.
215 scoped_refptr<ServiceWorkerRegistration> installing_registration = 213 scoped_refptr<ServiceWorkerRegistration> installing_registration =
216 FindInstallingRegistrationForPattern(scope); 214 FindInstallingRegistrationForPattern(scope);
217 CompleteFindSoon(FROM_HERE, installing_registration, 215 CompleteFindSoon(FROM_HERE, std::move(installing_registration),
218 installing_registration ? SERVICE_WORKER_OK 216 installing_registration ? SERVICE_WORKER_OK
nhiroki 2016/07/25 09:15:40 This ternary operation may be evaluated after the
horo 2016/07/25 09:32:01 Done.
219 : SERVICE_WORKER_ERROR_NOT_FOUND, 217 : SERVICE_WORKER_ERROR_NOT_FOUND,
220 callback); 218 callback);
221 return; 219 return;
222 } 220 }
223 221
224 database_task_manager_->GetTaskRunner()->PostTask( 222 database_task_manager_->GetTaskRunner()->PostTask(
225 FROM_HERE, 223 FROM_HERE,
226 base::Bind( 224 base::Bind(
227 &FindForPatternInDB, 225 &FindForPatternInDB,
228 database_.get(), 226 database_.get(),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 CompleteFindNow(installing_registration, 268 CompleteFindNow(installing_registration,
271 installing_registration ? SERVICE_WORKER_OK 269 installing_registration ? SERVICE_WORKER_OK
272 : SERVICE_WORKER_ERROR_NOT_FOUND, 270 : SERVICE_WORKER_ERROR_NOT_FOUND,
273 callback); 271 callback);
274 return; 272 return;
275 } 273 }
276 274
277 scoped_refptr<ServiceWorkerRegistration> registration = 275 scoped_refptr<ServiceWorkerRegistration> registration =
278 context_->GetLiveRegistration(registration_id); 276 context_->GetLiveRegistration(registration_id);
279 if (registration) { 277 if (registration) {
280 CompleteFindNow(registration, SERVICE_WORKER_OK, callback); 278 CompleteFindNow(std::move(registration), SERVICE_WORKER_OK, callback);
281 return; 279 return;
282 } 280 }
283 281
284 database_task_manager_->GetTaskRunner()->PostTask( 282 database_task_manager_->GetTaskRunner()->PostTask(
285 FROM_HERE, 283 FROM_HERE,
286 base::Bind(&FindForIdInDB, 284 base::Bind(&FindForIdInDB,
287 database_.get(), 285 database_.get(),
288 base::ThreadTaskRunnerHandle::Get(), 286 base::ThreadTaskRunnerHandle::Get(),
289 registration_id, 287 registration_id,
290 origin, 288 origin,
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 return; 887 return;
890 } 888 }
891 889
892 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { 890 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) {
893 // Look for something currently being installed. 891 // Look for something currently being installed.
894 scoped_refptr<ServiceWorkerRegistration> installing_registration = 892 scoped_refptr<ServiceWorkerRegistration> installing_registration =
895 FindInstallingRegistrationForDocument(document_url); 893 FindInstallingRegistrationForDocument(document_url);
896 ServiceWorkerStatusCode installing_status = 894 ServiceWorkerStatusCode installing_status =
897 installing_registration ? SERVICE_WORKER_OK 895 installing_registration ? SERVICE_WORKER_OK
898 : SERVICE_WORKER_ERROR_NOT_FOUND; 896 : SERVICE_WORKER_ERROR_NOT_FOUND;
899 callback.Run(installing_status, installing_registration); 897 callback.Run(installing_status, std::move(installing_registration));
900 TRACE_EVENT_ASYNC_END2( 898 TRACE_EVENT_ASYNC_END2(
901 "ServiceWorker", 899 "ServiceWorker",
902 "ServiceWorkerStorage::FindRegistrationForDocument", 900 "ServiceWorkerStorage::FindRegistrationForDocument",
903 callback_id, 901 callback_id,
904 "Status", ServiceWorkerDatabase::StatusToString(status), 902 "Status", ServiceWorkerDatabase::StatusToString(status),
905 "Info", 903 "Info",
906 (installing_status == SERVICE_WORKER_OK) ? 904 (installing_status == SERVICE_WORKER_OK) ?
907 "Installing registration is found" : 905 "Installing registration is found" :
908 "Any registrations are not found"); 906 "Any registrations are not found");
909 return; 907 return;
(...skipping 16 matching lines...) Expand all
926 const ResourceList& resources, 924 const ResourceList& resources,
927 ServiceWorkerDatabase::Status status) { 925 ServiceWorkerDatabase::Status status) {
928 if (status == ServiceWorkerDatabase::STATUS_OK) { 926 if (status == ServiceWorkerDatabase::STATUS_OK) {
929 ReturnFoundRegistration(callback, data, resources); 927 ReturnFoundRegistration(callback, data, resources);
930 return; 928 return;
931 } 929 }
932 930
933 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { 931 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) {
934 scoped_refptr<ServiceWorkerRegistration> installing_registration = 932 scoped_refptr<ServiceWorkerRegistration> installing_registration =
935 FindInstallingRegistrationForPattern(scope); 933 FindInstallingRegistrationForPattern(scope);
936 callback.Run(installing_registration ? SERVICE_WORKER_OK 934 ServiceWorkerStatusCode installing_status =
937 : SERVICE_WORKER_ERROR_NOT_FOUND, 935 installing_registration ? SERVICE_WORKER_OK
938 installing_registration); 936 : SERVICE_WORKER_ERROR_NOT_FOUND;
937 callback.Run(installing_status, std::move(installing_registration));
939 return; 938 return;
940 } 939 }
941 940
942 ScheduleDeleteAndStartOver(); 941 ScheduleDeleteAndStartOver();
943 callback.Run(DatabaseStatusToStatusCode(status), 942 callback.Run(DatabaseStatusToStatusCode(status),
944 scoped_refptr<ServiceWorkerRegistration>()); 943 scoped_refptr<ServiceWorkerRegistration>());
945 } 944 }
946 945
947 void ServiceWorkerStorage::DidFindRegistrationForId( 946 void ServiceWorkerStorage::DidFindRegistrationForId(
948 const FindRegistrationCallback& callback, 947 const FindRegistrationCallback& callback,
(...skipping 17 matching lines...) Expand all
966 scoped_refptr<ServiceWorkerRegistration>()); 965 scoped_refptr<ServiceWorkerRegistration>());
967 } 966 }
968 967
969 void ServiceWorkerStorage::ReturnFoundRegistration( 968 void ServiceWorkerStorage::ReturnFoundRegistration(
970 const FindRegistrationCallback& callback, 969 const FindRegistrationCallback& callback,
971 const ServiceWorkerDatabase::RegistrationData& data, 970 const ServiceWorkerDatabase::RegistrationData& data,
972 const ResourceList& resources) { 971 const ResourceList& resources) {
973 DCHECK(!resources.empty()); 972 DCHECK(!resources.empty());
974 scoped_refptr<ServiceWorkerRegistration> registration = 973 scoped_refptr<ServiceWorkerRegistration> registration =
975 GetOrCreateRegistration(data, resources); 974 GetOrCreateRegistration(data, resources);
976 CompleteFindNow(registration, SERVICE_WORKER_OK, callback); 975 CompleteFindNow(std::move(registration), SERVICE_WORKER_OK, callback);
977 } 976 }
978 977
979 void ServiceWorkerStorage::DidGetRegistrations( 978 void ServiceWorkerStorage::DidGetRegistrations(
980 const GetRegistrationsCallback& callback, 979 const GetRegistrationsCallback& callback,
981 RegistrationList* registration_data_list, 980 RegistrationList* registration_data_list,
982 std::vector<ResourceList>* resources_list, 981 std::vector<ResourceList>* resources_list,
983 const GURL& origin_filter, 982 const GURL& origin_filter,
984 ServiceWorkerDatabase::Status status) { 983 ServiceWorkerDatabase::Status status) {
985 DCHECK(registration_data_list); 984 DCHECK(registration_data_list);
986 DCHECK(resources_list); 985 DCHECK(resources_list);
(...skipping 18 matching lines...) Expand all
1005 1004
1006 // Add unstored registrations that are being installed. 1005 // Add unstored registrations that are being installed.
1007 for (const auto& registration : installing_registrations_) { 1006 for (const auto& registration : installing_registrations_) {
1008 if ((!origin_filter.is_valid() || 1007 if ((!origin_filter.is_valid() ||
1009 registration.second->pattern().GetOrigin() == origin_filter) && 1008 registration.second->pattern().GetOrigin() == origin_filter) &&
1010 registration_ids.insert(registration.first).second) { 1009 registration_ids.insert(registration.first).second) {
1011 registrations.push_back(registration.second); 1010 registrations.push_back(registration.second);
1012 } 1011 }
1013 } 1012 }
1014 1013
1015 callback.Run(SERVICE_WORKER_OK, registrations); 1014 callback.Run(SERVICE_WORKER_OK, std::move(registrations));
1016 } 1015 }
1017 1016
1018 void ServiceWorkerStorage::DidGetRegistrationsInfos( 1017 void ServiceWorkerStorage::DidGetRegistrationsInfos(
1019 const GetRegistrationsInfosCallback& callback, 1018 const GetRegistrationsInfosCallback& callback,
1020 RegistrationList* registration_data_list, 1019 RegistrationList* registration_data_list,
1021 const GURL& origin_filter, 1020 const GURL& origin_filter,
1022 ServiceWorkerDatabase::Status status) { 1021 ServiceWorkerDatabase::Status status) {
1023 DCHECK(registration_data_list); 1022 DCHECK(registration_data_list);
1024 if (status != ServiceWorkerDatabase::STATUS_OK && 1023 if (status != ServiceWorkerDatabase::STATUS_OK &&
1025 status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { 1024 status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) {
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 callback.Run(SERVICE_WORKER_ERROR_FAILED); 1769 callback.Run(SERVICE_WORKER_ERROR_FAILED);
1771 return; 1770 return;
1772 } 1771 }
1773 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; 1772 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully.";
1774 ServiceWorkerMetrics::RecordDeleteAndStartOverResult( 1773 ServiceWorkerMetrics::RecordDeleteAndStartOverResult(
1775 ServiceWorkerMetrics::DELETE_OK); 1774 ServiceWorkerMetrics::DELETE_OK);
1776 callback.Run(SERVICE_WORKER_OK); 1775 callback.Run(SERVICE_WORKER_OK);
1777 } 1776 }
1778 1777
1779 } // namespace content 1778 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698