OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/component_updater/component_updater_service.h" | 5 #include "chrome/browser/component_updater/component_updater_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
20 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
21 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
22 #include "base/timer/timer.h" | 22 #include "base/timer/timer.h" |
23 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/component_updater/component_patcher.h" |
24 #include "chrome/browser/component_updater/component_unpacker.h" | 25 #include "chrome/browser/component_updater/component_unpacker.h" |
25 #include "chrome/browser/component_updater/component_updater_ping_manager.h" | 26 #include "chrome/browser/component_updater/component_updater_ping_manager.h" |
26 #include "chrome/browser/component_updater/component_updater_utils.h" | 27 #include "chrome/browser/component_updater/component_updater_utils.h" |
27 #include "chrome/browser/component_updater/crx_downloader.h" | 28 #include "chrome/browser/component_updater/crx_downloader.h" |
28 #include "chrome/browser/component_updater/crx_update_item.h" | 29 #include "chrome/browser/component_updater/crx_update_item.h" |
29 #include "chrome/browser/component_updater/update_checker.h" | 30 #include "chrome/browser/component_updater/update_checker.h" |
30 #include "chrome/browser/component_updater/update_response.h" | 31 #include "chrome/browser/component_updater/update_response.h" |
31 #include "chrome/common/chrome_version_info.h" | 32 #include "chrome/common/chrome_version_info.h" |
32 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/resource_controller.h" | 34 #include "content/public/browser/resource_controller.h" |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 void NotifyComponentObservers(ComponentObserver::Events event, | 245 void NotifyComponentObservers(ComponentObserver::Events event, |
245 int extra) const; | 246 int extra) const; |
246 | 247 |
247 bool HasOnDemandItems() const; | 248 bool HasOnDemandItems() const; |
248 | 249 |
249 void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt, | 250 void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt, |
250 const std::string& crx_id); | 251 const std::string& crx_id); |
251 | 252 |
252 scoped_ptr<ComponentUpdateService::Configurator> config_; | 253 scoped_ptr<ComponentUpdateService::Configurator> config_; |
253 | 254 |
| 255 scoped_ptr<ComponentPatcher> component_patcher_; |
| 256 |
254 scoped_ptr<UpdateChecker> update_checker_; | 257 scoped_ptr<UpdateChecker> update_checker_; |
255 | 258 |
256 scoped_ptr<PingManager> ping_manager_; | 259 scoped_ptr<PingManager> ping_manager_; |
257 | 260 |
258 scoped_refptr<ComponentUnpacker> unpacker_; | 261 scoped_ptr<ComponentUnpacker> unpacker_; |
259 | 262 |
260 scoped_ptr<CrxDownloader> crx_downloader_; | 263 scoped_ptr<CrxDownloader> crx_downloader_; |
261 | 264 |
262 // A collection of every work item. | 265 // A collection of every work item. |
263 typedef std::vector<CrxUpdateItem*> UpdateItems; | 266 typedef std::vector<CrxUpdateItem*> UpdateItems; |
264 UpdateItems work_items_; | 267 UpdateItems work_items_; |
265 | 268 |
266 base::OneShotTimer<CrxUpdateService> timer_; | 269 base::OneShotTimer<CrxUpdateService> timer_; |
267 | 270 |
268 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 271 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
269 | 272 |
270 const Version chrome_version_; | 273 const Version chrome_version_; |
271 | 274 |
272 bool running_; | 275 bool running_; |
273 | 276 |
274 DISALLOW_COPY_AND_ASSIGN(CrxUpdateService); | 277 DISALLOW_COPY_AND_ASSIGN(CrxUpdateService); |
275 }; | 278 }; |
276 | 279 |
277 ////////////////////////////////////////////////////////////////////////////// | 280 ////////////////////////////////////////////////////////////////////////////// |
278 | 281 |
279 CrxUpdateService::CrxUpdateService(ComponentUpdateService::Configurator* config) | 282 CrxUpdateService::CrxUpdateService(ComponentUpdateService::Configurator* config) |
280 : config_(config), | 283 : config_(config), |
| 284 component_patcher_(config->CreateComponentPatcher()), |
281 ping_manager_(new PingManager(config->PingUrl(), | 285 ping_manager_(new PingManager(config->PingUrl(), |
282 config->RequestContext())), | 286 config->RequestContext())), |
283 blocking_task_runner_(BrowserThread::GetBlockingPool()-> | 287 blocking_task_runner_(BrowserThread::GetBlockingPool()-> |
284 GetSequencedTaskRunnerWithShutdownBehavior( | 288 GetSequencedTaskRunnerWithShutdownBehavior( |
285 BrowserThread::GetBlockingPool()->GetSequenceToken(), | 289 BrowserThread::GetBlockingPool()->GetSequenceToken(), |
286 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), | 290 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), |
287 chrome_version_(chrome::VersionInfo().Version()), | 291 chrome_version_(chrome::VersionInfo().Version()), |
288 running_(false) { | 292 running_(false) { |
289 } | 293 } |
290 | 294 |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 } | 849 } |
846 } | 850 } |
847 | 851 |
848 // Install consists of digital signature verification, unpacking and then | 852 // Install consists of digital signature verification, unpacking and then |
849 // calling the component specific installer. All that is handled by the | 853 // calling the component specific installer. All that is handled by the |
850 // |unpacker_|. If there is an error this function is in charge of deleting | 854 // |unpacker_|. If there is an error this function is in charge of deleting |
851 // the files created. | 855 // the files created. |
852 void CrxUpdateService::Install(scoped_ptr<CRXContext> context, | 856 void CrxUpdateService::Install(scoped_ptr<CRXContext> context, |
853 const base::FilePath& crx_path) { | 857 const base::FilePath& crx_path) { |
854 // This function owns the file at |crx_path| and the |context| object. | 858 // This function owns the file at |crx_path| and the |context| object. |
855 unpacker_ = new ComponentUnpacker(context->pk_hash, | 859 unpacker_.reset(new ComponentUnpacker(context->pk_hash, |
856 crx_path, | 860 crx_path, |
857 context->fingerprint, | 861 context->fingerprint, |
858 context->installer, | 862 component_patcher_.get(), |
859 config_->InProcess(), | 863 context->installer, |
860 blocking_task_runner_); | 864 blocking_task_runner_)); |
861 unpacker_->Unpack(base::Bind(&CrxUpdateService::EndUnpacking, | 865 unpacker_->Unpack(base::Bind(&CrxUpdateService::EndUnpacking, |
862 base::Unretained(this), | 866 base::Unretained(this), |
863 context->id, | 867 context->id, |
864 crx_path)); | 868 crx_path)); |
865 } | 869 } |
866 | 870 |
867 void CrxUpdateService::EndUnpacking(const std::string& component_id, | 871 void CrxUpdateService::EndUnpacking(const std::string& component_id, |
868 const base::FilePath& crx_path, | 872 const base::FilePath& crx_path, |
869 ComponentUnpacker::Error error, | 873 ComponentUnpacker::Error error, |
870 int extended_error) { | 874 int extended_error) { |
871 if (!DeleteFileAndEmptyParentDirectory(crx_path)) | 875 if (!DeleteFileAndEmptyParentDirectory(crx_path)) |
872 NOTREACHED() << crx_path.value(); | 876 NOTREACHED() << crx_path.value(); |
873 BrowserThread::PostDelayedTask( | 877 BrowserThread::PostDelayedTask( |
874 BrowserThread::UI, | 878 BrowserThread::UI, |
875 FROM_HERE, | 879 FROM_HERE, |
876 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this), | 880 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this), |
877 component_id, error, extended_error), | 881 component_id, error, extended_error), |
878 base::TimeDelta::FromMilliseconds(config_->StepDelay())); | 882 base::TimeDelta::FromMilliseconds(config_->StepDelay())); |
879 // Reset the unpacker last, otherwise we free our own arguments. | |
880 unpacker_ = NULL; | |
881 } | 883 } |
882 | 884 |
883 // Installation has been completed. Adjust the component status and | 885 // Installation has been completed. Adjust the component status and |
884 // schedule the next check. Schedule a short delay before trying the full | 886 // schedule the next check. Schedule a short delay before trying the full |
885 // update when the differential update failed. | 887 // update when the differential update failed. |
886 void CrxUpdateService::DoneInstalling(const std::string& component_id, | 888 void CrxUpdateService::DoneInstalling(const std::string& component_id, |
887 ComponentUnpacker::Error error, | 889 ComponentUnpacker::Error error, |
888 int extra_code) { | 890 int extra_code) { |
889 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 891 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
890 | 892 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 // The component update factory. Using the component updater as a singleton | 1011 // The component update factory. Using the component updater as a singleton |
1010 // is the job of the browser process. | 1012 // is the job of the browser process. |
1011 ComponentUpdateService* ComponentUpdateServiceFactory( | 1013 ComponentUpdateService* ComponentUpdateServiceFactory( |
1012 ComponentUpdateService::Configurator* config) { | 1014 ComponentUpdateService::Configurator* config) { |
1013 DCHECK(config); | 1015 DCHECK(config); |
1014 return new CrxUpdateService(config); | 1016 return new CrxUpdateService(config); |
1015 } | 1017 } |
1016 | 1018 |
1017 } // namespace component_updater | 1019 } // namespace component_updater |
1018 | 1020 |
OLD | NEW |