Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: chrome/browser/component_updater/component_updater_ping_manager.cc

Issue 375973003: Componentize component_updater: Use Configurator to build query parameters. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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(config.PingUrl(),
83 ping_url, BuildPing(item), this, url_request_context_getter)); 84 BuildPing(config, item),
85 this,
86 url_request_context_getter));
84 } 87 }
85 88
86 // Builds a ping message for the specified update item. 89 // Builds a ping message for the specified update item.
87 std::string PingSender::BuildPing(const CrxUpdateItem* item) { 90 std::string PingSender::BuildPing(const Configurator& config,
91 const CrxUpdateItem* item) {
88 const char app_element_format[] = 92 const char app_element_format[] =
89 "<app appid=\"%s\" version=\"%s\" nextversion=\"%s\">" 93 "<app appid=\"%s\" version=\"%s\" nextversion=\"%s\">"
90 "%s" 94 "%s"
91 "%s" 95 "%s"
92 "</app>"; 96 "</app>";
93 const std::string app_element(base::StringPrintf( 97 const std::string app_element(base::StringPrintf(
94 app_element_format, 98 app_element_format,
95 item->id.c_str(), // "appid" 99 item->id.c_str(), // "appid"
96 item->previous_version.GetString().c_str(), // "version" 100 item->previous_version.GetString().c_str(), // "version"
97 item->next_version.GetString().c_str(), // "nextversion" 101 item->next_version.GetString().c_str(), // "nextversion"
98 BuildUpdateCompleteEventElement(item).c_str(), // update event 102 BuildUpdateCompleteEventElement(item).c_str(), // update event
99 BuildDownloadCompleteEventElements(item).c_str())); // download events 103 BuildDownloadCompleteEventElements(item).c_str())); // download events
100 104
101 return BuildProtocolRequest(app_element, ""); 105 return BuildProtocolRequest(config.GetBrowserVersion().GetString(),
106 config.GetChannel(),
107 config.GetLang(),
108 config.GetOSLongName(),
109 app_element,
110 "");
102 } 111 }
103 112
104 // Returns a string representing a sequence of download complete events 113 // Returns a string representing a sequence of download complete events
105 // corresponding to each download metrics in |item|. 114 // corresponding to each download metrics in |item|.
106 std::string PingSender::BuildDownloadCompleteEventElements( 115 std::string PingSender::BuildDownloadCompleteEventElements(
107 const CrxUpdateItem* item) { 116 const CrxUpdateItem* item) {
108 using base::StringAppendF; 117 using base::StringAppendF;
109 std::string download_events; 118 std::string download_events;
110 for (size_t i = 0; i != item->download_metrics.size(); ++i) { 119 for (size_t i = 0; i != item->download_metrics.size(); ++i) {
111 const CrxDownloader::DownloadMetrics& metrics = item->download_metrics[i]; 120 const CrxDownloader::DownloadMetrics& metrics = item->download_metrics[i];
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 PingManager::PingManager(const Configurator& config) : config_(config) { 192 PingManager::PingManager(const Configurator& config) : config_(config) {
184 } 193 }
185 194
186 PingManager::~PingManager() { 195 PingManager::~PingManager() {
187 } 196 }
188 197
189 // Sends a fire and forget ping when the updates are complete. The ping 198 // Sends a fire and forget ping when the updates are complete. The ping
190 // sender object self-deletes after sending the ping. 199 // sender object self-deletes after sending the ping.
191 void PingManager::OnUpdateComplete(const CrxUpdateItem* item) { 200 void PingManager::OnUpdateComplete(const CrxUpdateItem* item) {
192 PingSender* ping_sender(new PingSender); 201 PingSender* ping_sender(new PingSender);
193 ping_sender->SendPing(config_.PingUrl(), config_.RequestContext(), item); 202 ping_sender->SendPing(config_, config_.RequestContext(), item);
194 } 203 }
195 204
196 } // namespace component_updater 205 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698