[email protected] | ab28412 | 2014-08-15 05:21:17 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
rockot | db519299 | 2014-09-16 21:27:02 | [diff] [blame] | 5 | #ifndef EXTENSIONS_BROWSER_UPDATER_MANIFEST_FETCH_DATA_H_ |
| 6 | #define EXTENSIONS_BROWSER_UPDATER_MANIFEST_FETCH_DATA_H_ |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 7 | |
| 8 | #include <map> |
| 9 | #include <set> |
| 10 | #include <string> |
| 11 | |
| 12 | #include "base/basictypes.h" |
[email protected] | a6483d2 | 2013-07-03 22:11:00 | [diff] [blame] | 13 | #include "url/gurl.h" |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 14 | |
| 15 | namespace extensions { |
| 16 | |
| 17 | // To save on server resources we can request updates for multiple extensions |
| 18 | // in one manifest check. This class helps us keep track of the id's for a |
| 19 | // given fetch, building up the actual URL, and what if anything to include |
| 20 | // in the ping parameter. |
| 21 | class ManifestFetchData { |
| 22 | public: |
| 23 | static const int kNeverPinged = -1; |
| 24 | |
rockot | db519299 | 2014-09-16 21:27:02 | [diff] [blame] | 25 | // What ping mode this fetch should use. |
| 26 | enum PingMode { |
| 27 | // No ping, no extra metrics. |
| 28 | NO_PING, |
| 29 | |
| 30 | // Ping without extra metrics. |
| 31 | PING, |
| 32 | |
| 33 | // Ping with extra metrics. |
| 34 | PING_WITH_METRICS, |
| 35 | }; |
| 36 | |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 37 | // Each ping type is sent at most once per day. |
| 38 | enum PingType { |
| 39 | // Used for counting total installs of an extension/app/theme. |
| 40 | ROLLCALL, |
| 41 | |
| 42 | // Used for counting number of active users of an app, where "active" means |
| 43 | // the app was launched at least once since the last active ping. |
| 44 | ACTIVE, |
| 45 | }; |
| 46 | |
| 47 | struct PingData { |
| 48 | // The number of days it's been since our last rollcall or active ping, |
| 49 | // respectively. These are calculated based on the start of day from the |
| 50 | // server's perspective. |
| 51 | int rollcall_days; |
| 52 | int active_days; |
[email protected] | 8bf3db5 | 2012-11-28 18:30:22 | [diff] [blame] | 53 | // Wether the extension is enabled or not. |
| 54 | bool is_enabled; |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 55 | |
[email protected] | 8bf3db5 | 2012-11-28 18:30:22 | [diff] [blame] | 56 | PingData() : rollcall_days(0), active_days(0), is_enabled(true) {} |
| 57 | PingData(int rollcall, int active, bool enabled) |
| 58 | : rollcall_days(rollcall), active_days(active), is_enabled(enabled) {} |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 59 | }; |
| 60 | |
rockot | db519299 | 2014-09-16 21:27:02 | [diff] [blame] | 61 | ManifestFetchData(const GURL& update_url, |
| 62 | int request_id, |
| 63 | const std::string& brand_code, |
| 64 | const std::string& base_query_params, |
| 65 | PingMode ping_mode); |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 66 | ~ManifestFetchData(); |
| 67 | |
| 68 | // Returns true if this extension information was successfully added. If the |
| 69 | // return value is false it means the full_url would have become too long, and |
| 70 | // this ManifestFetchData object remains unchanged. |
[email protected] | 0bb29bd | 2014-04-30 21:39:18 | [diff] [blame] | 71 | bool AddExtension(const std::string& id, |
| 72 | const std::string& version, |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 73 | const PingData* ping_data, |
| 74 | const std::string& update_url_data, |
rockot | b864d8b | 2014-09-05 17:32:26 | [diff] [blame] | 75 | const std::string& install_source, |
| 76 | bool force_update); |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 77 | |
| 78 | const GURL& base_url() const { return base_url_; } |
| 79 | const GURL& full_url() const { return full_url_; } |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 80 | const std::set<std::string>& extension_ids() const { return extension_ids_; } |
[email protected] | 2bb2ee8 | 2012-11-13 23:24:03 | [diff] [blame] | 81 | const std::set<int>& request_ids() const { return request_ids_; } |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 82 | |
| 83 | // Returns true if the given id is included in this manifest fetch. |
| 84 | bool Includes(const std::string& extension_id) const; |
| 85 | |
| 86 | // Returns true if a ping parameter for |type| was added to full_url for this |
| 87 | // extension id. |
[email protected] | 0bb29bd | 2014-04-30 21:39:18 | [diff] [blame] | 88 | bool DidPing(const std::string& extension_id, PingType type) const; |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 89 | |
[email protected] | 2bb2ee8 | 2012-11-13 23:24:03 | [diff] [blame] | 90 | // Assuming that both this ManifestFetchData and |other| have the same |
| 91 | // full_url, this method merges the other information associated with the |
| 92 | // fetch (in particular this adds all request ids associated with |other| |
| 93 | // to this ManifestFetchData). |
| 94 | void Merge(const ManifestFetchData& other); |
[email protected] | 786eaf5d | 2012-12-06 18:44:47 | [diff] [blame] | 95 | |
rockot | b864d8b | 2014-09-05 17:32:26 | [diff] [blame] | 96 | // Returns |true| if a given extension was forced to update. |
| 97 | bool DidForceUpdate(const std::string& extension_id) const; |
| 98 | |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 99 | private: |
| 100 | // The set of extension id's for this ManifestFetchData. |
| 101 | std::set<std::string> extension_ids_; |
| 102 | |
| 103 | // The set of ping data we actually sent. |
| 104 | std::map<std::string, PingData> pings_; |
| 105 | |
| 106 | // The base update url without any arguments added. |
| 107 | GURL base_url_; |
| 108 | |
| 109 | // The base update url plus arguments indicating the id, version, etc. |
| 110 | // information about each extension. |
| 111 | GURL full_url_; |
| 112 | |
[email protected] | 2bb2ee8 | 2012-11-13 23:24:03 | [diff] [blame] | 113 | // The set of request ids associated with this manifest fetch. If multiple |
| 114 | // requests are trying to fetch the same manifest, they can be merged into |
| 115 | // one fetch, so potentially multiple request ids can get associated with |
| 116 | // one ManifestFetchData. |
| 117 | std::set<int> request_ids_; |
| 118 | |
rockot | db519299 | 2014-09-16 21:27:02 | [diff] [blame] | 119 | // The brand code to include with manifest fetch queries, if non-empty and |
| 120 | // |ping_mode_| >= PING. |
| 121 | const std::string brand_code_; |
| 122 | |
| 123 | // The ping mode for this fetch. This determines whether or not ping data |
| 124 | // (and possibly extra metrics) will be included in the fetch query. |
| 125 | const PingMode ping_mode_; |
| 126 | |
rockot | b864d8b | 2014-09-05 17:32:26 | [diff] [blame] | 127 | // The set of extension IDs for which this fetch forced a CRX update. |
| 128 | std::set<std::string> forced_updates_; |
| 129 | |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 130 | DISALLOW_COPY_AND_ASSIGN(ManifestFetchData); |
| 131 | }; |
| 132 | |
| 133 | } // namespace extensions |
| 134 | |
rockot | db519299 | 2014-09-16 21:27:02 | [diff] [blame] | 135 | #endif // EXTENSIONS_BROWSER_UPDATER_MANIFEST_FETCH_DATA_H_ |