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