| 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/dom_storage/dom_storage_host.h" | 5 #include "webkit/dom_storage/dom_storage_host.h" |
| 6 | 6 |
| 7 #include "googleurl/src/gurl.h" | 7 #include "googleurl/src/gurl.h" |
| 8 #include "webkit/dom_storage/dom_storage_area.h" | 8 #include "webkit/dom_storage/dom_storage_area.h" |
| 9 #include "webkit/dom_storage/dom_storage_context.h" | 9 #include "webkit/dom_storage/dom_storage_context.h" |
| 10 #include "webkit/dom_storage/dom_storage_namespace.h" | 10 #include "webkit/dom_storage/dom_storage_namespace.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 bool DomStorageHost::SetAreaItem( | 82 bool DomStorageHost::SetAreaItem( |
| 83 int connection_id, const string16& key, | 83 int connection_id, const string16& key, |
| 84 const string16& value, const GURL& page_url, | 84 const string16& value, const GURL& page_url, |
| 85 NullableString16* old_value) { | 85 NullableString16* old_value) { |
| 86 DomStorageArea* area = GetOpenArea(connection_id); | 86 DomStorageArea* area = GetOpenArea(connection_id); |
| 87 if (!area) | 87 if (!area) |
| 88 return false; | 88 return false; |
| 89 if (!area->SetItem(key, value, old_value)) | 89 if (!area->SetItem(key, value, old_value)) |
| 90 return false; | 90 return false; |
| 91 if ((area->namespace_id() == kLocalStorageNamespaceId) && | 91 if (old_value->is_null() || old_value->string() != value) |
| 92 (old_value->is_null() || old_value->string() != value)) { | |
| 93 context_->NotifyItemSet(area, key, value, *old_value, page_url); | 92 context_->NotifyItemSet(area, key, value, *old_value, page_url); |
| 94 } | |
| 95 return true; | 93 return true; |
| 96 } | 94 } |
| 97 | 95 |
| 98 bool DomStorageHost::RemoveAreaItem( | 96 bool DomStorageHost::RemoveAreaItem( |
| 99 int connection_id, const string16& key, const GURL& page_url, | 97 int connection_id, const string16& key, const GURL& page_url, |
| 100 string16* old_value) { | 98 string16* old_value) { |
| 101 DomStorageArea* area = GetOpenArea(connection_id); | 99 DomStorageArea* area = GetOpenArea(connection_id); |
| 102 if (!area) | 100 if (!area) |
| 103 return false; | 101 return false; |
| 104 if (!area->RemoveItem(key, old_value)) | 102 if (!area->RemoveItem(key, old_value)) |
| 105 return false; | 103 return false; |
| 106 if (area->namespace_id() == kLocalStorageNamespaceId) | 104 context_->NotifyItemRemoved(area, key, *old_value, page_url); |
| 107 context_->NotifyItemRemoved(area, key, *old_value, page_url); | |
| 108 return true; | 105 return true; |
| 109 } | 106 } |
| 110 | 107 |
| 111 bool DomStorageHost::ClearArea(int connection_id, const GURL& page_url) { | 108 bool DomStorageHost::ClearArea(int connection_id, const GURL& page_url) { |
| 112 DomStorageArea* area = GetOpenArea(connection_id); | 109 DomStorageArea* area = GetOpenArea(connection_id); |
| 113 if (!area) | 110 if (!area) |
| 114 return false; | 111 return false; |
| 115 if (!area->Clear()) | 112 if (!area->Clear()) |
| 116 return false; | 113 return false; |
| 117 if (area->namespace_id() == kLocalStorageNamespaceId) | 114 context_->NotifyAreaCleared(area, page_url); |
| 118 context_->NotifyAreaCleared(area, page_url); | |
| 119 return true; | 115 return true; |
| 120 } | 116 } |
| 121 | 117 |
| 122 DomStorageArea* DomStorageHost::GetOpenArea(int connection_id) { | 118 DomStorageArea* DomStorageHost::GetOpenArea(int connection_id) { |
| 123 AreaMap::iterator found = connections_.find(connection_id); | 119 AreaMap::iterator found = connections_.find(connection_id); |
| 124 if (found == connections_.end()) | 120 if (found == connections_.end()) |
| 125 return NULL; | 121 return NULL; |
| 126 return found->second.area_; | 122 return found->second.area_; |
| 127 } | 123 } |
| 128 | 124 |
| 129 // NamespaceAndArea | 125 // NamespaceAndArea |
| 130 | 126 |
| 131 DomStorageHost::NamespaceAndArea::NamespaceAndArea() {} | 127 DomStorageHost::NamespaceAndArea::NamespaceAndArea() {} |
| 132 DomStorageHost::NamespaceAndArea::~NamespaceAndArea() {} | 128 DomStorageHost::NamespaceAndArea::~NamespaceAndArea() {} |
| 133 | 129 |
| 134 } // namespace dom_storage | 130 } // namespace dom_storage |
| OLD | NEW |