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

Unified Diff: content/browser/service_worker/service_worker_storage.cc

Issue 248803003: ServiceWorker: Store registration data in ServiceWorkerDatabase (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_storage.cc
diff --git a/content/browser/service_worker/service_worker_storage.cc b/content/browser/service_worker/service_worker_storage.cc
index c78f2ac8af0d41ff9971dd7c713869c6c14bbb83..1b2005daf12f6b6283b6f66a4ab92c41ca277924 100644
--- a/content/browser/service_worker/service_worker_storage.cc
+++ b/content/browser/service_worker/service_worker_storage.cc
@@ -5,8 +5,10 @@
#include "content/browser/service_worker/service_worker_storage.h"
#include <string>
+
#include "base/message_loop/message_loop.h"
#include "content/browser/service_worker/service_worker_context_core.h"
+#include "content/browser/service_worker/service_worker_database.pb.h"
#include "content/browser/service_worker/service_worker_info.h"
#include "content/browser/service_worker/service_worker_registration.h"
#include "content/browser/service_worker/service_worker_utils.h"
@@ -25,6 +27,11 @@ void RunSoon(const base::Closure& closure) {
const base::FilePath::CharType kServiceWorkerDirectory[] =
FILE_PATH_LITERAL("ServiceWorker");
+ServiceWorkerVersion::Status GetVersionStatus(bool is_active) {
+ return is_active ? ServiceWorkerVersion::ACTIVE
+ : ServiceWorkerVersion::INSTALLED;
+}
+
} // namespace
ServiceWorkerStorage::ServiceWorkerStorage(
@@ -69,10 +76,10 @@ void ServiceWorkerStorage::FindRegistrationForPattern(
// Find one with a matching scope.
for (RegistrationsMap::const_iterator it = found->second.begin();
it != found->second.end(); ++it) {
- if (scope == it->second.scope) {
- const ServiceWorkerDatabase::RegistrationData* data = &(it->second);
+ if (scope == GURL(it->second.scope_url())) {
+ const ServiceWorkerRegistrationData* data = &(it->second);
scoped_refptr<ServiceWorkerRegistration> registration =
- context_->GetLiveRegistration(data->registration_id);
+ context_->GetLiveRegistration(data->registration_id());
if (registration) {
RunSoon(base::Bind(
callback, SERVICE_WORKER_OK,
@@ -116,13 +123,14 @@ void ServiceWorkerStorage::FindRegistrationForDocument(
it != found->second.end(); ++it) {
// TODO(michaeln): if there are multiple matches the one with
// the longest scope should win.
- if (ServiceWorkerUtils::ScopeMatches(it->second.scope, document_url)) {
- const ServiceWorkerDatabase::RegistrationData* data = &(it->second);
+ if (ServiceWorkerUtils::ScopeMatches(
+ GURL(it->second.scope_url()), document_url)) {
+ const ServiceWorkerRegistrationData* data = &(it->second);
// If its in the live map, return syncly to simulate this class having
// iterated over the values in that map instead of reading the db.
scoped_refptr<ServiceWorkerRegistration> registration =
- context_->GetLiveRegistration(data->registration_id);
+ context_->GetLiveRegistration(data->registration_id());
if (registration) {
callback.Run(SERVICE_WORKER_OK, registration);
return;
@@ -186,10 +194,10 @@ void ServiceWorkerStorage::GetAllRegistrations(
continue;
}
ServiceWorkerRegistrationInfo info;
- info.pattern = it->second->scope;
- info.script_url = it->second->script;
+ info.pattern = GURL(it->second->scope_url());
+ info.script_url = GURL(it->second->script_url());
info.active_version.is_null = false;
- if (it->second->is_active)
+ if (it->second->is_active())
info.active_version.status = ServiceWorkerVersion::ACTIVE;
else
info.active_version.status = ServiceWorkerVersion::INSTALLED;
@@ -214,15 +222,14 @@ void ServiceWorkerStorage::StoreRegistration(
// Keep a database struct in the storage map.
RegistrationsMap& storage_map =
stored_registrations_[registration->script_url().GetOrigin()];
- ServiceWorkerDatabase::RegistrationData& data =
- storage_map[registration->id()];
- data.registration_id = registration->id();
- data.scope = registration->pattern();
- data.script = registration->script_url();
- data.has_fetch_handler = true;
- data.version_id = version->version_id();
- data.last_update_check = base::Time::Now();
- data.is_active = false; // initially stored in the waiting state
+ ServiceWorkerRegistrationData& data = storage_map[registration->id()];
+ data.set_registration_id(registration->id());
+ data.set_scope_url(registration->pattern().spec());
+ data.set_script_url(registration->script_url().spec());
+ data.set_has_fetch_handler(true);
+ data.set_version_id(version->version_id());
+ data.set_last_update_check_time(base::Time::Now().ToInternalValue());
+ data.set_is_active(false); // initially stored in the waiting state
// Keep a seperate map of ptrs keyed by id only.
registrations_by_id_[registration->id()] = &storage_map[registration->id()];
@@ -230,9 +237,9 @@ void ServiceWorkerStorage::StoreRegistration(
RunSoon(base::Bind(callback, SERVICE_WORKER_OK));
}
- void ServiceWorkerStorage::UpdateToActiveState(
- ServiceWorkerRegistration* registration,
- const StatusCallback& callback) {
+void ServiceWorkerStorage::UpdateToActiveState(
+ ServiceWorkerRegistration* registration,
+ const StatusCallback& callback) {
DCHECK(simulated_lazy_initted_);
if (!context_) {
RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_FAILED));
@@ -245,8 +252,8 @@ void ServiceWorkerStorage::StoreRegistration(
RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_NOT_FOUND));
return;
}
- DCHECK(!found->second->is_active);
- found->second->is_active = true;
+ DCHECK(!found->second->is_active());
+ found->second->set_is_active(true);
RunSoon(base::Bind(callback, SERVICE_WORKER_OK));
}
@@ -261,7 +268,7 @@ void ServiceWorkerStorage::DeleteRegistration(
return;
}
- GURL origin = found->second->script.GetOrigin();
+ GURL origin = GURL(found->second->script_url()).GetOrigin();
stored_registrations_[origin].erase(registration_id);
if (stored_registrations_[origin].empty())
stored_registrations_.erase(origin);
@@ -292,17 +299,18 @@ int64 ServiceWorkerStorage::NewResourceId() {
scoped_refptr<ServiceWorkerRegistration>
ServiceWorkerStorage::CreateRegistration(
- const ServiceWorkerDatabase::RegistrationData* data) {
+ const ServiceWorkerRegistrationData* data) {
scoped_refptr<ServiceWorkerRegistration> registration(
new ServiceWorkerRegistration(
- data->scope, data->script, data->registration_id, context_));
+ GURL(data->scope_url()), GURL(data->script_url()),
+ data->registration_id(), context_));
scoped_refptr<ServiceWorkerVersion> version =
- context_->GetLiveVersion(data->version_id);
+ context_->GetLiveVersion(data->version_id());
if (!version) {
version = new ServiceWorkerVersion(
- registration, data->version_id, context_);
- version->SetStatus(data->GetVersionStatus());
+ registration, data->version_id(), context_);
+ version->SetStatus(GetVersionStatus(data->is_active()));
}
if (version->status() == ServiceWorkerVersion::ACTIVE)

Powered by Google App Engine
This is Rietveld 408576698