Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: webkit/dom_storage/dom_storage_context.h

Issue 9695013: DOMStorageContextImpl that's implemented in terms of the new dom_storage classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_ 5 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_
6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_ 6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 10
11 #include "base/atomic_sequence_num.h" 11 #include "base/atomic_sequence_num.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/observer_list.h" 15 #include "base/observer_list.h"
16 #include "googleurl/src/gurl.h"
16 17
17 class FilePath; 18 class FilePath;
18 class GURL;
19 class NullableString16; 19 class NullableString16;
20 20
21 namespace base { 21 namespace base {
22 class Time; 22 class Time;
23 } 23 }
24 24
25 namespace quota { 25 namespace quota {
26 class SpecialStoragePolicy; 26 class SpecialStoragePolicy;
27 } 27 }
28 28
(...skipping 19 matching lines...) Expand all
48 // Session Namespaces are cloned by initially making a shallow copy of 48 // Session Namespaces are cloned by initially making a shallow copy of
49 // all contained Areas, the shallow copies refer to the same refcounted Map, 49 // all contained Areas, the shallow copies refer to the same refcounted Map,
50 // and does a deep copy-on-write if needed. 50 // and does a deep copy-on-write if needed.
51 // 51 //
52 // Classes intended to be used by an embedder are DomStorageContext, 52 // Classes intended to be used by an embedder are DomStorageContext,
53 // DomStorageHost, and DomStorageSession. The other classes are for 53 // DomStorageHost, and DomStorageSession. The other classes are for
54 // internal consumption. 54 // internal consumption.
55 class DomStorageContext 55 class DomStorageContext
56 : public base::RefCountedThreadSafe<DomStorageContext> { 56 : public base::RefCountedThreadSafe<DomStorageContext> {
57 public: 57 public:
58 struct UsageInfo {
59 GURL origin;
60 size_t data_size;
61 base::Time last_modified;
62 };
63
58 // An interface for observing LocalStorage events on the 64 // An interface for observing LocalStorage events on the
59 // background thread. 65 // background thread.
60 class EventObserver { 66 class EventObserver {
61 public: 67 public:
62 virtual void OnDomStorageItemSet( 68 virtual void OnDomStorageItemSet(
63 const DomStorageArea* area, 69 const DomStorageArea* area,
64 const string16& key, 70 const string16& key,
65 const string16& new_value, 71 const string16& new_value,
66 const NullableString16& old_value, // may be null on initial insert 72 const NullableString16& old_value, // may be null on initial insert
67 const GURL& page_url) = 0; 73 const GURL& page_url) = 0;
68 virtual void OnDomStorageItemRemoved( 74 virtual void OnDomStorageItemRemoved(
69 const DomStorageArea* area, 75 const DomStorageArea* area,
70 const string16& key, 76 const string16& key,
71 const string16& old_value, 77 const string16& old_value,
72 const GURL& page_url) = 0; 78 const GURL& page_url) = 0;
73 virtual void OnDomStorageAreaCleared( 79 virtual void OnDomStorageAreaCleared(
74 const DomStorageArea* area, 80 const DomStorageArea* area,
75 const GURL& page_url) = 0; 81 const GURL& page_url) = 0;
76 virtual ~EventObserver() {} 82 virtual ~EventObserver() {}
77 }; 83 };
78 84
79 DomStorageContext(const FilePath& directory, // empty for incognito profiles 85 DomStorageContext(const FilePath& directory, // empty for incognito profiles
80 quota::SpecialStoragePolicy* special_storage_policy, 86 quota::SpecialStoragePolicy* special_storage_policy,
81 DomStorageTaskRunner* task_runner); 87 DomStorageTaskRunner* task_runner);
88 const FilePath& directory() const { return directory_; }
82 DomStorageTaskRunner* task_runner() const { return task_runner_; } 89 DomStorageTaskRunner* task_runner() const { return task_runner_; }
83 DomStorageNamespace* GetStorageNamespace(int64 namespace_id); 90 DomStorageNamespace* GetStorageNamespace(int64 namespace_id);
84 91
92 void GetUsageInfo(std::vector<UsageInfo>* info);
93 void DeleteOrigin(const GURL& origin);;
94 void DeleteDataModifiedSince(const base::Time& cutoff);
95 void PurgeMemory();
96
97 // Used by content settings to alter the behavior around
98 // what data to keep and what data to discard at shutdown.
99 // The policy is not so straight forward to describe, see
100 // the implementation for details.
101 void SetClearLocalState(bool clear_local_state) {
102 clear_local_state_ = clear_local_state;
103 }
104 void SaveSessionState() {
105 save_session_state_ = true;
106 }
107
108 // Called when the BrowserContext/Profile is going away.
109 void Shutdown();
110
85 // Methods to add, remove, and notify EventObservers. 111 // Methods to add, remove, and notify EventObservers.
86 void AddEventObserver(EventObserver* observer); 112 void AddEventObserver(EventObserver* observer);
87 void RemoveEventObserver(EventObserver* observer); 113 void RemoveEventObserver(EventObserver* observer);
88 void NotifyItemSet( 114 void NotifyItemSet(
89 const DomStorageArea* area, 115 const DomStorageArea* area,
90 const string16& key, 116 const string16& key,
91 const string16& new_value, 117 const string16& new_value,
92 const NullableString16& old_value, 118 const NullableString16& old_value,
93 const GURL& page_url); 119 const GURL& page_url);
94 void NotifyItemRemoved( 120 void NotifyItemRemoved(
(...skipping 19 matching lines...) Expand all
114 friend class base::RefCountedThreadSafe<DomStorageContext>; 140 friend class base::RefCountedThreadSafe<DomStorageContext>;
115 typedef std::map<int64, scoped_refptr<DomStorageNamespace> > 141 typedef std::map<int64, scoped_refptr<DomStorageNamespace> >
116 StorageNamespaceMap; 142 StorageNamespaceMap;
117 143
118 ~DomStorageContext(); 144 ~DomStorageContext();
119 145
120 // Collection of namespaces keyed by id. 146 // Collection of namespaces keyed by id.
121 StorageNamespaceMap namespaces_; 147 StorageNamespaceMap namespaces_;
122 148
123 // Where localstorage data is stored, maybe empty for the incognito use case. 149 // Where localstorage data is stored, maybe empty for the incognito use case.
124 FilePath directory_; 150 const FilePath directory_;
125 151
126 // Used to schedule sequenced background tasks. 152 // Used to schedule sequenced background tasks.
127 scoped_refptr<DomStorageTaskRunner> task_runner_; 153 scoped_refptr<DomStorageTaskRunner> task_runner_;
128 154
129 // List of objects observing local storage events. 155 // List of objects observing local storage events.
130 ObserverList<EventObserver> event_observers_; 156 ObserverList<EventObserver> event_observers_;
131 157
132 // We use a 32 bit identifier for per tab storage sessions. 158 // We use a 32 bit identifier for per tab storage sessions.
133 // At a tab per second, this range is large enough for 68 years. 159 // At a tab per second, this range is large enough for 68 years.
134 base::AtomicSequenceNumber session_id_sequence_; 160 base::AtomicSequenceNumber session_id_sequence_;
161
162 bool clear_local_state_;
163 bool save_session_state_;
164
165 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
135 }; 166 };
136 167
137 } // namespace dom_storage 168 } // namespace dom_storage
138 169
139 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_ 170 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698