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_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 Loading... |
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 Loading... |
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 Loading... |
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 ServiceWorkerStatusCode installing_status = |
218 installing_registration ? SERVICE_WORKER_OK | 216 installing_registration ? SERVICE_WORKER_OK |
219 : SERVICE_WORKER_ERROR_NOT_FOUND, | 217 : SERVICE_WORKER_ERROR_NOT_FOUND; |
220 callback); | 218 CompleteFindSoon(FROM_HERE, std::move(installing_registration), |
| 219 installing_status, callback); |
221 return; | 220 return; |
222 } | 221 } |
223 | 222 |
224 database_task_manager_->GetTaskRunner()->PostTask( | 223 database_task_manager_->GetTaskRunner()->PostTask( |
225 FROM_HERE, | 224 FROM_HERE, |
226 base::Bind( | 225 base::Bind( |
227 &FindForPatternInDB, | 226 &FindForPatternInDB, |
228 database_.get(), | 227 database_.get(), |
229 base::ThreadTaskRunnerHandle::Get(), | 228 base::ThreadTaskRunnerHandle::Get(), |
230 scope, | 229 scope, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 CompleteFindNow(installing_registration, | 269 CompleteFindNow(installing_registration, |
271 installing_registration ? SERVICE_WORKER_OK | 270 installing_registration ? SERVICE_WORKER_OK |
272 : SERVICE_WORKER_ERROR_NOT_FOUND, | 271 : SERVICE_WORKER_ERROR_NOT_FOUND, |
273 callback); | 272 callback); |
274 return; | 273 return; |
275 } | 274 } |
276 | 275 |
277 scoped_refptr<ServiceWorkerRegistration> registration = | 276 scoped_refptr<ServiceWorkerRegistration> registration = |
278 context_->GetLiveRegistration(registration_id); | 277 context_->GetLiveRegistration(registration_id); |
279 if (registration) { | 278 if (registration) { |
280 CompleteFindNow(registration, SERVICE_WORKER_OK, callback); | 279 CompleteFindNow(std::move(registration), SERVICE_WORKER_OK, callback); |
281 return; | 280 return; |
282 } | 281 } |
283 | 282 |
284 database_task_manager_->GetTaskRunner()->PostTask( | 283 database_task_manager_->GetTaskRunner()->PostTask( |
285 FROM_HERE, | 284 FROM_HERE, |
286 base::Bind(&FindForIdInDB, | 285 base::Bind(&FindForIdInDB, |
287 database_.get(), | 286 database_.get(), |
288 base::ThreadTaskRunnerHandle::Get(), | 287 base::ThreadTaskRunnerHandle::Get(), |
289 registration_id, | 288 registration_id, |
290 origin, | 289 origin, |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 return; | 888 return; |
890 } | 889 } |
891 | 890 |
892 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { | 891 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { |
893 // Look for something currently being installed. | 892 // Look for something currently being installed. |
894 scoped_refptr<ServiceWorkerRegistration> installing_registration = | 893 scoped_refptr<ServiceWorkerRegistration> installing_registration = |
895 FindInstallingRegistrationForDocument(document_url); | 894 FindInstallingRegistrationForDocument(document_url); |
896 ServiceWorkerStatusCode installing_status = | 895 ServiceWorkerStatusCode installing_status = |
897 installing_registration ? SERVICE_WORKER_OK | 896 installing_registration ? SERVICE_WORKER_OK |
898 : SERVICE_WORKER_ERROR_NOT_FOUND; | 897 : SERVICE_WORKER_ERROR_NOT_FOUND; |
899 callback.Run(installing_status, installing_registration); | 898 callback.Run(installing_status, std::move(installing_registration)); |
900 TRACE_EVENT_ASYNC_END2( | 899 TRACE_EVENT_ASYNC_END2( |
901 "ServiceWorker", | 900 "ServiceWorker", |
902 "ServiceWorkerStorage::FindRegistrationForDocument", | 901 "ServiceWorkerStorage::FindRegistrationForDocument", |
903 callback_id, | 902 callback_id, |
904 "Status", ServiceWorkerDatabase::StatusToString(status), | 903 "Status", ServiceWorkerDatabase::StatusToString(status), |
905 "Info", | 904 "Info", |
906 (installing_status == SERVICE_WORKER_OK) ? | 905 (installing_status == SERVICE_WORKER_OK) ? |
907 "Installing registration is found" : | 906 "Installing registration is found" : |
908 "Any registrations are not found"); | 907 "Any registrations are not found"); |
909 return; | 908 return; |
(...skipping 16 matching lines...) Expand all Loading... |
926 const ResourceList& resources, | 925 const ResourceList& resources, |
927 ServiceWorkerDatabase::Status status) { | 926 ServiceWorkerDatabase::Status status) { |
928 if (status == ServiceWorkerDatabase::STATUS_OK) { | 927 if (status == ServiceWorkerDatabase::STATUS_OK) { |
929 ReturnFoundRegistration(callback, data, resources); | 928 ReturnFoundRegistration(callback, data, resources); |
930 return; | 929 return; |
931 } | 930 } |
932 | 931 |
933 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { | 932 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { |
934 scoped_refptr<ServiceWorkerRegistration> installing_registration = | 933 scoped_refptr<ServiceWorkerRegistration> installing_registration = |
935 FindInstallingRegistrationForPattern(scope); | 934 FindInstallingRegistrationForPattern(scope); |
936 callback.Run(installing_registration ? SERVICE_WORKER_OK | 935 ServiceWorkerStatusCode installing_status = |
937 : SERVICE_WORKER_ERROR_NOT_FOUND, | 936 installing_registration ? SERVICE_WORKER_OK |
938 installing_registration); | 937 : SERVICE_WORKER_ERROR_NOT_FOUND; |
| 938 callback.Run(installing_status, std::move(installing_registration)); |
939 return; | 939 return; |
940 } | 940 } |
941 | 941 |
942 ScheduleDeleteAndStartOver(); | 942 ScheduleDeleteAndStartOver(); |
943 callback.Run(DatabaseStatusToStatusCode(status), | 943 callback.Run(DatabaseStatusToStatusCode(status), |
944 scoped_refptr<ServiceWorkerRegistration>()); | 944 scoped_refptr<ServiceWorkerRegistration>()); |
945 } | 945 } |
946 | 946 |
947 void ServiceWorkerStorage::DidFindRegistrationForId( | 947 void ServiceWorkerStorage::DidFindRegistrationForId( |
948 const FindRegistrationCallback& callback, | 948 const FindRegistrationCallback& callback, |
(...skipping 17 matching lines...) Expand all Loading... |
966 scoped_refptr<ServiceWorkerRegistration>()); | 966 scoped_refptr<ServiceWorkerRegistration>()); |
967 } | 967 } |
968 | 968 |
969 void ServiceWorkerStorage::ReturnFoundRegistration( | 969 void ServiceWorkerStorage::ReturnFoundRegistration( |
970 const FindRegistrationCallback& callback, | 970 const FindRegistrationCallback& callback, |
971 const ServiceWorkerDatabase::RegistrationData& data, | 971 const ServiceWorkerDatabase::RegistrationData& data, |
972 const ResourceList& resources) { | 972 const ResourceList& resources) { |
973 DCHECK(!resources.empty()); | 973 DCHECK(!resources.empty()); |
974 scoped_refptr<ServiceWorkerRegistration> registration = | 974 scoped_refptr<ServiceWorkerRegistration> registration = |
975 GetOrCreateRegistration(data, resources); | 975 GetOrCreateRegistration(data, resources); |
976 CompleteFindNow(registration, SERVICE_WORKER_OK, callback); | 976 CompleteFindNow(std::move(registration), SERVICE_WORKER_OK, callback); |
977 } | 977 } |
978 | 978 |
979 void ServiceWorkerStorage::DidGetRegistrations( | 979 void ServiceWorkerStorage::DidGetRegistrations( |
980 const GetRegistrationsCallback& callback, | 980 const GetRegistrationsCallback& callback, |
981 RegistrationList* registration_data_list, | 981 RegistrationList* registration_data_list, |
982 std::vector<ResourceList>* resources_list, | 982 std::vector<ResourceList>* resources_list, |
983 const GURL& origin_filter, | 983 const GURL& origin_filter, |
984 ServiceWorkerDatabase::Status status) { | 984 ServiceWorkerDatabase::Status status) { |
985 DCHECK(registration_data_list); | 985 DCHECK(registration_data_list); |
986 DCHECK(resources_list); | 986 DCHECK(resources_list); |
(...skipping 18 matching lines...) Expand all Loading... |
1005 | 1005 |
1006 // Add unstored registrations that are being installed. | 1006 // Add unstored registrations that are being installed. |
1007 for (const auto& registration : installing_registrations_) { | 1007 for (const auto& registration : installing_registrations_) { |
1008 if ((!origin_filter.is_valid() || | 1008 if ((!origin_filter.is_valid() || |
1009 registration.second->pattern().GetOrigin() == origin_filter) && | 1009 registration.second->pattern().GetOrigin() == origin_filter) && |
1010 registration_ids.insert(registration.first).second) { | 1010 registration_ids.insert(registration.first).second) { |
1011 registrations.push_back(registration.second); | 1011 registrations.push_back(registration.second); |
1012 } | 1012 } |
1013 } | 1013 } |
1014 | 1014 |
1015 callback.Run(SERVICE_WORKER_OK, registrations); | 1015 callback.Run(SERVICE_WORKER_OK, std::move(registrations)); |
1016 } | 1016 } |
1017 | 1017 |
1018 void ServiceWorkerStorage::DidGetRegistrationsInfos( | 1018 void ServiceWorkerStorage::DidGetRegistrationsInfos( |
1019 const GetRegistrationsInfosCallback& callback, | 1019 const GetRegistrationsInfosCallback& callback, |
1020 RegistrationList* registration_data_list, | 1020 RegistrationList* registration_data_list, |
1021 const GURL& origin_filter, | 1021 const GURL& origin_filter, |
1022 ServiceWorkerDatabase::Status status) { | 1022 ServiceWorkerDatabase::Status status) { |
1023 DCHECK(registration_data_list); | 1023 DCHECK(registration_data_list); |
1024 if (status != ServiceWorkerDatabase::STATUS_OK && | 1024 if (status != ServiceWorkerDatabase::STATUS_OK && |
1025 status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { | 1025 status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1770 callback.Run(SERVICE_WORKER_ERROR_FAILED); | 1770 callback.Run(SERVICE_WORKER_ERROR_FAILED); |
1771 return; | 1771 return; |
1772 } | 1772 } |
1773 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; | 1773 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; |
1774 ServiceWorkerMetrics::RecordDeleteAndStartOverResult( | 1774 ServiceWorkerMetrics::RecordDeleteAndStartOverResult( |
1775 ServiceWorkerMetrics::DELETE_OK); | 1775 ServiceWorkerMetrics::DELETE_OK); |
1776 callback.Run(SERVICE_WORKER_OK); | 1776 callback.Run(SERVICE_WORKER_OK); |
1777 } | 1777 } |
1778 | 1778 |
1779 } // namespace content | 1779 } // namespace content |
OLD | NEW |