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

Side by Side Diff: net/sqlite/sqlite_server_bound_cert_store.cc

Issue 381073002: Move sqlite_channel_id_store from chrome/browser/net to net/extras. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implement chrome_special_storage_policy_delegate. Created 6 years, 5 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 (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 scoped_ptr<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.Pass()),
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
50 // Batch a server bound cert addition. 51 // Batch a server bound cert addition.
51 void AddServerBoundCert( 52 void AddServerBoundCert(
52 const net::DefaultServerBoundCertStore::ServerBoundCert& cert); 53 const net::DefaultServerBoundCertStore::ServerBoundCert& cert);
53 54
54 // Batch a server bound cert deletion. 55 // Batch a server bound cert deletion.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_ptr<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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 582
582 sql::Transaction transaction(db_.get()); 583 sql::Transaction transaction(db_.get());
583 if (!transaction.Begin()) { 584 if (!transaction.Begin()) {
584 LOG(WARNING) << "Unable to delete certificates on shutdown."; 585 LOG(WARNING) << "Unable to delete certificates on shutdown.";
585 return; 586 return;
586 } 587 }
587 588
588 for (std::set<std::string>::iterator it = cert_origins_.begin(); 589 for (std::set<std::string>::iterator it = cert_origins_.begin();
589 it != cert_origins_.end(); ++it) { 590 it != cert_origins_.end(); ++it) {
590 const GURL url(net::cookie_util::CookieOriginToURL(*it, true)); 591 const GURL url(net::cookie_util::CookieOriginToURL(*it, true));
591 if (!url.is_valid() || !special_storage_policy_->IsStorageSessionOnly(url)) 592 if (!url.is_valid() || !special_storage_policy_->IsStorageSessionOnly(url))
Ryan Sleevi 2014/07/14 19:18:04 So, to start the discussion: If we look at this,
mef 2014/07/14 20:18:02 I see your concern, although I kind of agree with
mef 2014/07/15 18:53:03 I think the answer is 'Maybe'. The quota::SpecialS
592 continue; 593 continue;
593 del_smt.Reset(true); 594 del_smt.Reset(true);
594 del_smt.BindString(0, *it); 595 del_smt.BindString(0, *it);
595 if (!del_smt.Run()) 596 if (!del_smt.Run())
596 NOTREACHED() << "Could not delete a certificate from the DB."; 597 NOTREACHED() << "Could not delete a certificate from the DB.";
597 } 598 }
598 599
599 if (!transaction.Commit()) 600 if (!transaction.Commit())
600 LOG(WARNING) << "Unable to delete certificates on shutdown."; 601 LOG(WARNING) << "Unable to delete certificates on shutdown.";
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 scoped_ptr<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.Pass())) {}
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
OLDNEW
« no previous file with comments | « net/sqlite/sqlite_server_bound_cert_store.h ('k') | net/sqlite/sqlite_server_bound_cert_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698