summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_data_deleter.h
blob: cf026a6afb59b255fc6f4b120af20038bd91af1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DATA_DELETER_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_DATA_DELETER_H_
#pragma once

#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/string16.h"
#include "content/browser/browser_thread.h"
#include "googleurl/src/gurl.h"

namespace webkit_database {
class DatabaseTracker;
}

namespace fileapi {
class FileSystemContext;
}

namespace net {
class URLRequestContextGetter;
}

class ChromeAppCacheService;
class ExtensionSettingsBackend;
class Profile;
class WebKitContext;

// A helper class that takes care of removing local storage, databases and
// cookies for a given extension. This is used by
// ExtensionService::ClearExtensionData() upon uninstalling an extension.
class ExtensionDataDeleter
  : public base::RefCountedThreadSafe<ExtensionDataDeleter,
                                      BrowserThread::DeleteOnUIThread> {
 public:
  // Starts removing data. The extension should not be running when this is
  // called. Cookies are deleted on the current thread, local storage and
  // databases/settings are deleted asynchronously on the webkit and file
  // threads, respectively. This function must be called from the UI thread.
  static void StartDeleting(
      Profile* profile,
      const std::string& extension_id,
      const GURL& storage_origin,
      bool is_storage_isolated);

 private:
  friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
  friend class DeleteTask<ExtensionDataDeleter>;

  ExtensionDataDeleter(
      Profile* profile,
      const std::string& extension_id,
      const GURL& storage_origin,
      bool is_storage_isolated);
  ~ExtensionDataDeleter();

  // Deletes the cookies for the extension. May only be called on the io
  // thread.
  void DeleteCookiesOnIOThread();

  // Deletes the database for the extension. May only be called on the file
  // thread.
  void DeleteDatabaseOnFileThread();

  // Deletes local storage for the extension. May only be called on the webkit
  // thread.
  void DeleteLocalStorageOnWebkitThread();

  // Deletes indexed db files for the extension. May only be called on the
  // webkit thread.
  void DeleteIndexedDBOnWebkitThread();

  // Deletes filesystem files for the extension. May only be called on the
  // file thread.
  void DeleteFileSystemOnFileThread();

  // Deletes appcache files for the extension. May only be called on the IO
  // thread.
  void DeleteAppcachesOnIOThread();

  // Deletes extension settings for the extension. Will be called on the FILE
  // thread via the ExtensionSettingsFrontend.
  void DeleteExtensionSettingsOnFileThread(ExtensionSettingsBackend* backend);

  // The ID of the extension being deleted.
  const std::string extension_id_;

  // The database context for deleting the database.
  scoped_refptr<webkit_database::DatabaseTracker> database_tracker_;

  // Provides access to the request context.
  scoped_refptr<net::URLRequestContextGetter> extension_request_context_;

  // The origin of the extension/app for which we're going to clear data.
  GURL storage_origin_;

  // The security origin identifier for which we're deleting stuff.
  string16 origin_id_;

  // Webkit context for accessing the DOM storage helper.
  scoped_refptr<WebKitContext> webkit_context_;

  scoped_refptr<fileapi::FileSystemContext> file_system_context_;

  scoped_refptr<ChromeAppCacheService> appcache_service_;

  // If non-empty, the extension we're deleting is an isolated app, and this
  // is its directory which we should delete.
  FilePath isolated_app_path_;

  DISALLOW_COPY_AND_ASSIGN(ExtensionDataDeleter);
};

#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_DATA_DELETER_H_