OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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" | 14 #include "extensions/browser/updater/manifest_fetch_data_delegate.h" |
15 #include "components/omaha_query_params/omaha_query_params.h" | |
16 #include "net/base/escape.h" | 15 #include "net/base/escape.h" |
17 | 16 |
18 namespace { | 17 namespace { |
19 | 18 |
20 // Maximum length of an extension manifest update check url, since it is a GET | 19 // 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. | 20 // request. We want to stay under 2K because of proxies, etc. |
22 const int kExtensionsManifestMaxURLSize = 2000; | 21 const int kExtensionsManifestMaxURLSize = 2000; |
23 | 22 |
24 } // namespace | 23 } // namespace |
25 | 24 |
26 namespace extensions { | 25 namespace extensions { |
27 | 26 |
28 ManifestFetchData::ManifestFetchData(const GURL& update_url, int request_id) | 27 ManifestFetchData::ManifestFetchData(const GURL& update_url, |
29 : base_url_(update_url), | 28 int request_id, |
30 full_url_(update_url) { | 29 ManifestFetchDataDelegate* delegate) |
31 std::string query = full_url_.has_query() ? | 30 : base_url_(update_url), full_url_(update_url), delegate_(delegate) { |
32 full_url_.query() + "&" : std::string(); | 31 std::string query = |
33 query += omaha_query_params::OmahaQueryParams::Get( | 32 full_url_.has_query() ? full_url_.query() + "&" : std::string(); |
34 omaha_query_params::OmahaQueryParams::CRX); | 33 query += delegate_->GetBaseQueryParams(); |
35 GURL::Replacements replacements; | 34 GURL::Replacements replacements; |
36 replacements.SetQueryStr(query); | 35 replacements.SetQueryStr(query); |
37 full_url_ = full_url_.ReplaceComponents(replacements); | 36 full_url_ = full_url_.ReplaceComponents(replacements); |
38 | 37 |
39 request_ids_.insert(request_id); | 38 request_ids_.insert(request_id); |
40 } | 39 } |
41 | 40 |
42 ManifestFetchData::~ManifestFetchData() {} | 41 ManifestFetchData::~ManifestFetchData() { |
42 } | |
43 | 43 |
44 // The format for request parameters in update checks is: | 44 // The format for request parameters in update checks is: |
45 // | 45 // |
46 // ?x=EXT1_INFO&x=EXT2_INFO | 46 // ?x=EXT1_INFO&x=EXT2_INFO |
47 // | 47 // |
48 // where EXT1_INFO and EXT2_INFO are url-encoded strings of the form: | 48 // where EXT1_INFO and EXT2_INFO are url-encoded strings of the form: |
49 // | 49 // |
50 // id=EXTENSION_ID&v=VERSION&uc | 50 // id=EXTENSION_ID&v=VERSION&uc |
51 // | 51 // |
52 // Additionally, we may include the parameter ping=PING_DATA where PING_DATA | 52 // Additionally, we may include brand code and ping data from the delegate. |
53 // 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'). | |
55 // 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. | |
57 // | 53 // |
58 // So for two extensions like: | 54 // So for two extensions like: |
59 // Extension 1- id:aaaa version:1.1 | 55 // Extension 1- id:aaaa version:1.1 |
60 // Extension 2- id:bbbb version:2.0 | 56 // Extension 2- id:bbbb version:2.0 |
61 // | 57 // |
62 // the full update url would be: | 58 // the full update url would be: |
63 // http://somehost/path?x=id%3Daaaa%26v%3D1.1%26uc&x=id%3Dbbbb%26v%3D2.0%26uc | 59 // http://somehost/path?x=id%3Daaaa%26v%3D1.1%26uc&x=id%3Dbbbb%26v%3D2.0%26uc |
64 // | 60 // |
65 // (Note that '=' is %3D and '&' is %26 when urlencoded.) | 61 // (Note that '=' is %3D and '&' is %26 when urlencoded.) |
66 bool ManifestFetchData::AddExtension(const std::string& id, | 62 bool ManifestFetchData::AddExtension(const std::string& id, |
(...skipping 16 matching lines...) Expand all Loading... | |
83 | 79 |
84 if (!update_url_data.empty()) { | 80 if (!update_url_data.empty()) { |
85 // Make sure the update_url_data string is escaped before using it so that | 81 // Make sure the update_url_data string is escaped before using it so that |
86 // there is no chance of overriding the id or v other parameter value | 82 // there is no chance of overriding the id or v other parameter value |
87 // we place into the x= value. | 83 // we place into the x= value. |
88 parts.push_back("ap=" + net::EscapeQueryParamValue(update_url_data, true)); | 84 parts.push_back("ap=" + net::EscapeQueryParamValue(update_url_data, true)); |
89 } | 85 } |
90 | 86 |
91 // Append brand code, rollcall and active ping parameters. | 87 // Append brand code, rollcall and active ping parameters. |
92 if (base_url_.DomainIs("google.com")) { | 88 if (base_url_.DomainIs("google.com")) { |
93 #if defined(GOOGLE_CHROME_BUILD) | 89 std::string brand_code = delegate_->GetBrandCode(); |
94 std::string brand; | 90 if (!brand_code.empty()) |
95 google_brand::GetBrand(&brand); | 91 parts.push_back(base::StringPrintf("brand=%s", brand_code.c_str())); |
96 if (!brand.empty() && !google_brand::IsOrganic(brand)) | |
97 parts.push_back("brand=" + brand); | |
98 #endif | |
99 | 92 |
100 std::string ping_value; | 93 std::string ping_value; |
101 pings_[id] = PingData(0, 0, false); | 94 pings_[id] = PingData(0, 0, false); |
102 | |
103 if (ping_data) { | 95 if (ping_data) { |
104 if (ping_data->rollcall_days == kNeverPinged || | 96 ping_value = delegate_->GetPingParamsAndData(id, *ping_data, &pings_[id]); |
not at google - send to devlin
2014/08/12 16:33:02
Why did you need to delegate-ify this? What's wron
| |
105 ping_data->rollcall_days > 0) { | |
106 ping_value += "r=" + base::IntToString(ping_data->rollcall_days); | |
107 if (ChromeMetricsServiceAccessor::IsMetricsReportingEnabled()) { | |
108 ping_value += "&e=" + std::string(ping_data->is_enabled ? "1" : "0"); | |
109 } | |
110 pings_[id].rollcall_days = ping_data->rollcall_days; | |
111 pings_[id].is_enabled = ping_data->is_enabled; | |
112 } | |
113 if (ping_data->active_days == kNeverPinged || | |
114 ping_data->active_days > 0) { | |
115 if (!ping_value.empty()) | |
116 ping_value += "&"; | |
117 ping_value += "a=" + base::IntToString(ping_data->active_days); | |
118 pings_[id].active_days = ping_data->active_days; | |
119 } | |
120 } | 97 } |
121 if (!ping_value.empty()) | 98 if (!ping_value.empty()) |
122 parts.push_back("ping=" + net::EscapeQueryParamValue(ping_value, true)); | 99 parts.push_back("ping=" + net::EscapeQueryParamValue(ping_value, true)); |
123 } | 100 } |
124 | 101 |
125 std::string extra = full_url_.has_query() ? "&" : "?"; | 102 std::string extra = full_url_.has_query() ? "&" : "?"; |
126 extra += "x=" + net::EscapeQueryParamValue(JoinString(parts, '&'), true); | 103 extra += "x=" + net::EscapeQueryParamValue(JoinString(parts, '&'), true); |
127 | 104 |
128 // Check against our max url size, exempting the first extension added. | 105 // Check against our max url size, exempting the first extension added. |
129 int new_size = full_url_.possibly_invalid_spec().size() + extra.size(); | 106 int new_size = full_url_.possibly_invalid_spec().size() + extra.size(); |
(...skipping 27 matching lines...) Expand all Loading... | |
157 NOTREACHED(); | 134 NOTREACHED(); |
158 return value == kNeverPinged || value > 0; | 135 return value == kNeverPinged || value > 0; |
159 } | 136 } |
160 | 137 |
161 void ManifestFetchData::Merge(const ManifestFetchData& other) { | 138 void ManifestFetchData::Merge(const ManifestFetchData& other) { |
162 DCHECK(full_url() == other.full_url()); | 139 DCHECK(full_url() == other.full_url()); |
163 request_ids_.insert(other.request_ids_.begin(), other.request_ids_.end()); | 140 request_ids_.insert(other.request_ids_.begin(), other.request_ids_.end()); |
164 } | 141 } |
165 | 142 |
166 } // namespace extensions | 143 } // namespace extensions |
OLD | NEW |