summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjkarlin <jkarlin@chromium.org>2015-04-22 10:55:07 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-22 17:56:32 +0000
commit291aca9d228366c57cc5a70572c3571c3c5149be (patch)
tree921771a12d4cb80f5b219177e7fb8f677a7c3388
parent3a599661a49fa5ebfe63cb4016bb8efcd2d02712 (diff)
downloadchromium_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}
-rw-r--r--content/browser/background_sync/background_sync.proto1
-rw-r--r--content/browser/background_sync/background_sync_manager.cc26
-rw-r--r--content/browser/background_sync/background_sync_manager.h7
3 files changed, 18 insertions, 16 deletions
diff --git a/content/browser/background_sync/background_sync.proto b/content/browser/background_sync/background_sync.proto
index b5f2e09..895117d 100644
--- a/content/browser/background_sync/background_sync.proto
+++ b/content/browser/background_sync/background_sync.proto
@@ -36,4 +36,5 @@ message BackgroundSyncRegistrationProto {
message BackgroundSyncRegistrationsProto {
repeated BackgroundSyncRegistrationProto registration = 1;
required int64 next_registration_id = 2;
+ required string origin = 3;
} \ No newline at end of file
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));
}
diff --git a/content/browser/background_sync/background_sync_manager.h b/content/browser/background_sync/background_sync_manager.h
index d9925a6..a4d7714 100644
--- a/content/browser/background_sync/background_sync_manager.h
+++ b/content/browser/background_sync/background_sync_manager.h
@@ -157,12 +157,11 @@ class CONTENT_EXPORT BackgroundSyncManager
std::map<RegistrationKey, BackgroundSyncRegistration>;
BackgroundSyncRegistrations();
- explicit BackgroundSyncRegistrations(
- BackgroundSyncRegistration::RegistrationId next_id);
~BackgroundSyncRegistrations();
RegistrationMap registration_map;
BackgroundSyncRegistration::RegistrationId next_id;
+ GURL origin;
};
using PermissionStatusCallback = base::Callback<void(bool)>;
@@ -188,8 +187,7 @@ class CONTENT_EXPORT BackgroundSyncManager
const RegistrationKey& registration_key);
// Store all registrations for a given |sw_registration_id|.
- void StoreRegistrations(const GURL& origin,
- int64 sw_registration_id,
+ void StoreRegistrations(int64 sw_registration_id,
const ServiceWorkerStorage::StatusCallback& callback);
// Removes the registration if it is in the map.
@@ -198,6 +196,7 @@ class CONTENT_EXPORT BackgroundSyncManager
void AddRegistrationToMap(
int64 sw_registration_id,
+ const GURL& origin,
const BackgroundSyncRegistration& sync_registration);
void InitImpl(const base::Closure& callback);