Chromium Code Reviews| 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" | |
| 9 #include "base/location.h" | 8 #include "base/location.h" |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 #include "base/time.h" | 10 #include "base/time.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 13 #include "webkit/database/database_util.h" | 12 #include "webkit/database/database_util.h" |
| 14 #include "webkit/dom_storage/dom_storage_map.h" | 13 #include "webkit/dom_storage/dom_storage_map.h" |
| 15 #include "webkit/dom_storage/dom_storage_namespace.h" | 14 #include "webkit/dom_storage/dom_storage_namespace.h" |
| 16 #include "webkit/dom_storage/dom_storage_task_runner.h" | 15 #include "webkit/dom_storage/dom_storage_task_runner.h" |
| 17 #include "webkit/dom_storage/dom_storage_types.h" | 16 #include "webkit/dom_storage/dom_storage_types.h" |
| 17 #include "webkit/dom_storage/local_storage_database_adapter.h" | |
|
michaeln
2012/06/15 19:02:43
depending on what happens in the .h file, this may
marja
2012/06/19 10:43:30
Include removed from the .h -> kept this.
| |
| 18 #include "webkit/fileapi/file_system_util.h" | 18 #include "webkit/fileapi/file_system_util.h" |
| 19 #include "webkit/glue/webkit_glue.h" | 19 #include "webkit/glue/webkit_glue.h" |
| 20 | 20 |
| 21 using webkit_database::DatabaseUtil; | 21 using webkit_database::DatabaseUtil; |
| 22 | 22 |
| 23 namespace dom_storage { | 23 namespace dom_storage { |
| 24 | 24 |
| 25 static const int kCommitTimerSeconds = 1; | 25 static const int kCommitTimerSeconds = 1; |
| 26 | 26 |
| 27 DomStorageArea::CommitBatch::CommitBatch() | 27 DomStorageArea::CommitBatch::CommitBatch() |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 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( |
| 56 int64 namespace_id, const GURL& origin, | 56 int64 namespace_id, const GURL& origin, const FilePath& directory, |
| 57 const FilePath& directory, DomStorageTaskRunner* task_runner) | 57 DomStorageTaskRunner* task_runner) |
| 58 : namespace_id_(namespace_id), origin_(origin), | 58 : namespace_id_(namespace_id), origin_(origin), |
| 59 directory_(directory), | 59 directory_(directory), |
| 60 task_runner_(task_runner), | 60 task_runner_(task_runner), |
| 61 map_(new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance)), | 61 map_(new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance)), |
| 62 is_initial_import_done_(true), | 62 is_initial_import_done_(true), |
| 63 is_shutdown_(false), | 63 is_shutdown_(false), |
| 64 commit_batches_in_flight_(0) { | 64 commit_batches_in_flight_(0) { |
| 65 if (namespace_id == kLocalStorageNamespaceId && !directory.empty()) { | 65 if (namespace_id == kLocalStorageNamespaceId && !directory.empty()) { |
| 66 FilePath path = directory.Append(DatabaseFileNameFromOrigin(origin_)); | 66 FilePath path = directory.Append(DatabaseFileNameFromOrigin(origin_)); |
| 67 backing_.reset(new DomStorageDatabase(path)); | 67 backing_.reset(new LocalStorageDatabaseAdapter(path)); |
| 68 is_initial_import_done_ = false; | 68 is_initial_import_done_ = false; |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 DomStorageArea::~DomStorageArea() { | 72 DomStorageArea::~DomStorageArea() { |
| 73 } | 73 } |
| 74 | 74 |
| 75 void DomStorageArea::ExtractValues(ValuesMap* map) { | 75 void DomStorageArea::ExtractValues(ValuesMap* map) { |
| 76 if (is_shutdown_) | 76 if (is_shutdown_) |
| 77 return; | 77 return; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 // and in a matter of a second, deletes the rows from the backing | 172 // and in a matter of a second, deletes the rows from the backing |
| 173 // database file, but the file itself will linger until shutdown | 173 // database file, but the file itself will linger until shutdown |
| 174 // or purge time. Ideally, this should delete the file more | 174 // or purge time. Ideally, this should delete the file more |
| 175 // quickly. | 175 // quickly. |
| 176 Clear(); | 176 Clear(); |
| 177 return; | 177 return; |
| 178 } | 178 } |
| 179 map_ = new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance); | 179 map_ = new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance); |
| 180 if (backing_.get()) { | 180 if (backing_.get()) { |
| 181 is_initial_import_done_ = false; | 181 is_initial_import_done_ = false; |
| 182 backing_.reset(new DomStorageDatabase(backing_->file_path())); | 182 backing_->Reset(); |
| 183 file_util::Delete(backing_->file_path(), false); | 183 backing_->DeleteFiles(); |
| 184 file_util::Delete( | |
| 185 DomStorageDatabase::GetJournalFilePath(backing_->file_path()), false); | |
| 186 } | 184 } |
| 187 } | 185 } |
| 188 | 186 |
| 189 void DomStorageArea::PurgeMemory() { | 187 void DomStorageArea::PurgeMemory() { |
| 190 DCHECK(!is_shutdown_); | 188 DCHECK(!is_shutdown_); |
| 191 if (!is_initial_import_done_ || // We're not using any memory. | 189 if (!is_initial_import_done_ || // We're not using any memory. |
| 192 !backing_.get() || // We can't purge anything. | 190 !backing_.get() || // We can't purge anything. |
| 193 HasUncommittedChanges()) // We leave things alone with changes pending. | 191 HasUncommittedChanges()) // We leave things alone with changes pending. |
| 194 return; | 192 return; |
| 195 | 193 |
| 196 // Drop the in memory cache, we'll reload when needed. | 194 // Drop the in memory cache, we'll reload when needed. |
| 197 is_initial_import_done_ = false; | 195 is_initial_import_done_ = false; |
| 198 map_ = new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance); | 196 map_ = new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance); |
| 199 | 197 |
| 200 // Recreate the database object, this frees up the open sqlite connection | 198 // Recreate the database object, this frees up the open sqlite connection |
| 201 // and its page cache. | 199 // and its page cache. |
| 202 backing_.reset(new DomStorageDatabase(backing_->file_path())); | 200 backing_->Reset(); |
| 203 } | 201 } |
| 204 | 202 |
| 205 void DomStorageArea::Shutdown() { | 203 void DomStorageArea::Shutdown() { |
| 206 DCHECK(!is_shutdown_); | 204 DCHECK(!is_shutdown_); |
| 207 is_shutdown_ = true; | 205 is_shutdown_ = true; |
| 208 map_ = NULL; | 206 map_ = NULL; |
| 209 if (!backing_.get()) | 207 if (!backing_.get()) |
| 210 return; | 208 return; |
| 211 | 209 |
| 212 bool success = task_runner_->PostShutdownBlockingTask( | 210 bool success = task_runner_->PostShutdownBlockingTask( |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 bool success = backing_->CommitChanges( | 301 bool success = backing_->CommitChanges( |
| 304 commit_batch_->clear_all_first, | 302 commit_batch_->clear_all_first, |
| 305 commit_batch_->changed_values); | 303 commit_batch_->changed_values); |
| 306 DCHECK(success); | 304 DCHECK(success); |
| 307 } | 305 } |
| 308 commit_batch_.reset(); | 306 commit_batch_.reset(); |
| 309 backing_.reset(); | 307 backing_.reset(); |
| 310 } | 308 } |
| 311 | 309 |
| 312 } // namespace dom_storage | 310 } // namespace dom_storage |
| OLD | NEW |