Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: webkit/dom_storage/dom_storage_area.cc

Issue 10556009: DomStorageArea -> DomStorageDatabase indirection; add *StorageDatabaseAdapter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/dom_storage/dom_storage_area.h ('k') | webkit/dom_storage/dom_storage_area_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
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 28 matching lines...) Expand all
56 DomStorageTaskRunner* task_runner) 56 DomStorageTaskRunner* task_runner)
57 : namespace_id_(kLocalStorageNamespaceId), origin_(origin), 57 : namespace_id_(kLocalStorageNamespaceId), origin_(origin),
58 directory_(directory), 58 directory_(directory),
59 task_runner_(task_runner), 59 task_runner_(task_runner),
60 map_(new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance)), 60 map_(new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance)),
61 is_initial_import_done_(true), 61 is_initial_import_done_(true),
62 is_shutdown_(false), 62 is_shutdown_(false),
63 commit_batches_in_flight_(0) { 63 commit_batches_in_flight_(0) {
64 if (!directory.empty()) { 64 if (!directory.empty()) {
65 FilePath path = directory.Append(DatabaseFileNameFromOrigin(origin_)); 65 FilePath path = directory.Append(DatabaseFileNameFromOrigin(origin_));
66 backing_.reset(new DomStorageDatabase(path)); 66 backing_.reset(new LocalStorageDatabaseAdapter(path));
67 is_initial_import_done_ = false; 67 is_initial_import_done_ = false;
68 } 68 }
69 } 69 }
70 70
71 DomStorageArea::DomStorageArea( 71 DomStorageArea::DomStorageArea(
72 int64 namespace_id, 72 int64 namespace_id,
73 const std::string& persistent_namespace_id, 73 const std::string& persistent_namespace_id,
74 const GURL& origin, 74 const GURL& origin,
75 DomStorageTaskRunner* task_runner) 75 DomStorageTaskRunner* task_runner)
76 : namespace_id_(namespace_id), 76 : namespace_id_(namespace_id),
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // and in a matter of a second, deletes the rows from the backing 190 // and in a matter of a second, deletes the rows from the backing
191 // database file, but the file itself will linger until shutdown 191 // database file, but the file itself will linger until shutdown
192 // or purge time. Ideally, this should delete the file more 192 // or purge time. Ideally, this should delete the file more
193 // quickly. 193 // quickly.
194 Clear(); 194 Clear();
195 return; 195 return;
196 } 196 }
197 map_ = new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance); 197 map_ = new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance);
198 if (backing_.get()) { 198 if (backing_.get()) {
199 is_initial_import_done_ = false; 199 is_initial_import_done_ = false;
200 backing_.reset(new DomStorageDatabase(backing_->file_path())); 200 backing_->Reset();
201 file_util::Delete(backing_->file_path(), false); 201 backing_->DeleteFiles();
202 file_util::Delete(
203 DomStorageDatabase::GetJournalFilePath(backing_->file_path()), false);
204 } 202 }
205 } 203 }
206 204
207 void DomStorageArea::PurgeMemory() { 205 void DomStorageArea::PurgeMemory() {
208 DCHECK(!is_shutdown_); 206 DCHECK(!is_shutdown_);
209 if (!is_initial_import_done_ || // We're not using any memory. 207 if (!is_initial_import_done_ || // We're not using any memory.
210 !backing_.get() || // We can't purge anything. 208 !backing_.get() || // We can't purge anything.
211 HasUncommittedChanges()) // We leave things alone with changes pending. 209 HasUncommittedChanges()) // We leave things alone with changes pending.
212 return; 210 return;
213 211
214 // Drop the in memory cache, we'll reload when needed. 212 // Drop the in memory cache, we'll reload when needed.
215 is_initial_import_done_ = false; 213 is_initial_import_done_ = false;
216 map_ = new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance); 214 map_ = new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance);
217 215
218 // Recreate the database object, this frees up the open sqlite connection 216 // Recreate the database object, this frees up the open sqlite connection
219 // and its page cache. 217 // and its page cache.
220 backing_.reset(new DomStorageDatabase(backing_->file_path())); 218 backing_->Reset();
221 } 219 }
222 220
223 void DomStorageArea::Shutdown() { 221 void DomStorageArea::Shutdown() {
224 DCHECK(!is_shutdown_); 222 DCHECK(!is_shutdown_);
225 is_shutdown_ = true; 223 is_shutdown_ = true;
226 map_ = NULL; 224 map_ = NULL;
227 if (!backing_.get()) 225 if (!backing_.get())
228 return; 226 return;
229 227
230 bool success = task_runner_->PostShutdownBlockingTask( 228 bool success = task_runner_->PostShutdownBlockingTask(
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 bool success = backing_->CommitChanges( 319 bool success = backing_->CommitChanges(
322 commit_batch_->clear_all_first, 320 commit_batch_->clear_all_first,
323 commit_batch_->changed_values); 321 commit_batch_->changed_values);
324 DCHECK(success); 322 DCHECK(success);
325 } 323 }
326 commit_batch_.reset(); 324 commit_batch_.reset();
327 backing_.reset(); 325 backing_.reset();
328 } 326 }
329 327
330 } // namespace dom_storage 328 } // namespace dom_storage
OLDNEW
« no previous file with comments | « webkit/dom_storage/dom_storage_area.h ('k') | webkit/dom_storage/dom_storage_area_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698