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

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: address comments 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(
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.GetBrowserVersion().GetString(),
105 config.GetChannel(), config.GetLang(),
Sorin Jianu 2014/07/10 16:25:23 small nit, maybe align vertically the arguments, s
tommycli 2014/07/10 17:46:36 Done.
106 config.GetOSLongName(), app_element, "");
102 } 107 }
103 108
104 // Returns a string representing a sequence of download complete events 109 // Returns a string representing a sequence of download complete events
105 // corresponding to each download metrics in |item|. 110 // corresponding to each download metrics in |item|.
106 std::string PingSender::BuildDownloadCompleteEventElements( 111 std::string PingSender::BuildDownloadCompleteEventElements(
107 const CrxUpdateItem* item) { 112 const CrxUpdateItem* item) {
108 using base::StringAppendF; 113 using base::StringAppendF;
109 std::string download_events; 114 std::string download_events;
110 for (size_t i = 0; i != item->download_metrics.size(); ++i) { 115 for (size_t i = 0; i != item->download_metrics.size(); ++i) {
111 const CrxDownloader::DownloadMetrics& metrics = item->download_metrics[i]; 116 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) { 188 PingManager::PingManager(const Configurator& config) : config_(config) {
184 } 189 }
185 190
186 PingManager::~PingManager() { 191 PingManager::~PingManager() {
187 } 192 }
188 193
189 // Sends a fire and forget ping when the updates are complete. The ping 194 // Sends a fire and forget ping when the updates are complete. The ping
190 // sender object self-deletes after sending the ping. 195 // sender object self-deletes after sending the ping.
191 void PingManager::OnUpdateComplete(const CrxUpdateItem* item) { 196 void PingManager::OnUpdateComplete(const CrxUpdateItem* item) {
192 PingSender* ping_sender(new PingSender); 197 PingSender* ping_sender(new PingSender);
193 ping_sender->SendPing(config_.PingUrl(), config_.RequestContext(), item); 198 ping_sender->SendPing(config_, config_.RequestContext(), item);
194 } 199 }
195 200
196 } // namespace component_updater 201 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698