blob: 14bd26eb499d3243ba69e594c507bcbfec75922b [file] [log] [blame]
[email protected]aa84a7e2012-03-15 21:29:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c10da4b02010-03-25 14:38:322// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]d9ede582012-08-14 19:21:385#include "chrome/browser/extensions/data_deleter.h"
[email protected]c10da4b02010-03-25 14:38:326
[email protected]dc0b5a12011-10-14 00:06:137#include "base/bind.h"
[email protected]0d6ec3a72011-09-02 02:09:438#include "base/file_util.h"
[email protected]dc0b5a12011-10-14 00:06:139#include "chrome/browser/extensions/extension_service.h"
[email protected]0d9a2202011-11-09 13:48:4110#include "chrome/browser/extensions/settings/settings_frontend.h"
[email protected]aa84a7e2012-03-15 21:29:0611#include "chrome/browser/profiles/profile.h"
[email protected]c10da4b02010-03-25 14:38:3212#include "chrome/common/extensions/extension.h"
[email protected]2a80aee2011-10-07 16:06:0313#include "chrome/common/url_constants.h"
[email protected]cc3d2912012-11-13 07:33:4114#include "content/public/browser/browser_context.h"
15#include "content/public/browser/browser_thread.h"
[email protected]35cc399e2012-02-23 18:19:2816#include "content/public/browser/dom_storage_context.h"
17#include "content/public/browser/indexed_db_context.h"
[email protected]4c3a23582012-08-18 08:54:3418#include "content/public/browser/storage_partition.h"
[email protected]885c0e92012-11-13 20:27:4219#include "extensions/common/constants.h"
[email protected]00bbe1662011-12-22 02:25:2120#include "net/base/completion_callback.h"
[email protected]c10da4b02010-03-25 14:38:3221#include "net/base/net_errors.h"
[email protected]aa84a7e2012-03-15 21:29:0622#include "net/cookies/cookie_monster.h"
[email protected]abe2c032011-03-31 18:49:3423#include "net/url_request/url_request_context_getter.h"
[email protected]cc3d2912012-11-13 07:33:4124#include "net/url_request/url_request_context.h"
[email protected]314c3e22012-02-21 03:57:4225#include "webkit/appcache/appcache_service.h"
[email protected]04068382010-08-26 22:51:5426#include "webkit/database/database_tracker.h"
[email protected]397281f2011-02-14 05:15:5327#include "webkit/database/database_util.h"
28#include "webkit/fileapi/file_system_context.h"
[email protected]c10da4b02010-03-25 14:38:3229
[email protected]55eb70e762012-02-20 17:38:3930using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:3931using content::BrowserThread;
[email protected]35cc399e2012-02-23 18:19:2832using content::IndexedDBContext;
[email protected]631bb742011-11-02 11:29:3933
[email protected]d9ede582012-08-14 19:21:3834namespace extensions {
35
[email protected]cc3d2912012-11-13 07:33:4136namespace {
37
38void HandleIOThreadContexts(const GURL& storage_origin,
39 net::URLRequestContextGetter* request_context,
40 appcache::AppCacheService* appcache_service) {
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
42
43 // Handle the cookies.
44 net::CookieMonster* cookie_monster =
45 request_context->GetURLRequestContext()->cookie_store()->
46 GetCookieMonster();
47 if (cookie_monster)
48 cookie_monster->DeleteAllForHostAsync(
49 storage_origin, net::CookieMonster::DeleteCallback());
50
51 // Clear out appcache.
52 appcache_service->DeleteAppCachesForOrigin(storage_origin,
53 net::CompletionCallback());
54}
55
56void HandleFileThreadContexts(
57 const GURL& storage_origin,
58 string16 origin_id,
59 webkit_database::DatabaseTracker* database_tracker,
60 fileapi::FileSystemContext* file_system_context) {
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
62
63 // Clear out the HTML5 filesystem.
64 file_system_context->DeleteDataForOriginOnFileThread(storage_origin);
65
66 // Clear out the database tracker. We just let this run until completion
67 // without notification.
68 int rv = database_tracker->DeleteDataForOrigin(
69 origin_id, net::CompletionCallback());
70 DCHECK(rv == net::OK || rv == net::ERR_IO_PENDING);
71}
72
73} // namespace
74
[email protected]123f2742011-12-02 04:26:5275// static
[email protected]d9ede582012-08-14 19:21:3876void DataDeleter::StartDeleting(Profile* profile,
77 const std::string& extension_id,
78 const GURL& storage_origin,
79 bool is_storage_isolated) {
[email protected]cc3d2912012-11-13 07:33:4180 // TODO(ajwong): If |is_storage_isolated|, we should just blowaway the
81 // whole directory that the associated StoragePartition is located at. To do
82 // this, we need to ensure that all contexts referencing that directory have
83 // closed their file handles, otherwise Windows will complain.
84 //
85 // http://www.crbug.com/85127
[email protected]dc0b5a12011-10-14 00:06:1386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]c10da4b02010-03-25 14:38:3287 DCHECK(profile);
[email protected]cc3d2912012-11-13 07:33:4188
89 const GURL& url = Extension::GetBaseURLFromExtensionId(extension_id);
90 content::StoragePartition* partition =
91 BrowserContext::GetStoragePartitionForSite(profile, url);
92 string16 origin_id =
93 webkit_database::DatabaseUtil::GetOriginIdentifier(storage_origin);
94
95 scoped_refptr<net::URLRequestContextGetter> request_context;
[email protected]885c0e92012-11-13 20:27:4296 if (storage_origin.SchemeIs(extensions::kExtensionScheme)) {
[email protected]cc3d2912012-11-13 07:33:4197 // TODO(ajwong): Cookies are not properly isolated for
98 // chrome-extension:// scheme. (http://crbug.com/158386).
99 //
100 // However, no isolated apps actually can write to kExtensionScheme
101 // origins. Thus, it is benign to delete from the
102 // RequestContextForExtensions because there's nothing stored there. We
103 // preserve this code path without checking for isolation because it's
104 // simpler than special casing. This code should go away once we merge
105 // the various URLRequestContexts (http://crbug.com/159193).
106 request_context = profile->GetRequestContextForExtensions();
107 } else {
108 // We don't need to worry about the media request context because that
109 // shares the same cookie store as the main request context.
110 request_context = partition->GetURLRequestContext();
111 }
[email protected]dc0b5a12011-10-14 00:06:13112
113 BrowserThread::PostTask(
114 BrowserThread::IO, FROM_HERE,
[email protected]cc3d2912012-11-13 07:33:41115 base::Bind(&HandleIOThreadContexts,
116 storage_origin,
117 request_context,
118 partition->GetAppCacheService()));
[email protected]dc0b5a12011-10-14 00:06:13119
[email protected]cc3d2912012-11-13 07:33:41120 BrowserThread::PostTask(
121 BrowserThread::FILE, FROM_HERE,
122 base::Bind(&HandleFileThreadContexts,
123 storage_origin,
124 origin_id,
125 make_scoped_refptr(partition->GetDatabaseTracker()),
126 make_scoped_refptr(partition->GetFileSystemContext())));
127
128 partition->GetDOMStorageContext()->DeleteLocalStorage(storage_origin);
[email protected]dc0b5a12011-10-14 00:06:13129
130 BrowserThread::PostTask(
[email protected]e1dd5622011-12-20 12:28:58131 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
[email protected]dc0b5a12011-10-14 00:06:13132 base::Bind(
[email protected]cc3d2912012-11-13 07:33:41133 &IndexedDBContext::DeleteForOrigin,
134 make_scoped_refptr(partition->GetIndexedDBContext()),
135 storage_origin));
[email protected]dc0b5a12011-10-14 00:06:13136
[email protected]cc3d2912012-11-13 07:33:41137 // Begin removal of the settings for the current extension.
[email protected]0d9a2202011-11-09 13:48:41138 profile->GetExtensionService()->settings_frontend()->
[email protected]27cc7332011-11-01 01:56:43139 DeleteStorageSoon(extension_id);
[email protected]dc0b5a12011-10-14 00:06:13140}
[email protected]d9ede582012-08-14 19:21:38141} // namespace extensions