[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 5 | #include "chrome/browser/extensions/data_deleter.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 6 | |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 8 | #include "base/file_util.h" |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 9 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 0d9a220 | 2011-11-09 13:48:41 | [diff] [blame] | 10 | #include "chrome/browser/extensions/settings/settings_frontend.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 11 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 12 | #include "chrome/common/chrome_constants.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 13 | #include "chrome/common/extensions/extension.h" |
[email protected] | 2a80aee | 2011-10-07 16:06:03 | [diff] [blame] | 14 | #include "chrome/common/url_constants.h" |
[email protected] | 35cc399e | 2012-02-23 18:19:28 | [diff] [blame] | 15 | #include "content/public/browser/dom_storage_context.h" |
| 16 | #include "content/public/browser/indexed_db_context.h" |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 17 | #include "content/public/browser/resource_context.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame^] | 18 | #include "content/public/browser/storage_partition.h" |
[email protected] | 00bbe166 | 2011-12-22 02:25:21 | [diff] [blame] | 19 | #include "net/base/completion_callback.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 20 | #include "net/base/net_errors.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 21 | #include "net/cookies/cookie_monster.h" |
[email protected] | 277ec26 | 2011-03-30 21:09:40 | [diff] [blame] | 22 | #include "net/url_request/url_request_context.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 23 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 24 | #include "webkit/appcache/appcache_service.h" |
[email protected] | 0406838 | 2010-08-26 22:51:54 | [diff] [blame] | 25 | #include "webkit/database/database_tracker.h" |
[email protected] | 397281f | 2011-02-14 05:15:53 | [diff] [blame] | 26 | #include "webkit/database/database_util.h" |
| 27 | #include "webkit/fileapi/file_system_context.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 28 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 29 | using content::BrowserContext; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 30 | using content::BrowserThread; |
[email protected] | 35cc399e | 2012-02-23 18:19:28 | [diff] [blame] | 31 | using content::DOMStorageContext; |
| 32 | using content::IndexedDBContext; |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 33 | using content::ResourceContext; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 34 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 35 | namespace extensions { |
| 36 | |
[email protected] | 123f274 | 2011-12-02 04:26:52 | [diff] [blame] | 37 | // static |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 38 | void DataDeleter::StartDeleting(Profile* profile, |
| 39 | const std::string& extension_id, |
| 40 | const GURL& storage_origin, |
| 41 | bool is_storage_isolated) { |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 42 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 43 | DCHECK(profile); |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 44 | scoped_refptr<DataDeleter> deleter = new DataDeleter( |
| 45 | profile, extension_id, storage_origin, is_storage_isolated); |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 46 | |
| 47 | BrowserThread::PostTask( |
| 48 | BrowserThread::IO, FROM_HERE, |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 49 | base::Bind(&DataDeleter::DeleteCookiesOnIOThread, deleter)); |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 50 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame^] | 51 | content::BrowserContext::GetDefaultStoragePartition(profile)-> |
| 52 | GetDOMStorageContext()->DeleteOrigin(storage_origin); |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 53 | |
| 54 | BrowserThread::PostTask( |
[email protected] | e1dd562 | 2011-12-20 12:28:58 | [diff] [blame] | 55 | BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 56 | base::Bind( |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 57 | &DataDeleter::DeleteIndexedDBOnWebkitThread, |
| 58 | deleter, |
[email protected] | c1fff07 | 2012-02-24 23:38:12 | [diff] [blame] | 59 | make_scoped_refptr(BrowserContext::GetIndexedDBContext(profile)))); |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 60 | |
| 61 | BrowserThread::PostTask( |
| 62 | BrowserThread::FILE, FROM_HERE, |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 63 | base::Bind(&DataDeleter::DeleteDatabaseOnFileThread, deleter)); |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 64 | |
| 65 | BrowserThread::PostTask( |
| 66 | BrowserThread::FILE, FROM_HERE, |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 67 | base::Bind(&DataDeleter::DeleteFileSystemOnFileThread, deleter)); |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 68 | |
| 69 | BrowserThread::PostTask( |
| 70 | BrowserThread::IO, FROM_HERE, |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 71 | base::Bind(&DataDeleter::DeleteAppcachesOnIOThread, |
| 72 | deleter, |
| 73 | profile->GetResourceContext())); |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 74 | |
[email protected] | 0d9a220 | 2011-11-09 13:48:41 | [diff] [blame] | 75 | profile->GetExtensionService()->settings_frontend()-> |
[email protected] | 27cc733 | 2011-11-01 01:56:43 | [diff] [blame] | 76 | DeleteStorageSoon(extension_id); |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 77 | } |
| 78 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 79 | DataDeleter::DataDeleter( |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 80 | Profile* profile, |
| 81 | const std::string& extension_id, |
| 82 | const GURL& storage_origin, |
| 83 | bool is_storage_isolated) |
| 84 | : extension_id_(extension_id) { |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 85 | database_tracker_ = BrowserContext::GetDatabaseTracker(profile); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 86 | // Pick the right request context depending on whether it's an extension, |
| 87 | // isolated app, or regular app. |
| 88 | if (storage_origin.SchemeIs(chrome::kExtensionScheme)) { |
| 89 | extension_request_context_ = profile->GetRequestContextForExtensions(); |
| 90 | } else if (is_storage_isolated) { |
| 91 | extension_request_context_ = |
| 92 | profile->GetRequestContextForIsolatedApp(extension_id); |
| 93 | isolated_app_path_ = profile->GetPath(). |
| 94 | Append(chrome::kIsolatedAppStateDirname).AppendASCII(extension_id); |
| 95 | } else { |
| 96 | extension_request_context_ = profile->GetRequestContext(); |
| 97 | } |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 98 | file_system_context_ = BrowserContext::GetFileSystemContext(profile); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 99 | storage_origin_ = storage_origin; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 100 | origin_id_ = |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 101 | webkit_database::DatabaseUtil::GetOriginIdentifier(storage_origin_); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 102 | } |
| 103 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 104 | DataDeleter::~DataDeleter() { |
[email protected] | 0406838 | 2010-08-26 22:51:54 | [diff] [blame] | 105 | } |
| 106 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 107 | void DataDeleter::DeleteCookiesOnIOThread() { |
[email protected] | ca4b5fa3 | 2010-10-09 12:42:18 | [diff] [blame] | 108 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 109 | net::CookieMonster* cookie_monster = |
[email protected] | 277ec26 | 2011-03-30 21:09:40 | [diff] [blame] | 110 | extension_request_context_->GetURLRequestContext()->cookie_store()-> |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 111 | GetCookieMonster(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 112 | if (cookie_monster) |
[email protected] | b9e48094d | 2011-07-20 14:27:13 | [diff] [blame] | 113 | cookie_monster->DeleteAllForHostAsync( |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 114 | storage_origin_, net::CookieMonster::DeleteCallback()); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 115 | } |
| 116 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 117 | void DataDeleter::DeleteDatabaseOnFileThread() { |
[email protected] | ca4b5fa3 | 2010-10-09 12:42:18 | [diff] [blame] | 118 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
[email protected] | 00bbe166 | 2011-12-22 02:25:21 | [diff] [blame] | 119 | int rv = database_tracker_->DeleteDataForOrigin( |
| 120 | origin_id_, net::CompletionCallback()); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 121 | DCHECK(rv == net::OK || rv == net::ERR_IO_PENDING); |
| 122 | } |
| 123 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 124 | void DataDeleter::DeleteIndexedDBOnWebkitThread( |
[email protected] | 35cc399e | 2012-02-23 18:19:28 | [diff] [blame] | 125 | scoped_refptr<IndexedDBContext> indexed_db_context) { |
[email protected] | e1dd562 | 2011-12-20 12:28:58 | [diff] [blame] | 126 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
[email protected] | 35cc399e | 2012-02-23 18:19:28 | [diff] [blame] | 127 | indexed_db_context->DeleteForOrigin(storage_origin_); |
[email protected] | e1dcf92 | 2010-11-22 19:12:12 | [diff] [blame] | 128 | } |
[email protected] | 09a31602 | 2010-12-03 03:21:37 | [diff] [blame] | 129 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 130 | void DataDeleter::DeleteFileSystemOnFileThread() { |
[email protected] | 09a31602 | 2010-12-03 03:21:37 | [diff] [blame] | 131 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 132 | file_system_context_->DeleteDataForOriginOnFileThread(storage_origin_); |
| 133 | |
| 134 | // TODO(creis): The following call fails because the request context is still |
| 135 | // around, and holding open file handles in this directory. |
| 136 | // See http://crbug.com/85127 |
| 137 | if (!isolated_app_path_.empty()) |
| 138 | file_util::Delete(isolated_app_path_, true); |
| 139 | } |
| 140 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 141 | void DataDeleter::DeleteAppcachesOnIOThread(ResourceContext* context) { |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 142 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 143 | ResourceContext::GetAppCacheService(context)->DeleteAppCachesForOrigin( |
[email protected] | 123f274 | 2011-12-02 04:26:52 | [diff] [blame] | 144 | storage_origin_, net::CompletionCallback()); |
[email protected] | 09a31602 | 2010-12-03 03:21:37 | [diff] [blame] | 145 | } |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 146 | |
| 147 | } // namespace extensions |