| 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 22 matching lines...) Expand all Loading... |
| 33 return "unknown"; | 33 return "unknown"; |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 // Sends a fire and forget ping. The instances of this class have no | 37 // Sends a fire and forget ping. The instances of this class have no |
| 38 // ownership and they self-delete upon completion. | 38 // ownership and they self-delete upon completion. |
| 39 class PingSender : public net::URLFetcherDelegate { | 39 class PingSender : public net::URLFetcherDelegate { |
| 40 public: | 40 public: |
| 41 PingSender(); | 41 PingSender(); |
| 42 | 42 |
| 43 void SendPing(const GURL& ping_url, | 43 void SendPing(const Configurator& config, |
| 44 net::URLRequestContextGetter* url_request_context_getter, | 44 net::URLRequestContextGetter* url_request_context_getter, |
| 45 const CrxUpdateItem* item); | 45 const CrxUpdateItem* item); |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 virtual ~PingSender(); | 48 virtual ~PingSender(); |
| 49 | 49 |
| 50 // Overrides for URLFetcherDelegate. | 50 // Overrides for URLFetcherDelegate. |
| 51 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 51 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 52 | 52 |
| 53 static std::string BuildPing(const CrxUpdateItem* item); | 53 static std::string BuildPing(const Configurator& config, |
| 54 const CrxUpdateItem* item); |
| 54 static std::string BuildDownloadCompleteEventElements( | 55 static std::string BuildDownloadCompleteEventElements( |
| 55 const CrxUpdateItem* item); | 56 const CrxUpdateItem* item); |
| 56 static std::string BuildUpdateCompleteEventElement(const CrxUpdateItem* item); | 57 static std::string BuildUpdateCompleteEventElement(const CrxUpdateItem* item); |
| 57 | 58 |
| 58 scoped_ptr<net::URLFetcher> url_fetcher_; | 59 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 59 | 60 |
| 60 DISALLOW_COPY_AND_ASSIGN(PingSender); | 61 DISALLOW_COPY_AND_ASSIGN(PingSender); |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 PingSender::PingSender() { | 64 PingSender::PingSender() { |
| 64 } | 65 } |
| 65 | 66 |
| 66 PingSender::~PingSender() { | 67 PingSender::~PingSender() { |
| 67 } | 68 } |
| 68 | 69 |
| 69 void PingSender::OnURLFetchComplete(const net::URLFetcher* source) { | 70 void PingSender::OnURLFetchComplete(const net::URLFetcher* source) { |
| 70 delete this; | 71 delete this; |
| 71 } | 72 } |
| 72 | 73 |
| 73 void PingSender::SendPing( | 74 void PingSender::SendPing( |
| 74 const GURL& ping_url, | 75 const Configurator& config, |
| 75 net::URLRequestContextGetter* url_request_context_getter, | 76 net::URLRequestContextGetter* url_request_context_getter, |
| 76 const CrxUpdateItem* item) { | 77 const CrxUpdateItem* item) { |
| 77 DCHECK(item); | 78 DCHECK(item); |
| 78 | 79 |
| 79 if (!ping_url.is_valid()) | 80 if (!config.PingUrl().is_valid()) |
| 80 return; | 81 return; |
| 81 | 82 |
| 82 url_fetcher_.reset(SendProtocolRequest( | 83 url_fetcher_.reset(SendProtocolRequest( |
| 83 ping_url, BuildPing(item), this, url_request_context_getter)); | 84 config.PingUrl(), BuildPing(config, item), this, |
| 85 url_request_context_getter)); |
| 84 } | 86 } |
| 85 | 87 |
| 86 // Builds a ping message for the specified update item. | 88 // Builds a ping message for the specified update item. |
| 87 std::string PingSender::BuildPing(const CrxUpdateItem* item) { | 89 std::string PingSender::BuildPing(const Configurator& config, |
| 90 const CrxUpdateItem* item) { |
| 88 const char app_element_format[] = | 91 const char app_element_format[] = |
| 89 "<app appid=\"%s\" version=\"%s\" nextversion=\"%s\">" | 92 "<app appid=\"%s\" version=\"%s\" nextversion=\"%s\">" |
| 90 "%s" | 93 "%s" |
| 91 "%s" | 94 "%s" |
| 92 "</app>"; | 95 "</app>"; |
| 93 const std::string app_element(base::StringPrintf( | 96 const std::string app_element(base::StringPrintf( |
| 94 app_element_format, | 97 app_element_format, |
| 95 item->id.c_str(), // "appid" | 98 item->id.c_str(), // "appid" |
| 96 item->previous_version.GetString().c_str(), // "version" | 99 item->previous_version.GetString().c_str(), // "version" |
| 97 item->next_version.GetString().c_str(), // "nextversion" | 100 item->next_version.GetString().c_str(), // "nextversion" |
| 98 BuildUpdateCompleteEventElement(item).c_str(), // update event | 101 BuildUpdateCompleteEventElement(item).c_str(), // update event |
| 99 BuildDownloadCompleteEventElements(item).c_str())); // download events | 102 BuildDownloadCompleteEventElements(item).c_str())); // download events |
| 100 | 103 |
| 101 return BuildProtocolRequest(app_element, ""); | 104 return BuildProtocolRequest(config, app_element, ""); |
| 102 } | 105 } |
| 103 | 106 |
| 104 // Returns a string representing a sequence of download complete events | 107 // Returns a string representing a sequence of download complete events |
| 105 // corresponding to each download metrics in |item|. | 108 // corresponding to each download metrics in |item|. |
| 106 std::string PingSender::BuildDownloadCompleteEventElements( | 109 std::string PingSender::BuildDownloadCompleteEventElements( |
| 107 const CrxUpdateItem* item) { | 110 const CrxUpdateItem* item) { |
| 108 using base::StringAppendF; | 111 using base::StringAppendF; |
| 109 std::string download_events; | 112 std::string download_events; |
| 110 for (size_t i = 0; i != item->download_metrics.size(); ++i) { | 113 for (size_t i = 0; i != item->download_metrics.size(); ++i) { |
| 111 const CrxDownloader::DownloadMetrics& metrics = item->download_metrics[i]; | 114 const CrxDownloader::DownloadMetrics& metrics = item->download_metrics[i]; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 PingManager::PingManager(const Configurator& config) : config_(config) { | 186 PingManager::PingManager(const Configurator& config) : config_(config) { |
| 184 } | 187 } |
| 185 | 188 |
| 186 PingManager::~PingManager() { | 189 PingManager::~PingManager() { |
| 187 } | 190 } |
| 188 | 191 |
| 189 // Sends a fire and forget ping when the updates are complete. The ping | 192 // Sends a fire and forget ping when the updates are complete. The ping |
| 190 // sender object self-deletes after sending the ping. | 193 // sender object self-deletes after sending the ping. |
| 191 void PingManager::OnUpdateComplete(const CrxUpdateItem* item) { | 194 void PingManager::OnUpdateComplete(const CrxUpdateItem* item) { |
| 192 PingSender* ping_sender(new PingSender); | 195 PingSender* ping_sender(new PingSender); |
| 193 ping_sender->SendPing(config_.PingUrl(), config_.RequestContext(), item); | 196 ping_sender->SendPing(config_, config_.RequestContext(), item); |
| 194 } | 197 } |
| 195 | 198 |
| 196 } // namespace component_updater | 199 } // namespace component_updater |
| OLD | NEW |