• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
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 
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/common/extensions/extension.h"
9 #include "content/browser/in_process_webkit/webkit_context.h"
10 #include "net/base/cookie_monster.h"
11 #include "net/base/net_errors.h"
12 #include "net/url_request/url_request_context.h"
13 #include "net/url_request/url_request_context_getter.h"
14 #include "webkit/database/database_tracker.h"
15 #include "webkit/database/database_util.h"
16 #include "webkit/fileapi/file_system_context.h"
17 
ExtensionDataDeleter(Profile * profile,const GURL & extension_url)18 ExtensionDataDeleter::ExtensionDataDeleter(Profile* profile,
19                                            const GURL& extension_url) {
20   DCHECK(profile);
21   webkit_context_ = profile->GetWebKitContext();
22   database_tracker_ = profile->GetDatabaseTracker();
23   extension_request_context_ = profile->GetRequestContextForExtensions();
24   file_system_context_ = profile->GetFileSystemContext();
25   extension_url_ = extension_url;
26   origin_id_ =
27       webkit_database::DatabaseUtil::GetOriginIdentifier(extension_url_);
28 }
29 
~ExtensionDataDeleter()30 ExtensionDataDeleter::~ExtensionDataDeleter() {
31 }
32 
StartDeleting()33 void ExtensionDataDeleter::StartDeleting() {
34   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
35 
36   BrowserThread::PostTask(
37       BrowserThread::IO, FROM_HERE,
38       NewRunnableMethod(this, &ExtensionDataDeleter::DeleteCookiesOnIOThread));
39 
40   BrowserThread::PostTask(
41       BrowserThread::WEBKIT, FROM_HERE,
42       NewRunnableMethod(
43           this, &ExtensionDataDeleter::DeleteLocalStorageOnWebkitThread));
44 
45   BrowserThread::PostTask(
46       BrowserThread::WEBKIT, FROM_HERE,
47       NewRunnableMethod(
48           this, &ExtensionDataDeleter::DeleteIndexedDBOnWebkitThread));
49 
50   BrowserThread::PostTask(
51       BrowserThread::FILE, FROM_HERE,
52       NewRunnableMethod(
53           this, &ExtensionDataDeleter::DeleteDatabaseOnFileThread));
54 
55   BrowserThread::PostTask(
56       BrowserThread::FILE, FROM_HERE,
57       NewRunnableMethod(
58           this, &ExtensionDataDeleter::DeleteFileSystemOnFileThread));
59 }
60 
DeleteCookiesOnIOThread()61 void ExtensionDataDeleter::DeleteCookiesOnIOThread() {
62   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
63   net::CookieMonster* cookie_monster =
64       extension_request_context_->GetURLRequestContext()->cookie_store()->
65       GetCookieMonster();
66   if (cookie_monster)
67     cookie_monster->DeleteAllForHost(extension_url_);
68 }
69 
DeleteDatabaseOnFileThread()70 void ExtensionDataDeleter::DeleteDatabaseOnFileThread() {
71   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
72   int rv = database_tracker_->DeleteDataForOrigin(origin_id_, NULL);
73   DCHECK(rv == net::OK || rv == net::ERR_IO_PENDING);
74 }
75 
DeleteLocalStorageOnWebkitThread()76 void ExtensionDataDeleter::DeleteLocalStorageOnWebkitThread() {
77   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT));
78   webkit_context_->dom_storage_context()->DeleteLocalStorageForOrigin(
79       origin_id_);
80 }
81 
DeleteIndexedDBOnWebkitThread()82 void ExtensionDataDeleter::DeleteIndexedDBOnWebkitThread() {
83   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT));
84   webkit_context_->indexed_db_context()->DeleteIndexedDBForOrigin(origin_id_);
85 }
86 
DeleteFileSystemOnFileThread()87 void ExtensionDataDeleter::DeleteFileSystemOnFileThread() {
88   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
89   file_system_context_->DeleteDataForOriginOnFileThread(extension_url_);
90 }
91