| OLD | NEW |
| 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 "chrome/browser/net/sqlite_server_bound_cert_store.h" | 5 #include "net/sqlite/sqlite_server_bound_cert_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" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 19 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
| 20 #include "net/cert/x509_certificate.h" | 20 #include "net/cert/x509_certificate.h" |
| 21 #include "net/cookies/cookie_util.h" | 21 #include "net/cookies/cookie_util.h" |
| 22 #include "net/sqlite/special_storage_policy_delegate.h" |
| 22 #include "net/ssl/ssl_client_cert_type.h" | 23 #include "net/ssl/ssl_client_cert_type.h" |
| 23 #include "sql/error_delegate_util.h" | 24 #include "sql/error_delegate_util.h" |
| 24 #include "sql/meta_table.h" | 25 #include "sql/meta_table.h" |
| 25 #include "sql/statement.h" | 26 #include "sql/statement.h" |
| 26 #include "sql/transaction.h" | 27 #include "sql/transaction.h" |
| 27 #include "third_party/sqlite/sqlite3.h" | |
| 28 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 29 #include "webkit/browser/quota/special_storage_policy.h" | 29 |
| 30 namespace net { |
| 30 | 31 |
| 31 // This class is designed to be shared between any calling threads and the | 32 // 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. | 33 // background task runner. It batches operations and commits them on a timer. |
| 33 class SQLiteServerBoundCertStore::Backend | 34 class SQLiteServerBoundCertStore::Backend |
| 34 : public base::RefCountedThreadSafe<SQLiteServerBoundCertStore::Backend> { | 35 : public base::RefCountedThreadSafe<SQLiteServerBoundCertStore::Backend> { |
| 35 public: | 36 public: |
| 36 Backend( | 37 Backend( |
| 37 const base::FilePath& path, | 38 const base::FilePath& path, |
| 38 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, | 39 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, |
| 39 quota::SpecialStoragePolicy* special_storage_policy) | 40 SpecialStoragePolicyDelegate* special_storage_policy) |
| 40 : path_(path), | 41 : path_(path), |
| 41 num_pending_(0), | 42 num_pending_(0), |
| 42 force_keep_session_state_(false), | 43 force_keep_session_state_(false), |
| 43 background_task_runner_(background_task_runner), | 44 background_task_runner_(background_task_runner), |
| 44 special_storage_policy_(special_storage_policy), | 45 special_storage_policy_(special_storage_policy), |
| 45 corruption_detected_(false) {} | 46 corruption_detected_(false) {} |
| 46 | 47 |
| 47 // Creates or loads the SQLite database. | 48 // Creates or loads the SQLite database. |
| 48 void Load(const LoadedCallback& loaded_callback); | 49 void Load(const LoadedCallback& loaded_callback); |
| 49 | 50 |
| (...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. | 124 // True if the persistent store should skip clear on exit rules. |
| 124 bool force_keep_session_state_; | 125 bool force_keep_session_state_; |
| 125 // Guard |pending_|, |num_pending_| and |force_keep_session_state_|. | 126 // Guard |pending_|, |num_pending_| and |force_keep_session_state_|. |
| 126 base::Lock lock_; | 127 base::Lock lock_; |
| 127 | 128 |
| 128 // Cache of origins we have certificates stored for. | 129 // Cache of origins we have certificates stored for. |
| 129 std::set<std::string> cert_origins_; | 130 std::set<std::string> cert_origins_; |
| 130 | 131 |
| 131 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; | 132 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; |
| 132 | 133 |
| 133 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; | 134 scoped_refptr<SpecialStoragePolicyDelegate> special_storage_policy_; |
| 134 | 135 |
| 135 // Indicates if the kill-database callback has been scheduled. | 136 // Indicates if the kill-database callback has been scheduled. |
| 136 bool corruption_detected_; | 137 bool corruption_detected_; |
| 137 | 138 |
| 138 DISALLOW_COPY_AND_ASSIGN(Backend); | 139 DISALLOW_COPY_AND_ASSIGN(Backend); |
| 139 }; | 140 }; |
| 140 | 141 |
| 141 // Version number of the database. | 142 // Version number of the database. |
| 142 static const int kCurrentVersionNumber = 4; | 143 static const int kCurrentVersionNumber = 4; |
| 143 static const int kCompatibleVersionNumber = 1; | 144 static const int kCompatibleVersionNumber = 1; |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 } | 602 } |
| 602 | 603 |
| 603 void SQLiteServerBoundCertStore::Backend::SetForceKeepSessionState() { | 604 void SQLiteServerBoundCertStore::Backend::SetForceKeepSessionState() { |
| 604 base::AutoLock locked(lock_); | 605 base::AutoLock locked(lock_); |
| 605 force_keep_session_state_ = true; | 606 force_keep_session_state_ = true; |
| 606 } | 607 } |
| 607 | 608 |
| 608 SQLiteServerBoundCertStore::SQLiteServerBoundCertStore( | 609 SQLiteServerBoundCertStore::SQLiteServerBoundCertStore( |
| 609 const base::FilePath& path, | 610 const base::FilePath& path, |
| 610 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, | 611 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, |
| 611 quota::SpecialStoragePolicy* special_storage_policy) | 612 SpecialStoragePolicyDelegate* special_storage_policy) |
| 612 : backend_(new Backend(path, | 613 : backend_(new Backend(path, |
| 613 background_task_runner, | 614 background_task_runner, |
| 614 special_storage_policy)) {} | 615 special_storage_policy)) {} |
| 615 | 616 |
| 616 void SQLiteServerBoundCertStore::Load( | 617 void SQLiteServerBoundCertStore::Load( |
| 617 const LoadedCallback& loaded_callback) { | 618 const LoadedCallback& loaded_callback) { |
| 618 backend_->Load(loaded_callback); | 619 backend_->Load(loaded_callback); |
| 619 } | 620 } |
| 620 | 621 |
| 621 void SQLiteServerBoundCertStore::AddServerBoundCert( | 622 void SQLiteServerBoundCertStore::AddServerBoundCert( |
| 622 const net::DefaultServerBoundCertStore::ServerBoundCert& cert) { | 623 const net::DefaultServerBoundCertStore::ServerBoundCert& cert) { |
| 623 backend_->AddServerBoundCert(cert); | 624 backend_->AddServerBoundCert(cert); |
| 624 } | 625 } |
| 625 | 626 |
| 626 void SQLiteServerBoundCertStore::DeleteServerBoundCert( | 627 void SQLiteServerBoundCertStore::DeleteServerBoundCert( |
| 627 const net::DefaultServerBoundCertStore::ServerBoundCert& cert) { | 628 const net::DefaultServerBoundCertStore::ServerBoundCert& cert) { |
| 628 backend_->DeleteServerBoundCert(cert); | 629 backend_->DeleteServerBoundCert(cert); |
| 629 } | 630 } |
| 630 | 631 |
| 631 void SQLiteServerBoundCertStore::SetForceKeepSessionState() { | 632 void SQLiteServerBoundCertStore::SetForceKeepSessionState() { |
| 632 backend_->SetForceKeepSessionState(); | 633 backend_->SetForceKeepSessionState(); |
| 633 } | 634 } |
| 634 | 635 |
| 635 SQLiteServerBoundCertStore::~SQLiteServerBoundCertStore() { | 636 SQLiteServerBoundCertStore::~SQLiteServerBoundCertStore() { |
| 636 backend_->Close(); | 637 backend_->Close(); |
| 637 // We release our reference to the Backend, though it will probably still have | 638 // We release our reference to the Backend, though it will probably still have |
| 638 // a reference if the background thread has not run Close() yet. | 639 // a reference if the background thread has not run Close() yet. |
| 639 } | 640 } |
| 641 |
| 642 } // namespace net |
| OLD | NEW |