1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_COMPONENT_UPDATER_CRX_UPDATE_ITEM_H_ 6 #define COMPONENTS_COMPONENT_UPDATER_CRX_UPDATE_ITEM_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/memory/weak_ptr.h" 12 #include "base/time/time.h" 13 #include "base/version.h" 14 #include "components/component_updater/component_updater_service.h" 15 #include "components/component_updater/crx_downloader.h" 16 17 namespace component_updater { 18 19 // This is the one and only per-item state structure. Designed to be hosted 20 // in a std::vector or a std::list. The two main members are |component| 21 // which is supplied by the the component updater client and |status| which 22 // is modified as the item is processed by the update pipeline. The expected 23 // transition graph is: 24 // 25 // on-demand on-demand 26 // +---------------------------> kNew <--------------+-------------+ 27 // | | | | 28 // | V | | 29 // | +--------------------> kChecking -<-------+---|---<-----+ | 30 // | | | | | | | 31 // | | error V no | | | | 32 // kNoUpdate <---------------- [update?] ->---- kUpToDate kUpdated 33 // ^ | ^ 34 // | yes | | 35 // | diff=false V | 36 // | +-----------> kCanUpdate | 37 // | | | | 38 // | | V no | 39 // | | [differential update?]->----+ | 40 // | | | | | 41 // | | yes | | | 42 // | | error V | | 43 // | +---------<- kDownloadingDiff | | 44 // | | | | | 45 // | | | | | 46 // | | error V | | 47 // | +---------<- kUpdatingDiff ->--------|-----------+ success 48 // | | | 49 // | error V | 50 // +----------------------------------------- kDownloading | 51 // | | | 52 // | error V | 53 // +------------------------------------------ kUpdating ->----+ success 54 // 55 struct CrxUpdateItem { 56 enum Status { 57 kNew, 58 kChecking, 59 kCanUpdate, 60 kDownloadingDiff, 61 kDownloading, 62 kUpdatingDiff, 63 kUpdating, 64 kUpdated, 65 kUpToDate, 66 kNoUpdate, 67 kLastStatus 68 }; 69 70 // Call CrxUpdateService::ChangeItemState to change |status|. The function may 71 // enforce conditions or notify observers of the change. 72 Status status; 73 74 std::string id; 75 CrxComponent component; 76 77 base::Time last_check; 78 79 // A component can be made available for download from several urls. 80 std::vector<GURL> crx_urls; 81 std::vector<GURL> crx_diffurls; 82 83 // The from/to version and fingerprint values. 84 Version previous_version; 85 Version next_version; 86 std::string previous_fp; 87 std::string next_fp; 88 89 // True if the current update check cycle is on-demand. 90 bool on_demand; 91 92 // True if the differential update failed for any reason. 93 bool diff_update_failed; 94 95 // The error information for full and differential updates. 96 // The |error_category| contains a hint about which module in the component 97 // updater generated the error. The |error_code| constains the error and 98 // the |extra_code1| usually contains a system error, but it can contain 99 // any extended information that is relevant to either the category or the 100 // error itself. 101 int error_category; 102 int error_code; 103 int extra_code1; 104 int diff_error_category; 105 int diff_error_code; 106 int diff_extra_code1; 107 108 std::vector<CrxDownloader::DownloadMetrics> download_metrics; 109 110 std::vector<base::Closure> ready_callbacks; 111 112 CrxUpdateItem(); 113 ~CrxUpdateItem(); 114 115 // Function object used to find a specific component. 116 class FindById { 117 public: 118 explicit FindById(const std::string& id) : id_(id) {} 119 120 bool operator()(CrxUpdateItem* item) const { return item->id == id_; } 121 122 private: 123 const std::string& id_; 124 }; 125 }; 126 127 } // namespace component_updater 128 129 #endif // COMPONENTS_COMPONENT_UPDATER_CRX_UPDATE_ITEM_H_ 130