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_utils.h" | 10 #include "chrome/browser/component_updater/component_updater_utils.h" |
(...skipping 14 matching lines...) Expand all Loading... |
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& chrome_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(chrome_version, platform_name, app_elements, |
| 64 additional_attributes); |
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& chrome_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 Loading... |
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& chrome_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(SendProtocolRequest( |
121 url_, | 128 url_, |
122 BuildUpdateCheckRequest(items_to_check, additional_attributes), | 129 BuildUpdateCheckRequest(chrome_version, platform_name, items_to_check, |
| 130 additional_attributes), |
123 this, | 131 this, |
124 url_request_context_getter_)); | 132 url_request_context_getter_)); |
125 | 133 |
126 return true; | 134 return true; |
127 } | 135 } |
128 | 136 |
129 void UpdateCheckerImpl::OnURLFetchComplete(const net::URLFetcher* source) { | 137 void UpdateCheckerImpl::OnURLFetchComplete(const net::URLFetcher* source) { |
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
131 DCHECK(url_fetcher_.get() == source); | 139 DCHECK(url_fetcher_.get() == source); |
132 | 140 |
(...skipping 13 matching lines...) Expand all Loading... |
146 error = GetFetchError(*source); | 154 error = GetFetchError(*source); |
147 error_message.assign("network error"); | 155 error_message.assign("network error"); |
148 VLOG(1) << "Update request failed: network error"; | 156 VLOG(1) << "Update request failed: network error"; |
149 } | 157 } |
150 | 158 |
151 url_fetcher_.reset(); | 159 url_fetcher_.reset(); |
152 update_check_callback_.Run(error, error_message, update_response.results()); | 160 update_check_callback_.Run(error, error_message, update_response.results()); |
153 } | 161 } |
154 | 162 |
155 } // namespace component_updater | 163 } // namespace component_updater |
OLD | NEW |