[Android WebViewShell] Add inclusion test for webview exposed stable interfaces.
[chromium-blink-merge.git] / extensions / browser / updater / manifest_fetch_data.h
blob6ff339630ebfb36f7a8930c15f3955ae9b8ff3c4
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 EXTENSIONS_BROWSER_UPDATER_MANIFEST_FETCH_DATA_H_
6 #define EXTENSIONS_BROWSER_UPDATER_MANIFEST_FETCH_DATA_H_
8 #include <map>
9 #include <set>
10 #include <string>
12 #include "base/basictypes.h"
13 #include "url/gurl.h"
15 namespace extensions {
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;
25 // What ping mode this fetch should use.
26 enum PingMode {
27 // No ping, no extra metrics.
28 NO_PING,
30 // Ping without extra metrics.
31 PING,
33 // Ping with information about enabled/disabled state.
34 PING_WITH_ENABLED_STATE,
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,
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,
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;
54 // Whether the extension is enabled or not.
55 bool is_enabled;
57 // A bitmask of Extension::DisableReason's, which may contain one or more
58 // reasons why an extension is disabled.
59 int disable_reasons;
61 PingData()
62 : rollcall_days(0),
63 active_days(0),
64 is_enabled(true),
65 disable_reasons(0) {}
66 PingData(int rollcall, int active, bool enabled, int reasons)
67 : rollcall_days(rollcall),
68 active_days(active),
69 is_enabled(enabled),
70 disable_reasons(reasons) {}
73 ManifestFetchData(const GURL& update_url,
74 int request_id,
75 const std::string& brand_code,
76 const std::string& base_query_params,
77 PingMode ping_mode);
78 ~ManifestFetchData();
80 // Returns true if this extension information was successfully added. If the
81 // return value is false it means the full_url would have become too long, and
82 // this ManifestFetchData object remains unchanged.
83 bool AddExtension(const std::string& id,
84 const std::string& version,
85 const PingData* ping_data,
86 const std::string& update_url_data,
87 const std::string& install_source,
88 bool force_update);
90 const GURL& base_url() const { return base_url_; }
91 const GURL& full_url() const { return full_url_; }
92 const std::set<std::string>& extension_ids() const { return extension_ids_; }
93 const std::set<int>& request_ids() const { return request_ids_; }
95 // Returns true if the given id is included in this manifest fetch.
96 bool Includes(const std::string& extension_id) const;
98 // Returns true if a ping parameter for |type| was added to full_url for this
99 // extension id.
100 bool DidPing(const std::string& extension_id, PingType type) const;
102 // Assuming that both this ManifestFetchData and |other| have the same
103 // full_url, this method merges the other information associated with the
104 // fetch (in particular this adds all request ids associated with |other|
105 // to this ManifestFetchData).
106 void Merge(const ManifestFetchData& other);
108 // Returns |true| if a given extension was forced to update.
109 bool DidForceUpdate(const std::string& extension_id) const;
111 private:
112 // The set of extension id's for this ManifestFetchData.
113 std::set<std::string> extension_ids_;
115 // The set of ping data we actually sent.
116 std::map<std::string, PingData> pings_;
118 // The base update url without any arguments added.
119 GURL base_url_;
121 // The base update url plus arguments indicating the id, version, etc.
122 // information about each extension.
123 GURL full_url_;
125 // The set of request ids associated with this manifest fetch. If multiple
126 // requests are trying to fetch the same manifest, they can be merged into
127 // one fetch, so potentially multiple request ids can get associated with
128 // one ManifestFetchData.
129 std::set<int> request_ids_;
131 // The brand code to include with manifest fetch queries, if non-empty and
132 // |ping_mode_| >= PING.
133 const std::string brand_code_;
135 // The ping mode for this fetch. This determines whether or not ping data
136 // (and possibly extra metrics) will be included in the fetch query.
137 const PingMode ping_mode_;
139 // The set of extension IDs for which this fetch forced a CRX update.
140 std::set<std::string> forced_updates_;
142 DISALLOW_COPY_AND_ASSIGN(ManifestFetchData);
145 } // namespace extensions
147 #endif // EXTENSIONS_BROWSER_UPDATER_MANIFEST_FETCH_DATA_H_