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

Side by Side Diff: chromeos/network/cert_loader.cc

Issue 14729017: Add NetworkHandler to own network handlers in src/chromeos/network (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix chromeos_unittests Created 7 years, 7 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
« no previous file with comments | « chromeos/network/cert_loader.h ('k') | chromeos/network/geolocation_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chromeos/network/cert_loader.h" 5 #include "chromeos/network/cert_loader.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/chromeos/chromeos_version.h" 9 #include "base/chromeos/chromeos_version.h"
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
(...skipping 30 matching lines...) Expand all
41 return next_delay; 41 return next_delay;
42 } 42 }
43 43
44 void LoadNSSCertificates(net::CertificateList* cert_list) { 44 void LoadNSSCertificates(net::CertificateList* cert_list) {
45 if (base::chromeos::IsRunningOnChromeOS()) 45 if (base::chromeos::IsRunningOnChromeOS())
46 net::NSSCertDatabase::GetInstance()->ListCerts(cert_list); 46 net::NSSCertDatabase::GetInstance()->ListCerts(cert_list);
47 } 47 }
48 48
49 } // namespace 49 } // namespace
50 50
51 static CertLoader* g_cert_loader = NULL;
52
53 // static
54 void CertLoader::Initialize() {
55 CHECK(!g_cert_loader);
56 g_cert_loader = new CertLoader();
57 }
58
59 // static
60 void CertLoader::Shutdown() {
61 CHECK(g_cert_loader);
62 delete g_cert_loader;
63 g_cert_loader = NULL;
64 }
65
66 // static
67 CertLoader* CertLoader::Get() {
68 CHECK(g_cert_loader) << "CertLoader::Get() called before Initialize()";
69 return g_cert_loader;
70 }
71
72 // static
73 bool CertLoader::IsInitialized() {
74 return g_cert_loader;
75 }
76
77 CertLoader::CertLoader() 51 CertLoader::CertLoader()
78 : certificates_requested_(false), 52 : certificates_requested_(false),
79 certificates_loaded_(false), 53 certificates_loaded_(false),
80 certificates_update_required_(false), 54 certificates_update_required_(false),
81 certificates_update_running_(false), 55 certificates_update_running_(false),
82 tpm_token_state_(TPM_STATE_UNKNOWN), 56 tpm_token_state_(TPM_STATE_UNKNOWN),
83 tpm_request_delay_( 57 tpm_request_delay_(
84 base::TimeDelta::FromMilliseconds(kInitialRequestDelayMs)), 58 base::TimeDelta::FromMilliseconds(kInitialRequestDelayMs)),
85 initialize_token_factory_(this), 59 initialize_token_factory_(this),
86 update_certificates_factory_(this) { 60 update_certificates_factory_(this) {
87 net::CertDatabase::GetInstance()->AddObserver(this); 61 net::CertDatabase::GetInstance()->AddObserver(this);
88 LoginState::Get()->AddObserver(this); 62 if (LoginState::IsInitialized())
63 LoginState::Get()->AddObserver(this);
89 RequestCertificates(); 64 RequestCertificates();
90 } 65 }
91 66
92 CertLoader::~CertLoader() { 67 CertLoader::~CertLoader() {
93 net::CertDatabase::GetInstance()->RemoveObserver(this); 68 net::CertDatabase::GetInstance()->RemoveObserver(this);
94 LoginState::Get()->RemoveObserver(this); 69 if (LoginState::IsInitialized())
70 LoginState::Get()->RemoveObserver(this);
95 } 71 }
96 72
97 void CertLoader::AddObserver(CertLoader::Observer* observer) { 73 void CertLoader::AddObserver(CertLoader::Observer* observer) {
98 observers_.AddObserver(observer); 74 observers_.AddObserver(observer);
99 } 75 }
100 76
101 void CertLoader::RemoveObserver(CertLoader::Observer* observer) { 77 void CertLoader::RemoveObserver(CertLoader::Observer* observer) {
102 observers_.RemoveObserver(observer); 78 observers_.RemoveObserver(observer);
103 } 79 }
104 80
105 bool CertLoader::CertificatesLoading() const { 81 bool CertLoader::CertificatesLoading() const {
106 return certificates_requested_ && !certificates_loaded_; 82 return certificates_requested_ && !certificates_loaded_;
107 } 83 }
108 84
109 bool CertLoader::IsHardwareBacked() const { 85 bool CertLoader::IsHardwareBacked() const {
110 return !tpm_token_name_.empty(); 86 return !tpm_token_name_.empty();
111 } 87 }
112 88
113 void CertLoader::RequestCertificates() { 89 void CertLoader::RequestCertificates() {
114 CHECK(thread_checker_.CalledOnValidThread()); 90 CHECK(thread_checker_.CalledOnValidThread());
115 VLOG(1) << "RequestCertificates: " << LoginState::Get()->IsUserLoggedIn(); 91 const bool logged_in = LoginState::IsInitialized() ?
116 if (certificates_requested_ || !LoginState::Get()->IsUserLoggedIn()) 92 LoginState::Get()->IsUserLoggedIn() : false;
93 VLOG(1) << "RequestCertificates: " << logged_in;
94 if (certificates_requested_ || !logged_in)
117 return; 95 return;
118 96
119 certificates_requested_ = true; 97 certificates_requested_ = true;
120 98
121 // Ensure we've opened the user's key/certificate database. 99 // Ensure we've opened the user's key/certificate database.
122 crypto::OpenPersistentNSSDB(); 100 crypto::OpenPersistentNSSDB();
123 if (base::chromeos::IsRunningOnChromeOS()) 101 if (base::chromeos::IsRunningOnChromeOS())
124 crypto::EnableTPMTokenForNSS(); 102 crypto::EnableTPMTokenForNSS();
125 103
126 // This is the entry point to the TPM token initialization process, which we 104 // This is the entry point to the TPM token initialization process, which we
127 // should do at most once. 105 // should do at most once.
128 DCHECK(!initialize_token_factory_.HasWeakPtrs()); 106 DCHECK(!initialize_token_factory_.HasWeakPtrs());
129 InitializeTokenAndLoadCertificates(); 107 InitializeTokenAndLoadCertificates();
130 } 108 }
131 109
132 void CertLoader::InitializeTokenAndLoadCertificates() { 110 void CertLoader::InitializeTokenAndLoadCertificates() {
133 CHECK(thread_checker_.CalledOnValidThread()); 111 CHECK(thread_checker_.CalledOnValidThread());
134 VLOG(1) << "InitializeTokenAndLoadCertificates"; 112 VLOG(1) << "InitializeTokenAndLoadCertificates";
135 113
136 switch(tpm_token_state_) { 114 switch (tpm_token_state_) {
137 case TPM_STATE_UNKNOWN: { 115 case TPM_STATE_UNKNOWN: {
138 DBusThreadManager::Get()->GetCryptohomeClient()->TpmIsEnabled( 116 DBusThreadManager::Get()->GetCryptohomeClient()->TpmIsEnabled(
139 base::Bind(&CertLoader::OnTpmIsEnabled, 117 base::Bind(&CertLoader::OnTpmIsEnabled,
140 initialize_token_factory_.GetWeakPtr())); 118 initialize_token_factory_.GetWeakPtr()));
141 return; 119 return;
142 } 120 }
143 case TPM_DISABLED: { 121 case TPM_DISABLED: {
144 // TPM is disabled, so proceed with empty tpm token name. 122 // TPM is disabled, so proceed with empty tpm token name.
145 StartLoadCertificates(); 123 StartLoadCertificates();
146 return; 124 return;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 VLOG(1) << "OnCertRemoved"; 300 VLOG(1) << "OnCertRemoved";
323 StartLoadCertificates(); 301 StartLoadCertificates();
324 } 302 }
325 303
326 void CertLoader::LoggedInStateChanged(LoginState::LoggedInState state) { 304 void CertLoader::LoggedInStateChanged(LoginState::LoggedInState state) {
327 VLOG(1) << "LoggedInStateChanged: " << state; 305 VLOG(1) << "LoggedInStateChanged: " << state;
328 RequestCertificates(); 306 RequestCertificates();
329 } 307 }
330 308
331 } // namespace chromeos 309 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/cert_loader.h ('k') | chromeos/network/geolocation_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698