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/crl_set_fetcher.h" | 5 #include "chrome/browser/net/crl_set_fetcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "chrome/browser/component_updater/component_updater_service.h" | 15 #include "chrome/browser/component_updater/component_updater_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" |
18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 #include "net/cert/crl_set.h" | 20 #include "net/cert/crl_set.h" |
21 #include "net/cert/crl_set_storage.h" | 21 #include "net/cert/crl_set_storage.h" |
22 #include "net/ssl/ssl_config_service.h" | 22 #include "net/ssl/ssl_config_service.h" |
23 #if defined(OS_CHROMEOS) | |
24 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
25 #endif | |
23 | 26 |
24 using component_updater::ComponentUpdateService; | 27 using component_updater::ComponentUpdateService; |
25 using content::BrowserThread; | 28 using content::BrowserThread; |
26 | 29 |
27 CRLSetFetcher::CRLSetFetcher() : cus_(NULL) {} | 30 CRLSetFetcher::CRLSetFetcher() : cus_(NULL) {} |
28 | 31 |
29 bool CRLSetFetcher::GetCRLSetFilePath(base::FilePath* path) const { | 32 bool CRLSetFetcher::SetCRLSetFilePath(const std::string* user_id_hash) { |
30 bool ok = PathService::Get(chrome::DIR_USER_DATA, path); | 33 |
34 base::FilePath path; | |
35 bool ok = PathService::Get(chrome::DIR_USER_DATA, &path); | |
31 if (!ok) { | 36 if (!ok) { |
32 NOTREACHED(); | 37 NOTREACHED(); |
33 return false; | 38 return false; |
34 } | 39 } |
35 *path = path->Append(chrome::kCRLSetFilename); | 40 #if defined(OS_CHROMEOS) |
Ryan Sleevi
2014/07/16 19:39:28
Every #ifdef makes for a sad panda. We should try
| |
41 if (user_id_hash) | |
42 path = | |
43 path.Append(chromeos::ProfileHelper::GetUserProfileDir(*user_id_hash)); | |
Jorge Lucangeli Obes
2014/07/16 16:36:34
Four-space indentation (double indentation) after
| |
44 #endif | |
45 crl_path_ = path.Append(chrome::kCRLSetFilename); | |
36 return true; | 46 return true; |
37 } | 47 } |
38 | 48 |
49 base::FilePath CRLSetFetcher::GetCRLSetFilePath() const { | |
50 return crl_path_; | |
51 } | |
52 | |
39 void CRLSetFetcher::StartInitialLoad(ComponentUpdateService* cus) { | 53 void CRLSetFetcher::StartInitialLoad(ComponentUpdateService* cus) { |
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
41 | 55 |
56 if (!SetCRLSetFilePath(NULL)) | |
57 return; | |
58 PostInitialLoad(cus); | |
59 } | |
60 | |
61 void CRLSetFetcher::StartInitialLoadWithHash(ComponentUpdateService* cus, | |
62 const std::string& user_id_hash) { | |
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
64 | |
65 if (!SetCRLSetFilePath(&user_id_hash)) | |
66 return; | |
67 PostInitialLoad(cus); | |
68 } | |
69 | |
70 void CRLSetFetcher::DeleteFromDisk() { | |
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
72 | |
73 if (!SetCRLSetFilePath(NULL)) | |
74 return; | |
75 if (!BrowserThread::PostTask( | |
76 BrowserThread::FILE, FROM_HERE, | |
77 base::Bind(&CRLSetFetcher::DoDeleteFromDisk, this))) { | |
78 NOTREACHED(); | |
79 } | |
80 } | |
81 | |
82 void CRLSetFetcher::PostInitialLoad(ComponentUpdateService* cus) { | |
42 cus_ = cus; | 83 cus_ = cus; |
43 | 84 |
44 if (!BrowserThread::PostTask( | 85 if (!BrowserThread::PostTask( |
45 BrowserThread::FILE, FROM_HERE, | 86 BrowserThread::FILE, FROM_HERE, |
46 base::Bind(&CRLSetFetcher::DoInitialLoadFromDisk, this))) { | 87 base::Bind(&CRLSetFetcher::DoInitialLoadFromDisk, this))) { |
47 NOTREACHED(); | 88 NOTREACHED(); |
48 } | 89 } |
49 } | 90 } |
50 | |
51 void CRLSetFetcher::DeleteFromDisk() { | |
52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
53 | |
54 if (!BrowserThread::PostTask( | |
55 BrowserThread::FILE, FROM_HERE, | |
56 base::Bind(&CRLSetFetcher::DoDeleteFromDisk, this))) { | |
57 NOTREACHED(); | |
58 } | |
59 } | |
60 | 91 |
61 void CRLSetFetcher::DoInitialLoadFromDisk() { | 92 void CRLSetFetcher::DoInitialLoadFromDisk() { |
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
63 | 94 |
64 base::FilePath crl_set_file_path; | 95 LoadFromDisk(GetCRLSetFilePath(), &crl_set_); |
65 if (!GetCRLSetFilePath(&crl_set_file_path)) | |
66 return; | |
67 | |
68 LoadFromDisk(crl_set_file_path, &crl_set_); | |
69 | 96 |
70 uint32 sequence_of_loaded_crl = 0; | 97 uint32 sequence_of_loaded_crl = 0; |
71 if (crl_set_.get()) | 98 if (crl_set_.get()) |
72 sequence_of_loaded_crl = crl_set_->sequence(); | 99 sequence_of_loaded_crl = crl_set_->sequence(); |
73 | 100 |
74 // Get updates, advertising the sequence number of the CRL set that we just | 101 // Get updates, advertising the sequence number of the CRL set that we just |
75 // loaded, if any. | 102 // loaded, if any. |
76 if (!BrowserThread::PostTask( | 103 if (!BrowserThread::PostTask( |
77 BrowserThread::UI, FROM_HERE, | 104 BrowserThread::UI, FROM_HERE, |
78 base::Bind( | 105 base::Bind( |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 | 180 |
154 if (cus_->RegisterComponent(component) != | 181 if (cus_->RegisterComponent(component) != |
155 ComponentUpdateService::kOk) { | 182 ComponentUpdateService::kOk) { |
156 NOTREACHED() << "RegisterComponent returned error"; | 183 NOTREACHED() << "RegisterComponent returned error"; |
157 } | 184 } |
158 } | 185 } |
159 | 186 |
160 void CRLSetFetcher::DoDeleteFromDisk() { | 187 void CRLSetFetcher::DoDeleteFromDisk() { |
161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
162 | 189 |
163 base::FilePath crl_set_file_path; | 190 DeleteFile(GetCRLSetFilePath(), false /* not recursive */); |
164 if (!GetCRLSetFilePath(&crl_set_file_path)) | |
165 return; | |
166 | |
167 DeleteFile(crl_set_file_path, false /* not recursive */); | |
168 } | 191 } |
169 | 192 |
170 void CRLSetFetcher::OnUpdateError(int error) { | 193 void CRLSetFetcher::OnUpdateError(int error) { |
171 LOG(WARNING) << "CRLSetFetcher got error " << error | 194 LOG(WARNING) << "CRLSetFetcher got error " << error |
172 << " from component installer"; | 195 << " from component installer"; |
173 } | 196 } |
174 | 197 |
175 bool CRLSetFetcher::Install(const base::DictionaryValue& manifest, | 198 bool CRLSetFetcher::Install(const base::DictionaryValue& manifest, |
176 const base::FilePath& unpack_path) { | 199 const base::FilePath& unpack_path) { |
177 base::FilePath crl_set_file_path = | 200 base::FilePath crl_set_file_path = |
178 unpack_path.Append(FILE_PATH_LITERAL("crl-set")); | 201 unpack_path.Append(FILE_PATH_LITERAL("crl-set")); |
179 base::FilePath save_to; | 202 base::FilePath save_to = GetCRLSetFilePath(); |
180 if (!GetCRLSetFilePath(&save_to)) | |
181 return true; | |
182 | 203 |
183 std::string crl_set_bytes; | 204 std::string crl_set_bytes; |
184 if (!base::ReadFileToString(crl_set_file_path, &crl_set_bytes)) { | 205 if (!base::ReadFileToString(crl_set_file_path, &crl_set_bytes)) { |
185 LOG(WARNING) << "Failed to find crl-set file inside CRX"; | 206 LOG(WARNING) << "Failed to find crl-set file inside CRX"; |
186 return false; | 207 return false; |
187 } | 208 } |
188 | 209 |
189 bool is_delta; | 210 bool is_delta; |
190 if (!net::CRLSetStorage::GetIsDeltaUpdate(crl_set_bytes, &is_delta)) { | 211 if (!net::CRLSetStorage::GetIsDeltaUpdate(crl_set_bytes, &is_delta)) { |
191 LOG(WARNING) << "GetIsDeltaUpdate failed on CRL set from update CRX"; | 212 LOG(WARNING) << "GetIsDeltaUpdate failed on CRL set from update CRX"; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 | 255 |
235 return true; | 256 return true; |
236 } | 257 } |
237 | 258 |
238 bool CRLSetFetcher::GetInstalledFile( | 259 bool CRLSetFetcher::GetInstalledFile( |
239 const std::string& file, base::FilePath* installed_file) { | 260 const std::string& file, base::FilePath* installed_file) { |
240 return false; | 261 return false; |
241 } | 262 } |
242 | 263 |
243 CRLSetFetcher::~CRLSetFetcher() {} | 264 CRLSetFetcher::~CRLSetFetcher() {} |
OLD | NEW |