| 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" |
| 11 #include "webkit/dom_storage/dom_storage_types.h" | 11 #include "webkit/dom_storage/dom_storage_types.h" |
| 12 | 12 |
| 13 namespace dom_storage { | 13 namespace dom_storage { |
| 14 | 14 |
| 15 DomStorageHost::DomStorageHost(DomStorageContext* context) | 15 DomStorageHost::DomStorageHost(DomStorageContext* context) |
| 16 : context_(context) { | 16 : context_(context) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 DomStorageHost::~DomStorageHost() { | 19 DomStorageHost::~DomStorageHost() { |
| 20 AreaMap::const_iterator it = connections_.begin(); | 20 AreaMap::const_iterator it = connections_.begin(); |
| 21 for (; it != connections_.end(); ++it) | 21 for (; it != connections_.end(); ++it) |
| 22 it->second.namespace_->CloseStorageArea(it->second.area_); | 22 it->second.namespace_->CloseStorageArea(it->second.area_.get()); |
| 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_) { | 33 if (!references.namespace_.get()) { |
| 34 // TODO(michaeln): Fix crbug/134003 and return false here. | 34 // TODO(michaeln): Fix crbug/134003 and return false here. |
| 35 // Until then return true to avoid crashing the renderer for | 35 // Until then return true to avoid crashing the renderer for |
| 36 // sending a bad message. | 36 // sending a bad message. |
| 37 return true; | 37 return true; |
| 38 } | 38 } |
| 39 references.area_ = references.namespace_->OpenStorageArea(origin); | 39 references.area_ = references.namespace_->OpenStorageArea(origin); |
| 40 DCHECK(references.area_); | 40 DCHECK(references.area_.get()); |
| 41 connections_[connection_id] = references; | 41 connections_[connection_id] = references; |
| 42 return true; | 42 return true; |
| 43 } | 43 } |
| 44 | 44 |
| 45 void DomStorageHost::CloseStorageArea(int connection_id) { | 45 void DomStorageHost::CloseStorageArea(int connection_id) { |
| 46 AreaMap::iterator found = connections_.find(connection_id); | 46 AreaMap::iterator found = connections_.find(connection_id); |
| 47 if (found == connections_.end()) | 47 if (found == connections_.end()) |
| 48 return; | 48 return; |
| 49 found->second.namespace_->CloseStorageArea( | 49 found->second.namespace_->CloseStorageArea(found->second.area_.get()); |
| 50 found->second.area_); | |
| 51 connections_.erase(found); | 50 connections_.erase(found); |
| 52 } | 51 } |
| 53 | 52 |
| 54 bool DomStorageHost::ExtractAreaValues( | 53 bool DomStorageHost::ExtractAreaValues( |
| 55 int connection_id, ValuesMap* map) { | 54 int connection_id, ValuesMap* map) { |
| 56 map->clear(); | 55 map->clear(); |
| 57 DomStorageArea* area = GetOpenArea(connection_id); | 56 DomStorageArea* area = GetOpenArea(connection_id); |
| 58 if (!area) { | 57 if (!area) { |
| 59 // TODO(michaeln): Fix crbug/134003 and return false here. | 58 // TODO(michaeln): Fix crbug/134003 and return false here. |
| 60 // Until then return true to avoid crashing the renderer | 59 // Until then return true to avoid crashing the renderer |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 return true; | 144 return true; |
| 146 } | 145 } |
| 147 } | 146 } |
| 148 return false; | 147 return false; |
| 149 } | 148 } |
| 150 | 149 |
| 151 DomStorageArea* DomStorageHost::GetOpenArea(int connection_id) { | 150 DomStorageArea* DomStorageHost::GetOpenArea(int connection_id) { |
| 152 AreaMap::iterator found = connections_.find(connection_id); | 151 AreaMap::iterator found = connections_.find(connection_id); |
| 153 if (found == connections_.end()) | 152 if (found == connections_.end()) |
| 154 return NULL; | 153 return NULL; |
| 155 return found->second.area_; | 154 return found->second.area_.get(); |
| 156 } | 155 } |
| 157 | 156 |
| 158 DomStorageNamespace* DomStorageHost::GetNamespace(int connection_id) { | 157 DomStorageNamespace* DomStorageHost::GetNamespace(int connection_id) { |
| 159 AreaMap::iterator found = connections_.find(connection_id); | 158 AreaMap::iterator found = connections_.find(connection_id); |
| 160 if (found == connections_.end()) | 159 if (found == connections_.end()) |
| 161 return NULL; | 160 return NULL; |
| 162 return found->second.namespace_; | 161 return found->second.namespace_.get(); |
| 163 } | 162 } |
| 164 | 163 |
| 165 // NamespaceAndArea | 164 // NamespaceAndArea |
| 166 | 165 |
| 167 DomStorageHost::NamespaceAndArea::NamespaceAndArea() {} | 166 DomStorageHost::NamespaceAndArea::NamespaceAndArea() {} |
| 168 DomStorageHost::NamespaceAndArea::~NamespaceAndArea() {} | 167 DomStorageHost::NamespaceAndArea::~NamespaceAndArea() {} |
| 169 | 168 |
| 170 } // namespace dom_storage | 169 } // namespace dom_storage |
| OLD | NEW |