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