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

Side by Side Diff: content/browser/dom_storage/dom_storage_database.cc

Issue 1953703004: Purge browser cache for dom storage in a smarter way (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dom_storage
Patch Set: Fix limit and description for UMA. Created 4 years, 7 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/browser/dom_storage/dom_storage_database.h" 5 #include "content/browser/dom_storage/dom_storage_database.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "sql/statement.h" 10 #include "sql/statement.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 "SELECT * from ItemTable")); 61 "SELECT * from ItemTable"));
62 DCHECK(statement.is_valid()); 62 DCHECK(statement.is_valid());
63 63
64 while (statement.Step()) { 64 while (statement.Step()) {
65 base::string16 key = statement.ColumnString16(0); 65 base::string16 key = statement.ColumnString16(0);
66 base::string16 value; 66 base::string16 value;
67 statement.ColumnBlobAsString16(1, &value); 67 statement.ColumnBlobAsString16(1, &value);
68 (*result)[key] = base::NullableString16(value, false); 68 (*result)[key] = base::NullableString16(value, false);
69 } 69 }
70 known_to_be_empty_ = result->empty(); 70 known_to_be_empty_ = result->empty();
71
72 // Reduce the size of sqlite caches.
73 db_->TrimMemory(false /* aggressively */);
71 } 74 }
72 75
73 bool DOMStorageDatabase::CommitChanges(bool clear_all_first, 76 bool DOMStorageDatabase::CommitChanges(bool clear_all_first,
74 const DOMStorageValuesMap& changes) { 77 const DOMStorageValuesMap& changes) {
75 if (!LazyOpen(!changes.empty())) { 78 if (!LazyOpen(!changes.empty())) {
76 // If we're being asked to commit changes that will result in an 79 // If we're being asked to commit changes that will result in an
77 // empty database, we return true if the database file doesn't exist. 80 // empty database, we return true if the database file doesn't exist.
78 return clear_all_first && changes.empty() && 81 return clear_all_first && changes.empty() &&
79 !base::PathExists(file_path_); 82 !base::PathExists(file_path_);
80 } 83 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 if (!known_to_be_empty_ && did_delete && !did_insert) { 121 if (!known_to_be_empty_ && did_delete && !did_insert) {
119 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, 122 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE,
120 "SELECT count(key) from ItemTable")); 123 "SELECT count(key) from ItemTable"));
121 if (statement.Step()) 124 if (statement.Step())
122 known_to_be_empty_ = statement.ColumnInt(0) == 0; 125 known_to_be_empty_ = statement.ColumnInt(0) == 0;
123 } 126 }
124 127
125 bool success = transaction.Commit(); 128 bool success = transaction.Commit();
126 if (!success) 129 if (!success)
127 known_to_be_empty_ = old_known_to_be_empty; 130 known_to_be_empty_ = old_known_to_be_empty;
131
132 // Reduce the size of sqlite caches.
133 db_->TrimMemory(false /* aggressively */);
134
128 return success; 135 return success;
129 } 136 }
130 137
131 bool DOMStorageDatabase::LazyOpen(bool create_if_needed) { 138 bool DOMStorageDatabase::LazyOpen(bool create_if_needed) {
132 if (failed_to_open_) { 139 if (failed_to_open_) {
133 // Don't try to open a database that we know has failed 140 // Don't try to open a database that we know has failed
134 // already. 141 // already.
135 return false; 142 return false;
136 } 143 }
137 144
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 CreateTableV2() && 295 CreateTableV2() &&
289 CommitChanges(false, values) && 296 CommitChanges(false, values) &&
290 migration.Commit(); 297 migration.Commit();
291 } 298 }
292 299
293 void DOMStorageDatabase::Close() { 300 void DOMStorageDatabase::Close() {
294 db_.reset(NULL); 301 db_.reset(NULL);
295 } 302 }
296 303
297 } // namespace content 304 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/dom_storage/dom_storage_context_wrapper.cc ('k') | content/browser/dom_storage/dom_storage_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698