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