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

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

Issue 334783002: Componentize component_updater: Move some paths/constants to component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge origin/master Created 6 years, 6 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_utils.h" 10 #include "chrome/browser/component_updater/component_updater_utils.h"
(...skipping 14 matching lines...) Expand all
25 // the <request>. 25 // the <request>.
26 // 26 //
27 // An app element looks like this: 27 // An app element looks like this:
28 // <app appid="hnimpnehoodheedghdeeijklkeaacbdc" 28 // <app appid="hnimpnehoodheedghdeeijklkeaacbdc"
29 // version="0.1.2.3" installsource="ondemand"> 29 // version="0.1.2.3" installsource="ondemand">
30 // <updatecheck /> 30 // <updatecheck />
31 // <packages> 31 // <packages>
32 // <package fp="abcd" /> 32 // <package fp="abcd" />
33 // </packages> 33 // </packages>
34 // </app> 34 // </app>
35 std::string BuildUpdateCheckRequest(const std::vector<CrxUpdateItem*>& items, 35 std::string BuildUpdateCheckRequest(const std::string& application_version,
36 const std::string& platform_name,
37 const std::vector<CrxUpdateItem*>& items,
36 const std::string& additional_attributes) { 38 const std::string& additional_attributes) {
37 std::string app_elements; 39 std::string app_elements;
38 for (size_t i = 0; i != items.size(); ++i) { 40 for (size_t i = 0; i != items.size(); ++i) {
39 const CrxUpdateItem* item = items[i]; 41 const CrxUpdateItem* item = items[i];
40 std::string app("<app "); 42 std::string app("<app ");
41 base::StringAppendF(&app, 43 base::StringAppendF(&app,
42 "appid=\"%s\" version=\"%s\"", 44 "appid=\"%s\" version=\"%s\"",
43 item->id.c_str(), 45 item->id.c_str(),
44 item->component.version.GetString().c_str()); 46 item->component.version.GetString().c_str());
45 if (item->on_demand) 47 if (item->on_demand)
46 base::StringAppendF(&app, " installsource=\"ondemand\""); 48 base::StringAppendF(&app, " installsource=\"ondemand\"");
47 base::StringAppendF(&app, ">"); 49 base::StringAppendF(&app, ">");
48 base::StringAppendF(&app, "<updatecheck />"); 50 base::StringAppendF(&app, "<updatecheck />");
49 if (!item->component.fingerprint.empty()) { 51 if (!item->component.fingerprint.empty()) {
50 base::StringAppendF(&app, 52 base::StringAppendF(&app,
51 "<packages>" 53 "<packages>"
52 "<package fp=\"%s\"/>" 54 "<package fp=\"%s\"/>"
53 "</packages>", 55 "</packages>",
54 item->component.fingerprint.c_str()); 56 item->component.fingerprint.c_str());
55 } 57 }
56 base::StringAppendF(&app, "</app>"); 58 base::StringAppendF(&app, "</app>");
57 app_elements.append(app); 59 app_elements.append(app);
58 VLOG(1) << "Appending to update request: " << app; 60 VLOG(1) << "Appending to update request: " << app;
59 } 61 }
60 62
61 return BuildProtocolRequest(app_elements, additional_attributes); 63 return BuildProtocolRequest(
64 application_version, platform_name, app_elements, additional_attributes);
Sorin Jianu 2014/06/19 00:48:22 Same thing as for the ping manager.
62 } 65 }
63 66
64 class UpdateCheckerImpl : public UpdateChecker, public net::URLFetcherDelegate { 67 class UpdateCheckerImpl : public UpdateChecker, public net::URLFetcherDelegate {
65 public: 68 public:
66 UpdateCheckerImpl(const GURL& url, 69 UpdateCheckerImpl(const GURL& url,
67 net::URLRequestContextGetter* url_request_context_getter, 70 net::URLRequestContextGetter* url_request_context_getter,
68 const UpdateCheckCallback& update_check_callback); 71 const UpdateCheckCallback& update_check_callback);
69 virtual ~UpdateCheckerImpl(); 72 virtual ~UpdateCheckerImpl();
70 73
71 // Overrides for UpdateChecker. 74 // Overrides for UpdateChecker.
72 virtual bool CheckForUpdates( 75 virtual bool CheckForUpdates(
76 const std::string& application_version,
77 const std::string& platform_name,
73 const std::vector<CrxUpdateItem*>& items_to_check, 78 const std::vector<CrxUpdateItem*>& items_to_check,
74 const std::string& additional_attributes) OVERRIDE; 79 const std::string& additional_attributes) OVERRIDE;
75 80
76 // Overrides for UrlFetcher. 81 // Overrides for UrlFetcher.
77 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 82 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
78 83
79 private: 84 private:
80 const GURL url_; 85 const GURL url_;
81 net::URLRequestContextGetter* url_request_context_getter_; // Not owned. 86 net::URLRequestContextGetter* url_request_context_getter_; // Not owned.
82 const UpdateCheckCallback update_check_callback_; 87 const UpdateCheckCallback update_check_callback_;
(...skipping 20 matching lines...) Expand all
103 url_request_context_getter_(url_request_context_getter), 108 url_request_context_getter_(url_request_context_getter),
104 update_check_callback_(update_check_callback) { 109 update_check_callback_(update_check_callback) {
105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
106 } 111 }
107 112
108 UpdateCheckerImpl::~UpdateCheckerImpl() { 113 UpdateCheckerImpl::~UpdateCheckerImpl() {
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
110 } 115 }
111 116
112 bool UpdateCheckerImpl::CheckForUpdates( 117 bool UpdateCheckerImpl::CheckForUpdates(
118 const std::string& application_version,
119 const std::string& platform_name,
113 const std::vector<CrxUpdateItem*>& items_to_check, 120 const std::vector<CrxUpdateItem*>& items_to_check,
114 const std::string& additional_attributes) { 121 const std::string& additional_attributes) {
115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
116 123
117 if (url_fetcher_) 124 if (url_fetcher_)
118 return false; // Another fetch is in progress. 125 return false; // Another fetch is in progress.
119 126
120 url_fetcher_.reset(SendProtocolRequest( 127 url_fetcher_.reset(
121 url_, 128 SendProtocolRequest(url_,
122 BuildUpdateCheckRequest(items_to_check, additional_attributes), 129 BuildUpdateCheckRequest(application_version,
123 this, 130 platform_name,
124 url_request_context_getter_)); 131 items_to_check,
132 additional_attributes),
133 this,
134 url_request_context_getter_));
125 135
126 return true; 136 return true;
127 } 137 }
128 138
129 void UpdateCheckerImpl::OnURLFetchComplete(const net::URLFetcher* source) { 139 void UpdateCheckerImpl::OnURLFetchComplete(const net::URLFetcher* source) {
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
131 DCHECK(url_fetcher_.get() == source); 141 DCHECK(url_fetcher_.get() == source);
132 142
133 int error = 0; 143 int error = 0;
134 std::string error_message; 144 std::string error_message;
(...skipping 11 matching lines...) Expand all
146 error = GetFetchError(*source); 156 error = GetFetchError(*source);
147 error_message.assign("network error"); 157 error_message.assign("network error");
148 VLOG(1) << "Update request failed: network error"; 158 VLOG(1) << "Update request failed: network error";
149 } 159 }
150 160
151 url_fetcher_.reset(); 161 url_fetcher_.reset();
152 update_check_callback_.Run(error, error_message, update_response.results()); 162 update_check_callback_.Run(error, error_message, update_response.results());
153 } 163 }
154 164
155 } // namespace component_updater 165 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698