| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013 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 #include "chrome/browser/component_updater/ping_sender.h" |
| 6 #include "base/guid.h" |
| 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/sys_info.h" |
| 11 #include "base/win/windows_version.h" |
| 12 #include "chrome/browser/component_updater/crx_update_item.h" |
| 13 #include "chrome/common/chrome_version_info.h" |
| 14 #include "chrome/common/omaha_query_params/omaha_query_params.h" |
| 15 #include "net/base/load_flags.h" |
| 16 #include "net/base/net_errors.h" |
| 17 #include "net/url_request/url_fetcher.h" |
| 18 #include "net/url_request/url_request_status.h" |
| 19 |
| 20 namespace { |
| 21 |
| 22 // Returns true if the |update_item| contains a valid differential update url. |
| 23 bool HasDiffUpdate(const CrxUpdateItem* update_item) { |
| 24 return update_item->diff_crx_url.is_valid(); |
| 25 } |
| 26 |
| 27 } // namespace |
| 28 |
| 29 namespace component_updater { |
| 30 |
| 31 PingSender::PingSender(ComponentUpdateService::Configurator* configurator) |
| 32 : configurator_(configurator) {} |
| 33 |
| 34 PingSender::~PingSender() {} |
| 35 |
| 36 void PingSender::OnURLFetchComplete(const net::URLFetcher* source) { |
| 37 delete this; |
| 38 } |
| 39 |
| 40 void PingSender::SendPing(const CrxUpdateItem* item) { |
| 41 DCHECK(item); |
| 42 |
| 43 const GURL ping_url(configurator_->PingUrl()); |
| 44 if (!ping_url.is_valid()) |
| 45 return; |
| 46 |
| 47 url_fetcher_.reset(net::URLFetcher::Create(0, |
| 48 ping_url, |
| 49 net::URLFetcher::POST, |
| 50 this)); |
| 51 |
| 52 url_fetcher_->SetUploadData(std::string("application/xml"), BuildPing(item)); |
| 53 url_fetcher_->SetRequestContext(configurator_->RequestContext()); |
| 54 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 55 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 56 net::LOAD_DISABLE_CACHE); |
| 57 url_fetcher_->SetAutomaticallyRetryOn5xx(false); |
| 58 url_fetcher_->Start(); |
| 59 } |
| 60 |
| 61 // Builds a ping message for the specified update item. |
| 62 std::string PingSender::BuildPing(const CrxUpdateItem* item) const { |
| 63 const std::string prod_id(chrome::OmahaQueryParams::GetProdIdString( |
| 64 chrome::OmahaQueryParams::CHROME)); |
| 65 |
| 66 const char response_format[] = |
| 67 "<o:gupdate xmlns:o=\"http://www.google.com/update2/request\" " |
| 68 "protocol=\"2.0\" version=\"%s-%s\" requestid=\"{%s}\"> " |
| 69 "<o:os platform=\"%s\" version=\"%s\"/> " |
| 70 "<o:app appid=\"%s\" version=\"%s\">" |
| 71 "%s" |
| 72 "</o:app></o:gupdate>"; |
| 73 const std::string response( |
| 74 base::StringPrintf(response_format, |
| 75 prod_id.c_str(), |
| 76 chrome::VersionInfo().Version().c_str(), |
| 77 base::GenerateGUID().c_str(), |
| 78 chrome::VersionInfo().OSType().c_str(), |
| 79 base::SysInfo().OperatingSystemVersion().c_str(), |
| 80 item->id.c_str(), |
| 81 item->component.version.GetString().c_str(), |
| 82 BuildPingEvent(item).c_str())); |
| 83 return response; |
| 84 } |
| 85 |
| 86 // Returns a string representing one ping event for an update item. |
| 87 std::string PingSender::BuildPingEvent(const CrxUpdateItem* item) { |
| 88 DCHECK(item->status == CrxUpdateItem::kNoUpdate || |
| 89 item->status == CrxUpdateItem::kUpdated); |
| 90 |
| 91 using base::StringAppendF; |
| 92 |
| 93 std::string ping_event("<o:event eventtype=\"3\""); |
| 94 const int event_result = item->status == CrxUpdateItem::kUpdated; |
| 95 StringAppendF(&ping_event, " eventresult=\"%d\"", event_result); |
| 96 StringAppendF(&ping_event, " previousversion=\"%s\"", |
| 97 item->previous_version.GetString().c_str()); |
| 98 StringAppendF(&ping_event, " nextversion=\"%s\"", |
| 99 item->next_version.GetString().c_str()); |
| 100 if (item->error_category) |
| 101 StringAppendF(&ping_event, " errorcat=\"%d\"", item->error_category); |
| 102 if (item->error_code) |
| 103 StringAppendF(&ping_event, " errorcode=\"%d\"", item->error_code); |
| 104 if (item->extra_code1) |
| 105 StringAppendF(&ping_event, " extracode1=\"%d\"", item->extra_code1); |
| 106 if (HasDiffUpdate(item)) |
| 107 StringAppendF(&ping_event, " diffresult=\"%d\"", !item->diff_update_failed); |
| 108 if (item->diff_error_category) |
| 109 StringAppendF(&ping_event, " errorcat=\"%d\"", item->diff_error_category); |
| 110 if (item->diff_error_code) |
| 111 StringAppendF(&ping_event, " differrorcode=\"%d\"", item->diff_error_code); |
| 112 if (item->diff_extra_code1) { |
| 113 StringAppendF(&ping_event, |
| 114 " diffextracode1=\"%d\"", |
| 115 item->diff_extra_code1); |
| 116 } |
| 117 if (!item->previous_fp.empty()) |
| 118 StringAppendF(&ping_event, " previousfp=\"%s\"", item->previous_fp.c_str()); |
| 119 if (!item->next_fp.empty()) |
| 120 StringAppendF(&ping_event, " nextfp=\"%s\"", item->next_fp.c_str()); |
| 121 StringAppendF(&ping_event, "/>"); |
| 122 return ping_event; |
| 123 } |
| 124 |
| 125 } // namespace component_updater |
| 126 |
| OLD | NEW |