diff options
author | jkarlin <jkarlin@chromium.org> | 2015-04-22 10:55:07 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-22 17:56:32 +0000 |
commit | 291aca9d228366c57cc5a70572c3571c3c5149be (patch) | |
tree | 921771a12d4cb80f5b219177e7fb8f677a7c3388 /content/browser/background_sync/background_sync_manager.cc | |
parent | 3a599661a49fa5ebfe63cb4016bb8efcd2d02712 (diff) | |
download | chromium_src-291aca9d228366c57cc5a70572c3571c3c5149be.zip chromium_src-291aca9d228366c57cc5a70572c3571c3c5149be.tar.gz chromium_src-291aca9d228366c57cc5a70572c3571c3c5149be.tar.bz2 |
[BackgroundSync] Store origin with registration data
The origin GURL needs to be stored along with the registration for
looking up service worker registrations (to start the necessary service worker and
fire its events).
BUG=479665
Review URL: https://codereview.chromium.org/1084043003
Cr-Commit-Position: refs/heads/master@{#326339}
Diffstat (limited to 'content/browser/background_sync/background_sync_manager.cc')
-rw-r--r-- | content/browser/background_sync/background_sync_manager.cc | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/content/browser/background_sync/background_sync_manager.cc b/content/browser/background_sync/background_sync_manager.cc index 0ab0234..3a7a958 100644 --- a/content/browser/background_sync/background_sync_manager.cc +++ b/content/browser/background_sync/background_sync_manager.cc @@ -28,10 +28,7 @@ BackgroundSyncManager::BackgroundSyncRegistrations:: BackgroundSyncRegistrations() : next_id(BackgroundSyncRegistration::kInitialId) { } -BackgroundSyncManager::BackgroundSyncRegistrations::BackgroundSyncRegistrations( - BackgroundSyncRegistration::RegistrationId next_id) - : next_id(next_id) { -} + BackgroundSyncManager::BackgroundSyncRegistrations:: ~BackgroundSyncRegistrations() { } @@ -206,10 +203,10 @@ void BackgroundSyncManager::InitDidGetDataFromBackend( for (const std::pair<int64, std::string>& data : user_data) { BackgroundSyncRegistrationsProto registrations_proto; if (registrations_proto.ParseFromString(data.second)) { - sw_to_registrations_map_[data.first] = BackgroundSyncRegistrations( - registrations_proto.next_registration_id()); BackgroundSyncRegistrations* registrations = &sw_to_registrations_map_[data.first]; + registrations->next_id = registrations_proto.next_registration_id(); + registrations->origin = GURL(registrations_proto.origin()); for (int i = 0, max = registrations_proto.registration_size(); i < max; ++i) { @@ -276,10 +273,10 @@ void BackgroundSyncManager::RegisterImpl( &sw_to_registrations_map_[sw_registration_id]; new_registration.id = registrations->next_id++; - AddRegistrationToMap(sw_registration_id, new_registration); + AddRegistrationToMap(sw_registration_id, origin, new_registration); StoreRegistrations( - origin, sw_registration_id, + sw_registration_id, base::Bind(&BackgroundSyncManager::RegisterDidStore, weak_ptr_factory_.GetWeakPtr(), sw_registration_id, new_registration, callback)); @@ -342,6 +339,9 @@ BackgroundSyncManager::LookupRegistration( return nullptr; BackgroundSyncRegistrations& registrations = it->second; + DCHECK_LE(BackgroundSyncRegistration::kInitialId, registrations.next_id); + DCHECK(!registrations.origin.is_empty()); + auto key_and_registration_iter = registrations.registration_map.find(registration_key); if (key_and_registration_iter == registrations.registration_map.end()) @@ -351,7 +351,6 @@ BackgroundSyncManager::LookupRegistration( } void BackgroundSyncManager::StoreRegistrations( - const GURL& origin, int64 sw_registration_id, const ServiceWorkerStorage::StatusCallback& callback) { // Serialize the data. @@ -359,6 +358,7 @@ void BackgroundSyncManager::StoreRegistrations( sw_to_registrations_map_[sw_registration_id]; BackgroundSyncRegistrationsProto registrations_proto; registrations_proto.set_next_registration_id(registrations.next_id); + registrations_proto.set_origin(registrations.origin.spec()); for (const auto& key_and_registration : registrations.registration_map) { const BackgroundSyncRegistration& registration = @@ -376,8 +376,8 @@ void BackgroundSyncManager::StoreRegistrations( bool success = registrations_proto.SerializeToString(&serialized); DCHECK(success); - StoreDataInBackend(sw_registration_id, origin, kBackgroundSyncUserDataKey, - serialized, callback); + StoreDataInBackend(sw_registration_id, registrations.origin, + kBackgroundSyncUserDataKey, serialized, callback); } void BackgroundSyncManager::RegisterDidStore( @@ -420,12 +420,14 @@ void BackgroundSyncManager::RemoveRegistrationFromMap( void BackgroundSyncManager::AddRegistrationToMap( int64 sw_registration_id, + const GURL& origin, const BackgroundSyncRegistration& sync_registration) { DCHECK_NE(BackgroundSyncRegistration::kInvalidRegistrationId, sw_registration_id); BackgroundSyncRegistrations* registrations = &sw_to_registrations_map_[sw_registration_id]; + registrations->origin = origin; RegistrationKey registration_key(sync_registration); registrations->registration_map[registration_key] = sync_registration; @@ -475,7 +477,7 @@ void BackgroundSyncManager::UnregisterImpl( RemoveRegistrationFromMap(sw_registration_id, registration_key); StoreRegistrations( - origin, sw_registration_id, + sw_registration_id, base::Bind(&BackgroundSyncManager::UnregisterDidStore, weak_ptr_factory_.GetWeakPtr(), sw_registration_id, callback)); } |