| 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_area.h" | 5 #include "webkit/dom_storage/dom_storage_area.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } | 45 } |
| 46 | 46 |
| 47 // static | 47 // static |
| 48 GURL DomStorageArea::OriginFromDatabaseFileName(const FilePath& name) { | 48 GURL DomStorageArea::OriginFromDatabaseFileName(const FilePath& name) { |
| 49 DCHECK(name.MatchesExtension(kDatabaseFileExtension)); | 49 DCHECK(name.MatchesExtension(kDatabaseFileExtension)); |
| 50 WebKit::WebString origin_id = webkit_glue::FilePathToWebString( | 50 WebKit::WebString origin_id = webkit_glue::FilePathToWebString( |
| 51 name.BaseName().RemoveExtension()); | 51 name.BaseName().RemoveExtension()); |
| 52 return DatabaseUtil::GetOriginFromIdentifier(origin_id); | 52 return DatabaseUtil::GetOriginFromIdentifier(origin_id); |
| 53 } | 53 } |
| 54 | 54 |
| 55 DomStorageArea::DomStorageArea( | 55 DomStorageArea::DomStorageArea(const GURL& origin, const FilePath& directory, |
| 56 int64 namespace_id, const GURL& origin, | 56 DomStorageTaskRunner* task_runner) |
| 57 const FilePath& directory, DomStorageTaskRunner* task_runner) | 57 : namespace_id_(kLocalStorageNamespaceId), origin_(origin), |
| 58 : namespace_id_(namespace_id), origin_(origin), | |
| 59 directory_(directory), | 58 directory_(directory), |
| 60 task_runner_(task_runner), | 59 task_runner_(task_runner), |
| 61 map_(new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance)), | 60 map_(new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance)), |
| 62 is_initial_import_done_(true), | 61 is_initial_import_done_(true), |
| 63 is_shutdown_(false), | 62 is_shutdown_(false), |
| 64 commit_batches_in_flight_(0) { | 63 commit_batches_in_flight_(0) { |
| 65 if (namespace_id == kLocalStorageNamespaceId && !directory.empty()) { | 64 if (!directory.empty()) { |
| 66 FilePath path = directory.Append(DatabaseFileNameFromOrigin(origin_)); | 65 FilePath path = directory.Append(DatabaseFileNameFromOrigin(origin_)); |
| 67 backing_.reset(new DomStorageDatabase(path)); | 66 backing_.reset(new DomStorageDatabase(path)); |
| 68 is_initial_import_done_ = false; | 67 is_initial_import_done_ = false; |
| 69 } | 68 } |
| 70 } | 69 } |
| 71 | 70 |
| 71 DomStorageArea::DomStorageArea( |
| 72 int64 namespace_id, |
| 73 const std::string& persistent_namespace_id, |
| 74 const GURL& origin, |
| 75 DomStorageTaskRunner* task_runner) |
| 76 : namespace_id_(namespace_id), |
| 77 persistent_namespace_id_(persistent_namespace_id), |
| 78 origin_(origin), |
| 79 task_runner_(task_runner), |
| 80 map_(new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance)), |
| 81 is_initial_import_done_(true), |
| 82 is_shutdown_(false), |
| 83 commit_batches_in_flight_(0) { |
| 84 DCHECK(namespace_id != kLocalStorageNamespaceId); |
| 85 } |
| 86 |
| 72 DomStorageArea::~DomStorageArea() { | 87 DomStorageArea::~DomStorageArea() { |
| 73 } | 88 } |
| 74 | 89 |
| 75 void DomStorageArea::ExtractValues(ValuesMap* map) { | 90 void DomStorageArea::ExtractValues(ValuesMap* map) { |
| 76 if (is_shutdown_) | 91 if (is_shutdown_) |
| 77 return; | 92 return; |
| 78 InitialImportIfNeeded(); | 93 InitialImportIfNeeded(); |
| 79 map_->ExtractValues(map); | 94 map_->ExtractValues(map); |
| 80 } | 95 } |
| 81 | 96 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 156 |
| 142 if (backing_.get()) { | 157 if (backing_.get()) { |
| 143 CommitBatch* commit_batch = CreateCommitBatchIfNeeded(); | 158 CommitBatch* commit_batch = CreateCommitBatchIfNeeded(); |
| 144 commit_batch->clear_all_first = true; | 159 commit_batch->clear_all_first = true; |
| 145 commit_batch->changed_values.clear(); | 160 commit_batch->changed_values.clear(); |
| 146 } | 161 } |
| 147 | 162 |
| 148 return true; | 163 return true; |
| 149 } | 164 } |
| 150 | 165 |
| 151 DomStorageArea* DomStorageArea::ShallowCopy(int64 destination_namespace_id) { | 166 DomStorageArea* DomStorageArea::ShallowCopy( |
| 167 int64 destination_namespace_id, |
| 168 const std::string& destination_persistent_namespace_id) { |
| 152 DCHECK_NE(kLocalStorageNamespaceId, namespace_id_); | 169 DCHECK_NE(kLocalStorageNamespaceId, namespace_id_); |
| 153 DCHECK_NE(kLocalStorageNamespaceId, destination_namespace_id); | 170 DCHECK_NE(kLocalStorageNamespaceId, destination_namespace_id); |
| 154 DCHECK(!backing_.get()); // SessionNamespaces aren't stored on disk. | 171 DCHECK(!backing_.get()); // SessionNamespaces aren't stored on disk. |
| 155 | 172 |
| 156 DomStorageArea* copy = new DomStorageArea(destination_namespace_id, origin_, | 173 DomStorageArea* copy = new DomStorageArea( |
| 157 FilePath(), task_runner_); | 174 destination_namespace_id, destination_persistent_namespace_id, origin_, |
| 175 task_runner_); |
| 158 copy->map_ = map_; | 176 copy->map_ = map_; |
| 159 copy->is_shutdown_ = is_shutdown_; | 177 copy->is_shutdown_ = is_shutdown_; |
| 160 return copy; | 178 return copy; |
| 161 } | 179 } |
| 162 | 180 |
| 163 bool DomStorageArea::HasUncommittedChanges() const { | 181 bool DomStorageArea::HasUncommittedChanges() const { |
| 164 DCHECK(!is_shutdown_); | 182 DCHECK(!is_shutdown_); |
| 165 return commit_batch_.get() || commit_batches_in_flight_; | 183 return commit_batch_.get() || commit_batches_in_flight_; |
| 166 } | 184 } |
| 167 | 185 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 bool success = backing_->CommitChanges( | 321 bool success = backing_->CommitChanges( |
| 304 commit_batch_->clear_all_first, | 322 commit_batch_->clear_all_first, |
| 305 commit_batch_->changed_values); | 323 commit_batch_->changed_values); |
| 306 DCHECK(success); | 324 DCHECK(success); |
| 307 } | 325 } |
| 308 commit_batch_.reset(); | 326 commit_batch_.reset(); |
| 309 backing_.reset(); | 327 backing_.reset(); |
| 310 } | 328 } |
| 311 | 329 |
| 312 } // namespace dom_storage | 330 } // namespace dom_storage |
| OLD | NEW |