| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_util.h" | 8 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 9 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 10 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 11 #include "base/time.h" | 12 #include "base/time.h" |
| 12 #include "chrome/browser/component_updater/component_updater_service.h" | 13 #include "chrome/browser/component_updater/component_updater_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
| 15 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 35 return true; | 36 return true; |
| 36 } | 37 } |
| 37 | 38 |
| 38 void CRLSetFetcher::StartInitialLoad(ComponentUpdateService* cus) { | 39 void CRLSetFetcher::StartInitialLoad(ComponentUpdateService* cus) { |
| 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 40 | 41 |
| 41 cus_ = cus; | 42 cus_ = cus; |
| 42 | 43 |
| 43 if (!BrowserThread::PostTask( | 44 if (!BrowserThread::PostTask( |
| 44 BrowserThread::FILE, FROM_HERE, | 45 BrowserThread::FILE, FROM_HERE, |
| 45 NewRunnableMethod( | 46 base::Bind(&CRLSetFetcher::DoInitialLoadFromDisk, this))) { |
| 46 this, | |
| 47 &CRLSetFetcher::DoInitialLoadFromDisk))) { | |
| 48 NOTREACHED(); | 47 NOTREACHED(); |
| 49 } | 48 } |
| 50 } | 49 } |
| 51 | 50 |
| 52 void CRLSetFetcher::DoInitialLoadFromDisk() { | 51 void CRLSetFetcher::DoInitialLoadFromDisk() { |
| 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 54 | 53 |
| 55 FilePath crl_set_file_path; | 54 FilePath crl_set_file_path; |
| 56 if (!GetCRLSetFilePath(&crl_set_file_path)) | 55 if (!GetCRLSetFilePath(&crl_set_file_path)) |
| 57 return; | 56 return; |
| 58 | 57 |
| 59 scoped_refptr<net::CRLSet> crl_set; | 58 scoped_refptr<net::CRLSet> crl_set; |
| 60 LoadFromDisk(crl_set_file_path, | 59 LoadFromDisk(crl_set_file_path, |
| 61 FilePath() /* don't copy the data anywhere */, | 60 FilePath() /* don't copy the data anywhere */, |
| 62 &crl_set); | 61 &crl_set); |
| 63 | 62 |
| 64 uint32 sequence_of_loaded_crl = 0; | 63 uint32 sequence_of_loaded_crl = 0; |
| 65 if (crl_set.get()) | 64 if (crl_set.get()) |
| 66 sequence_of_loaded_crl = crl_set->sequence(); | 65 sequence_of_loaded_crl = crl_set->sequence(); |
| 67 | 66 |
| 68 // Get updates, advertising the sequence number of the CRL set that we just | 67 // Get updates, advertising the sequence number of the CRL set that we just |
| 69 // loaded, if any. | 68 // loaded, if any. |
| 70 if (!BrowserThread::PostTask( | 69 if (!BrowserThread::PostTask( |
| 71 BrowserThread::UI, FROM_HERE, | 70 BrowserThread::UI, FROM_HERE, |
| 72 NewRunnableMethod( | 71 base::Bind( |
| 72 &CRLSetFetcher::RegisterComponent, |
| 73 this, | 73 this, |
| 74 &CRLSetFetcher::RegisterComponent, | |
| 75 sequence_of_loaded_crl))) { | 74 sequence_of_loaded_crl))) { |
| 76 NOTREACHED(); | 75 NOTREACHED(); |
| 77 } | 76 } |
| 78 } | 77 } |
| 79 | 78 |
| 80 void CRLSetFetcher::LoadFromDisk(FilePath path, | 79 void CRLSetFetcher::LoadFromDisk(FilePath path, |
| 81 FilePath save_to, | 80 FilePath save_to, |
| 82 scoped_refptr<net::CRLSet>* out_crl_set) { | 81 scoped_refptr<net::CRLSet>* out_crl_set) { |
| 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 84 | 83 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 95 if (out_crl_set) | 94 if (out_crl_set) |
| 96 *out_crl_set = crl_set; | 95 *out_crl_set = crl_set; |
| 97 | 96 |
| 98 if (!save_to.empty()) | 97 if (!save_to.empty()) |
| 99 file_util::WriteFile(save_to, crl_set_bytes.data(), crl_set_bytes.size()); | 98 file_util::WriteFile(save_to, crl_set_bytes.data(), crl_set_bytes.size()); |
| 100 | 99 |
| 101 VLOG(1) << "Loaded " << crl_set_bytes.size() << " bytes of CRL set from disk"; | 100 VLOG(1) << "Loaded " << crl_set_bytes.size() << " bytes of CRL set from disk"; |
| 102 | 101 |
| 103 if (!BrowserThread::PostTask( | 102 if (!BrowserThread::PostTask( |
| 104 BrowserThread::IO, FROM_HERE, | 103 BrowserThread::IO, FROM_HERE, |
| 105 NewRunnableMethod( | 104 base::Bind( |
| 106 this, &CRLSetFetcher::SetCRLSetIfNewer, crl_set))) { | 105 &CRLSetFetcher::SetCRLSetIfNewer, this, crl_set))) { |
| 107 NOTREACHED(); | 106 NOTREACHED(); |
| 108 } | 107 } |
| 109 } | 108 } |
| 110 | 109 |
| 111 void CRLSetFetcher::SetCRLSetIfNewer( | 110 void CRLSetFetcher::SetCRLSetIfNewer( |
| 112 scoped_refptr<net::CRLSet> crl_set) { | 111 scoped_refptr<net::CRLSet> crl_set) { |
| 113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 114 | 113 |
| 115 scoped_refptr<net::CRLSet> old_crl_set(net::SSLConfigService::GetCRLSet()); | 114 scoped_refptr<net::CRLSet> old_crl_set(net::SSLConfigService::GetCRLSet()); |
| 116 if (old_crl_set.get() && old_crl_set->sequence() > crl_set->sequence()) { | 115 if (old_crl_set.get() && old_crl_set->sequence() > crl_set->sequence()) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 const FilePath& unpack_path) { | 161 const FilePath& unpack_path) { |
| 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 164 | 163 |
| 165 FilePath crl_set_file_path = unpack_path.Append(FILE_PATH_LITERAL("crl-set")); | 164 FilePath crl_set_file_path = unpack_path.Append(FILE_PATH_LITERAL("crl-set")); |
| 166 FilePath save_to; | 165 FilePath save_to; |
| 167 if (!GetCRLSetFilePath(&save_to)) | 166 if (!GetCRLSetFilePath(&save_to)) |
| 168 return true; | 167 return true; |
| 169 LoadFromDisk(crl_set_file_path, save_to, NULL); | 168 LoadFromDisk(crl_set_file_path, save_to, NULL); |
| 170 return true; | 169 return true; |
| 171 } | 170 } |
| OLD | NEW |