OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/background_sync/background_sync_manager.h" | 5 #include "content/browser/background_sync/background_sync_manager.h" |
6 | 6 |
7 #include "base/barrier_closure.h" | 7 #include "base/barrier_closure.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "content/browser/background_sync/background_sync.pb.h" | |
10 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 9 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
11 #include "content/browser/service_worker/service_worker_storage.h" | 10 #include "content/browser/service_worker/service_worker_storage.h" |
12 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
13 | 12 |
14 namespace { | 13 namespace { |
15 const char kBackgroundSyncUserDataKey[] = "BackgroundSyncUserData"; | 14 const char kBackgroundSyncUserDataKey[] = "BackgroundSyncUserData"; |
16 } | 15 } |
17 | 16 |
18 namespace content { | 17 namespace content { |
19 | 18 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 for (int i = 0, max = registrations_proto.registration_size(); i < max; | 186 for (int i = 0, max = registrations_proto.registration_size(); i < max; |
188 ++i) { | 187 ++i) { |
189 const BackgroundSyncRegistrationProto& registration_proto = | 188 const BackgroundSyncRegistrationProto& registration_proto = |
190 registrations_proto.registration(i); | 189 registrations_proto.registration(i); |
191 | 190 |
192 if (registration_proto.id() >= registrations->next_id) { | 191 if (registration_proto.id() >= registrations->next_id) { |
193 corruption_detected = true; | 192 corruption_detected = true; |
194 break; | 193 break; |
195 } | 194 } |
196 | 195 |
197 BackgroundSyncRegistration registration(registration_proto.id(), | 196 BackgroundSyncRegistration* registration = |
198 registration_proto.name()); | 197 ®istrations->name_to_registration_map[registration_proto.name()]; |
199 if (registration_proto.has_min_period()) | 198 |
200 registration.min_period = registration_proto.min_period(); | 199 registration->id = registration_proto.id(); |
201 registrations->name_to_registration_map[registration_proto.name()] = | 200 registration->name = registration_proto.name(); |
202 registration; | 201 registration->fire_once = registration_proto.fire_once(); |
| 202 registration->min_period = registration_proto.min_period(); |
| 203 registration->network_state = registration_proto.network_state(); |
| 204 registration->power_state = registration_proto.power_state(); |
203 } | 205 } |
204 } | 206 } |
205 | 207 |
206 if (corruption_detected) | 208 if (corruption_detected) |
207 break; | 209 break; |
208 } | 210 } |
209 | 211 |
210 if (corruption_detected) { | 212 if (corruption_detected) { |
211 LOG(ERROR) << "Corruption detected in background sync backend"; | 213 LOG(ERROR) << "Corruption detected in background sync backend"; |
212 DisableAndClearManager(base::Bind(callback)); | 214 DisableAndClearManager(base::Bind(callback)); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 registrations_proto.set_next_registration_id(registrations.next_id); | 337 registrations_proto.set_next_registration_id(registrations.next_id); |
336 | 338 |
337 for (const auto& name_and_registration : | 339 for (const auto& name_and_registration : |
338 registrations.name_to_registration_map) { | 340 registrations.name_to_registration_map) { |
339 const BackgroundSyncRegistration& registration = | 341 const BackgroundSyncRegistration& registration = |
340 name_and_registration.second; | 342 name_and_registration.second; |
341 BackgroundSyncRegistrationProto* registration_proto = | 343 BackgroundSyncRegistrationProto* registration_proto = |
342 registrations_proto.add_registration(); | 344 registrations_proto.add_registration(); |
343 registration_proto->set_id(registration.id); | 345 registration_proto->set_id(registration.id); |
344 registration_proto->set_name(registration.name); | 346 registration_proto->set_name(registration.name); |
345 if (registration.min_period != 0) | 347 registration_proto->set_fire_once(registration.fire_once); |
346 registration_proto->set_min_period(registration.min_period); | 348 registration_proto->set_min_period(registration.min_period); |
| 349 registration_proto->set_network_state(registration.network_state); |
| 350 registration_proto->set_power_state(registration.power_state); |
347 } | 351 } |
348 std::string serialized; | 352 std::string serialized; |
349 bool success = registrations_proto.SerializeToString(&serialized); | 353 bool success = registrations_proto.SerializeToString(&serialized); |
350 DCHECK(success); | 354 DCHECK(success); |
351 | 355 |
352 StoreDataInBackend(sw_registration_id, origin, kBackgroundSyncUserDataKey, | 356 StoreDataInBackend(sw_registration_id, origin, kBackgroundSyncUserDataKey, |
353 serialized, callback); | 357 serialized, callback); |
354 } | 358 } |
355 | 359 |
356 void BackgroundSyncManager::RegisterDidStore( | 360 void BackgroundSyncManager::RegisterDidStore( |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 weak_ptr_factory_.GetWeakPtr(), callback); | 573 weak_ptr_factory_.GetWeakPtr(), callback); |
570 } | 574 } |
571 | 575 |
572 BackgroundSyncManager::StatusCallback | 576 BackgroundSyncManager::StatusCallback |
573 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { | 577 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { |
574 return base::Bind(&BackgroundSyncManager::PendingStatusCallback, | 578 return base::Bind(&BackgroundSyncManager::PendingStatusCallback, |
575 weak_ptr_factory_.GetWeakPtr(), callback); | 579 weak_ptr_factory_.GetWeakPtr(), callback); |
576 } | 580 } |
577 | 581 |
578 } // namespace content | 582 } // namespace content |
OLD | NEW |