OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "content/renderer/dom_storage/local_storage_area.h" | 5 #include "content/renderer/dom_storage/local_storage_area.h" |
6 | 6 |
| 7 #include "base/rand_util.h" |
| 8 #include "base/strings/string_number_conversions.h" |
7 #include "third_party/WebKit/public/platform/WebURL.h" | 9 #include "third_party/WebKit/public/platform/WebURL.h" |
8 | 10 |
9 using blink::WebString; | 11 using blink::WebString; |
10 using blink::WebURL; | 12 using blink::WebURL; |
11 | 13 |
12 namespace content { | 14 namespace content { |
13 | 15 |
14 LocalStorageArea::LocalStorageArea( | 16 LocalStorageArea::LocalStorageArea( |
15 scoped_refptr<LocalStorageCachedArea> cached_area) | 17 scoped_refptr<LocalStorageCachedArea> cached_area) |
16 : cached_area_(std::move(cached_area)) { | 18 : cached_area_(std::move(cached_area)), |
| 19 id_(base::Uint64ToString(base::RandUint64())) { |
| 20 cached_area_->AreaCreated(this); |
17 } | 21 } |
18 | 22 |
19 LocalStorageArea::~LocalStorageArea() { | 23 LocalStorageArea::~LocalStorageArea() { |
| 24 cached_area_->AreaDestroyed(this); |
20 } | 25 } |
21 | 26 |
22 unsigned LocalStorageArea::length() { | 27 unsigned LocalStorageArea::length() { |
23 return cached_area_->GetLength(); | 28 return cached_area_->GetLength(); |
24 } | 29 } |
25 | 30 |
26 WebString LocalStorageArea::key(unsigned index) { | 31 WebString LocalStorageArea::key(unsigned index) { |
27 return cached_area_->GetKey(index); | 32 return cached_area_->GetKey(index); |
28 } | 33 } |
29 | 34 |
30 WebString LocalStorageArea::getItem(const WebString& key) { | 35 WebString LocalStorageArea::getItem(const WebString& key) { |
31 return cached_area_->GetItem(key); | 36 return cached_area_->GetItem(key); |
32 } | 37 } |
33 | 38 |
34 void LocalStorageArea::setItem( | 39 void LocalStorageArea::setItem( |
35 const WebString& key, const WebString& value, const WebURL& page_url, | 40 const WebString& key, const WebString& value, const WebURL& page_url, |
36 WebStorageArea::Result& result) { | 41 WebStorageArea::Result& result) { |
37 if (!cached_area_->SetItem(key, value, page_url)) | 42 if (!cached_area_->SetItem(key, value, page_url, id_)) |
38 result = ResultBlockedByQuota; | 43 result = ResultBlockedByQuota; |
39 else | 44 else |
40 result = ResultOK; | 45 result = ResultOK; |
41 } | 46 } |
42 | 47 |
43 void LocalStorageArea::removeItem( | 48 void LocalStorageArea::removeItem( |
44 const WebString& key, const WebURL& page_url) { | 49 const WebString& key, const WebURL& page_url) { |
45 cached_area_->RemoveItem(key, page_url); | 50 cached_area_->RemoveItem(key, page_url, id_); |
46 } | 51 } |
47 | 52 |
48 void LocalStorageArea::clear(const WebURL& page_url) { | 53 void LocalStorageArea::clear(const WebURL& page_url) { |
| 54 cached_area_->Clear(page_url, id_); |
49 } | 55 } |
50 | 56 |
51 } // namespace content | 57 } // namespace content |
OLD | NEW |