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

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

Issue 5430004: Refactored cookies persistent store clean-up on shutdown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tiny style fixes. Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 8
9 #include "app/sql/meta_table.h" 9 #include "app/sql/meta_table.h"
10 #include "app/sql/statement.h" 10 #include "app/sql/statement.h"
(...skipping 13 matching lines...) Expand all
24 using base::Time; 24 using base::Time;
25 25
26 // This class is designed to be shared between any calling threads and the 26 // This class is designed to be shared between any calling threads and the
27 // database thread. It batches operations and commits them on a timer. 27 // database thread. It batches operations and commits them on a timer.
28 class SQLitePersistentCookieStore::Backend 28 class SQLitePersistentCookieStore::Backend
29 : public base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend> { 29 : public base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend> {
30 public: 30 public:
31 explicit Backend(const FilePath& path) 31 explicit Backend(const FilePath& path)
32 : path_(path), 32 : path_(path),
33 db_(NULL), 33 db_(NULL),
34 num_pending_(0) { 34 num_pending_(0),
35 clear_local_state_on_exit_(false) {
35 } 36 }
36 37
37 // Creates or load the SQLite database. 38 // Creates or load the SQLite database.
38 bool Load(std::vector<net::CookieMonster::CanonicalCookie*>* cookies); 39 bool Load(std::vector<net::CookieMonster::CanonicalCookie*>* cookies);
39 40
40 // Batch a cookie addition. 41 // Batch a cookie addition.
41 void AddCookie(const net::CookieMonster::CanonicalCookie& cc); 42 void AddCookie(const net::CookieMonster::CanonicalCookie& cc);
42 43
43 // Batch a cookie access time update. 44 // Batch a cookie access time update.
44 void UpdateCookieAccessTime(const net::CookieMonster::CanonicalCookie& cc); 45 void UpdateCookieAccessTime(const net::CookieMonster::CanonicalCookie& cc);
45 46
46 // Batch a cookie deletion. 47 // Batch a cookie deletion.
47 void DeleteCookie(const net::CookieMonster::CanonicalCookie& cc); 48 void DeleteCookie(const net::CookieMonster::CanonicalCookie& cc);
48 49
49 // Commit any pending operations and close the database. This must be called 50 // Commit any pending operations and close the database. This must be called
50 // before the object is destructed. 51 // before the object is destructed.
51 void Close(); 52 void Close();
52 53
54 void SetClearLocalStateOnExit(bool clear_local_state) {
55 clear_local_state_on_exit_ = clear_local_state;
56 }
57
53 private: 58 private:
54 friend class base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend>; 59 friend class base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend>;
55 60
56 // You should call Close() before destructing this object. 61 // You should call Close() before destructing this object.
57 ~Backend() { 62 ~Backend() {
58 DCHECK(!db_.get()) << "Close should have already been called."; 63 DCHECK(!db_.get()) << "Close should have already been called.";
59 DCHECK(num_pending_ == 0 && pending_.empty()); 64 DCHECK(num_pending_ == 0 && pending_.empty());
60 } 65 }
61 66
62 // Database upgrade statements. 67 // Database upgrade statements.
(...skipping 29 matching lines...) Expand all
92 void InternalBackgroundClose(); 97 void InternalBackgroundClose();
93 98
94 FilePath path_; 99 FilePath path_;
95 scoped_ptr<sql::Connection> db_; 100 scoped_ptr<sql::Connection> db_;
96 sql::MetaTable meta_table_; 101 sql::MetaTable meta_table_;
97 102
98 typedef std::list<PendingOperation*> PendingOperationsList; 103 typedef std::list<PendingOperation*> PendingOperationsList;
99 PendingOperationsList pending_; 104 PendingOperationsList pending_;
100 PendingOperationsList::size_type num_pending_; 105 PendingOperationsList::size_type num_pending_;
101 Lock pending_lock_; // Guard pending_ and num_pending_ 106 Lock pending_lock_; // Guard pending_ and num_pending_
107 // True if the persistent store should be deleted upon destruction.
108 bool clear_local_state_on_exit_;
102 109
103 DISALLOW_COPY_AND_ASSIGN(Backend); 110 DISALLOW_COPY_AND_ASSIGN(Backend);
104 }; 111 };
105 112
106 // Version number of the database. In version 4, we migrated the time epoch. 113 // Version number of the database. In version 4, we migrated the time epoch.
107 // If you open the DB with an older version on Mac or Linux, the times will 114 // If you open the DB with an older version on Mac or Linux, the times will
108 // look wonky, but the file will likely be usable. On Windows version 3 and 4 115 // look wonky, but the file will likely be usable. On Windows version 3 and 4
109 // are the same. 116 // are the same.
110 // 117 //
111 // Version 3 updated the database to include the last access time, so we can 118 // Version 3 updated the database to include the last access time, so we can
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 BrowserThread::DB, FROM_HERE, 420 BrowserThread::DB, FROM_HERE,
414 NewRunnableMethod(this, &Backend::InternalBackgroundClose)); 421 NewRunnableMethod(this, &Backend::InternalBackgroundClose));
415 } 422 }
416 423
417 void SQLitePersistentCookieStore::Backend::InternalBackgroundClose() { 424 void SQLitePersistentCookieStore::Backend::InternalBackgroundClose() {
418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
419 // Commit any pending operations 426 // Commit any pending operations
420 Commit(); 427 Commit();
421 428
422 db_.reset(); 429 db_.reset();
430
431 if (clear_local_state_on_exit_)
432 file_util::Delete(path_, false);
423 } 433 }
424 434
425 SQLitePersistentCookieStore::SQLitePersistentCookieStore(const FilePath& path) 435 SQLitePersistentCookieStore::SQLitePersistentCookieStore(const FilePath& path)
426 : backend_(new Backend(path)) { 436 : backend_(new Backend(path)) {
427 } 437 }
428 438
429 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { 439 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() {
430 if (backend_.get()) { 440 if (backend_.get()) {
431 backend_->Close(); 441 backend_->Close();
432 // Release our reference, it will probably still have a reference if the 442 // Release our reference, it will probably still have a reference if the
(...skipping 18 matching lines...) Expand all
451 if (backend_.get()) 461 if (backend_.get())
452 backend_->UpdateCookieAccessTime(cc); 462 backend_->UpdateCookieAccessTime(cc);
453 } 463 }
454 464
455 void SQLitePersistentCookieStore::DeleteCookie( 465 void SQLitePersistentCookieStore::DeleteCookie(
456 const net::CookieMonster::CanonicalCookie& cc) { 466 const net::CookieMonster::CanonicalCookie& cc) {
457 if (backend_.get()) 467 if (backend_.get())
458 backend_->DeleteCookie(cc); 468 backend_->DeleteCookie(cc);
459 } 469 }
460 470
461 // static 471 void SQLitePersistentCookieStore::SetClearLocalStateOnExit(
462 void SQLitePersistentCookieStore::ClearLocalState( 472 bool clear_local_state) {
463 const FilePath& path) { 473 if (backend_.get())
464 file_util::Delete(path, false); 474 backend_->SetClearLocalStateOnExit(clear_local_state);
Randy Smith (Not in Mondays) 2010/12/03 18:42:27 Could you protect this with the lock (and modify t
pastarmovj 2010/12/06 08:57:40 Done. I had exactly the same thoughts and didn't p
465 } 475 }
OLDNEW
« no previous file with comments | « chrome/browser/net/sqlite_persistent_cookie_store.h ('k') | chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698