OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/component_updater_service.h" | 5 #include "chrome/browser/component_updater/component_updater_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/win/windows_version.h" | 15 #include "base/win/windows_version.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/chrome_version_info.h" | 18 #include "chrome/common/omaha_query_params.h" |
19 #include "net/url_request/url_request_context_getter.h" | 19 #include "net/url_request/url_request_context_getter.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 // Default time constants. | 22 // Default time constants. |
23 const int kDelayOneMinute = 60; | 23 const int kDelayOneMinute = 60; |
24 const int kDelayOneHour = kDelayOneMinute * 60; | 24 const int kDelayOneHour = kDelayOneMinute * 60; |
25 | 25 |
26 // Debug values you can pass to --component-updater-debug=value1,value2. | 26 // Debug values you can pass to --component-updater-debug=value1,value2. |
27 // Speed up component checking. | 27 // Speed up component checking. |
28 const char kDebugFastUpdate[] = "fast-update"; | 28 const char kDebugFastUpdate[] = "fast-update"; |
29 // Force out-of-process-xml parsing. | 29 // Force out-of-process-xml parsing. |
30 const char kDebugOutOfProcess[] = "out-of-process"; | 30 const char kDebugOutOfProcess[] = "out-of-process"; |
31 // Add "testrequest=1" parameter to the update check query. | 31 // Add "testrequest=1" parameter to the update check query. |
32 const char kDebugRequestParam[] = "test-request"; | 32 const char kDebugRequestParam[] = "test-request"; |
33 | 33 |
34 // The urls from which an update manifest can be fetched. | 34 // The urls from which an update manifest can be fetched. |
35 const char* kUrlSources[] = { | 35 const char* kUrlSources[] = { |
36 "http://clients2.google.com/service/update2/crx", // BANDAID | 36 "http://clients2.google.com/service/update2/crx", // BANDAID |
37 "http://omaha.google.com/service/update2/crx", // CWS_PUBLIC | 37 "http://omaha.google.com/service/update2/crx", // CWS_PUBLIC |
38 "http://omaha.sandbox.google.com/service/update2/crx" // CWS_SANDBOX | 38 "http://omaha.sandbox.google.com/service/update2/crx" // CWS_SANDBOX |
39 }; | 39 }; |
40 | 40 |
41 bool HasDebugValue(const std::vector<std::string>& vec, const char* test) { | 41 bool HasDebugValue(const std::vector<std::string>& vec, const char* test) { |
42 if (vec.empty()) | 42 if (vec.empty()) |
43 return 0; | 43 return 0; |
44 return (std::find(vec.begin(), vec.end(), test) != vec.end()); | 44 return (std::find(vec.begin(), vec.end(), test) != vec.end()); |
45 } | 45 } |
46 | 46 |
47 // The request extra information is the OS and architecture, this helps | |
48 // the server select the right package to be delivered. | |
49 const char kExtraInfo[] = | |
50 #if defined(OS_MACOSX) | |
51 #if defined(__amd64__) | |
52 "os=mac&arch=x64&prod=chrome&prodversion="; | |
53 #elif defined(__i386__) | |
54 "os=mac&arch=x86&prod=chrome&prodversion="; | |
55 #else | |
56 #error "unknown mac architecture" | |
57 #endif | |
58 #elif defined(OS_WIN) | |
59 #if defined(_WIN64) | |
60 "os=win&arch=x64&prod=chrome&prodversion="; | |
61 #elif defined(_WIN32) | |
62 "os=win&arch=x86&prod=chrome&prodversion="; | |
63 #else | |
64 #error "unknown windows architecture" | |
65 #endif | |
66 #elif defined(OS_ANDROID) | |
67 #if defined(__i386__) | |
68 "os=android&arch=x86&prod=chrome&prodversion="; | |
69 #elif defined(__arm__) | |
70 "os=android&arch=arm&prod=chrome&prodversion="; | |
71 #else | |
72 "os=android&arch=unknown&prod=chrome&prodversion="; | |
73 #endif | |
74 #elif defined(OS_CHROMEOS) | |
75 #if defined(__i386__) | |
76 "os=cros&arch=x86&prod=chrome&prodversion="; | |
77 #elif defined(__arm__) | |
78 "os=cros&arch=arm&prod=chrome&prodversion="; | |
79 #else | |
80 "os=cros&arch=unknown&prod=chrome&prodversion="; | |
81 #endif | |
82 #elif defined(OS_LINUX) | |
83 #if defined(__amd64__) | |
84 "os=linux&arch=x64&prod=chrome&prodversion="; | |
85 #elif defined(__i386__) | |
86 "os=linux&arch=x86&prod=chrome&prodversion="; | |
87 #elif defined(__arm__) | |
88 "os=linux&arch=arm&prod=chrome&prodversion="; | |
89 #else | |
90 "os=linux&arch=unknown&prod=chrome&prodversion="; | |
91 #endif | |
92 #elif defined(OS_OPENBSD) | |
93 #if defined(__amd64__) | |
94 "os=openbsd&arch=x64"; | |
95 #elif defined(__i386__) | |
96 "os=openbsd&arch=x86"; | |
97 #else | |
98 "os=openbsd&arch=unknown"; | |
99 #endif | |
100 #else | |
101 #error "unknown os or architecture" | |
102 #endif | |
103 | |
104 } // namespace | 47 } // namespace |
105 | 48 |
106 class ChromeConfigurator : public ComponentUpdateService::Configurator { | 49 class ChromeConfigurator : public ComponentUpdateService::Configurator { |
107 public: | 50 public: |
108 ChromeConfigurator(const CommandLine* cmdline, | 51 ChromeConfigurator(const CommandLine* cmdline, |
109 net::URLRequestContextGetter* url_request_getter); | 52 net::URLRequestContextGetter* url_request_getter); |
110 | 53 |
111 virtual ~ChromeConfigurator() {} | 54 virtual ~ChromeConfigurator() {} |
112 | 55 |
113 virtual int InitialDelay() OVERRIDE; | 56 virtual int InitialDelay() OVERRIDE; |
(...skipping 11 matching lines...) Expand all Loading... |
125 private: | 68 private: |
126 net::URLRequestContextGetter* url_request_getter_; | 69 net::URLRequestContextGetter* url_request_getter_; |
127 std::string extra_info_; | 70 std::string extra_info_; |
128 bool fast_update_; | 71 bool fast_update_; |
129 bool out_of_process_; | 72 bool out_of_process_; |
130 }; | 73 }; |
131 | 74 |
132 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, | 75 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, |
133 net::URLRequestContextGetter* url_request_getter) | 76 net::URLRequestContextGetter* url_request_getter) |
134 : url_request_getter_(url_request_getter), | 77 : url_request_getter_(url_request_getter), |
135 extra_info_(kExtraInfo) { | 78 extra_info_(chrome::OmahaQueryParams::Get( |
| 79 chrome::OmahaQueryParams::CHROME)) { |
136 // Parse comma-delimited debug flags. | 80 // Parse comma-delimited debug flags. |
137 std::vector<std::string> debug_values; | 81 std::vector<std::string> debug_values; |
138 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdaterDebug), | 82 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdaterDebug), |
139 ",", &debug_values); | 83 ",", &debug_values); |
140 fast_update_ = HasDebugValue(debug_values, kDebugFastUpdate); | 84 fast_update_ = HasDebugValue(debug_values, kDebugFastUpdate); |
141 out_of_process_ = HasDebugValue(debug_values, kDebugOutOfProcess); | 85 out_of_process_ = HasDebugValue(debug_values, kDebugOutOfProcess); |
142 | 86 |
143 // Make the extra request params, they are necessary so omaha does | 87 // Make the extra request params, they are necessary so omaha does |
144 // not deliver components that are going to be rejected at install time. | 88 // not deliver components that are going to be rejected at install time. |
145 extra_info_ += chrome::VersionInfo().Version(); | |
146 #if defined(OS_WIN) | 89 #if defined(OS_WIN) |
147 if (base::win::OSInfo::GetInstance()->wow64_status() == | 90 if (base::win::OSInfo::GetInstance()->wow64_status() == |
148 base::win::OSInfo::WOW64_ENABLED) | 91 base::win::OSInfo::WOW64_ENABLED) |
149 extra_info_ += "&wow64=1"; | 92 extra_info_ += "&wow64=1"; |
150 #endif | 93 #endif |
151 if (HasDebugValue(debug_values, kDebugRequestParam)) | 94 if (HasDebugValue(debug_values, kDebugRequestParam)) |
152 extra_info_ += "&testrequest=1"; | 95 extra_info_ += "&testrequest=1"; |
153 } | 96 } |
154 | 97 |
155 int ChromeConfigurator::InitialDelay() { | 98 int ChromeConfigurator::InitialDelay() { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 default: | 158 default: |
216 NOTREACHED(); | 159 NOTREACHED(); |
217 break; | 160 break; |
218 } | 161 } |
219 } | 162 } |
220 | 163 |
221 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( | 164 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( |
222 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { | 165 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { |
223 return new ChromeConfigurator(cmdline, context_getter); | 166 return new ChromeConfigurator(cmdline, context_getter); |
224 } | 167 } |
OLD | NEW |