OLD | NEW |
1 // Copyright (c) 2011 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 CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_AREA_H_ | 5 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
6 #define CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_AREA_H_ | 6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/hash_tables.h" | 9 #include "base/file_path.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/nullable_string16.h" | 11 #include "base/nullable_string16.h" |
13 #include "base/string16.h" | 12 #include "base/string16.h" |
14 #include "content/common/dom_storage_common.h" | |
15 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h" | 14 #include "webkit/dom_storage/dom_storage_task_runner.h" |
17 | 15 |
18 class DOMStorageNamespace; | 16 class FilePath; |
19 // Only use on the WebKit thread. DOMStorageNamespace manages our registration | 17 class GURL; |
20 // with DOMStorageContext. | 18 |
21 class DOMStorageArea { | 19 namespace dom_storage { |
| 20 |
| 21 class DomStorageMap; |
| 22 |
| 23 // Container for a per-origin Map of key/value pairs potentially |
| 24 // backed by storage on disk and lazily commits changes to disk. |
| 25 // See class comments for DomStorageContext for a larger overview. |
| 26 class DomStorageArea |
| 27 : public base::RefCountedThreadSafe<DomStorageArea> { |
| 28 |
22 public: | 29 public: |
23 DOMStorageArea(const string16& origin, | 30 DomStorageArea(int64 namespace_id, |
24 int64 id, | 31 const GURL& origin, |
25 DOMStorageNamespace* owner); | 32 const FilePath& directory, |
26 ~DOMStorageArea(); | 33 DomStorageTaskRunner* task_runner); |
| 34 |
| 35 const GURL& origin() const { return origin_; } |
| 36 int64 namespace_id() const { return namespace_id_; } |
27 | 37 |
28 unsigned Length(); | 38 unsigned Length(); |
29 NullableString16 Key(unsigned index); | 39 NullableString16 Key(unsigned index); |
30 NullableString16 GetItem(const string16& key); | 40 NullableString16 GetItem(const string16& key); |
31 NullableString16 SetItem( | 41 bool SetItem(const string16& key, const string16& value, |
32 const string16& key, const string16& value, | 42 NullableString16* old_value); |
33 WebKit::WebStorageArea::Result* result); | 43 bool RemoveItem(const string16& key, string16* old_value); |
34 NullableString16 RemoveItem(const string16& key); | |
35 bool Clear(); | 44 bool Clear(); |
36 void PurgeMemory(); | |
37 | 45 |
38 int64 id() const { return id_; } | 46 DomStorageArea* ShallowCopy(int64 destination_namespace_id); |
39 | |
40 DOMStorageNamespace* owner() const { return owner_; } | |
41 | 47 |
42 private: | 48 private: |
43 // Creates the underlying WebStorageArea on demand. | 49 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DomStorageAreaBasics); |
44 void CreateWebStorageAreaIfNecessary(); | 50 friend class base::RefCountedThreadSafe<DomStorageArea>; |
45 | 51 |
46 // The origin this storage area represents. | 52 ~DomStorageArea(); |
47 string16 origin_; | |
48 GURL origin_url_; | |
49 | 53 |
50 // The storage area we wrap. | 54 int64 namespace_id_; |
51 scoped_ptr<WebKit::WebStorageArea> storage_area_; | 55 GURL origin_; |
52 | 56 FilePath directory_; |
53 // Our storage area id. Unique to our parent WebKitContext. | 57 scoped_refptr<DomStorageTaskRunner> task_runner_; |
54 int64 id_; | 58 scoped_refptr<DomStorageMap> map_; |
55 | 59 // TODO(benm): integrate with DomStorageDatabase to read from |
56 // The DOMStorageNamespace that owns us. | 60 // and lazily write to disk. |
57 DOMStorageNamespace* owner_; | |
58 | |
59 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageArea); | |
60 }; | 61 }; |
61 | 62 |
62 #if defined(COMPILER_GCC) | 63 } // namespace dom_storage |
63 namespace __gnu_cxx { | |
64 | 64 |
65 template<> | 65 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
66 struct hash<DOMStorageArea*> { | |
67 std::size_t operator()(DOMStorageArea* const& p) const { | |
68 return reinterpret_cast<std::size_t>(p); | |
69 } | |
70 }; | |
71 | |
72 } // namespace __gnu_cxx | |
73 #endif | |
74 | |
75 #endif // CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_AREA_H_ | |
OLD | NEW |