| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_channel_id_store.h" | 5 #include "chrome/browser/net/sqlite_channel_id_store.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "webkit/browser/quota/special_storage_policy.h" | 29 #include "webkit/browser/quota/special_storage_policy.h" |
| 30 | 30 |
| 31 // This class is designed to be shared between any calling threads and the | 31 // This class is designed to be shared between any calling threads and the |
| 32 // background task runner. It batches operations and commits them on a timer. | 32 // background task runner. It batches operations and commits them on a timer. |
| 33 class SQLiteChannelIDStore::Backend | 33 class SQLiteChannelIDStore::Backend |
| 34 : public base::RefCountedThreadSafe<SQLiteChannelIDStore::Backend> { | 34 : public base::RefCountedThreadSafe<SQLiteChannelIDStore::Backend> { |
| 35 public: | 35 public: |
| 36 Backend( | 36 Backend( |
| 37 const base::FilePath& path, | 37 const base::FilePath& path, |
| 38 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, | 38 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, |
| 39 quota::SpecialStoragePolicy* special_storage_policy) | 39 storage::SpecialStoragePolicy* special_storage_policy) |
| 40 : path_(path), | 40 : path_(path), |
| 41 num_pending_(0), | 41 num_pending_(0), |
| 42 force_keep_session_state_(false), | 42 force_keep_session_state_(false), |
| 43 background_task_runner_(background_task_runner), | 43 background_task_runner_(background_task_runner), |
| 44 special_storage_policy_(special_storage_policy), | 44 special_storage_policy_(special_storage_policy), |
| 45 corruption_detected_(false) {} | 45 corruption_detected_(false) {} |
| 46 | 46 |
| 47 // Creates or loads the SQLite database. | 47 // Creates or loads the SQLite database. |
| 48 void Load(const LoadedCallback& loaded_callback); | 48 void Load(const LoadedCallback& loaded_callback); |
| 49 | 49 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // True if the persistent store should skip clear on exit rules. | 123 // True if the persistent store should skip clear on exit rules. |
| 124 bool force_keep_session_state_; | 124 bool force_keep_session_state_; |
| 125 // Guard |pending_|, |num_pending_| and |force_keep_session_state_|. | 125 // Guard |pending_|, |num_pending_| and |force_keep_session_state_|. |
| 126 base::Lock lock_; | 126 base::Lock lock_; |
| 127 | 127 |
| 128 // Cache of origins we have channel IDs stored for. | 128 // Cache of origins we have channel IDs stored for. |
| 129 std::set<std::string> channel_id_origins_; | 129 std::set<std::string> channel_id_origins_; |
| 130 | 130 |
| 131 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; | 131 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; |
| 132 | 132 |
| 133 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; | 133 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; |
| 134 | 134 |
| 135 // Indicates if the kill-database callback has been scheduled. | 135 // Indicates if the kill-database callback has been scheduled. |
| 136 bool corruption_detected_; | 136 bool corruption_detected_; |
| 137 | 137 |
| 138 DISALLOW_COPY_AND_ASSIGN(Backend); | 138 DISALLOW_COPY_AND_ASSIGN(Backend); |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 // Version number of the database. | 141 // Version number of the database. |
| 142 static const int kCurrentVersionNumber = 4; | 142 static const int kCurrentVersionNumber = 4; |
| 143 static const int kCompatibleVersionNumber = 1; | 143 static const int kCompatibleVersionNumber = 1; |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 } | 603 } |
| 604 | 604 |
| 605 void SQLiteChannelIDStore::Backend::SetForceKeepSessionState() { | 605 void SQLiteChannelIDStore::Backend::SetForceKeepSessionState() { |
| 606 base::AutoLock locked(lock_); | 606 base::AutoLock locked(lock_); |
| 607 force_keep_session_state_ = true; | 607 force_keep_session_state_ = true; |
| 608 } | 608 } |
| 609 | 609 |
| 610 SQLiteChannelIDStore::SQLiteChannelIDStore( | 610 SQLiteChannelIDStore::SQLiteChannelIDStore( |
| 611 const base::FilePath& path, | 611 const base::FilePath& path, |
| 612 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, | 612 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, |
| 613 quota::SpecialStoragePolicy* special_storage_policy) | 613 storage::SpecialStoragePolicy* special_storage_policy) |
| 614 : backend_(new Backend(path, | 614 : backend_( |
| 615 background_task_runner, | 615 new Backend(path, background_task_runner, special_storage_policy)) { |
| 616 special_storage_policy)) {} | 616 } |
| 617 | 617 |
| 618 void SQLiteChannelIDStore::Load( | 618 void SQLiteChannelIDStore::Load( |
| 619 const LoadedCallback& loaded_callback) { | 619 const LoadedCallback& loaded_callback) { |
| 620 backend_->Load(loaded_callback); | 620 backend_->Load(loaded_callback); |
| 621 } | 621 } |
| 622 | 622 |
| 623 void SQLiteChannelIDStore::AddChannelID( | 623 void SQLiteChannelIDStore::AddChannelID( |
| 624 const net::DefaultChannelIDStore::ChannelID& channel_id) { | 624 const net::DefaultChannelIDStore::ChannelID& channel_id) { |
| 625 backend_->AddChannelID(channel_id); | 625 backend_->AddChannelID(channel_id); |
| 626 } | 626 } |
| 627 | 627 |
| 628 void SQLiteChannelIDStore::DeleteChannelID( | 628 void SQLiteChannelIDStore::DeleteChannelID( |
| 629 const net::DefaultChannelIDStore::ChannelID& channel_id) { | 629 const net::DefaultChannelIDStore::ChannelID& channel_id) { |
| 630 backend_->DeleteChannelID(channel_id); | 630 backend_->DeleteChannelID(channel_id); |
| 631 } | 631 } |
| 632 | 632 |
| 633 void SQLiteChannelIDStore::SetForceKeepSessionState() { | 633 void SQLiteChannelIDStore::SetForceKeepSessionState() { |
| 634 backend_->SetForceKeepSessionState(); | 634 backend_->SetForceKeepSessionState(); |
| 635 } | 635 } |
| 636 | 636 |
| 637 SQLiteChannelIDStore::~SQLiteChannelIDStore() { | 637 SQLiteChannelIDStore::~SQLiteChannelIDStore() { |
| 638 backend_->Close(); | 638 backend_->Close(); |
| 639 // We release our reference to the Backend, though it will probably still have | 639 // We release our reference to the Backend, though it will probably still have |
| 640 // a reference if the background thread has not run Close() yet. | 640 // a reference if the background thread has not run Close() yet. |
| 641 } | 641 } |
| OLD | NEW |