storage_partition.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1// Copyright (c) 2012 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 CONTENT_PUBLIC_BROWSER_STORAGE_PARTITION_H_
6#define CONTENT_PUBLIC_BROWSER_STORAGE_PARTITION_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/files/file_path.h"
12
13class GURL;
14
15namespace appcache {
16class AppCacheService;
17}
18
19namespace fileapi {
20class FileSystemContext;
21}
22
23namespace net {
24class URLRequestContextGetter;
25}
26
27namespace quota {
28class QuotaManager;
29class SpecialStoragePolicy;
30}
31
32namespace webkit_database {
33class DatabaseTracker;
34}
35
36namespace content {
37
38class BrowserContext;
39class IndexedDBContext;
40class DOMStorageContext;
41class ServiceWorkerContextWrapper;
42
43// Defines what persistent state a child process can access.
44//
45// The StoragePartition defines the view each child process has of the
46// persistent state inside the BrowserContext. This is used to implement
47// isolated storage where a renderer with isolated storage cannot see
48// the cookies, localStorage, etc., that normal web renderers have access to.
49class StoragePartition {
50 public:
51  virtual base::FilePath GetPath() = 0;
52  virtual net::URLRequestContextGetter* GetURLRequestContext() = 0;
53  virtual net::URLRequestContextGetter* GetMediaURLRequestContext() = 0;
54  virtual quota::QuotaManager* GetQuotaManager() = 0;
55  virtual appcache::AppCacheService* GetAppCacheService() = 0;
56  virtual fileapi::FileSystemContext* GetFileSystemContext() = 0;
57  virtual webkit_database::DatabaseTracker* GetDatabaseTracker() = 0;
58  virtual DOMStorageContext* GetDOMStorageContext() = 0;
59  virtual IndexedDBContext* GetIndexedDBContext() = 0;
60  virtual ServiceWorkerContextWrapper* GetServiceWorkerContext() = 0;
61
62  enum RemoveDataMask {
63    REMOVE_DATA_MASK_APPCACHE = 1 << 0,
64    REMOVE_DATA_MASK_COOKIES = 1 << 1,
65    REMOVE_DATA_MASK_FILE_SYSTEMS = 1 << 2,
66    REMOVE_DATA_MASK_INDEXEDDB = 1 << 3,
67    REMOVE_DATA_MASK_LOCAL_STORAGE = 1 << 4,
68    REMOVE_DATA_MASK_SHADER_CACHE = 1 << 5,
69    REMOVE_DATA_MASK_WEBSQL = 1 << 6,
70    REMOVE_DATA_MASK_WEBRTC_IDENTITY = 1 << 7,
71    REMOVE_DATA_MASK_ALL = -1
72  };
73
74  enum QuotaManagedStorageMask {
75    // Corresponds to quota::kStorageTypeTemporary.
76    QUOTA_MANAGED_STORAGE_MASK_TEMPORARY = 1 << 0,
77
78    // Corresponds to quota::kStorageTypePersistent.
79    QUOTA_MANAGED_STORAGE_MASK_PERSISTENT = 1 << 1,
80
81    // Corresponds to quota::kStorageTypeSyncable.
82    QUOTA_MANAGED_STORAGE_MASK_SYNCABLE = 1 << 2,
83
84    QUOTA_MANAGED_STORAGE_MASK_ALL = -1
85  };
86
87  // Starts an asynchronous task that does a best-effort clear the data
88  // corresponding to the given |remove_mask| and |quota_storage_remove_mask|
89  // inside this StoragePartition for the given |storage_origin|.
90  // Note session dom storage is not cleared even if you specify
91  // REMOVE_DATA_MASK_LOCAL_STORAGE.
92  //
93  // TODO(ajwong): Right now, the embedder may have some
94  // URLRequestContextGetter objects that the StoragePartition does not know
95  // about.  This will no longer be the case when we resolve
96  // http://crbug.com/159193. Remove |request_context_getter| when that bug
97  // is fixed.
98  virtual void ClearDataForOrigin(uint32 remove_mask,
99                                  uint32 quota_storage_remove_mask,
100                                  const GURL& storage_origin,
101                                  net::URLRequestContextGetter* rq_context) = 0;
102
103  // A callback type to check if a given origin matches a storage policy.
104  // Can be passed empty/null where used, which means the origin will always
105  // match.
106  typedef base::Callback<bool(const GURL&,
107                              quota::SpecialStoragePolicy*)>
108      OriginMatcherFunction;
109
110  // Similar to ClearDataForOrigin().
111  // Deletes all data out fo the StoragePartition if |storage_origin| is NULL.
112  // |origin_matcher| is present if special storage policy is to be handled,
113  // otherwise the callback can be null (base::Callback::is_null() == true).
114  // |callback| is called when data deletion is done or at least the deletion is
115  // scheduled.
116  virtual void ClearData(uint32 remove_mask,
117                         uint32 quota_storage_remove_mask,
118                         const GURL& storage_origin,
119                         const OriginMatcherFunction& origin_matcher,
120                         const base::Time begin,
121                         const base::Time end,
122                         const base::Closure& callback) = 0;
123
124 protected:
125  virtual ~StoragePartition() {}
126};
127
128}  // namespace content
129
130#endif  // CONTENT_PUBLIC_BROWSER_STORAGE_PARTITION_H_
131