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

Side by Side Diff: chrome/browser/net/sqlite_persistent_cookie_store.cc

Issue 7864008: Split initial load of cookies by domains (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/net/sqlite_persistent_cookie_store.h" 5 #include "chrome/browser/net/sqlite_persistent_cookie_store.h"
6 6
7 #include <list> 7 #include <list>
8 #include <map>
9 #include <set>
10 #include <utility>
8 11
9 #include "base/basictypes.h" 12 #include "base/basictypes.h"
10 #include "base/bind.h" 13 #include "base/bind.h"
11 #include "base/file_path.h" 14 #include "base/file_path.h"
12 #include "base/file_util.h" 15 #include "base/file_util.h"
13 #include "base/logging.h" 16 #include "base/logging.h"
14 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
16 #include "base/metrics/histogram.h" 19 #include "base/metrics/histogram.h"
17 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/synchronization/lock.h"
18 #include "base/threading/thread.h" 22 #include "base/threading/thread.h"
19 #include "base/threading/thread_restrictions.h" 23 #include "base/threading/thread_restrictions.h"
20 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" 24 #include "chrome/browser/diagnostics/sqlite_diagnostics.h"
21 #include "content/browser/browser_thread.h" 25 #include "content/browser/browser_thread.h"
22 #include "googleurl/src/gurl.h" 26 #include "googleurl/src/gurl.h"
27 #include "net/base/registry_controlled_domain.h"
28
erikwright (departed) 2011/10/04 19:55:02 remove this blank line
guohui 2011/10/06 15:40:00 Done.
23 #include "sql/meta_table.h" 29 #include "sql/meta_table.h"
24 #include "sql/statement.h" 30 #include "sql/statement.h"
25 #include "sql/transaction.h" 31 #include "sql/transaction.h"
26 32
27 using base::Time; 33 using base::Time;
28 34
29 // This class is designed to be shared between any calling threads and the 35 // This class is designed to be shared between any calling threads and the
30 // database thread. It batches operations and commits them on a timer. 36 // database thread. It batches operations and commits them on a timer.
31 // This class expects to be Load()'ed once on any thread. Loading occurs 37 //
32 // asynchronously on the DB thread and the caller will be notified on the IO 38 // SQLitePersistentCookieStore::Load is called to load all cookies. It
33 // thread. Subsequent to loading, mutations may be queued by any thread using 39 // delegates to Backend::Load, which posts a Backend::LoadAndNotifyOnDBThread
40 // task to the DB thread. This task calls Backend::ChainLoadCookies(), which
41 // repeatedly posts itself to the DB thread to load each eTLD+1's cookie in
erikwright (departed) 2011/10/04 19:55:02 'cookie in' => 'cookies in'
guohui 2011/10/06 15:40:00 Done.
42 // separate tasks. When this is complete, Backend::NotifyOnIOThread is posted
43 // to the IO thread, which notifies the caller of SQLitePersistentCookieStore::
44 // Load that the load is complete.
45 //
46 // If a priority load request is invoked via SQLitePersistentCookieStore::
47 // LoadCookiesForKey, it is delegated to Backend::LoadCookiesForKey, which posts
48 // Backend::LoadKeyAndNotifyOnDBThread to the DB thread.That routine loads just
erikwright (departed) 2011/10/04 19:55:02 "thread.That" => "thread. That"
guohui 2011/10/06 15:40:00 Done.
49 // that single domain key (eTLD+1)'s cookies, and posts a Backend::
50 // NotifyOnIOThread to the IO thread to notify the caller of
51 // SQLitePersistentCookieStore::LoadCookiesForKey that load is complete.
erikwright (departed) 2011/10/04 19:55:02 "that load is" => "that that load is" It's awkwar
guohui 2011/10/06 15:40:00 Done.
52 //
53 // Subsequent to loading, mutations may be queued by any thread using
34 // AddCookie, UpdateCookieAccessTime, and DeleteCookie. These are flushed to 54 // AddCookie, UpdateCookieAccessTime, and DeleteCookie. These are flushed to
35 // disk on the DB thread every 30 seconds, 512 operations, or call to Flush(), 55 // disk on the DB thread every 30 seconds, 512 operations, or call to Flush(),
36 // whichever occurs first. 56 // whichever occurs first.
37 class SQLitePersistentCookieStore::Backend 57 class SQLitePersistentCookieStore::Backend
38 : public base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend> { 58 : public base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend> {
39 public: 59 public:
40 explicit Backend(const FilePath& path) 60 explicit Backend(const FilePath& path)
41 : path_(path), 61 : path_(path),
42 db_(NULL), 62 db_(NULL),
43 num_pending_(0), 63 num_pending_(0),
44 clear_local_state_on_exit_(false) { 64 clear_local_state_on_exit_(false),
65 initialized_(false) {
45 } 66 }
46 67
47 // Creates or load the SQLite database. 68 // Creates or loads the SQLite database.
48 bool Load(const LoadedCallback& loaded_callback); 69 void Load(const LoadedCallback& loaded_callback);
70
71 // Loads cookies for the domain key (eTLD+1).
72 void LoadCookiesForKey(const std::string& domain,
73 const LoadedCallback& loaded_callback);
49 74
50 // Batch a cookie addition. 75 // Batch a cookie addition.
51 void AddCookie(const net::CookieMonster::CanonicalCookie& cc); 76 void AddCookie(const net::CookieMonster::CanonicalCookie& cc);
52 77
53 // Batch a cookie access time update. 78 // Batch a cookie access time update.
54 void UpdateCookieAccessTime(const net::CookieMonster::CanonicalCookie& cc); 79 void UpdateCookieAccessTime(const net::CookieMonster::CanonicalCookie& cc);
55 80
56 // Batch a cookie deletion. 81 // Batch a cookie deletion.
57 void DeleteCookie(const net::CookieMonster::CanonicalCookie& cc); 82 void DeleteCookie(const net::CookieMonster::CanonicalCookie& cc);
58 83
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 116
92 OperationType op() const { return op_; } 117 OperationType op() const { return op_; }
93 const net::CookieMonster::CanonicalCookie& cc() const { return cc_; } 118 const net::CookieMonster::CanonicalCookie& cc() const { return cc_; }
94 119
95 private: 120 private:
96 OperationType op_; 121 OperationType op_;
97 net::CookieMonster::CanonicalCookie cc_; 122 net::CookieMonster::CanonicalCookie cc_;
98 }; 123 };
99 124
100 private: 125 private:
101 // Creates or load the SQLite database on DB thread. 126 // Creates or loads the SQLite database on DB thread.
102 void LoadAndNotifyOnDBThread(const LoadedCallback& loaded_callback); 127 void LoadAndNotifyOnDBThread(const LoadedCallback& loaded_callback);
103 // Notify the CookieMonster when loading complete. 128
129 // Loads cookies for the domain key (eTLD+1) on DB thread.
130 void LoadKeyAndNotifyOnDBThread(const std::string& domains,
131 const LoadedCallback& loaded_callback);
132
133 // Notifies the CookieMonster when loading completes for a specific domain key
134 // or for all domain keys. Triggers the callback and passes it all cookies
135 // that have been loaded from DB since last IO notification.
104 void NotifyOnIOThread( 136 void NotifyOnIOThread(
105 const LoadedCallback& loaded_callback, 137 const LoadedCallback& loaded_callback,
106 bool load_success, 138 bool load_success);
107 const std::vector<net::CookieMonster::CanonicalCookie*>& cookies);
108 // Initialize the data base. 139 // Initialize the data base.
140
109 bool InitializeDatabase(); 141 bool InitializeDatabase();
110 // Load cookies to the data base, and read cookies. 142
111 bool LoadInternal(std::vector<net::CookieMonster::CanonicalCookie*>* cookies); 143 // Chain load cookies from DB by domain key.
144 void ChainLoadCookies(const LoadedCallback& loaded_callback);
145
146 // Load all cookies for a set of domains/hosts
147 bool LoadCookiesForDomains(const std::set<std::string>& key);
112 148
113 // Batch a cookie operation (add or delete) 149 // Batch a cookie operation (add or delete)
114 void BatchOperation(PendingOperation::OperationType op, 150 void BatchOperation(PendingOperation::OperationType op,
115 const net::CookieMonster::CanonicalCookie& cc); 151 const net::CookieMonster::CanonicalCookie& cc);
116 // Commit our pending operations to the database. 152 // Commit our pending operations to the database.
117 void Commit(); 153 void Commit();
118 // Close() executed on the background thread. 154 // Close() executed on the background thread.
119 void InternalBackgroundClose(); 155 void InternalBackgroundClose();
120 156
121 FilePath path_; 157 FilePath path_;
122 scoped_ptr<sql::Connection> db_; 158 scoped_ptr<sql::Connection> db_;
123 sql::MetaTable meta_table_; 159 sql::MetaTable meta_table_;
124 160
125 typedef std::list<PendingOperation*> PendingOperationsList; 161 typedef std::list<PendingOperation*> PendingOperationsList;
126 PendingOperationsList pending_; 162 PendingOperationsList pending_;
127 PendingOperationsList::size_type num_pending_; 163 PendingOperationsList::size_type num_pending_;
128 // True if the persistent store should be deleted upon destruction. 164 // True if the persistent store should be deleted upon destruction.
129 bool clear_local_state_on_exit_; 165 bool clear_local_state_on_exit_;
130 // Guard |pending_|, |num_pending_| and |clear_local_state_on_exit_|. 166 // Guard |cookies_|, |pending_|, |num_pending_| and
167 // |clear_local_state_on_exit_|.
131 base::Lock lock_; 168 base::Lock lock_;
132 169
170 // Temporary buffer for cookies loaded from DB. Accumulates cookies to reduce
171 // the number of messages sent to the IO thread. Sent back in response to
172 // individual load requests for domain keys or when all loading completes.
173 std::vector<net::CookieMonster::CanonicalCookie*> cookies_;
174
175 // Map of domain keys(eTLD+1) to domains/hosts that are to be loaded from DB.
176 std::map<std::string, std::set<std::string>> keys_to_load_;
177
178 // Indicates if DB has been initialized.
179 bool initialized_;
180
133 DISALLOW_COPY_AND_ASSIGN(Backend); 181 DISALLOW_COPY_AND_ASSIGN(Backend);
134 }; 182 };
135 183
136 // Version number of the database. In version 4, we migrated the time epoch. 184 // Version number of the database. In version 4, we migrated the time epoch.
137 // If you open the DB with an older version on Mac or Linux, the times will 185 // If you open the DB with an older version on Mac or Linux, the times will
138 // look wonky, but the file will likely be usable. On Windows version 3 and 4 186 // look wonky, but the file will likely be usable. On Windows version 3 and 4
139 // are the same. 187 // are the same.
140 // 188 //
141 // Version 3 updated the database to include the last access time, so we can 189 // Version 3 updated the database to include the last access time, so we can
142 // expire them in decreasing order of use when we've reached the maximum 190 // expire them in decreasing order of use when we've reached the maximum
(...skipping 17 matching lines...) Expand all
160 "secure INTEGER NOT NULL," 208 "secure INTEGER NOT NULL,"
161 "httponly INTEGER NOT NULL," 209 "httponly INTEGER NOT NULL,"
162 "last_access_utc INTEGER NOT NULL)")) 210 "last_access_utc INTEGER NOT NULL)"))
163 return false; 211 return false;
164 } 212 }
165 213
166 // Try to create the index every time. Older versions did not have this index, 214 // Try to create the index every time. Older versions did not have this index,
167 // so we want those people to get it. Ignore errors, since it may exist. 215 // so we want those people to get it. Ignore errors, since it may exist.
168 db->Execute("CREATE INDEX IF NOT EXISTS cookie_times ON cookies" 216 db->Execute("CREATE INDEX IF NOT EXISTS cookie_times ON cookies"
169 " (creation_utc)"); 217 " (creation_utc)");
218
219 db->Execute("CREATE INDEX IF NOT EXISTS domain ON cookies(host_key)");
220
170 return true; 221 return true;
171 } 222 }
172 223
173 } // namespace 224 } // namespace
174 225
175 bool SQLitePersistentCookieStore::Backend::Load( 226 void SQLitePersistentCookieStore::Backend::Load(
176 const LoadedCallback& loaded_callback) { 227 const LoadedCallback& loaded_callback) {
177 // This function should be called only once per instance. 228 // This function should be called only once per instance.
178 DCHECK(!db_.get()); 229 DCHECK(!db_.get());
179 BrowserThread::PostTask( 230 BrowserThread::PostTask(
180 BrowserThread::DB, FROM_HERE, 231 BrowserThread::DB, FROM_HERE,
181 base::Bind(&Backend::LoadAndNotifyOnDBThread, base::Unretained(this), 232 base::Bind(&Backend::LoadAndNotifyOnDBThread, this, loaded_callback));
182 loaded_callback)); 233 }
183 return true; 234
235 void SQLitePersistentCookieStore::Backend::LoadCookiesForKey(
236 const std::string& key,
237 const LoadedCallback& loaded_callback) {
238 BrowserThread::PostTask(
239 BrowserThread::DB, FROM_HERE,
240 base::Bind(&Backend::LoadKeyAndNotifyOnDBThread, this,
241 key,
242 loaded_callback));
184 } 243 }
185 244
186 void SQLitePersistentCookieStore::Backend::LoadAndNotifyOnDBThread( 245 void SQLitePersistentCookieStore::Backend::LoadAndNotifyOnDBThread(
187 const LoadedCallback& loaded_callback) { 246 const LoadedCallback& loaded_callback) {
188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
189 std::vector<net::CookieMonster::CanonicalCookie*> cookies;
190 248
191 bool load_success = LoadInternal(&cookies); 249 if (!InitializeDatabase()) {
250 BrowserThread::PostTask(
251 BrowserThread::IO, FROM_HERE,
252 base::Bind(&SQLitePersistentCookieStore::Backend::NotifyOnIOThread,
253 this, loaded_callback, false));
254 } else {
255 ChainLoadCookies(loaded_callback);
256 }
257 }
192 258
193 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( 259 void SQLitePersistentCookieStore::Backend::LoadKeyAndNotifyOnDBThread(
194 &SQLitePersistentCookieStore::Backend::NotifyOnIOThread, 260 const std::string& key,
195 base::Unretained(this), loaded_callback, load_success, cookies)); 261 const LoadedCallback& loaded_callback) {
262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
263
264 bool success = false;
265 if (InitializeDatabase()) {
266 std::map<std::string, std::set<std::string> >::iterator
267 it = keys_to_load_.find(key);
268 if (it != keys_to_load_.end()) {
269 success = LoadCookiesForDomains(it->second);
270 keys_to_load_.erase(it);
271 } else {
272 success = true;
273 }
274 }
275
276 BrowserThread::PostTask(
277 BrowserThread::IO, FROM_HERE,
278 base::Bind(&SQLitePersistentCookieStore::Backend::NotifyOnIOThread,
279 this, loaded_callback, success));
196 } 280 }
197 281
198 void SQLitePersistentCookieStore::Backend::NotifyOnIOThread( 282 void SQLitePersistentCookieStore::Backend::NotifyOnIOThread(
199 const LoadedCallback& loaded_callback, 283 const LoadedCallback& loaded_callback,
200 bool load_success, 284 bool load_success) {
201 const std::vector<net::CookieMonster::CanonicalCookie*>& cookies) {
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
286
287 std::vector<net::CookieMonster::CanonicalCookie*> cookies;
288 {
289 base::AutoLock locked(lock_);
290 cookies = cookies_;
291 cookies_.clear();
292 }
293
203 loaded_callback.Run(cookies); 294 loaded_callback.Run(cookies);
204 } 295 }
205 296
206 bool SQLitePersistentCookieStore::Backend::InitializeDatabase() { 297 bool SQLitePersistentCookieStore::Backend::InitializeDatabase() {
298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
299
300 if (initialized_) {
301 return true;
302 }
303
207 const FilePath dir = path_.DirName(); 304 const FilePath dir = path_.DirName();
208 if (!file_util::PathExists(dir) && !file_util::CreateDirectory(dir)) { 305 if (!file_util::PathExists(dir) && !file_util::CreateDirectory(dir)) {
209 return false; 306 return false;
210 } 307 }
211 308
212 db_.reset(new sql::Connection); 309 db_.reset(new sql::Connection);
213 if (!db_->Open(path_)) { 310 if (!db_->Open(path_)) {
214 NOTREACHED() << "Unable to open cookie DB."; 311 NOTREACHED() << "Unable to open cookie DB.";
215 db_.reset(); 312 db_.reset();
216 return false; 313 return false;
217 } 314 }
218 315
219 db_->set_error_delegate(GetErrorHandlerForCookieDb()); 316 db_->set_error_delegate(GetErrorHandlerForCookieDb());
220 317
221 if (!EnsureDatabaseVersion() || !InitTable(db_.get())) { 318 if (!EnsureDatabaseVersion() || !InitTable(db_.get())) {
222 NOTREACHED() << "Unable to open cookie DB."; 319 NOTREACHED() << "Unable to open cookie DB.";
223 db_.reset(); 320 db_.reset();
224 return false; 321 return false;
225 } 322 }
226 323
227 db_->Preload(); 324 db_->Preload();
228 return true;
229 }
230 325
231 bool SQLitePersistentCookieStore::Backend::LoadInternal( 326 // Retrieve all the domains
232 std::vector<net::CookieMonster::CanonicalCookie*>* cookies) { 327 sql::Statement smt(db_->GetUniqueStatement(
233 if (!InitializeDatabase()) { 328 "SELECT DISTINCT host_key FROM cookies"));
234 return false;
235 }
236 329
237 // Slurp all the cookies into the out-vector.
238 sql::Statement smt(db_->GetUniqueStatement(
239 "SELECT creation_utc, host_key, name, value, path, expires_utc, secure, "
240 "httponly, last_access_utc FROM cookies"));
241 if (!smt) { 330 if (!smt) {
242 NOTREACHED() << "select statement prep failed"; 331 NOTREACHED() << "select statement prep failed";
243 db_.reset(); 332 db_.reset();
244 return false; 333 return false;
245 } 334 }
246 335
336 // Build a map of domain keys (always eTLD+1) to domains.
247 while (smt.Step()) { 337 while (smt.Step()) {
248 scoped_ptr<net::CookieMonster::CanonicalCookie> cc( 338 std::string domain = smt.ColumnString(0);
249 new net::CookieMonster::CanonicalCookie( 339 std::string key =
250 // The "source" URL is not used with persisted cookies. 340 net::RegistryControlledDomainService::GetDomainAndRegistry(domain);
251 GURL(), // Source 341
252 smt.ColumnString(2), // name 342 std::map<std::string, std::set<std::string> >::iterator it =
253 smt.ColumnString(3), // value 343 keys_to_load_.find(key);
254 smt.ColumnString(1), // domain 344 if (it == keys_to_load_.end())
255 smt.ColumnString(4), // path 345 it = keys_to_load_.insert(std::make_pair
256 std::string(), // TODO(abarth): Persist mac_key 346 (key, std::set<std::string>())).first;
257 std::string(), // TODO(abarth): Persist mac_algorithm 347 it->second.insert(domain);
258 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc
259 Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc
260 Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc
261 smt.ColumnInt(6) != 0, // secure
262 smt.ColumnInt(7) != 0, // httponly
263 true)); // has_expires
264 DLOG_IF(WARNING,
265 cc->CreationDate() > Time::Now()) << L"CreationDate too recent";
266 cookies->push_back(cc.release());
267 } 348 }
268 349
350 initialized_ = true;
269 return true; 351 return true;
270 } 352 }
271 353
354 void SQLitePersistentCookieStore::Backend::ChainLoadCookies(
355 const LoadedCallback& loaded_callback) {
356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
357
358 bool load_success = true;
359
360 if (keys_to_load_.size() > 0) {
361 // Load cookies for the first domain key.
362 std::map<std::string, std::set<std::string> >::iterator
363 it = keys_to_load_.begin();
364 load_success = LoadCookiesForDomains(it->second);
365 keys_to_load_.erase(it);
366 }
367
368 // If load is successful and there are more domain keys to be loaded,
369 // then post a DB task to continue chain-load;
370 // Otherwise notify on IO thread.
371 if (load_success && keys_to_load_.size() > 0) {
372 BrowserThread::PostTask(
373 BrowserThread::DB, FROM_HERE,
374 base::Bind(&Backend::ChainLoadCookies, this, loaded_callback));
375 } else {
376 BrowserThread::PostTask(
377 BrowserThread::IO, FROM_HERE,
378 base::Bind(&SQLitePersistentCookieStore::Backend::NotifyOnIOThread,
379 this, loaded_callback, load_success));
380 }
381 }
382
383 bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains(
384 const std::set<std::string>& domains) {
385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
386
387 sql::Statement smt(db_->GetCachedStatement(SQL_FROM_HERE,
388 "SELECT creation_utc, host_key, name, value, path, expires_utc, secure, "
389 "httponly, last_access_utc FROM cookies WHERE host_key = ?"));
390 if (!smt) {
391 NOTREACHED() << "select statement prep failed";
392 db_.reset();
393 return false;
394 }
395
396 std::vector<net::CookieMonster::CanonicalCookie*> cookies;
397 std::set<std::string>::const_iterator it = domains.begin();
398 for (; it != domains.end(); ++it) {
399 smt.BindString(0, *it);
400 while (smt.Step()) {
401 scoped_ptr<net::CookieMonster::CanonicalCookie> cc(
402 new net::CookieMonster::CanonicalCookie(
403 // The "source" URL is not used with persisted cookies.
404 GURL(), // Source
405 smt.ColumnString(2), // name
406 smt.ColumnString(3), // value
407 smt.ColumnString(1), // domain
408 smt.ColumnString(4), // path
409 std::string(), // TODO(abarth): Persist mac_key
410 std::string(), // TODO(abarth): Persist mac_algorithm
411 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc
412 Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc
413 Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc
414 smt.ColumnInt(6) != 0, // secure
415 smt.ColumnInt(7) != 0, // httponly
416 true)); // has_expires
417 DLOG_IF(WARNING,
418 cc->CreationDate() > Time::Now()) << L"CreationDate too recent";
419 cookies.push_back(cc.release());
420 }
421 smt.Reset();
422 }
423 {
424 base::AutoLock locked(lock_);
425 cookies_.insert(cookies_.end(), cookies.begin(), cookies.end());
426 }
427 return true;
428 }
429
272 bool SQLitePersistentCookieStore::Backend::EnsureDatabaseVersion() { 430 bool SQLitePersistentCookieStore::Backend::EnsureDatabaseVersion() {
273 // Version check. 431 // Version check.
274 if (!meta_table_.Init( 432 if (!meta_table_.Init(
275 db_.get(), kCurrentVersionNumber, kCompatibleVersionNumber)) { 433 db_.get(), kCurrentVersionNumber, kCompatibleVersionNumber)) {
276 return false; 434 return false;
277 } 435 }
278 436
279 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { 437 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) {
280 LOG(WARNING) << "Cookie database is too new."; 438 LOG(WARNING) << "Cookie database is too new.";
281 return false; 439 return false;
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 685
528 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { 686 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() {
529 if (backend_.get()) { 687 if (backend_.get()) {
530 backend_->Close(); 688 backend_->Close();
531 // Release our reference, it will probably still have a reference if the 689 // Release our reference, it will probably still have a reference if the
532 // background thread has not run Close() yet. 690 // background thread has not run Close() yet.
533 backend_ = NULL; 691 backend_ = NULL;
534 } 692 }
535 } 693 }
536 694
537 bool SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) { 695 void SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) {
538 return backend_->Load(loaded_callback); 696 backend_->Load(loaded_callback);
697 }
698
699 void SQLitePersistentCookieStore::LoadCookiesForKey(
700 const std::string& key,
701 const LoadedCallback& loaded_callback) {
702 backend_->LoadCookiesForKey(key, loaded_callback);
539 } 703 }
540 704
541 void SQLitePersistentCookieStore::AddCookie( 705 void SQLitePersistentCookieStore::AddCookie(
542 const net::CookieMonster::CanonicalCookie& cc) { 706 const net::CookieMonster::CanonicalCookie& cc) {
543 if (backend_.get()) 707 if (backend_.get())
544 backend_->AddCookie(cc); 708 backend_->AddCookie(cc);
545 } 709 }
546 710
547 void SQLitePersistentCookieStore::UpdateCookieAccessTime( 711 void SQLitePersistentCookieStore::UpdateCookieAccessTime(
548 const net::CookieMonster::CanonicalCookie& cc) { 712 const net::CookieMonster::CanonicalCookie& cc) {
(...skipping 12 matching lines...) Expand all
561 if (backend_.get()) 725 if (backend_.get())
562 backend_->SetClearLocalStateOnExit(clear_local_state); 726 backend_->SetClearLocalStateOnExit(clear_local_state);
563 } 727 }
564 728
565 void SQLitePersistentCookieStore::Flush(Task* completion_task) { 729 void SQLitePersistentCookieStore::Flush(Task* completion_task) {
566 if (backend_.get()) 730 if (backend_.get())
567 backend_->Flush(completion_task); 731 backend_->Flush(completion_task);
568 else if (completion_task) 732 else if (completion_task)
569 MessageLoop::current()->PostTask(FROM_HERE, completion_task); 733 MessageLoop::current()->PostTask(FROM_HERE, completion_task);
570 } 734 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698