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

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

Issue 375973003: Componentize component_updater: Use Configurator to build query parameters. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix tests 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/update_checker.h" 5 #include "chrome/browser/component_updater/update_checker.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/component_updater/component_updater_configurator.h" 10 #include "chrome/browser/component_updater/component_updater_configurator.h"
(...skipping 15 matching lines...) Expand all
26 // the <request>. 26 // the <request>.
27 // 27 //
28 // An app element looks like this: 28 // An app element looks like this:
29 // <app appid="hnimpnehoodheedghdeeijklkeaacbdc" 29 // <app appid="hnimpnehoodheedghdeeijklkeaacbdc"
30 // version="0.1.2.3" installsource="ondemand"> 30 // version="0.1.2.3" installsource="ondemand">
31 // <updatecheck /> 31 // <updatecheck />
32 // <packages> 32 // <packages>
33 // <package fp="abcd" /> 33 // <package fp="abcd" />
34 // </packages> 34 // </packages>
35 // </app> 35 // </app>
36 std::string BuildUpdateCheckRequest(const std::vector<CrxUpdateItem*>& items, 36 std::string BuildUpdateCheckRequest(const Configurator& config,
37 const std::vector<CrxUpdateItem*>& items,
37 const std::string& additional_attributes) { 38 const std::string& additional_attributes) {
38 std::string app_elements; 39 std::string app_elements;
39 for (size_t i = 0; i != items.size(); ++i) { 40 for (size_t i = 0; i != items.size(); ++i) {
40 const CrxUpdateItem* item = items[i]; 41 const CrxUpdateItem* item = items[i];
41 std::string app("<app "); 42 std::string app("<app ");
42 base::StringAppendF(&app, 43 base::StringAppendF(&app,
43 "appid=\"%s\" version=\"%s\"", 44 "appid=\"%s\" version=\"%s\"",
44 item->id.c_str(), 45 item->id.c_str(),
45 item->component.version.GetString().c_str()); 46 item->component.version.GetString().c_str());
46 if (item->on_demand) 47 if (item->on_demand)
47 base::StringAppendF(&app, " installsource=\"ondemand\""); 48 base::StringAppendF(&app, " installsource=\"ondemand\"");
48 base::StringAppendF(&app, ">"); 49 base::StringAppendF(&app, ">");
49 base::StringAppendF(&app, "<updatecheck />"); 50 base::StringAppendF(&app, "<updatecheck />");
50 if (!item->component.fingerprint.empty()) { 51 if (!item->component.fingerprint.empty()) {
51 base::StringAppendF(&app, 52 base::StringAppendF(&app,
52 "<packages>" 53 "<packages>"
53 "<package fp=\"%s\"/>" 54 "<package fp=\"%s\"/>"
54 "</packages>", 55 "</packages>",
55 item->component.fingerprint.c_str()); 56 item->component.fingerprint.c_str());
56 } 57 }
57 base::StringAppendF(&app, "</app>"); 58 base::StringAppendF(&app, "</app>");
58 app_elements.append(app); 59 app_elements.append(app);
59 VLOG(1) << "Appending to update request: " << app; 60 VLOG(1) << "Appending to update request: " << app;
60 } 61 }
61 62
62 return BuildProtocolRequest(app_elements, additional_attributes); 63 return BuildProtocolRequest(config, app_elements, additional_attributes);
63 } 64 }
64 65
65 class UpdateCheckerImpl : public UpdateChecker, public net::URLFetcherDelegate { 66 class UpdateCheckerImpl : public UpdateChecker, public net::URLFetcherDelegate {
66 public: 67 public:
67 UpdateCheckerImpl(const Configurator& config, 68 UpdateCheckerImpl(const Configurator& config,
68 const UpdateCheckCallback& update_check_callback); 69 const UpdateCheckCallback& update_check_callback);
69 virtual ~UpdateCheckerImpl(); 70 virtual ~UpdateCheckerImpl();
70 71
71 // Overrides for UpdateChecker. 72 // Overrides for UpdateChecker.
72 virtual bool CheckForUpdates( 73 virtual bool CheckForUpdates(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 bool UpdateCheckerImpl::CheckForUpdates( 108 bool UpdateCheckerImpl::CheckForUpdates(
108 const std::vector<CrxUpdateItem*>& items_to_check, 109 const std::vector<CrxUpdateItem*>& items_to_check,
109 const std::string& additional_attributes) { 110 const std::string& additional_attributes) {
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
111 112
112 if (url_fetcher_) 113 if (url_fetcher_)
113 return false; // Another fetch is in progress. 114 return false; // Another fetch is in progress.
114 115
115 url_fetcher_.reset(SendProtocolRequest( 116 url_fetcher_.reset(SendProtocolRequest(
116 config_.UpdateUrl(), 117 config_.UpdateUrl(),
117 BuildUpdateCheckRequest(items_to_check, additional_attributes), 118 BuildUpdateCheckRequest(config_, items_to_check, additional_attributes),
118 this, 119 this,
119 config_.RequestContext())); 120 config_.RequestContext()));
120 121
121 return true; 122 return true;
122 } 123 }
123 124
124 void UpdateCheckerImpl::OnURLFetchComplete(const net::URLFetcher* source) { 125 void UpdateCheckerImpl::OnURLFetchComplete(const net::URLFetcher* source) {
125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
126 DCHECK(url_fetcher_.get() == source); 127 DCHECK(url_fetcher_.get() == source);
127 128
(...skipping 13 matching lines...) Expand all
141 error = GetFetchError(*source); 142 error = GetFetchError(*source);
142 error_message.assign("network error"); 143 error_message.assign("network error");
143 VLOG(1) << "Update request failed: network error"; 144 VLOG(1) << "Update request failed: network error";
144 } 145 }
145 146
146 url_fetcher_.reset(); 147 url_fetcher_.reset();
147 update_check_callback_.Run(error, error_message, update_response.results()); 148 update_check_callback_.Run(error, error_message, update_response.results());
148 } 149 }
149 150
150 } // namespace component_updater 151 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698