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 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 bool AddItemToUpdateCheck(CrxUpdateItem* item, std::string* query); | 342 bool AddItemToUpdateCheck(CrxUpdateItem* item, std::string* query); |
343 | 343 |
344 void ProcessPendingItems(); | 344 void ProcessPendingItems(); |
345 | 345 |
346 void ScheduleNextRun(StepDelayInterval step_delay); | 346 void ScheduleNextRun(StepDelayInterval step_delay); |
347 | 347 |
348 void ParseManifest(const std::string& xml); | 348 void ParseManifest(const std::string& xml); |
349 | 349 |
350 void Install(const CRXContext* context, const base::FilePath& crx_path); | 350 void Install(const CRXContext* context, const base::FilePath& crx_path); |
351 | 351 |
| 352 void DoneUnpacking(const std::string& component_id, |
| 353 const base::FilePath& crx_path, |
| 354 component_updater::Error error, |
| 355 int extended_error); |
| 356 |
352 void DoneInstalling(const std::string& component_id, | 357 void DoneInstalling(const std::string& component_id, |
353 ComponentUnpacker::Error error, | 358 component_updater::Error error, |
354 int extended_error); | 359 int extended_error); |
355 | 360 |
356 size_t ChangeItemStatus(CrxUpdateItem::Status from, | 361 size_t ChangeItemStatus(CrxUpdateItem::Status from, |
357 CrxUpdateItem::Status to); | 362 CrxUpdateItem::Status to); |
358 | 363 |
359 CrxUpdateItem* FindUpdateItemById(const std::string& id); | 364 CrxUpdateItem* FindUpdateItemById(const std::string& id); |
360 | 365 |
361 void NotifyComponentObservers(ComponentObserver::Events event, | 366 void NotifyComponentObservers(ComponentObserver::Events event, |
362 int extra) const; | 367 int extra) const; |
363 | 368 |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 } | 920 } |
916 | 921 |
917 // Install consists of digital signature verification, unpacking and then | 922 // Install consists of digital signature verification, unpacking and then |
918 // calling the component specific installer. All that is handled by the | 923 // calling the component specific installer. All that is handled by the |
919 // |unpacker|. If there is an error this function is in charge of deleting | 924 // |unpacker|. If there is an error this function is in charge of deleting |
920 // the files created. | 925 // the files created. |
921 void CrxUpdateService::Install(const CRXContext* context, | 926 void CrxUpdateService::Install(const CRXContext* context, |
922 const base::FilePath& crx_path) { | 927 const base::FilePath& crx_path) { |
923 // This function owns the |crx_path| and the |context| object. | 928 // This function owns the |crx_path| and the |context| object. |
924 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 929 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
925 ComponentUnpacker unpacker(context->pk_hash, | 930 component_updater::Unpack(context->pk_hash, |
926 crx_path, | 931 crx_path, |
927 context->fingerprint, | 932 context->fingerprint, |
928 component_patcher_.get(), | 933 component_patcher_.get(), |
929 context->installer); | 934 context->installer, |
| 935 base::Bind(&CrxUpdateService::DoneUnpacking, |
| 936 base::Unretained(this), |
| 937 context->id, |
| 938 crx_path)); |
| 939 delete context; |
| 940 } |
| 941 |
| 942 // Do some cleanup before we skip back to the UI thread. |
| 943 void CrxUpdateService::DoneUnpacking(const std::string& component_id, |
| 944 const base::FilePath& crx_path, |
| 945 component_updater::Error error, |
| 946 int extended_error) { |
| 947 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
930 if (!base::DeleteFile(crx_path, false)) | 948 if (!base::DeleteFile(crx_path, false)) |
931 NOTREACHED() << crx_path.value(); | 949 NOTREACHED() << crx_path.value(); |
932 // Why unretained? See comment at top of file. | |
933 BrowserThread::PostDelayedTask( | 950 BrowserThread::PostDelayedTask( |
934 BrowserThread::UI, | 951 BrowserThread::UI, |
935 FROM_HERE, | 952 FROM_HERE, |
936 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this), | 953 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this), |
937 context->id, unpacker.error(), unpacker.extended_error()), | 954 component_id, error, extended_error), |
938 base::TimeDelta::FromMilliseconds(config_->StepDelay())); | 955 base::TimeDelta::FromMilliseconds(config_->StepDelay())); |
939 delete context; | |
940 } | 956 } |
941 | 957 |
942 // Installation has been completed. Adjust the component status and | 958 // Installation has been completed. Adjust the component status and |
943 // schedule the next check. Schedule a short delay before trying the full | 959 // schedule the next check. Schedule a short delay before trying the full |
944 // update when the differential update failed. | 960 // update when the differential update failed. |
945 void CrxUpdateService::DoneInstalling(const std::string& component_id, | 961 void CrxUpdateService::DoneInstalling(const std::string& component_id, |
946 ComponentUnpacker::Error error, | 962 component_updater::Error error, |
947 int extra_code) { | 963 int extra_code) { |
948 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 964 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
949 | 965 |
950 ErrorCategory error_category = kErrorNone; | 966 ErrorCategory error_category = kErrorNone; |
951 switch (error) { | 967 switch (error) { |
952 case ComponentUnpacker::kNone: | 968 case component_updater::kNone: |
953 break; | 969 break; |
954 case ComponentUnpacker::kInstallerError: | 970 case component_updater::kInstallerError: |
955 error_category = kInstallError; | 971 error_category = kInstallError; |
956 break; | 972 break; |
957 default: | 973 default: |
958 error_category = kUnpackError; | 974 error_category = kUnpackError; |
959 break; | 975 break; |
960 } | 976 } |
961 | 977 |
962 const bool is_success = error == ComponentUnpacker::kNone; | 978 const bool is_success = error == component_updater::kNone; |
963 | 979 |
964 CrxUpdateItem* item = FindUpdateItemById(component_id); | 980 CrxUpdateItem* item = FindUpdateItemById(component_id); |
965 if (item->status == CrxUpdateItem::kUpdatingDiff && !is_success) { | 981 if (item->status == CrxUpdateItem::kUpdatingDiff && !is_success) { |
966 item->diff_error_category = error_category; | 982 item->diff_error_category = error_category; |
967 item->diff_error_code = error; | 983 item->diff_error_code = error; |
968 item->diff_extra_code1 = extra_code; | 984 item->diff_extra_code1 = extra_code; |
969 item->diff_update_failed = true; | 985 item->diff_update_failed = true; |
970 size_t count = ChangeItemStatus(CrxUpdateItem::kUpdatingDiff, | 986 size_t count = ChangeItemStatus(CrxUpdateItem::kUpdatingDiff, |
971 CrxUpdateItem::kCanUpdate); | 987 CrxUpdateItem::kCanUpdate); |
972 DCHECK_EQ(count, 1ul); | 988 DCHECK_EQ(count, 1ul); |
(...skipping 28 matching lines...) Expand all Loading... |
1001 } | 1017 } |
1002 } | 1018 } |
1003 | 1019 |
1004 // The component update factory. Using the component updater as a singleton | 1020 // The component update factory. Using the component updater as a singleton |
1005 // is the job of the browser process. | 1021 // is the job of the browser process. |
1006 ComponentUpdateService* ComponentUpdateServiceFactory( | 1022 ComponentUpdateService* ComponentUpdateServiceFactory( |
1007 ComponentUpdateService::Configurator* config) { | 1023 ComponentUpdateService::Configurator* config) { |
1008 DCHECK(config); | 1024 DCHECK(config); |
1009 return new CrxUpdateService(config); | 1025 return new CrxUpdateService(config); |
1010 } | 1026 } |
OLD | NEW |