extension_data_deleter.h revision c407dc5cd9bdc5668497f21b26b09d988ab439de
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
8#include <string>
9
10#include "base/ref_counted.h"
11#include "chrome/browser/chrome_thread.h"
12#include "chrome/browser/in_process_webkit/webkit_context.h"
13#include "chrome/common/net/url_request_context_getter.h"
14#include "googleurl/src/gurl.h"
15#include "webkit/database/database_tracker.h"
16
17class Extension;
18class Profile;
19
20// A helper class that takes care of removing local storage, databases and
21// cookies for a given extension. This is used by
22// ExtensionsService::ClearExtensionData() upon uninstalling an extension.
23class ExtensionDataDeleter
24  : public base::RefCountedThreadSafe<ExtensionDataDeleter,
25                                      ChromeThread::DeleteOnUIThread> {
26 public:
27  ExtensionDataDeleter(Profile* profile, const GURL& extension_url);
28
29  // Start removing data. The extension should not be running when this is
30  // called. Cookies are deleted on the current thread, local storage and
31  // databases are deleted asynchronously on the webkit and file threads,
32  // respectively. This function must be called from the UI thread.
33  void StartDeleting();
34
35 private:
36  // Deletes the cookies for the extension. May only be called on the io
37  // thread.
38  void DeleteCookiesOnIOThread();
39
40  // Deletes the database for the extension. May only be called on the file
41  // thread.
42  void DeleteDatabaseOnFileThread();
43
44  // Deletes local storage for the extension. May only be called on the webkit
45  // thread.
46  void DeleteLocalStorageOnWebkitThread();
47
48  // The database context for deleting the database.
49  scoped_refptr<webkit_database::DatabaseTracker> database_tracker_;
50
51  // Provides access to the extension request context.
52  scoped_refptr<URLRequestContextGetter> extension_request_context_;
53
54  // The URL of the extension we're removing data for.
55  GURL extension_url_;
56
57  // The security origin identifier for which we're deleting stuff.
58  string16 origin_id_;
59
60  // Webkit context for accessing the DOM storage helper.
61  scoped_refptr<WebKitContext> webkit_context_;
62
63  DISALLOW_COPY_AND_ASSIGN(ExtensionDataDeleter);
64};
65
66#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_DATA_DELETER_H_
67