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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DATA_DELETER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_DATA_DELETER_H_ 7 #pragma once 8 9 #include "base/memory/ref_counted.h" 10 #include "base/string16.h" 11 #include "content/browser/browser_thread.h" 12 #include "googleurl/src/gurl.h" 13 14 namespace webkit_database { 15 class DatabaseTracker; 16 } 17 18 namespace fileapi { 19 class FileSystemContext; 20 } 21 22 class Profile; 23 class WebKitContext; 24 25 namespace net { 26 class URLRequestContextGetter; 27 } 28 29 // A helper class that takes care of removing local storage, databases and 30 // cookies for a given extension. This is used by 31 // ExtensionService::ClearExtensionData() upon uninstalling an extension. 32 class ExtensionDataDeleter 33 : public base::RefCountedThreadSafe<ExtensionDataDeleter, 34 BrowserThread::DeleteOnUIThread> { 35 public: 36 ExtensionDataDeleter(Profile* profile, const GURL& extension_url); 37 38 // Start removing data. The extension should not be running when this is 39 // called. Cookies are deleted on the current thread, local storage and 40 // databases are deleted asynchronously on the webkit and file threads, 41 // respectively. This function must be called from the UI thread. 42 void StartDeleting(); 43 44 private: 45 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; 46 friend class DeleteTask<ExtensionDataDeleter>; 47 48 ~ExtensionDataDeleter(); 49 50 // Deletes the cookies for the extension. May only be called on the io 51 // thread. 52 void DeleteCookiesOnIOThread(); 53 54 // Deletes the database for the extension. May only be called on the file 55 // thread. 56 void DeleteDatabaseOnFileThread(); 57 58 // Deletes local storage for the extension. May only be called on the webkit 59 // thread. 60 void DeleteLocalStorageOnWebkitThread(); 61 62 // Deletes indexed db files for the extension. May only be called on the 63 // webkit thread. 64 void DeleteIndexedDBOnWebkitThread(); 65 66 // Deletes filesystem files for the extension. May only be called on the 67 // file thread. 68 void DeleteFileSystemOnFileThread(); 69 70 // The database context for deleting the database. 71 scoped_refptr<webkit_database::DatabaseTracker> database_tracker_; 72 73 // Provides access to the extension request context. 74 scoped_refptr<net::URLRequestContextGetter> extension_request_context_; 75 76 // The URL of the extension we're removing data for. 77 GURL extension_url_; 78 79 // The security origin identifier for which we're deleting stuff. 80 string16 origin_id_; 81 82 // Webkit context for accessing the DOM storage helper. 83 scoped_refptr<WebKitContext> webkit_context_; 84 85 scoped_refptr<fileapi::FileSystemContext> file_system_context_; 86 87 DISALLOW_COPY_AND_ASSIGN(ExtensionDataDeleter); 88 }; 89 90 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DATA_DELETER_H_ 91