| 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_area.h" | 5 #include "webkit/browser/dom_storage/dom_storage_area.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 map_->ExtractValues(map); | 106 map_->ExtractValues(map); |
| 107 } | 107 } |
| 108 | 108 |
| 109 unsigned DomStorageArea::Length() { | 109 unsigned DomStorageArea::Length() { |
| 110 if (is_shutdown_) | 110 if (is_shutdown_) |
| 111 return 0; | 111 return 0; |
| 112 InitialImportIfNeeded(); | 112 InitialImportIfNeeded(); |
| 113 return map_->Length(); | 113 return map_->Length(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 NullableString16 DomStorageArea::Key(unsigned index) { | 116 base::NullableString16 DomStorageArea::Key(unsigned index) { |
| 117 if (is_shutdown_) | 117 if (is_shutdown_) |
| 118 return NullableString16(true); | 118 return base::NullableString16(true); |
| 119 InitialImportIfNeeded(); | 119 InitialImportIfNeeded(); |
| 120 return map_->Key(index); | 120 return map_->Key(index); |
| 121 } | 121 } |
| 122 | 122 |
| 123 NullableString16 DomStorageArea::GetItem(const base::string16& key) { | 123 base::NullableString16 DomStorageArea::GetItem(const base::string16& key) { |
| 124 if (is_shutdown_) | 124 if (is_shutdown_) |
| 125 return NullableString16(true); | 125 return base::NullableString16(true); |
| 126 InitialImportIfNeeded(); | 126 InitialImportIfNeeded(); |
| 127 return map_->GetItem(key); | 127 return map_->GetItem(key); |
| 128 } | 128 } |
| 129 | 129 |
| 130 bool DomStorageArea::SetItem(const base::string16& key, | 130 bool DomStorageArea::SetItem(const base::string16& key, |
| 131 const base::string16& value, | 131 const base::string16& value, |
| 132 NullableString16* old_value) { | 132 base::NullableString16* old_value) { |
| 133 if (is_shutdown_) | 133 if (is_shutdown_) |
| 134 return false; | 134 return false; |
| 135 InitialImportIfNeeded(); | 135 InitialImportIfNeeded(); |
| 136 if (!map_->HasOneRef()) | 136 if (!map_->HasOneRef()) |
| 137 map_ = map_->DeepCopy(); | 137 map_ = map_->DeepCopy(); |
| 138 bool success = map_->SetItem(key, value, old_value); | 138 bool success = map_->SetItem(key, value, old_value); |
| 139 if (success && backing_) { | 139 if (success && backing_) { |
| 140 CommitBatch* commit_batch = CreateCommitBatchIfNeeded(); | 140 CommitBatch* commit_batch = CreateCommitBatchIfNeeded(); |
| 141 commit_batch->changed_values[key] = NullableString16(value, false); | 141 commit_batch->changed_values[key] = base::NullableString16(value, false); |
| 142 } | 142 } |
| 143 return success; | 143 return success; |
| 144 } | 144 } |
| 145 | 145 |
| 146 bool DomStorageArea::RemoveItem(const base::string16& key, | 146 bool DomStorageArea::RemoveItem(const base::string16& key, |
| 147 base::string16* old_value) { | 147 base::string16* old_value) { |
| 148 if (is_shutdown_) | 148 if (is_shutdown_) |
| 149 return false; | 149 return false; |
| 150 InitialImportIfNeeded(); | 150 InitialImportIfNeeded(); |
| 151 if (!map_->HasOneRef()) | 151 if (!map_->HasOneRef()) |
| 152 map_ = map_->DeepCopy(); | 152 map_ = map_->DeepCopy(); |
| 153 bool success = map_->RemoveItem(key, old_value); | 153 bool success = map_->RemoveItem(key, old_value); |
| 154 if (success && backing_) { | 154 if (success && backing_) { |
| 155 CommitBatch* commit_batch = CreateCommitBatchIfNeeded(); | 155 CommitBatch* commit_batch = CreateCommitBatchIfNeeded(); |
| 156 commit_batch->changed_values[key] = NullableString16(true); | 156 commit_batch->changed_values[key] = base::NullableString16(true); |
| 157 } | 157 } |
| 158 return success; | 158 return success; |
| 159 } | 159 } |
| 160 | 160 |
| 161 bool DomStorageArea::Clear() { | 161 bool DomStorageArea::Clear() { |
| 162 if (is_shutdown_) | 162 if (is_shutdown_) |
| 163 return false; | 163 return false; |
| 164 InitialImportIfNeeded(); | 164 InitialImportIfNeeded(); |
| 165 if (map_->Length() == 0) | 165 if (map_->Length() == 0) |
| 166 return false; | 166 return false; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 commit_batch_->clear_all_first, | 389 commit_batch_->clear_all_first, |
| 390 commit_batch_->changed_values); | 390 commit_batch_->changed_values); |
| 391 DCHECK(success); | 391 DCHECK(success); |
| 392 } | 392 } |
| 393 commit_batch_.reset(); | 393 commit_batch_.reset(); |
| 394 backing_.reset(); | 394 backing_.reset(); |
| 395 session_storage_backing_ = NULL; | 395 session_storage_backing_ = NULL; |
| 396 } | 396 } |
| 397 | 397 |
| 398 } // namespace dom_storage | 398 } // namespace dom_storage |
| OLD | NEW |