[email protected] | 277ec26 | 2011-03-30 21:09:40 | [diff] [blame] | 1 | // Copyright (c) 2011 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 | |
| 5 | #include "chrome/browser/extensions/extension_data_deleter.h" |
| 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] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 9 | #include "chrome/browser/profiles/profile.h" |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 10 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_settings_frontend.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] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 15 | #include "content/browser/appcache/chrome_appcache_service.h" |
[email protected] | 567812d | 2011-02-24 17:40:50 | [diff] [blame] | 16 | #include "content/browser/in_process_webkit/webkit_context.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 17 | #include "net/base/cookie_monster.h" |
| 18 | #include "net/base/net_errors.h" |
[email protected] | 277ec26 | 2011-03-30 21:09:40 | [diff] [blame] | 19 | #include "net/url_request/url_request_context.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 20 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | 0406838 | 2010-08-26 22:51:54 | [diff] [blame] | 21 | #include "webkit/database/database_tracker.h" |
[email protected] | 397281f | 2011-02-14 05:15:53 | [diff] [blame] | 22 | #include "webkit/database/database_util.h" |
| 23 | #include "webkit/fileapi/file_system_context.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 24 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame^] | 25 | using content::BrowserThread; |
| 26 | |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 27 | /* static */ |
| 28 | void ExtensionDataDeleter::StartDeleting( |
| 29 | Profile* profile, |
| 30 | const std::string& extension_id, |
| 31 | const GURL& storage_origin, |
| 32 | bool is_storage_isolated) { |
| 33 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 34 | DCHECK(profile); |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 35 | scoped_refptr<ExtensionDataDeleter> deleter = |
| 36 | new ExtensionDataDeleter( |
| 37 | profile, extension_id, storage_origin, is_storage_isolated); |
| 38 | |
| 39 | BrowserThread::PostTask( |
| 40 | BrowserThread::IO, FROM_HERE, |
| 41 | base::Bind( |
| 42 | &ExtensionDataDeleter::DeleteCookiesOnIOThread, deleter)); |
| 43 | |
| 44 | BrowserThread::PostTask( |
| 45 | BrowserThread::WEBKIT, FROM_HERE, |
| 46 | base::Bind( |
| 47 | &ExtensionDataDeleter::DeleteLocalStorageOnWebkitThread, deleter)); |
| 48 | |
| 49 | BrowserThread::PostTask( |
| 50 | BrowserThread::WEBKIT, FROM_HERE, |
| 51 | base::Bind( |
| 52 | &ExtensionDataDeleter::DeleteIndexedDBOnWebkitThread, deleter)); |
| 53 | |
| 54 | BrowserThread::PostTask( |
| 55 | BrowserThread::FILE, FROM_HERE, |
| 56 | base::Bind( |
| 57 | &ExtensionDataDeleter::DeleteDatabaseOnFileThread, deleter)); |
| 58 | |
| 59 | BrowserThread::PostTask( |
| 60 | BrowserThread::FILE, FROM_HERE, |
| 61 | base::Bind( |
| 62 | &ExtensionDataDeleter::DeleteFileSystemOnFileThread, deleter)); |
| 63 | |
| 64 | BrowserThread::PostTask( |
| 65 | BrowserThread::IO, FROM_HERE, |
| 66 | base::Bind( |
| 67 | &ExtensionDataDeleter::DeleteAppcachesOnIOThread, deleter)); |
| 68 | |
[email protected] | 27cc733 | 2011-11-01 01:56:43 | [diff] [blame] | 69 | profile->GetExtensionService()->extension_settings_frontend()-> |
| 70 | DeleteStorageSoon(extension_id); |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | ExtensionDataDeleter::ExtensionDataDeleter( |
| 74 | Profile* profile, |
| 75 | const std::string& extension_id, |
| 76 | const GURL& storage_origin, |
| 77 | bool is_storage_isolated) |
| 78 | : extension_id_(extension_id) { |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 79 | appcache_service_ = profile->GetAppCacheService(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 80 | webkit_context_ = profile->GetWebKitContext(); |
| 81 | database_tracker_ = profile->GetDatabaseTracker(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 82 | // Pick the right request context depending on whether it's an extension, |
| 83 | // isolated app, or regular app. |
| 84 | if (storage_origin.SchemeIs(chrome::kExtensionScheme)) { |
| 85 | extension_request_context_ = profile->GetRequestContextForExtensions(); |
| 86 | } else if (is_storage_isolated) { |
| 87 | extension_request_context_ = |
| 88 | profile->GetRequestContextForIsolatedApp(extension_id); |
| 89 | isolated_app_path_ = profile->GetPath(). |
| 90 | Append(chrome::kIsolatedAppStateDirname).AppendASCII(extension_id); |
| 91 | } else { |
| 92 | extension_request_context_ = profile->GetRequestContext(); |
| 93 | } |
[email protected] | 09a31602 | 2010-12-03 03:21:37 | [diff] [blame] | 94 | file_system_context_ = profile->GetFileSystemContext(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 95 | storage_origin_ = storage_origin; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 96 | origin_id_ = |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 97 | webkit_database::DatabaseUtil::GetOriginIdentifier(storage_origin_); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 98 | } |
| 99 | |
[email protected] | 0406838 | 2010-08-26 22:51:54 | [diff] [blame] | 100 | ExtensionDataDeleter::~ExtensionDataDeleter() { |
| 101 | } |
| 102 | |
[email protected] | 9eaa18e | 2010-06-29 20:51:01 | [diff] [blame] | 103 | void ExtensionDataDeleter::DeleteCookiesOnIOThread() { |
[email protected] | ca4b5fa3 | 2010-10-09 12:42:18 | [diff] [blame] | 104 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 105 | net::CookieMonster* cookie_monster = |
[email protected] | 277ec26 | 2011-03-30 21:09:40 | [diff] [blame] | 106 | extension_request_context_->GetURLRequestContext()->cookie_store()-> |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 107 | GetCookieMonster(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 108 | if (cookie_monster) |
[email protected] | b9e48094d | 2011-07-20 14:27:13 | [diff] [blame] | 109 | cookie_monster->DeleteAllForHostAsync( |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 110 | storage_origin_, net::CookieMonster::DeleteCallback()); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void ExtensionDataDeleter::DeleteDatabaseOnFileThread() { |
[email protected] | ca4b5fa3 | 2010-10-09 12:42:18 | [diff] [blame] | 114 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 115 | int rv = database_tracker_->DeleteDataForOrigin(origin_id_, NULL); |
| 116 | DCHECK(rv == net::OK || rv == net::ERR_IO_PENDING); |
| 117 | } |
| 118 | |
| 119 | void ExtensionDataDeleter::DeleteLocalStorageOnWebkitThread() { |
[email protected] | ca4b5fa3 | 2010-10-09 12:42:18 | [diff] [blame] | 120 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 121 | webkit_context_->dom_storage_context()->DeleteLocalStorageForOrigin( |
| 122 | origin_id_); |
| 123 | } |
[email protected] | e1dcf92 | 2010-11-22 19:12:12 | [diff] [blame] | 124 | |
| 125 | void ExtensionDataDeleter::DeleteIndexedDBOnWebkitThread() { |
| 126 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
[email protected] | 682394a | 2011-08-05 23:53:15 | [diff] [blame] | 127 | webkit_context_->indexed_db_context()->DeleteIndexedDBForOrigin( |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 128 | storage_origin_); |
[email protected] | e1dcf92 | 2010-11-22 19:12:12 | [diff] [blame] | 129 | } |
[email protected] | 09a31602 | 2010-12-03 03:21:37 | [diff] [blame] | 130 | |
| 131 | void ExtensionDataDeleter::DeleteFileSystemOnFileThread() { |
| 132 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 133 | file_system_context_->DeleteDataForOriginOnFileThread(storage_origin_); |
| 134 | |
| 135 | // TODO(creis): The following call fails because the request context is still |
| 136 | // around, and holding open file handles in this directory. |
| 137 | // See http://crbug.com/85127 |
| 138 | if (!isolated_app_path_.empty()) |
| 139 | file_util::Delete(isolated_app_path_, true); |
| 140 | } |
| 141 | |
| 142 | void ExtensionDataDeleter::DeleteAppcachesOnIOThread() { |
| 143 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 144 | appcache_service_->DeleteAppCachesForOrigin(storage_origin_, NULL); |
[email protected] | 09a31602 | 2010-12-03 03:21:37 | [diff] [blame] | 145 | } |