[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 1 | // Copyright (c) 2012 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_EXTENSIONS_UPDATER_MANIFEST_FETCH_DATA_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_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" |
| 13 | #include "googleurl/src/gurl.h" |
| 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 | |
| 25 | // Each ping type is sent at most once per day. |
| 26 | enum PingType { |
| 27 | // Used for counting total installs of an extension/app/theme. |
| 28 | ROLLCALL, |
| 29 | |
| 30 | // Used for counting number of active users of an app, where "active" means |
| 31 | // the app was launched at least once since the last active ping. |
| 32 | ACTIVE, |
| 33 | }; |
| 34 | |
| 35 | struct PingData { |
| 36 | // The number of days it's been since our last rollcall or active ping, |
| 37 | // respectively. These are calculated based on the start of day from the |
| 38 | // server's perspective. |
| 39 | int rollcall_days; |
| 40 | int active_days; |
| 41 | |
| 42 | PingData() : rollcall_days(0), active_days(0) {} |
| 43 | PingData(int rollcall, int active) |
| 44 | : rollcall_days(rollcall), active_days(active) {} |
| 45 | }; |
| 46 | |
[email protected] | 2bb2ee8 | 2012-11-13 23:24:03 | [diff] [blame^] | 47 | ManifestFetchData(const GURL& update_url, int request_id); |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 48 | ~ManifestFetchData(); |
| 49 | |
| 50 | // Returns true if this extension information was successfully added. If the |
| 51 | // return value is false it means the full_url would have become too long, and |
| 52 | // this ManifestFetchData object remains unchanged. |
| 53 | bool AddExtension(std::string id, std::string version, |
| 54 | const PingData* ping_data, |
| 55 | const std::string& update_url_data, |
| 56 | const std::string& install_source); |
| 57 | |
| 58 | const GURL& base_url() const { return base_url_; } |
| 59 | const GURL& full_url() const { return full_url_; } |
| 60 | int extension_count() { return extension_ids_.size(); } |
| 61 | const std::set<std::string>& extension_ids() const { return extension_ids_; } |
[email protected] | 2bb2ee8 | 2012-11-13 23:24:03 | [diff] [blame^] | 62 | const std::set<int>& request_ids() const { return request_ids_; } |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 63 | |
| 64 | // Returns true if the given id is included in this manifest fetch. |
| 65 | bool Includes(const std::string& extension_id) const; |
| 66 | |
| 67 | // Returns true if a ping parameter for |type| was added to full_url for this |
| 68 | // extension id. |
| 69 | bool DidPing(std::string extension_id, PingType type) const; |
| 70 | |
[email protected] | 2bb2ee8 | 2012-11-13 23:24:03 | [diff] [blame^] | 71 | // Assuming that both this ManifestFetchData and |other| have the same |
| 72 | // full_url, this method merges the other information associated with the |
| 73 | // fetch (in particular this adds all request ids associated with |other| |
| 74 | // to this ManifestFetchData). |
| 75 | void Merge(const ManifestFetchData& other); |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 76 | private: |
| 77 | // The set of extension id's for this ManifestFetchData. |
| 78 | std::set<std::string> extension_ids_; |
| 79 | |
| 80 | // The set of ping data we actually sent. |
| 81 | std::map<std::string, PingData> pings_; |
| 82 | |
| 83 | // The base update url without any arguments added. |
| 84 | GURL base_url_; |
| 85 | |
| 86 | // The base update url plus arguments indicating the id, version, etc. |
| 87 | // information about each extension. |
| 88 | GURL full_url_; |
| 89 | |
[email protected] | 2bb2ee8 | 2012-11-13 23:24:03 | [diff] [blame^] | 90 | // The set of request ids associated with this manifest fetch. If multiple |
| 91 | // requests are trying to fetch the same manifest, they can be merged into |
| 92 | // one fetch, so potentially multiple request ids can get associated with |
| 93 | // one ManifestFetchData. |
| 94 | std::set<int> request_ids_; |
| 95 | |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 96 | DISALLOW_COPY_AND_ASSIGN(ManifestFetchData); |
| 97 | }; |
| 98 | |
| 99 | } // namespace extensions |
| 100 | |
| 101 | #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_MANIFEST_FETCH_DATA_H_ |