dom_storage_context.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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_DOM_STORAGE_CONTEXT_H_
6#define CONTENT_PUBLIC_BROWSER_DOM_STORAGE_CONTEXT_H_
7
8#include <string>
9#include <vector>
10
11#include "base/callback.h"
12#include "content/common/content_export.h"
13
14class GURL;
15
16namespace dom_storage {
17struct LocalStorageUsageInfo;
18struct SessionStorageUsageInfo;
19}
20
21namespace content {
22
23class BrowserContext;
24class SessionStorageNamespace;
25
26// Represents the per-BrowserContext Local Storage data.
27class DOMStorageContext {
28 public:
29  typedef base::Callback<
30      void(const std::vector<dom_storage::LocalStorageUsageInfo>&)>
31          GetLocalStorageUsageCallback;
32
33  typedef base::Callback<
34      void(const std::vector<dom_storage::SessionStorageUsageInfo>&)>
35          GetSessionStorageUsageCallback;
36
37  // Returns a collection of origins using local storage to the given callback.
38  virtual void GetLocalStorageUsage(
39      const GetLocalStorageUsageCallback& callback) = 0;
40
41  // Returns a collection of origins using session storage to the given
42  // callback.
43  virtual void GetSessionStorageUsage(
44      const GetSessionStorageUsageCallback& callback) = 0;
45
46  // Deletes the local storage data for the given origin.
47  virtual void DeleteLocalStorage(const GURL& origin) = 0;
48
49  // Deletes the session storage data identified by |usage_info|.
50  virtual void DeleteSessionStorage(
51      const dom_storage::SessionStorageUsageInfo& usage_info) = 0;
52
53  // If this is called, sessionStorage data will be stored on disk, and can be
54  // restored after a browser restart (with RecreateSessionStorage). This
55  // function must be called right after DOMStorageContextImpl is created, and
56  // before it's used.
57  virtual void SetSaveSessionStorageOnDisk() = 0;
58
59  // Creates a SessionStorageNamespace with the given |persistent_id|. Used
60  // after tabs are restored by session restore. When created, the
61  // SessionStorageNamespace with the correct |persistent_id| will be
62  // associated with the persisted sessionStorage data.
63  virtual scoped_refptr<SessionStorageNamespace> RecreateSessionStorage(
64      const std::string& persistent_id) = 0;
65
66  // Starts deleting sessionStorages which don't have an associated
67  // SessionStorageNamespace alive. Called when SessionStorageNamespaces have
68  // been created after a session restore, or a session restore won't happen.
69  virtual void StartScavengingUnusedSessionStorage() = 0;
70
71 protected:
72  virtual ~DOMStorageContext() {}
73};
74
75}  // namespace content
76
77#endif  // CONTENT_PUBLIC_BROWSER_DOM_STORAGE_CONTEXT_H_
78