storage_partition.h revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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/callback_forward.h"
12#include "base/files/file_path.h"
13#include "base/time/time.h"
14#include "content/common/content_export.h"
15
16class GURL;
17
18namespace base {
19class Time;
20}
21
22namespace fileapi {
23class FileSystemContext;
24}
25
26namespace net {
27class URLRequestContextGetter;
28}
29
30namespace quota {
31class QuotaManager;
32class SpecialStoragePolicy;
33}
34
35namespace webkit_database {
36class DatabaseTracker;
37}
38
39namespace content {
40
41class AppCacheService;
42class BrowserContext;
43class IndexedDBContext;
44class DOMStorageContext;
45class ServiceWorkerContext;
46
47// Defines what persistent state a child process can access.
48//
49// The StoragePartition defines the view each child process has of the
50// persistent state inside the BrowserContext. This is used to implement
51// isolated storage where a renderer with isolated storage cannot see
52// the cookies, localStorage, etc., that normal web renderers have access to.
53class CONTENT_EXPORT StoragePartition {
54 public:
55  virtual base::FilePath GetPath() = 0;
56  virtual net::URLRequestContextGetter* GetURLRequestContext() = 0;
57  virtual net::URLRequestContextGetter* GetMediaURLRequestContext() = 0;
58  virtual quota::QuotaManager* GetQuotaManager() = 0;
59  virtual AppCacheService* GetAppCacheService() = 0;
60  virtual fileapi::FileSystemContext* GetFileSystemContext() = 0;
61  virtual webkit_database::DatabaseTracker* GetDatabaseTracker() = 0;
62  virtual DOMStorageContext* GetDOMStorageContext() = 0;
63  virtual IndexedDBContext* GetIndexedDBContext() = 0;
64  virtual ServiceWorkerContext* GetServiceWorkerContext() = 0;
65
66  static const uint32 REMOVE_DATA_MASK_APPCACHE        = 1 << 0;
67  static const uint32 REMOVE_DATA_MASK_COOKIES         = 1 << 1;
68  static const uint32 REMOVE_DATA_MASK_FILE_SYSTEMS    = 1 << 2;
69  static const uint32 REMOVE_DATA_MASK_INDEXEDDB       = 1 << 3;
70  static const uint32 REMOVE_DATA_MASK_LOCAL_STORAGE   = 1 << 4;
71  static const uint32 REMOVE_DATA_MASK_SHADER_CACHE    = 1 << 5;
72  static const uint32 REMOVE_DATA_MASK_WEBSQL          = 1 << 6;
73  static const uint32 REMOVE_DATA_MASK_WEBRTC_IDENTITY = 1 << 7;
74  static const uint32 REMOVE_DATA_MASK_ALL             = 0xFFFFFFFF;
75
76  // Corresponds to quota::kStorageTypeTemporary.
77  static const uint32 QUOTA_MANAGED_STORAGE_MASK_TEMPORARY  = 1 << 0;
78  // Corresponds to quota::kStorageTypePersistent.
79  static const uint32 QUOTA_MANAGED_STORAGE_MASK_PERSISTENT = 1 << 1;
80  // Corresponds to quota::kStorageTypeSyncable.
81  static const uint32 QUOTA_MANAGED_STORAGE_MASK_SYNCABLE   = 1 << 2;
82  static const uint32 QUOTA_MANAGED_STORAGE_MASK_ALL        = 0xFFFFFFFF;
83
84  // Starts an asynchronous task that does a best-effort clear the data
85  // corresponding to the given |remove_mask| and |quota_storage_remove_mask|
86  // inside this StoragePartition for the given |storage_origin|.
87  // Note session dom storage is not cleared even if you specify
88  // REMOVE_DATA_MASK_LOCAL_STORAGE.
89  // |callback| is called when data deletion is done or at least the deletion is
90  // scheduled.
91  //
92  // TODO(ajwong): Right now, the embedder may have some
93  // URLRequestContextGetter objects that the StoragePartition does not know
94  // about.  This will no longer be the case when we resolve
95  // http://crbug.com/159193. Remove |request_context_getter| when that bug
96  // is fixed.
97  virtual void ClearDataForOrigin(uint32 remove_mask,
98                                  uint32 quota_storage_remove_mask,
99                                  const GURL& storage_origin,
100                                  net::URLRequestContextGetter* rq_context,
101                                  const base::Closure& callback) = 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