Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / component_updater / crx_update_item.h
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 namespace component_updater {
19
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:
25 //
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
55 //
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
69   };
70
71   // Call CrxUpdateService::ChangeItemState to change |status|. The function may
72   // enforce conditions or notify observers of the change.
73   Status status;
74
75   std::string id;
76   CrxComponent component;
77
78   base::Time last_check;
79
80   // A component can be made available for download from several urls.
81   std::vector<GURL> crx_urls;
82   std::vector<GURL> crx_diffurls;
83
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;
89
90   // True if the current update check cycle is on-demand.
91   bool on_demand;
92
93   // True if the differential update failed for any reason.
94   bool diff_update_failed;
95
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;
108
109   std::vector<CrxDownloader::DownloadMetrics> download_metrics;
110
111   std::vector<base::Closure> ready_callbacks;
112
113   CrxUpdateItem();
114   ~CrxUpdateItem();
115
116   // Function object used to find a specific component.
117   class FindById {
118    public:
119     explicit FindById(const std::string& id) : id_(id) {}
120
121     bool operator()(CrxUpdateItem* item) const { return item->id == id_; }
122
123    private:
124     const std::string& id_;
125   };
126 };
127
128 }  // namespace component_updater
129
130 #endif  // CHROME_BROWSER_COMPONENT_UPDATER_CRX_UPDATE_ITEM_H_