OLD | NEW |
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 Loading... |
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.GetBrowserVersion().GetString(), |
| 64 config.GetChannel(), |
| 65 config.GetLang(), |
| 66 config.GetOSLongName(), |
| 67 app_elements, |
| 68 additional_attributes); |
63 } | 69 } |
64 | 70 |
65 class UpdateCheckerImpl : public UpdateChecker, public net::URLFetcherDelegate { | 71 class UpdateCheckerImpl : public UpdateChecker, public net::URLFetcherDelegate { |
66 public: | 72 public: |
67 UpdateCheckerImpl(const Configurator& config, | 73 UpdateCheckerImpl(const Configurator& config, |
68 const UpdateCheckCallback& update_check_callback); | 74 const UpdateCheckCallback& update_check_callback); |
69 virtual ~UpdateCheckerImpl(); | 75 virtual ~UpdateCheckerImpl(); |
70 | 76 |
71 // Overrides for UpdateChecker. | 77 // Overrides for UpdateChecker. |
72 virtual bool CheckForUpdates( | 78 virtual bool CheckForUpdates( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 bool UpdateCheckerImpl::CheckForUpdates( | 113 bool UpdateCheckerImpl::CheckForUpdates( |
108 const std::vector<CrxUpdateItem*>& items_to_check, | 114 const std::vector<CrxUpdateItem*>& items_to_check, |
109 const std::string& additional_attributes) { | 115 const std::string& additional_attributes) { |
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
111 | 117 |
112 if (url_fetcher_) | 118 if (url_fetcher_) |
113 return false; // Another fetch is in progress. | 119 return false; // Another fetch is in progress. |
114 | 120 |
115 url_fetcher_.reset(SendProtocolRequest( | 121 url_fetcher_.reset(SendProtocolRequest( |
116 config_.UpdateUrl(), | 122 config_.UpdateUrl(), |
117 BuildUpdateCheckRequest(items_to_check, additional_attributes), | 123 BuildUpdateCheckRequest(config_, items_to_check, additional_attributes), |
118 this, | 124 this, |
119 config_.RequestContext())); | 125 config_.RequestContext())); |
120 | 126 |
121 return true; | 127 return true; |
122 } | 128 } |
123 | 129 |
124 void UpdateCheckerImpl::OnURLFetchComplete(const net::URLFetcher* source) { | 130 void UpdateCheckerImpl::OnURLFetchComplete(const net::URLFetcher* source) { |
125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
126 DCHECK(url_fetcher_.get() == source); | 132 DCHECK(url_fetcher_.get() == source); |
127 | 133 |
(...skipping 13 matching lines...) Expand all Loading... |
141 error = GetFetchError(*source); | 147 error = GetFetchError(*source); |
142 error_message.assign("network error"); | 148 error_message.assign("network error"); |
143 VLOG(1) << "Update request failed: network error"; | 149 VLOG(1) << "Update request failed: network error"; |
144 } | 150 } |
145 | 151 |
146 url_fetcher_.reset(); | 152 url_fetcher_.reset(); |
147 update_check_callback_.Run(error, error_message, update_response.results()); | 153 update_check_callback_.Run(error, error_message, update_response.results()); |
148 } | 154 } |
149 | 155 |
150 } // namespace component_updater | 156 } // namespace component_updater |
OLD | NEW |