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 "components/component_updater/update_checker.h" | 5 #include "components/update_client/update_checker.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
19 #include "components/component_updater/component_updater_configurator.h" | 19 #include "components/update_client/configurator.h" |
20 #include "components/component_updater/component_updater_utils.h" | 20 #include "components/update_client/crx_update_item.h" |
21 #include "components/component_updater/crx_update_item.h" | 21 #include "components/update_client/request_sender.h" |
22 #include "components/component_updater/request_sender.h" | 22 #include "components/update_client/utils.h" |
23 #include "net/url_request/url_fetcher.h" | 23 #include "net/url_request/url_fetcher.h" |
24 #include "url/gurl.h" | 24 #include "url/gurl.h" |
25 | 25 |
26 namespace component_updater { | 26 namespace update_client { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 // Builds an update check request for |components|. |additional_attributes| is | 30 // Builds an update check request for |components|. |additional_attributes| is |
31 // serialized as part of the <request> element of the request to customize it | 31 // serialized as part of the <request> element of the request to customize it |
32 // with data that is not platform or component specific. For each |item|, a | 32 // with data that is not platform or component specific. For each |item|, a |
33 // corresponding <app> element is created and inserted as a child node of | 33 // corresponding <app> element is created and inserted as a child node of |
34 // the <request>. | 34 // the <request>. |
35 // | 35 // |
36 // An app element looks like this: | 36 // An app element looks like this: |
37 // <app appid="hnimpnehoodheedghdeeijklkeaacbdc" | 37 // <app appid="hnimpnehoodheedghdeeijklkeaacbdc" |
38 // version="0.1.2.3" installsource="ondemand"> | 38 // version="0.1.2.3" installsource="ondemand"> |
39 // <updatecheck /> | 39 // <updatecheck /> |
40 // <packages> | 40 // <packages> |
41 // <package fp="abcd" /> | 41 // <package fp="abcd" /> |
42 // </packages> | 42 // </packages> |
43 // </app> | 43 // </app> |
44 std::string BuildUpdateCheckRequest(const Configurator& config, | 44 std::string BuildUpdateCheckRequest(const Configurator& config, |
45 const std::vector<CrxUpdateItem*>& items, | 45 const std::vector<CrxUpdateItem*>& items, |
46 const std::string& additional_attributes) { | 46 const std::string& additional_attributes) { |
47 std::string app_elements; | 47 std::string app_elements; |
48 for (size_t i = 0; i != items.size(); ++i) { | 48 for (size_t i = 0; i != items.size(); ++i) { |
49 const CrxUpdateItem* item = items[i]; | 49 const CrxUpdateItem* item = items[i]; |
50 std::string app("<app "); | 50 std::string app("<app "); |
51 base::StringAppendF(&app, | 51 base::StringAppendF(&app, "appid=\"%s\" version=\"%s\"", item->id.c_str(), |
52 "appid=\"%s\" version=\"%s\"", | |
53 item->id.c_str(), | |
54 item->component.version.GetString().c_str()); | 52 item->component.version.GetString().c_str()); |
55 if (item->on_demand) | 53 if (item->on_demand) |
56 base::StringAppendF(&app, " installsource=\"ondemand\""); | 54 base::StringAppendF(&app, " installsource=\"ondemand\""); |
57 base::StringAppendF(&app, ">"); | 55 base::StringAppendF(&app, ">"); |
58 base::StringAppendF(&app, "<updatecheck />"); | 56 base::StringAppendF(&app, "<updatecheck />"); |
59 if (!item->component.fingerprint.empty()) { | 57 if (!item->component.fingerprint.empty()) { |
60 base::StringAppendF(&app, | 58 base::StringAppendF(&app, |
61 "<packages>" | 59 "<packages>" |
62 "<package fp=\"%s\"/>" | 60 "<package fp=\"%s\"/>" |
63 "</packages>", | 61 "</packages>", |
64 item->component.fingerprint.c_str()); | 62 item->component.fingerprint.c_str()); |
65 } | 63 } |
66 base::StringAppendF(&app, "</app>"); | 64 base::StringAppendF(&app, "</app>"); |
67 app_elements.append(app); | 65 app_elements.append(app); |
68 VLOG(1) << "Appending to update request: " << app; | 66 VLOG(1) << "Appending to update request: " << app; |
69 } | 67 } |
70 | 68 |
71 return BuildProtocolRequest(config.GetBrowserVersion().GetString(), | 69 return BuildProtocolRequest(config.GetBrowserVersion().GetString(), |
72 config.GetChannel(), | 70 config.GetChannel(), config.GetLang(), |
73 config.GetLang(), | 71 config.GetOSLongName(), app_elements, |
74 config.GetOSLongName(), | |
75 app_elements, | |
76 additional_attributes); | 72 additional_attributes); |
77 } | 73 } |
78 | 74 |
79 class UpdateCheckerImpl : public UpdateChecker { | 75 class UpdateCheckerImpl : public UpdateChecker { |
80 public: | 76 public: |
81 explicit UpdateCheckerImpl(const Configurator& config); | 77 explicit UpdateCheckerImpl(const Configurator& config); |
82 ~UpdateCheckerImpl() override; | 78 ~UpdateCheckerImpl() override; |
83 | 79 |
84 // Overrides for UpdateChecker. | 80 // Overrides for UpdateChecker. |
85 bool CheckForUpdates( | 81 bool CheckForUpdates( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 error_message = update_response.errors(); | 143 error_message = update_response.errors(); |
148 VLOG(1) << "Update request failed: " << error_message; | 144 VLOG(1) << "Update request failed: " << error_message; |
149 } | 145 } |
150 } else { | 146 } else { |
151 error = GetFetchError(*source); | 147 error = GetFetchError(*source); |
152 error_message.assign("network error"); | 148 error_message.assign("network error"); |
153 VLOG(1) << "Update request failed: network error"; | 149 VLOG(1) << "Update request failed: network error"; |
154 } | 150 } |
155 | 151 |
156 request_sender_.reset(); | 152 request_sender_.reset(); |
157 update_check_callback_.Run( | 153 update_check_callback_.Run(original_url, error, error_message, |
158 original_url, error, error_message, update_response.results()); | 154 update_response.results()); |
159 } | 155 } |
160 | 156 |
161 } // namespace | 157 } // namespace |
162 | 158 |
163 scoped_ptr<UpdateChecker> UpdateChecker::Create(const Configurator& config) { | 159 scoped_ptr<UpdateChecker> UpdateChecker::Create(const Configurator& config) { |
164 return scoped_ptr<UpdateChecker>(new UpdateCheckerImpl(config)); | 160 return scoped_ptr<UpdateChecker>(new UpdateCheckerImpl(config)); |
165 } | 161 } |
166 | 162 |
167 } // namespace component_updater | 163 } // namespace update_client |
OLD | NEW |