| 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" | |
| 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 19 matching lines...) Expand all Loading... |
| 82 parts.push_back("uc"); | 86 parts.push_back("uc"); |
| 83 | 87 |
| 84 if (!update_url_data.empty()) { | 88 if (!update_url_data.empty()) { |
| 85 // Make sure the update_url_data string is escaped before using it so that | 89 // 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 | 90 // there is no chance of overriding the id or v other parameter value |
| 87 // we place into the x= value. | 91 // we place into the x= value. |
| 88 parts.push_back("ap=" + net::EscapeQueryParamValue(update_url_data, true)); | 92 parts.push_back("ap=" + net::EscapeQueryParamValue(update_url_data, true)); |
| 89 } | 93 } |
| 90 | 94 |
| 91 // Append brand code, rollcall and active ping parameters. | 95 // Append brand code, rollcall and active ping parameters. |
| 92 if (base_url_.DomainIs("google.com")) { | 96 if (ping_mode_ != NO_PING) { |
| 93 #if defined(GOOGLE_CHROME_BUILD) | 97 if (!brand_code_.empty()) |
| 94 std::string brand; | 98 parts.push_back(base::StringPrintf("brand=%s", brand_code_.c_str())); |
| 95 google_brand::GetBrand(&brand); | |
| 96 if (!brand.empty() && !google_brand::IsOrganic(brand)) | |
| 97 parts.push_back("brand=" + brand); | |
| 98 #endif | |
| 99 | 99 |
| 100 std::string ping_value; | 100 std::string ping_value; |
| 101 pings_[id] = PingData(0, 0, false); | 101 pings_[id] = PingData(0, 0, false); |
| 102 | |
| 103 if (ping_data) { | 102 if (ping_data) { |
| 104 if (ping_data->rollcall_days == kNeverPinged || | 103 if (ping_data->rollcall_days == kNeverPinged || |
| 105 ping_data->rollcall_days > 0) { | 104 ping_data->rollcall_days > 0) { |
| 106 ping_value += "r=" + base::IntToString(ping_data->rollcall_days); | 105 ping_value += "r=" + base::IntToString(ping_data->rollcall_days); |
| 107 if (ChromeMetricsServiceAccessor::IsMetricsReportingEnabled()) { | 106 if (ping_mode_ == PING_WITH_METRICS) { |
| 108 ping_value += "&e=" + std::string(ping_data->is_enabled ? "1" : "0"); | 107 ping_value += "&e=" + std::string(ping_data->is_enabled ? "1" : "0"); |
| 109 } | 108 } |
| 110 pings_[id].rollcall_days = ping_data->rollcall_days; | 109 pings_[id].rollcall_days = ping_data->rollcall_days; |
| 111 pings_[id].is_enabled = ping_data->is_enabled; | 110 pings_[id].is_enabled = ping_data->is_enabled; |
| 112 } | 111 } |
| 113 if (ping_data->active_days == kNeverPinged || | 112 if (ping_data->active_days == kNeverPinged || |
| 114 ping_data->active_days > 0) { | 113 ping_data->active_days > 0) { |
| 115 if (!ping_value.empty()) | 114 if (!ping_value.empty()) |
| 116 ping_value += "&"; | 115 ping_value += "&"; |
| 117 ping_value += "a=" + base::IntToString(ping_data->active_days); | 116 ping_value += "a=" + base::IntToString(ping_data->active_days); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 NOTREACHED(); | 156 NOTREACHED(); |
| 158 return value == kNeverPinged || value > 0; | 157 return value == kNeverPinged || value > 0; |
| 159 } | 158 } |
| 160 | 159 |
| 161 void ManifestFetchData::Merge(const ManifestFetchData& other) { | 160 void ManifestFetchData::Merge(const ManifestFetchData& other) { |
| 162 DCHECK(full_url() == other.full_url()); | 161 DCHECK(full_url() == other.full_url()); |
| 163 request_ids_.insert(other.request_ids_.begin(), other.request_ids_.end()); | 162 request_ids_.insert(other.request_ids_.begin(), other.request_ids_.end()); |
| 164 } | 163 } |
| 165 | 164 |
| 166 } // namespace extensions | 165 } // namespace extensions |
| OLD | NEW |