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/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/stl_util.h" | 20 #include "base/stl_util.h" |
20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
21 #include "base/strings/string_piece.h" | 22 #include "base/strings/string_piece.h" |
22 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
23 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
24 #include "base/threading/sequenced_worker_pool.h" | 25 #include "base/threading/sequenced_worker_pool.h" |
25 #include "base/timer/timer.h" | 26 #include "base/timer/timer.h" |
26 #include "chrome/browser/browser_process.h" | 27 #include "chrome/browser/browser_process.h" |
27 #include "chrome/browser/component_updater/component_patcher.h" | 28 #include "chrome/browser/component_updater/component_patcher.h" |
28 #include "chrome/browser/component_updater/component_unpacker.h" | 29 #include "chrome/browser/component_updater/component_unpacker.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 void AddUpdateCheckItems(std::string* update_check_items); | 326 void AddUpdateCheckItems(std::string* update_check_items); |
326 | 327 |
327 void DoUpdateCheck(const std::string& update_check_items); | 328 void DoUpdateCheck(const std::string& update_check_items); |
328 | 329 |
329 void ScheduleNextRun(StepDelayInterval step_delay); | 330 void ScheduleNextRun(StepDelayInterval step_delay); |
330 | 331 |
331 void ParseManifest(const std::string& xml); | 332 void ParseManifest(const std::string& xml); |
332 | 333 |
333 void Install(const CRXContext* context, const base::FilePath& crx_path); | 334 void Install(const CRXContext* context, const base::FilePath& crx_path); |
334 | 335 |
| 336 void DoneUnpacking(const std::string& component_id, |
| 337 const base::FilePath& crx_path, |
| 338 component_updater::ComponentUnpacker::Error error, |
| 339 int extended_error); |
| 340 |
335 void DoneInstalling(const std::string& component_id, | 341 void DoneInstalling(const std::string& component_id, |
336 ComponentUnpacker::Error error, | 342 component_updater::ComponentUnpacker::Error error, |
337 int extended_error); | 343 int extended_error); |
338 | 344 |
339 void ChangeItemState(CrxUpdateItem* item, CrxUpdateItem::Status to); | 345 void ChangeItemState(CrxUpdateItem* item, CrxUpdateItem::Status to); |
340 | 346 |
341 size_t ChangeItemStatus(CrxUpdateItem::Status from, | 347 size_t ChangeItemStatus(CrxUpdateItem::Status from, |
342 CrxUpdateItem::Status to); | 348 CrxUpdateItem::Status to); |
343 | 349 |
344 CrxUpdateItem* FindUpdateItemById(const std::string& id); | 350 CrxUpdateItem* FindUpdateItemById(const std::string& id); |
345 | 351 |
346 void NotifyComponentObservers(ComponentObserver::Events event, | 352 void NotifyComponentObservers(ComponentObserver::Events event, |
347 int extra) const; | 353 int extra) const; |
348 | 354 |
349 bool HasOnDemandItems() const; | 355 bool HasOnDemandItems() const; |
350 | 356 |
351 void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt, | 357 void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt, |
352 const std::string& crx_id); | 358 const std::string& crx_id); |
353 | 359 |
354 scoped_ptr<ComponentUpdateService::Configurator> config_; | 360 scoped_ptr<ComponentUpdateService::Configurator> config_; |
355 | 361 |
356 scoped_ptr<ComponentPatcher> component_patcher_; | 362 scoped_ptr<component_updater::ComponentPatcher> component_patcher_; |
357 | 363 |
358 scoped_ptr<net::URLFetcher> url_fetcher_; | 364 scoped_ptr<net::URLFetcher> url_fetcher_; |
359 | 365 |
360 scoped_ptr<component_updater::PingManager> ping_manager_; | 366 scoped_ptr<component_updater::PingManager> ping_manager_; |
361 | 367 |
| 368 scoped_ptr<component_updater::ComponentUnpacker> unpacker_; |
| 369 |
362 // A collection of every work item. | 370 // A collection of every work item. |
363 typedef std::vector<CrxUpdateItem*> UpdateItems; | 371 typedef std::vector<CrxUpdateItem*> UpdateItems; |
364 UpdateItems work_items_; | 372 UpdateItems work_items_; |
365 | 373 |
366 base::OneShotTimer<CrxUpdateService> timer_; | 374 base::OneShotTimer<CrxUpdateService> timer_; |
367 | 375 |
368 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 376 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
369 | 377 |
370 const Version chrome_version_; | 378 const Version chrome_version_; |
371 | 379 |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 base::Bind(&CrxUpdateService::Install, | 1015 base::Bind(&CrxUpdateService::Install, |
1008 base::Unretained(this), | 1016 base::Unretained(this), |
1009 crx_context.release(), | 1017 crx_context.release(), |
1010 temp_crx_path), | 1018 temp_crx_path), |
1011 base::TimeDelta::FromMilliseconds(config_->StepDelay())); | 1019 base::TimeDelta::FromMilliseconds(config_->StepDelay())); |
1012 } | 1020 } |
1013 } | 1021 } |
1014 | 1022 |
1015 // Install consists of digital signature verification, unpacking and then | 1023 // Install consists of digital signature verification, unpacking and then |
1016 // calling the component specific installer. All that is handled by the | 1024 // calling the component specific installer. All that is handled by the |
1017 // |unpacker|. If there is an error this function is in charge of deleting | 1025 // |unpacker_|. If there is an error this function is in charge of deleting |
1018 // the files created. | 1026 // the files created. |
1019 void CrxUpdateService::Install(const CRXContext* context, | 1027 void CrxUpdateService::Install(const CRXContext* context, |
1020 const base::FilePath& crx_path) { | 1028 const base::FilePath& crx_path) { |
1021 // This function owns the file at |crx_path| and the |context| object. | 1029 // This function owns the file at |crx_path| and the |context| object. |
1022 ComponentUnpacker unpacker(context->pk_hash, | 1030 unpacker_.reset(new component_updater::ComponentUnpacker( |
1023 crx_path, | 1031 context->pk_hash, |
1024 context->fingerprint, | 1032 crx_path, |
1025 component_patcher_.get(), | 1033 context->fingerprint, |
1026 context->installer); | 1034 component_patcher_.get(), |
| 1035 context->installer, |
| 1036 blocking_task_runner_)); |
| 1037 unpacker_->Unpack(base::Bind(&CrxUpdateService::DoneUnpacking, |
| 1038 base::Unretained(this), |
| 1039 context->id, |
| 1040 crx_path)); |
| 1041 delete context; |
| 1042 } |
| 1043 |
| 1044 // Do some cleanup before we skip back to the UI thread. |
| 1045 void CrxUpdateService::DoneUnpacking( |
| 1046 const std::string& component_id, |
| 1047 const base::FilePath& crx_path, |
| 1048 component_updater::ComponentUnpacker::Error error, |
| 1049 int extended_error) { |
1027 if (!base::DeleteFile(crx_path, false)) | 1050 if (!base::DeleteFile(crx_path, false)) |
1028 NOTREACHED() << crx_path.value(); | 1051 NOTREACHED() << crx_path.value(); |
1029 // Why unretained? See comment at top of file. | |
1030 BrowserThread::PostDelayedTask( | 1052 BrowserThread::PostDelayedTask( |
1031 BrowserThread::UI, | 1053 BrowserThread::UI, |
1032 FROM_HERE, | 1054 FROM_HERE, |
1033 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this), | 1055 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this), |
1034 context->id, unpacker.error(), unpacker.extended_error()), | 1056 component_id, error, extended_error), |
1035 base::TimeDelta::FromMilliseconds(config_->StepDelay())); | 1057 base::TimeDelta::FromMilliseconds(config_->StepDelay())); |
1036 delete context; | |
1037 } | 1058 } |
1038 | 1059 |
1039 // Installation has been completed. Adjust the component status and | 1060 // Installation has been completed. Adjust the component status and |
1040 // schedule the next check. Schedule a short delay before trying the full | 1061 // schedule the next check. Schedule a short delay before trying the full |
1041 // update when the differential update failed. | 1062 // update when the differential update failed. |
1042 void CrxUpdateService::DoneInstalling(const std::string& component_id, | 1063 void CrxUpdateService::DoneInstalling( |
1043 ComponentUnpacker::Error error, | 1064 const std::string& component_id, |
1044 int extra_code) { | 1065 component_updater::ComponentUnpacker::Error error, |
| 1066 int extra_code) { |
1045 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1067 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1046 | 1068 |
1047 ErrorCategory error_category = kErrorNone; | 1069 ErrorCategory error_category = kErrorNone; |
1048 switch (error) { | 1070 switch (error) { |
1049 case ComponentUnpacker::kNone: | 1071 case component_updater::ComponentUnpacker::kNone: |
1050 break; | 1072 break; |
1051 case ComponentUnpacker::kInstallerError: | 1073 case component_updater::ComponentUnpacker::kInstallerError: |
1052 error_category = kInstallError; | 1074 error_category = kInstallError; |
1053 break; | 1075 break; |
1054 default: | 1076 default: |
1055 error_category = kUnpackError; | 1077 error_category = kUnpackError; |
1056 break; | 1078 break; |
1057 } | 1079 } |
1058 | 1080 |
1059 const bool is_success = error == ComponentUnpacker::kNone; | 1081 const bool is_success = error == component_updater::ComponentUnpacker::kNone; |
1060 | 1082 |
1061 CrxUpdateItem* item = FindUpdateItemById(component_id); | 1083 CrxUpdateItem* item = FindUpdateItemById(component_id); |
1062 if (item->status == CrxUpdateItem::kUpdatingDiff && !is_success) { | 1084 if (item->status == CrxUpdateItem::kUpdatingDiff && !is_success) { |
1063 item->diff_error_category = error_category; | 1085 item->diff_error_category = error_category; |
1064 item->diff_error_code = error; | 1086 item->diff_error_code = error; |
1065 item->diff_extra_code1 = extra_code; | 1087 item->diff_extra_code1 = extra_code; |
1066 item->diff_update_failed = true; | 1088 item->diff_update_failed = true; |
1067 size_t count = ChangeItemStatus(CrxUpdateItem::kUpdatingDiff, | 1089 size_t count = ChangeItemStatus(CrxUpdateItem::kUpdatingDiff, |
1068 CrxUpdateItem::kCanUpdate); | 1090 CrxUpdateItem::kCanUpdate); |
1069 DCHECK_EQ(count, 1ul); | 1091 DCHECK_EQ(count, 1ul); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 } | 1181 } |
1160 | 1182 |
1161 // The component update factory. Using the component updater as a singleton | 1183 // The component update factory. Using the component updater as a singleton |
1162 // is the job of the browser process. | 1184 // is the job of the browser process. |
1163 ComponentUpdateService* ComponentUpdateServiceFactory( | 1185 ComponentUpdateService* ComponentUpdateServiceFactory( |
1164 ComponentUpdateService::Configurator* config) { | 1186 ComponentUpdateService::Configurator* config) { |
1165 DCHECK(config); | 1187 DCHECK(config); |
1166 return new CrxUpdateService(config); | 1188 return new CrxUpdateService(config); |
1167 } | 1189 } |
1168 | 1190 |
OLD | NEW |