OLD | NEW |
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 #include "webkit/browser/dom_storage/dom_storage_host.h" | 5 #include "webkit/browser/dom_storage/dom_storage_host.h" |
6 | 6 |
7 #include "url/gurl.h" | 7 #include "url/gurl.h" |
8 #include "webkit/browser/dom_storage/dom_storage_area.h" | 8 #include "webkit/browser/dom_storage/dom_storage_area.h" |
9 #include "webkit/browser/dom_storage/dom_storage_context.h" | 9 #include "webkit/browser/dom_storage/dom_storage_context.h" |
10 #include "webkit/browser/dom_storage/dom_storage_namespace.h" | 10 #include "webkit/browser/dom_storage/dom_storage_namespace.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 connections_.clear(); // Clear prior to releasing the context_ | 23 connections_.clear(); // Clear prior to releasing the context_ |
24 } | 24 } |
25 | 25 |
26 bool DomStorageHost::OpenStorageArea(int connection_id, int namespace_id, | 26 bool DomStorageHost::OpenStorageArea(int connection_id, int namespace_id, |
27 const GURL& origin) { | 27 const GURL& origin) { |
28 DCHECK(!GetOpenArea(connection_id)); | 28 DCHECK(!GetOpenArea(connection_id)); |
29 if (GetOpenArea(connection_id)) | 29 if (GetOpenArea(connection_id)) |
30 return false; // Indicates the renderer gave us very bad data. | 30 return false; // Indicates the renderer gave us very bad data. |
31 NamespaceAndArea references; | 31 NamespaceAndArea references; |
32 references.namespace_ = context_->GetStorageNamespace(namespace_id); | 32 references.namespace_ = context_->GetStorageNamespace(namespace_id); |
33 if (!references.namespace_.get()) | 33 if (!references.namespace_.get()) { |
34 return false; | 34 // TODO(michaeln): Fix crbug/134003 and return false here. |
| 35 // Until then return true to avoid crashing the renderer for |
| 36 // sending a bad message. |
| 37 return true; |
| 38 } |
35 references.area_ = references.namespace_->OpenStorageArea(origin); | 39 references.area_ = references.namespace_->OpenStorageArea(origin); |
36 DCHECK(references.area_.get()); | 40 DCHECK(references.area_.get()); |
37 connections_[connection_id] = references; | 41 connections_[connection_id] = references; |
38 return true; | 42 return true; |
39 } | 43 } |
40 | 44 |
41 void DomStorageHost::CloseStorageArea(int connection_id) { | 45 void DomStorageHost::CloseStorageArea(int connection_id) { |
42 AreaMap::iterator found = connections_.find(connection_id); | 46 AreaMap::iterator found = connections_.find(connection_id); |
43 if (found == connections_.end()) | 47 if (found == connections_.end()) |
44 return; | 48 return; |
45 found->second.namespace_->CloseStorageArea(found->second.area_.get()); | 49 found->second.namespace_->CloseStorageArea(found->second.area_.get()); |
46 connections_.erase(found); | 50 connections_.erase(found); |
47 } | 51 } |
48 | 52 |
49 bool DomStorageHost::ExtractAreaValues( | 53 bool DomStorageHost::ExtractAreaValues( |
50 int connection_id, ValuesMap* map) { | 54 int connection_id, ValuesMap* map) { |
51 map->clear(); | 55 map->clear(); |
52 DomStorageArea* area = GetOpenArea(connection_id); | 56 DomStorageArea* area = GetOpenArea(connection_id); |
53 if (!area) | 57 if (!area) { |
54 return false; | 58 // TODO(michaeln): Fix crbug/134003 and return false here. |
| 59 // Until then return true to avoid crashing the renderer |
| 60 // for sending a bad message. |
| 61 return true; |
| 62 } |
55 if (!area->IsLoadedInMemory()) { | 63 if (!area->IsLoadedInMemory()) { |
56 DomStorageNamespace* ns = GetNamespace(connection_id); | 64 DomStorageNamespace* ns = GetNamespace(connection_id); |
57 DCHECK(ns); | 65 DCHECK(ns); |
58 if (ns->CountInMemoryAreas() > kMaxInMemoryAreas) { | 66 if (ns->CountInMemoryAreas() > kMaxInMemoryAreas) { |
59 ns->PurgeMemory(DomStorageNamespace::PURGE_UNOPENED); | 67 ns->PurgeMemory(DomStorageNamespace::PURGE_UNOPENED); |
60 if (ns->CountInMemoryAreas() > kMaxInMemoryAreas) | 68 if (ns->CountInMemoryAreas() > kMaxInMemoryAreas) |
61 ns->PurgeMemory(DomStorageNamespace::PURGE_AGGRESSIVE); | 69 ns->PurgeMemory(DomStorageNamespace::PURGE_AGGRESSIVE); |
62 } | 70 } |
63 } | 71 } |
64 area->ExtractValues(map); | 72 area->ExtractValues(map); |
(...skipping 21 matching lines...) Expand all Loading... |
86 if (!area) | 94 if (!area) |
87 return base::NullableString16(); | 95 return base::NullableString16(); |
88 return area->GetItem(key); | 96 return area->GetItem(key); |
89 } | 97 } |
90 | 98 |
91 bool DomStorageHost::SetAreaItem( | 99 bool DomStorageHost::SetAreaItem( |
92 int connection_id, const base::string16& key, | 100 int connection_id, const base::string16& key, |
93 const base::string16& value, const GURL& page_url, | 101 const base::string16& value, const GURL& page_url, |
94 base::NullableString16* old_value) { | 102 base::NullableString16* old_value) { |
95 DomStorageArea* area = GetOpenArea(connection_id); | 103 DomStorageArea* area = GetOpenArea(connection_id); |
96 if (!area) | 104 if (!area) { |
97 return false; | 105 // TODO(michaeln): Fix crbug/134003 and return false here. |
| 106 // Until then return true to allow the renderer to operate |
| 107 // to a limited degree out of its cache. |
| 108 return true; |
| 109 } |
98 if (!area->SetItem(key, value, old_value)) | 110 if (!area->SetItem(key, value, old_value)) |
99 return false; | 111 return false; |
100 if (old_value->is_null() || old_value->string() != value) | 112 if (old_value->is_null() || old_value->string() != value) |
101 context_->NotifyItemSet(area, key, value, *old_value, page_url); | 113 context_->NotifyItemSet(area, key, value, *old_value, page_url); |
102 return true; | 114 return true; |
103 } | 115 } |
104 | 116 |
105 bool DomStorageHost::RemoveAreaItem( | 117 bool DomStorageHost::RemoveAreaItem( |
106 int connection_id, const base::string16& key, const GURL& page_url, | 118 int connection_id, const base::string16& key, const GURL& page_url, |
107 base::string16* old_value) { | 119 base::string16* old_value) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 return NULL; | 161 return NULL; |
150 return found->second.namespace_.get(); | 162 return found->second.namespace_.get(); |
151 } | 163 } |
152 | 164 |
153 // NamespaceAndArea | 165 // NamespaceAndArea |
154 | 166 |
155 DomStorageHost::NamespaceAndArea::NamespaceAndArea() {} | 167 DomStorageHost::NamespaceAndArea::NamespaceAndArea() {} |
156 DomStorageHost::NamespaceAndArea::~NamespaceAndArea() {} | 168 DomStorageHost::NamespaceAndArea::~NamespaceAndArea() {} |
157 | 169 |
158 } // namespace dom_storage | 170 } // namespace dom_storage |
OLD | NEW |