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

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

Issue 10383123: Switch to using the async DomStorage IPC messages and add a caching layer … (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: 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 | « content/renderer/render_thread_impl.h ('k') | webkit/dom_storage/dom_storage_types.h » ('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" 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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,
57 const FilePath& directory, DomStorageTaskRunner* task_runner) 57 const FilePath& directory, 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)), 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 DomStorageDatabase(path));
68 is_initial_import_done_ = false; 68 is_initial_import_done_ = false;
69 } 69 }
70 } 70 }
71 71
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 return success; 130 return success;
131 } 131 }
132 132
133 bool DomStorageArea::Clear() { 133 bool DomStorageArea::Clear() {
134 if (is_shutdown_) 134 if (is_shutdown_)
135 return false; 135 return false;
136 InitialImportIfNeeded(); 136 InitialImportIfNeeded();
137 if (map_->Length() == 0) 137 if (map_->Length() == 0)
138 return false; 138 return false;
139 139
140 map_ = new DomStorageMap(kPerAreaQuota); 140 map_ = new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance);
141 141
142 if (backing_.get()) { 142 if (backing_.get()) {
143 CommitBatch* commit_batch = CreateCommitBatchIfNeeded(); 143 CommitBatch* commit_batch = CreateCommitBatchIfNeeded();
144 commit_batch->clear_all_first = true; 144 commit_batch->clear_all_first = true;
145 commit_batch->changed_values.clear(); 145 commit_batch->changed_values.clear();
146 } 146 }
147 147
148 return true; 148 return true;
149 } 149 }
150 150
(...skipping 18 matching lines...) Expand all
169 DCHECK(!is_shutdown_); 169 DCHECK(!is_shutdown_);
170 if (HasUncommittedChanges()) { 170 if (HasUncommittedChanges()) {
171 // TODO(michaeln): This logically deletes the data immediately, 171 // TODO(michaeln): This logically deletes the data immediately,
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); 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(new DomStorageDatabase(backing_->file_path()));
183 file_util::Delete(backing_->file_path(), false); 183 file_util::Delete(backing_->file_path(), false);
184 file_util::Delete( 184 file_util::Delete(
185 DomStorageDatabase::GetJournalFilePath(backing_->file_path()), false); 185 DomStorageDatabase::GetJournalFilePath(backing_->file_path()), false);
186 } 186 }
187 } 187 }
188 188
189 void DomStorageArea::PurgeMemory() { 189 void DomStorageArea::PurgeMemory() {
190 DCHECK(!is_shutdown_); 190 DCHECK(!is_shutdown_);
191 if (!is_initial_import_done_ || // We're not using any memory. 191 if (!is_initial_import_done_ || // We're not using any memory.
192 !backing_.get() || // We can't purge anything. 192 !backing_.get() || // We can't purge anything.
193 HasUncommittedChanges()) // We leave things alone with changes pending. 193 HasUncommittedChanges()) // We leave things alone with changes pending.
194 return; 194 return;
195 195
196 // Drop the in memory cache, we'll reload when needed. 196 // Drop the in memory cache, we'll reload when needed.
197 is_initial_import_done_ = false; 197 is_initial_import_done_ = false;
198 map_ = new DomStorageMap(kPerAreaQuota); 198 map_ = new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance);
199 199
200 // Recreate the database object, this frees up the open sqlite connection 200 // Recreate the database object, this frees up the open sqlite connection
201 // and its page cache. 201 // and its page cache.
202 backing_.reset(new DomStorageDatabase(backing_->file_path())); 202 backing_.reset(new DomStorageDatabase(backing_->file_path()));
203 } 203 }
204 204
205 void DomStorageArea::Shutdown() { 205 void DomStorageArea::Shutdown() {
206 DCHECK(!is_shutdown_); 206 DCHECK(!is_shutdown_);
207 is_shutdown_ = true; 207 is_shutdown_ = true;
208 map_ = NULL; 208 map_ = NULL;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 bool success = backing_->CommitChanges( 303 bool success = backing_->CommitChanges(
304 commit_batch_->clear_all_first, 304 commit_batch_->clear_all_first,
305 commit_batch_->changed_values); 305 commit_batch_->changed_values);
306 DCHECK(success); 306 DCHECK(success);
307 } 307 }
308 commit_batch_.reset(); 308 commit_batch_.reset();
309 backing_.reset(); 309 backing_.reset();
310 } 310 }
311 311
312 } // namespace dom_storage 312 } // namespace dom_storage
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | webkit/dom_storage/dom_storage_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698