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