blob: 0971f889835f7b72e57e799e7bef4c0bfacf7754 [file] [log] [blame]
Ben Murdochbb1529c2013-08-08 10:24:53 +01001// Copyright 2013 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_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_WRAPPER_H_
6#define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_WRAPPER_H_
7
8#include "base/memory/ref_counted.h"
9#include "content/common/content_export.h"
10#include "content/public/browser/dom_storage_context.h"
11
12namespace base {
13class FilePath;
14}
15
16namespace quota {
17class SpecialStoragePolicy;
18}
19
20namespace content {
21
22class DOMStorageContextImpl;
23
24// This is owned by BrowserContext (aka Profile) and encapsulates all
25// per-profile dom storage state.
26class CONTENT_EXPORT DOMStorageContextWrapper :
27 NON_EXPORTED_BASE(public DOMStorageContext),
28 public base::RefCountedThreadSafe<DOMStorageContextWrapper> {
29 public:
30 // If |data_path| is empty, nothing will be saved to disk.
31 DOMStorageContextWrapper(const base::FilePath& data_path,
32 quota::SpecialStoragePolicy* special_storage_policy);
33
34 // DOMStorageContext implementation.
35 virtual void GetLocalStorageUsage(
36 const GetLocalStorageUsageCallback& callback) OVERRIDE;
37 virtual void GetSessionStorageUsage(
38 const GetSessionStorageUsageCallback& callback) OVERRIDE;
39 virtual void DeleteLocalStorage(const GURL& origin) OVERRIDE;
40 virtual void DeleteSessionStorage(
41 const SessionStorageUsageInfo& usage_info) OVERRIDE;
42 virtual void SetSaveSessionStorageOnDisk() OVERRIDE;
43 virtual scoped_refptr<SessionStorageNamespace>
44 RecreateSessionStorage(const std::string& persistent_id) OVERRIDE;
45 virtual void StartScavengingUnusedSessionStorage() OVERRIDE;
46
47 // Called to free up memory that's not strictly needed.
48 void PurgeMemory();
49
50 // Used by content settings to alter the behavior around
51 // what data to keep and what data to discard at shutdown.
52 // The policy is not so straight forward to describe, see
53 // the implementation for details.
54 void SetForceKeepSessionState();
55
56 // Called when the BrowserContext/Profile is going away.
57 void Shutdown();
58
59 private:
60 friend class DOMStorageMessageFilter; // for access to context()
61 friend class SessionStorageNamespaceImpl; // ditto
62 friend class base::RefCountedThreadSafe<DOMStorageContextWrapper>;
63
64 virtual ~DOMStorageContextWrapper();
65 DOMStorageContextImpl* context() const { return context_.get(); }
66
67 scoped_refptr<DOMStorageContextImpl> context_;
68
69 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContextWrapper);
70};
71
72} // namespace content
73
74#endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_WRAPPER_H_