summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorjsbell@chromium.org <jsbell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-11 20:22:13 +0000
committerjsbell@chromium.org <jsbell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-11 20:23:26 +0000
commit1f19f126d66a541c478b84268765d06e489f798a (patch)
treed793e5fbe718f0d17ad1a309fde796840fe80aea /content
parentfd659c2b8616bb5ecbac4b7c070b3fc024f7df57 (diff)
downloadchromium_src-1f19f126d66a541c478b84268765d06e489f798a.zip
chromium_src-1f19f126d66a541c478b84268765d06e489f798a.tar.gz
chromium_src-1f19f126d66a541c478b84268765d06e489f798a.tar.bz2
Service Worker: Hook up browsing data deletion
Ensure that chrome://settings/cookies lists origins containing Service Workers and that users can delete the storage. While this is minimally functional, there are several caveats: * A dummy size and timestamp are displayed in the UI, as the actual data is not yet available from the SW context. * Integration with quota remains to be implemented. In particular, UI and extension APIs that allow browsing data to be deleted by date range (e.g. "clear last hour") continue to ignore SW data. * Deletion is done by simply unregistering all SWs in the origin. If unregistration is delayed by an active controllee, the deletion also be (silently) delayed. BUG=388164 Review URL: https://codereview.chromium.org/394063003 Cr-Commit-Position: refs/heads/master@{#288784} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288784 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/service_worker/service_worker_context_wrapper.cc73
-rw-r--r--content/browser/service_worker/service_worker_context_wrapper.h9
-rw-r--r--content/browser/storage_partition_impl.cc6
-rw-r--r--content/content_browser.gypi2
-rw-r--r--content/public/browser/service_worker_context.h10
-rw-r--r--content/public/browser/service_worker_usage_info.cc24
-rw-r--r--content/public/browser/service_worker_usage_info.h36
-rw-r--r--content/public/browser/storage_partition.h1
8 files changed, 159 insertions, 2 deletions
diff --git a/content/browser/service_worker/service_worker_context_wrapper.cc b/content/browser/service_worker/service_worker_context_wrapper.cc
index 21ecc73..c202dd8 100644
--- a/content/browser/service_worker/service_worker_context_wrapper.cc
+++ b/content/browser/service_worker/service_worker_context_wrapper.cc
@@ -4,6 +4,8 @@
#include "content/browser/service_worker/service_worker_context_wrapper.h"
+#include <map>
+
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/threading/sequenced_worker_pool.h"
@@ -139,6 +141,77 @@ void ServiceWorkerContextWrapper::Terminate() {
process_manager_->Shutdown();
}
+void ServiceWorkerContextWrapper::GetAllOriginsInfo(
+ const GetUsageInfoCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ context_core_->storage()->GetAllRegistrations(base::Bind(
+ &ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins,
+ this,
+ callback));
+}
+
+void ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins(
+ const GetUsageInfoCallback& callback,
+ const std::vector<ServiceWorkerRegistrationInfo>& registrations) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ std::vector<ServiceWorkerUsageInfo> usage_infos;
+
+ std::map<GURL, ServiceWorkerUsageInfo> origins;
+ for (std::vector<ServiceWorkerRegistrationInfo>::const_iterator it =
+ registrations.begin();
+ it != registrations.end();
+ ++it) {
+ const ServiceWorkerRegistrationInfo& registration_info = *it;
+ GURL origin = registration_info.script_url.GetOrigin();
+
+ ServiceWorkerUsageInfo& usage_info = origins[origin];
+ if (usage_info.origin.is_empty())
+ usage_info.origin = origin;
+ usage_info.scopes.push_back(registration_info.pattern);
+ }
+
+ for (std::map<GURL, ServiceWorkerUsageInfo>::const_iterator it =
+ origins.begin();
+ it != origins.end();
+ ++it) {
+ usage_infos.push_back(it->second);
+ }
+
+ callback.Run(usage_infos);
+}
+
+namespace {
+
+void EmptySuccessCallback(bool success) {
+}
+
+} // namespace
+
+void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin_url) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ context_core_->storage()->GetAllRegistrations(base::Bind(
+ &ServiceWorkerContextWrapper::DidGetAllRegistrationsForDeleteForOrigin,
+ this,
+ origin_url));
+}
+
+void ServiceWorkerContextWrapper::DidGetAllRegistrationsForDeleteForOrigin(
+ const GURL& origin,
+ const std::vector<ServiceWorkerRegistrationInfo>& registrations) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ for (std::vector<ServiceWorkerRegistrationInfo>::const_iterator it =
+ registrations.begin();
+ it != registrations.end();
+ ++it) {
+ const ServiceWorkerRegistrationInfo& registration_info = *it;
+ if (origin == registration_info.script_url.GetOrigin()) {
+ UnregisterServiceWorker(registration_info.pattern,
+ base::Bind(&EmptySuccessCallback));
+ }
+ }
+}
+
void ServiceWorkerContextWrapper::AddObserver(
ServiceWorkerContextObserver* observer) {
observer_list_->AddObserver(observer);
diff --git a/content/browser/service_worker/service_worker_context_wrapper.h b/content/browser/service_worker/service_worker_context_wrapper.h
index e593b24..8da96f5 100644
--- a/content/browser/service_worker/service_worker_context_wrapper.h
+++ b/content/browser/service_worker/service_worker_context_wrapper.h
@@ -68,6 +68,8 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper
const ResultCallback& continuation)
OVERRIDE;
virtual void Terminate() OVERRIDE;
+ virtual void GetAllOriginsInfo(const GetUsageInfoCallback& callback) OVERRIDE;
+ virtual void DeleteForOrigin(const GURL& origin_url) OVERRIDE;
void AddObserver(ServiceWorkerContextObserver* observer);
void RemoveObserver(ServiceWorkerContextObserver* observer);
@@ -89,6 +91,13 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper
void DidDeleteAndStartOver(ServiceWorkerStatusCode status);
+ void DidGetAllRegistrationsForGetAllOrigins(
+ const GetUsageInfoCallback& callback,
+ const std::vector<ServiceWorkerRegistrationInfo>& registrations);
+ void DidGetAllRegistrationsForDeleteForOrigin(
+ const GURL& origin,
+ const std::vector<ServiceWorkerRegistrationInfo>& registrations);
+
const scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> >
observer_list_;
const scoped_ptr<ServiceWorkerProcessManager> process_manager_;
diff --git a/content/browser/storage_partition_impl.cc b/content/browser/storage_partition_impl.cc
index ea344ce..134c161 100644
--- a/content/browser/storage_partition_impl.cc
+++ b/content/browser/storage_partition_impl.cc
@@ -203,6 +203,8 @@ STATIC_CONST_MEMBER_DEFINITION const uint32
STATIC_CONST_MEMBER_DEFINITION const uint32
StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE;
STATIC_CONST_MEMBER_DEFINITION const uint32
+ StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS;
+STATIC_CONST_MEMBER_DEFINITION const uint32
StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE;
STATIC_CONST_MEMBER_DEFINITION const uint32
StoragePartition::REMOVE_DATA_MASK_WEBSQL;
@@ -231,6 +233,7 @@ int StoragePartitionImpl::GenerateQuotaClientMask(uint32 remove_mask) {
quota_client_mask |= quota::QuotaClient::kAppcache;
if (remove_mask & StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)
quota_client_mask |= quota::QuotaClient::kIndexedDatabase;
+ // TODO(jsbell): StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS)
return quota_client_mask;
}
@@ -698,7 +701,8 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
if (remove_mask & REMOVE_DATA_MASK_INDEXEDDB ||
remove_mask & REMOVE_DATA_MASK_WEBSQL ||
remove_mask & REMOVE_DATA_MASK_APPCACHE ||
- remove_mask & REMOVE_DATA_MASK_FILE_SYSTEMS) {
+ remove_mask & REMOVE_DATA_MASK_FILE_SYSTEMS ||
+ remove_mask & REMOVE_DATA_MASK_SERVICE_WORKERS) {
IncrementTaskCountOnUI();
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index 2796054..f39704f 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -191,6 +191,8 @@
'public/browser/resource_throttle.h',
'public/browser/save_page_type.h',
'public/browser/service_worker_context.h',
+ 'public/browser/service_worker_usage_info.cc',
+ 'public/browser/service_worker_usage_info.h',
'public/browser/session_storage_namespace.h',
'public/browser/session_storage_usage_info.h',
'public/browser/signed_certificate_timestamp_store.h',
diff --git a/content/public/browser/service_worker_context.h b/content/public/browser/service_worker_context.h
index 2d0805e..e035fbe 100644
--- a/content/public/browser/service_worker_context.h
+++ b/content/public/browser/service_worker_context.h
@@ -7,12 +7,13 @@
#include "base/basictypes.h"
#include "base/callback_forward.h"
+#include "content/public/browser/service_worker_usage_info.h"
#include "url/gurl.h"
namespace content {
// Represents the per-StoragePartition ServiceWorker data. Must be used from
-// the UI thread.
+// the IO thread.
class ServiceWorkerContext {
public:
// https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/index.html#url-scope:
@@ -21,6 +22,9 @@ class ServiceWorkerContext {
typedef base::Callback<void(bool success)> ResultCallback;
+ typedef base::Callback<void(const std::vector<ServiceWorkerUsageInfo>&
+ usage_info)> GetUsageInfoCallback;
+
// Equivalent to calling navigator.serviceWorker.register(script_url, {scope:
// pattern}) from a renderer, except that |pattern| is an absolute URL instead
// of relative to some current origin. |callback| is passed true when the JS
@@ -54,6 +58,10 @@ class ServiceWorkerContext {
// from starting up.
virtual void Terminate() = 0;
+ // Methods used in response to browsing data and quota manager requests.
+ virtual void GetAllOriginsInfo(const GetUsageInfoCallback& callback) = 0;
+ virtual void DeleteForOrigin(const GURL& origin_url) = 0;
+
protected:
ServiceWorkerContext() {}
virtual ~ServiceWorkerContext() {}
diff --git a/content/public/browser/service_worker_usage_info.cc b/content/public/browser/service_worker_usage_info.cc
new file mode 100644
index 0000000..c35d545
--- /dev/null
+++ b/content/public/browser/service_worker_usage_info.cc
@@ -0,0 +1,24 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/public/browser/service_worker_usage_info.h"
+
+namespace content {
+
+ServiceWorkerUsageInfo::ServiceWorkerUsageInfo(const GURL& origin,
+ const std::vector<GURL>& scopes)
+ : origin(origin), scopes(scopes) {
+}
+
+ServiceWorkerUsageInfo::ServiceWorkerUsageInfo(const GURL& origin)
+ : origin(origin) {
+}
+
+ServiceWorkerUsageInfo::ServiceWorkerUsageInfo() {
+}
+
+ServiceWorkerUsageInfo::~ServiceWorkerUsageInfo() {
+}
+
+} // namespace content
diff --git a/content/public/browser/service_worker_usage_info.h b/content/public/browser/service_worker_usage_info.h
new file mode 100644
index 0000000..bfd6fc5
--- /dev/null
+++ b/content/public/browser/service_worker_usage_info.h
@@ -0,0 +1,36 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_USAGE_INFO_H_
+#define CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_USAGE_INFO_H_
+
+#include <vector>
+
+#include "content/common/content_export.h"
+#include "url/gurl.h"
+
+namespace content {
+
+// Used to report per-origin storage info for registered Service Workers.
+class CONTENT_EXPORT ServiceWorkerUsageInfo {
+ public:
+ ServiceWorkerUsageInfo(const GURL& origin, const std::vector<GURL>& scopes);
+ ServiceWorkerUsageInfo(const GURL& origin);
+ ServiceWorkerUsageInfo();
+ ~ServiceWorkerUsageInfo();
+
+ // The origin this object is describing.
+ GURL origin;
+
+ // The set of all Service Worker registrations within this origin;
+ // a registration is a 'scope' - a URL with optional wildcard.
+ std::vector<GURL> scopes;
+
+ // TODO(jsbell): Add size on disk (in bytes).
+ // TODO(jsbell): Add last modified time.
+};
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_USAGE_INFO_H_
diff --git a/content/public/browser/storage_partition.h b/content/public/browser/storage_partition.h
index fdce3b5..8e6fc9c 100644
--- a/content/public/browser/storage_partition.h
+++ b/content/public/browser/storage_partition.h
@@ -71,6 +71,7 @@ class CONTENT_EXPORT StoragePartition {
static const uint32 REMOVE_DATA_MASK_SHADER_CACHE = 1 << 5;
static const uint32 REMOVE_DATA_MASK_WEBSQL = 1 << 6;
static const uint32 REMOVE_DATA_MASK_WEBRTC_IDENTITY = 1 << 7;
+ static const uint32 REMOVE_DATA_MASK_SERVICE_WORKERS = 1 << 8;
static const uint32 REMOVE_DATA_MASK_ALL = 0xFFFFFFFF;
// Corresponds to quota::kStorageTypeTemporary.