OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" | 5 #include "extensions/browser/updater/manifest_fetch_data.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "chrome/browser/google/google_brand.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | |
15 #include "components/omaha_query_params/omaha_query_params.h" | |
16 #include "net/base/escape.h" | 14 #include "net/base/escape.h" |
17 | 15 |
18 namespace { | 16 namespace { |
19 | 17 |
20 // Maximum length of an extension manifest update check url, since it is a GET | 18 // Maximum length of an extension manifest update check url, since it is a GET |
21 // request. We want to stay under 2K because of proxies, etc. | 19 // request. We want to stay under 2K because of proxies, etc. |
22 const int kExtensionsManifestMaxURLSize = 2000; | 20 const int kExtensionsManifestMaxURLSize = 2000; |
23 | 21 |
24 } // namespace | 22 } // namespace |
25 | 23 |
26 namespace extensions { | 24 namespace extensions { |
27 | 25 |
28 ManifestFetchData::ManifestFetchData(const GURL& update_url, int request_id) | 26 ManifestFetchData::ManifestFetchData(const GURL& update_url, |
| 27 int request_id, |
| 28 const std::string& brand_code, |
| 29 const std::string& base_query_params, |
| 30 PingMode ping_mode) |
29 : base_url_(update_url), | 31 : base_url_(update_url), |
30 full_url_(update_url) { | 32 full_url_(update_url), |
31 std::string query = full_url_.has_query() ? | 33 brand_code_(brand_code), |
32 full_url_.query() + "&" : std::string(); | 34 ping_mode_(ping_mode) { |
33 query += omaha_query_params::OmahaQueryParams::Get( | 35 std::string query = |
34 omaha_query_params::OmahaQueryParams::CRX); | 36 full_url_.has_query() ? full_url_.query() + "&" : std::string(); |
| 37 query += base_query_params; |
35 GURL::Replacements replacements; | 38 GURL::Replacements replacements; |
36 replacements.SetQueryStr(query); | 39 replacements.SetQueryStr(query); |
37 full_url_ = full_url_.ReplaceComponents(replacements); | 40 full_url_ = full_url_.ReplaceComponents(replacements); |
38 | 41 |
39 request_ids_.insert(request_id); | 42 request_ids_.insert(request_id); |
40 } | 43 } |
41 | 44 |
42 ManifestFetchData::~ManifestFetchData() {} | 45 ManifestFetchData::~ManifestFetchData() { |
| 46 } |
43 | 47 |
44 // The format for request parameters in update checks is: | 48 // The format for request parameters in update checks is: |
45 // | 49 // |
46 // ?x=EXT1_INFO&x=EXT2_INFO | 50 // ?x=EXT1_INFO&x=EXT2_INFO |
47 // | 51 // |
48 // where EXT1_INFO and EXT2_INFO are url-encoded strings of the form: | 52 // where EXT1_INFO and EXT2_INFO are url-encoded strings of the form: |
49 // | 53 // |
50 // id=EXTENSION_ID&v=VERSION&uc | 54 // id=EXTENSION_ID&v=VERSION&uc |
51 // | 55 // |
52 // Additionally, we may include the parameter ping=PING_DATA where PING_DATA | 56 // Provide ping data with the parameter ping=PING_DATA where PING_DATA |
53 // looks like r=DAYS or a=DAYS for extensions in the Chrome extensions gallery. | 57 // looks like r=DAYS or a=DAYS for extensions in the Chrome extensions gallery. |
54 // ('r' refers to 'roll call' ie installation, and 'a' refers to 'active'). | 58 // ('r' refers to 'roll call' ie installation, and 'a' refers to 'active'). |
55 // These values will each be present at most once every 24 hours, and indicate | 59 // These values will each be present at most once every 24 hours, and indicate |
56 // the number of days since the last time it was present in an update check. | 60 // the number of days since the last time it was present in an update check. |
57 // | 61 // |
58 // So for two extensions like: | 62 // So for two extensions like: |
59 // Extension 1- id:aaaa version:1.1 | 63 // Extension 1- id:aaaa version:1.1 |
60 // Extension 2- id:bbbb version:2.0 | 64 // Extension 2- id:bbbb version:2.0 |
61 // | 65 // |
62 // the full update url would be: | 66 // the full update url would be: |
(...skipping 27 matching lines...) Expand all Loading... |
90 parts.push_back("uc"); | 94 parts.push_back("uc"); |
91 | 95 |
92 if (!update_url_data.empty()) { | 96 if (!update_url_data.empty()) { |
93 // Make sure the update_url_data string is escaped before using it so that | 97 // Make sure the update_url_data string is escaped before using it so that |
94 // there is no chance of overriding the id or v other parameter value | 98 // there is no chance of overriding the id or v other parameter value |
95 // we place into the x= value. | 99 // we place into the x= value. |
96 parts.push_back("ap=" + net::EscapeQueryParamValue(update_url_data, true)); | 100 parts.push_back("ap=" + net::EscapeQueryParamValue(update_url_data, true)); |
97 } | 101 } |
98 | 102 |
99 // Append brand code, rollcall and active ping parameters. | 103 // Append brand code, rollcall and active ping parameters. |
100 if (base_url_.DomainIs("google.com")) { | 104 if (ping_mode_ != NO_PING) { |
101 #if defined(GOOGLE_CHROME_BUILD) | 105 if (!brand_code_.empty()) |
102 std::string brand; | 106 parts.push_back(base::StringPrintf("brand=%s", brand_code_.c_str())); |
103 google_brand::GetBrand(&brand); | |
104 if (!brand.empty() && !google_brand::IsOrganic(brand)) | |
105 parts.push_back("brand=" + brand); | |
106 #endif | |
107 | 107 |
108 std::string ping_value; | 108 std::string ping_value; |
109 pings_[id] = PingData(0, 0, false); | 109 pings_[id] = PingData(0, 0, false); |
110 | |
111 if (ping_data) { | 110 if (ping_data) { |
112 if (ping_data->rollcall_days == kNeverPinged || | 111 if (ping_data->rollcall_days == kNeverPinged || |
113 ping_data->rollcall_days > 0) { | 112 ping_data->rollcall_days > 0) { |
114 ping_value += "r=" + base::IntToString(ping_data->rollcall_days); | 113 ping_value += "r=" + base::IntToString(ping_data->rollcall_days); |
115 if (ChromeMetricsServiceAccessor::IsMetricsReportingEnabled()) { | 114 if (ping_mode_ == PING_WITH_METRICS) { |
116 ping_value += "&e=" + std::string(ping_data->is_enabled ? "1" : "0"); | 115 ping_value += "&e=" + std::string(ping_data->is_enabled ? "1" : "0"); |
117 } | 116 } |
118 pings_[id].rollcall_days = ping_data->rollcall_days; | 117 pings_[id].rollcall_days = ping_data->rollcall_days; |
119 pings_[id].is_enabled = ping_data->is_enabled; | 118 pings_[id].is_enabled = ping_data->is_enabled; |
120 } | 119 } |
121 if (ping_data->active_days == kNeverPinged || | 120 if (ping_data->active_days == kNeverPinged || |
122 ping_data->active_days > 0) { | 121 ping_data->active_days > 0) { |
123 if (!ping_value.empty()) | 122 if (!ping_value.empty()) |
124 ping_value += "&"; | 123 ping_value += "&"; |
125 ping_value += "a=" + base::IntToString(ping_data->active_days); | 124 ping_value += "a=" + base::IntToString(ping_data->active_days); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 void ManifestFetchData::Merge(const ManifestFetchData& other) { | 168 void ManifestFetchData::Merge(const ManifestFetchData& other) { |
170 DCHECK(full_url() == other.full_url()); | 169 DCHECK(full_url() == other.full_url()); |
171 request_ids_.insert(other.request_ids_.begin(), other.request_ids_.end()); | 170 request_ids_.insert(other.request_ids_.begin(), other.request_ids_.end()); |
172 } | 171 } |
173 | 172 |
174 bool ManifestFetchData::DidForceUpdate(const std::string& extension_id) const { | 173 bool ManifestFetchData::DidForceUpdate(const std::string& extension_id) const { |
175 return forced_updates_.find(extension_id) != forced_updates_.end(); | 174 return forced_updates_.find(extension_id) != forced_updates_.end(); |
176 } | 175 } |
177 | 176 |
178 } // namespace extensions | 177 } // namespace extensions |
OLD | NEW |