Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/component_updater/component_updater_ping_manager.h" | 5 #include "chrome/browser/component_updater/component_updater_ping_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/guid.h" | 10 #include "base/guid.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 return "unknown"; | 31 return "unknown"; |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Sends a fire and forget ping. The instances of this class have no | 35 // Sends a fire and forget ping. The instances of this class have no |
| 36 // ownership and they self-delete upon completion. | 36 // ownership and they self-delete upon completion. |
| 37 class PingSender : public net::URLFetcherDelegate { | 37 class PingSender : public net::URLFetcherDelegate { |
| 38 public: | 38 public: |
| 39 PingSender(); | 39 PingSender(); |
| 40 | 40 |
| 41 void SendPing(const GURL& ping_url, | 41 void SendPing(const std::string& chrome_version, |
|
blundell
2014/06/17 19:16:24
s/chrome_version/application_version everywhere in
tommycli
2014/06/17 19:31:07
Done.
| |
| 42 const std::string& platform_name, const GURL& ping_url, | |
| 42 net::URLRequestContextGetter* url_request_context_getter, | 43 net::URLRequestContextGetter* url_request_context_getter, |
| 43 const CrxUpdateItem* item); | 44 const CrxUpdateItem* item); |
| 44 | 45 |
| 45 private: | 46 private: |
| 46 virtual ~PingSender(); | 47 virtual ~PingSender(); |
| 47 | 48 |
| 48 // Overrides for URLFetcherDelegate. | 49 // Overrides for URLFetcherDelegate. |
| 49 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 50 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 50 | 51 |
| 51 static std::string BuildPing(const CrxUpdateItem* item); | 52 static std::string BuildPing(const std::string& chrome_version, |
| 53 const std::string& platform_name, | |
| 54 const CrxUpdateItem* item); | |
| 52 static std::string BuildDownloadCompleteEventElements( | 55 static std::string BuildDownloadCompleteEventElements( |
| 53 const CrxUpdateItem* item); | 56 const CrxUpdateItem* item); |
| 54 static std::string BuildUpdateCompleteEventElement(const CrxUpdateItem* item); | 57 static std::string BuildUpdateCompleteEventElement(const CrxUpdateItem* item); |
| 55 | 58 |
| 56 scoped_ptr<net::URLFetcher> url_fetcher_; | 59 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 57 | 60 |
| 58 DISALLOW_COPY_AND_ASSIGN(PingSender); | 61 DISALLOW_COPY_AND_ASSIGN(PingSender); |
| 59 }; | 62 }; |
| 60 | 63 |
| 61 PingSender::PingSender() { | 64 PingSender::PingSender() { |
| 62 } | 65 } |
| 63 | 66 |
| 64 PingSender::~PingSender() { | 67 PingSender::~PingSender() { |
| 65 } | 68 } |
| 66 | 69 |
| 67 void PingSender::OnURLFetchComplete(const net::URLFetcher* source) { | 70 void PingSender::OnURLFetchComplete(const net::URLFetcher* source) { |
| 68 delete this; | 71 delete this; |
| 69 } | 72 } |
| 70 | 73 |
| 71 void PingSender::SendPing( | 74 void PingSender::SendPing( |
| 75 const std::string& chrome_version, | |
| 76 const std::string& platform_name, | |
| 72 const GURL& ping_url, | 77 const GURL& ping_url, |
| 73 net::URLRequestContextGetter* url_request_context_getter, | 78 net::URLRequestContextGetter* url_request_context_getter, |
| 74 const CrxUpdateItem* item) { | 79 const CrxUpdateItem* item) { |
| 75 DCHECK(item); | 80 DCHECK(item); |
| 76 | 81 |
| 77 if (!ping_url.is_valid()) | 82 if (!ping_url.is_valid()) |
| 78 return; | 83 return; |
| 79 | 84 |
| 80 url_fetcher_.reset(SendProtocolRequest( | 85 url_fetcher_.reset(SendProtocolRequest( |
| 81 ping_url, BuildPing(item), this, url_request_context_getter)); | 86 ping_url, BuildPing(chrome_version, platform_name, item), this, |
| 87 url_request_context_getter)); | |
| 82 } | 88 } |
| 83 | 89 |
| 84 // Builds a ping message for the specified update item. | 90 // Builds a ping message for the specified update item. |
| 85 std::string PingSender::BuildPing(const CrxUpdateItem* item) { | 91 std::string PingSender::BuildPing(const std::string& chrome_version, |
| 92 const std::string& platform_name, | |
| 93 const CrxUpdateItem* item) { | |
| 86 const char app_element_format[] = | 94 const char app_element_format[] = |
| 87 "<app appid=\"%s\" version=\"%s\" nextversion=\"%s\">" | 95 "<app appid=\"%s\" version=\"%s\" nextversion=\"%s\">" |
| 88 "%s" | 96 "%s" |
| 89 "%s" | 97 "%s" |
| 90 "</app>"; | 98 "</app>"; |
| 91 const std::string app_element(base::StringPrintf( | 99 const std::string app_element(base::StringPrintf( |
| 92 app_element_format, | 100 app_element_format, |
| 93 item->id.c_str(), // "appid" | 101 item->id.c_str(), // "appid" |
| 94 item->previous_version.GetString().c_str(), // "version" | 102 item->previous_version.GetString().c_str(), // "version" |
| 95 item->next_version.GetString().c_str(), // "nextversion" | 103 item->next_version.GetString().c_str(), // "nextversion" |
| 96 BuildUpdateCompleteEventElement(item).c_str(), // update event | 104 BuildUpdateCompleteEventElement(item).c_str(), // update event |
| 97 BuildDownloadCompleteEventElements(item).c_str())); // download events | 105 BuildDownloadCompleteEventElements(item).c_str())); // download events |
| 98 | 106 |
| 99 return BuildProtocolRequest(app_element, ""); | 107 return BuildProtocolRequest(chrome_version, platform_name, app_element, ""); |
| 100 } | 108 } |
| 101 | 109 |
| 102 // Returns a string representing a sequence of download complete events | 110 // Returns a string representing a sequence of download complete events |
| 103 // corresponding to each download metrics in |item|. | 111 // corresponding to each download metrics in |item|. |
| 104 std::string PingSender::BuildDownloadCompleteEventElements( | 112 std::string PingSender::BuildDownloadCompleteEventElements( |
| 105 const CrxUpdateItem* item) { | 113 const CrxUpdateItem* item) { |
| 106 using base::StringAppendF; | 114 using base::StringAppendF; |
| 107 std::string download_events; | 115 std::string download_events; |
| 108 for (size_t i = 0; i != item->download_metrics.size(); ++i) { | 116 for (size_t i = 0; i != item->download_metrics.size(); ++i) { |
| 109 const CrxDownloader::DownloadMetrics& metrics = item->download_metrics[i]; | 117 const CrxDownloader::DownloadMetrics& metrics = item->download_metrics[i]; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 } | 180 } |
| 173 if (!item->previous_fp.empty()) | 181 if (!item->previous_fp.empty()) |
| 174 StringAppendF(&ping_event, " previousfp=\"%s\"", item->previous_fp.c_str()); | 182 StringAppendF(&ping_event, " previousfp=\"%s\"", item->previous_fp.c_str()); |
| 175 if (!item->next_fp.empty()) | 183 if (!item->next_fp.empty()) |
| 176 StringAppendF(&ping_event, " nextfp=\"%s\"", item->next_fp.c_str()); | 184 StringAppendF(&ping_event, " nextfp=\"%s\"", item->next_fp.c_str()); |
| 177 StringAppendF(&ping_event, "/>"); | 185 StringAppendF(&ping_event, "/>"); |
| 178 return ping_event; | 186 return ping_event; |
| 179 } | 187 } |
| 180 | 188 |
| 181 PingManager::PingManager( | 189 PingManager::PingManager( |
| 190 const std::string& application_version, | |
| 191 const std::string& platform_name, | |
| 182 const GURL& ping_url, | 192 const GURL& ping_url, |
| 183 net::URLRequestContextGetter* url_request_context_getter) | 193 net::URLRequestContextGetter* url_request_context_getter) |
| 184 : ping_url_(ping_url), | 194 : application_version_(application_version), |
| 195 platform_name_(platform_name), | |
| 196 ping_url_(ping_url), | |
| 185 url_request_context_getter_(url_request_context_getter) { | 197 url_request_context_getter_(url_request_context_getter) { |
| 186 } | 198 } |
| 187 | 199 |
| 188 PingManager::~PingManager() { | 200 PingManager::~PingManager() { |
| 189 } | 201 } |
| 190 | 202 |
| 191 // Sends a fire and forget ping when the updates are complete. The ping | 203 // Sends a fire and forget ping when the updates are complete. The ping |
| 192 // sender object self-deletes after sending the ping. | 204 // sender object self-deletes after sending the ping. |
| 193 void PingManager::OnUpdateComplete(const CrxUpdateItem* item) { | 205 void PingManager::OnUpdateComplete(const CrxUpdateItem* item) { |
| 194 PingSender* ping_sender(new PingSender); | 206 PingSender* ping_sender(new PingSender); |
| 195 ping_sender->SendPing(ping_url_, url_request_context_getter_, item); | 207 ping_sender->SendPing(application_version_, platform_name_, ping_url_, |
| 208 url_request_context_getter_, item); | |
| 196 } | 209 } |
| 197 | 210 |
| 198 } // namespace component_updater | 211 } // namespace component_updater |
| OLD | NEW |