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_configurator.h" | 5 #include "chrome/browser/component_updater/component_updater_configurator.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/strings/string_util.h" | 14 #include "base/strings/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/browser/component_updater/component_patcher.h" |
17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/omaha_query_params/omaha_query_params.h" | 19 #include "chrome/common/omaha_query_params/omaha_query_params.h" |
19 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
20 | 21 |
| 22 #if defined(OS_WIN) |
| 23 #include "chrome/browser/component_updater/component_patcher_win.h" |
| 24 #endif |
| 25 |
21 namespace { | 26 namespace { |
| 27 |
22 // Default time constants. | 28 // Default time constants. |
23 const int kDelayOneMinute = 60; | 29 const int kDelayOneMinute = 60; |
24 const int kDelayOneHour = kDelayOneMinute * 60; | 30 const int kDelayOneHour = kDelayOneMinute * 60; |
25 | 31 |
26 // Debug values you can pass to --component-updater-debug=value1,value2. | 32 // Debug values you can pass to --component-updater-debug=value1,value2. |
27 // Speed up component checking. | 33 // Speed up component checking. |
28 const char kDebugFastUpdate[] = "fast-update"; | 34 const char kSwitchFastUpdate[] = "fast-update"; |
29 // Force out-of-process-xml parsing. | 35 // Force out-of-process-xml parsing. |
30 const char kDebugOutOfProcess[] = "out-of-process"; | 36 const char kSwitchOutOfProcess[] = "out-of-process"; |
31 // Add "testrequest=1" parameter to the update check query. | 37 // Add "testrequest=1" parameter to the update check query. |
32 const char kDebugRequestParam[] = "test-request"; | 38 const char kSwitchRequestParam[] = "test-request"; |
| 39 // Disables differential updates. |
| 40 const char kSwitchDisableDeltaUpdates[] = "disable-delta-updates"; |
33 | 41 |
34 // The urls from which an update manifest can be fetched. | 42 // The urls from which an update manifest can be fetched. |
35 const char* kUrlSources[] = { | 43 const char* kUrlSources[] = { |
36 "http://clients2.google.com/service/update2/crx", // BANDAID | 44 "http://clients2.google.com/service/update2/crx", // BANDAID |
37 "http://omaha.google.com/service/update2/crx", // CWS_PUBLIC | 45 "http://omaha.google.com/service/update2/crx", // CWS_PUBLIC |
38 "http://omaha.sandbox.google.com/service/update2/crx" // CWS_SANDBOX | 46 "http://omaha.sandbox.google.com/service/update2/crx", // CWS_SANDBOX |
39 }; | 47 }; |
40 | 48 |
41 bool HasDebugValue(const std::vector<std::string>& vec, const char* test) { | 49 bool HasSwitchValue(const std::vector<std::string>& vec, const char* test) { |
42 if (vec.empty()) | 50 if (vec.empty()) |
43 return 0; | 51 return 0; |
44 return (std::find(vec.begin(), vec.end(), test) != vec.end()); | 52 return (std::find(vec.begin(), vec.end(), test) != vec.end()); |
45 } | 53 } |
46 | 54 |
47 } // namespace | 55 } // namespace |
48 | 56 |
49 class ChromeConfigurator : public ComponentUpdateService::Configurator { | 57 class ChromeConfigurator : public ComponentUpdateService::Configurator { |
50 public: | 58 public: |
51 ChromeConfigurator(const CommandLine* cmdline, | 59 ChromeConfigurator(const CommandLine* cmdline, |
52 net::URLRequestContextGetter* url_request_getter); | 60 net::URLRequestContextGetter* url_request_getter); |
53 | 61 |
54 virtual ~ChromeConfigurator() {} | 62 virtual ~ChromeConfigurator() {} |
55 | 63 |
56 virtual int InitialDelay() OVERRIDE; | 64 virtual int InitialDelay() OVERRIDE; |
57 virtual int NextCheckDelay() OVERRIDE; | 65 virtual int NextCheckDelay() OVERRIDE; |
58 virtual int StepDelay() OVERRIDE; | 66 virtual int StepDelay() OVERRIDE; |
59 virtual int MinimumReCheckWait() OVERRIDE; | 67 virtual int MinimumReCheckWait() OVERRIDE; |
60 virtual int OnDemandDelay() OVERRIDE; | 68 virtual int OnDemandDelay() OVERRIDE; |
61 virtual GURL UpdateUrl(CrxComponent::UrlSource source) OVERRIDE; | 69 virtual GURL UpdateUrl(CrxComponent::UrlSource source) OVERRIDE; |
62 virtual const char* ExtraRequestParams() OVERRIDE; | 70 virtual const char* ExtraRequestParams() OVERRIDE; |
63 virtual size_t UrlSizeLimit() OVERRIDE; | 71 virtual size_t UrlSizeLimit() OVERRIDE; |
64 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; | 72 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; |
65 virtual bool InProcess() OVERRIDE; | 73 virtual bool InProcess() OVERRIDE; |
66 virtual void OnEvent(Events event, int val) OVERRIDE; | 74 virtual void OnEvent(Events event, int val) OVERRIDE; |
| 75 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE; |
| 76 virtual bool DeltasEnabled() const OVERRIDE; |
67 | 77 |
68 private: | 78 private: |
69 net::URLRequestContextGetter* url_request_getter_; | 79 net::URLRequestContextGetter* url_request_getter_; |
70 std::string extra_info_; | 80 std::string extra_info_; |
71 bool fast_update_; | 81 bool fast_update_; |
72 bool out_of_process_; | 82 bool out_of_process_; |
| 83 bool deltas_enabled_; |
73 }; | 84 }; |
74 | 85 |
75 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, | 86 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, |
76 net::URLRequestContextGetter* url_request_getter) | 87 net::URLRequestContextGetter* url_request_getter) |
77 : url_request_getter_(url_request_getter), | 88 : url_request_getter_(url_request_getter), |
78 extra_info_(chrome::OmahaQueryParams::Get( | 89 extra_info_(chrome::OmahaQueryParams::Get( |
79 chrome::OmahaQueryParams::CHROME)) { | 90 chrome::OmahaQueryParams::CHROME)), |
| 91 fast_update_(false), |
| 92 out_of_process_(false), |
| 93 deltas_enabled_(false) { |
80 // Parse comma-delimited debug flags. | 94 // Parse comma-delimited debug flags. |
81 std::vector<std::string> debug_values; | 95 std::vector<std::string> switch_values; |
82 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdaterDebug), | 96 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater), |
83 ",", &debug_values); | 97 ",", &switch_values); |
84 fast_update_ = HasDebugValue(debug_values, kDebugFastUpdate); | 98 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate); |
85 out_of_process_ = HasDebugValue(debug_values, kDebugOutOfProcess); | 99 out_of_process_ = HasSwitchValue(switch_values, kSwitchOutOfProcess); |
| 100 #if defined(OS_WIN) |
| 101 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); |
| 102 #else |
| 103 deltas_enabled_ = false; |
| 104 #endif |
86 | 105 |
87 // Make the extra request params, they are necessary so omaha does | 106 // Make the extra request params, they are necessary so omaha does |
88 // not deliver components that are going to be rejected at install time. | 107 // not deliver components that are going to be rejected at install time. |
89 #if defined(OS_WIN) | 108 #if defined(OS_WIN) |
90 if (base::win::OSInfo::GetInstance()->wow64_status() == | 109 if (base::win::OSInfo::GetInstance()->wow64_status() == |
91 base::win::OSInfo::WOW64_ENABLED) | 110 base::win::OSInfo::WOW64_ENABLED) |
92 extra_info_ += "&wow64=1"; | 111 extra_info_ += "&wow64=1"; |
93 #endif | 112 #endif |
94 if (HasDebugValue(debug_values, kDebugRequestParam)) | 113 if (HasSwitchValue(switch_values, kSwitchRequestParam)) |
95 extra_info_ += "&testrequest=1"; | 114 extra_info_ += "&testrequest=1"; |
96 } | 115 } |
97 | 116 |
98 int ChromeConfigurator::InitialDelay() { | 117 int ChromeConfigurator::InitialDelay() { |
99 return fast_update_ ? 1 : (6 * kDelayOneMinute); | 118 return fast_update_ ? 1 : (6 * kDelayOneMinute); |
100 } | 119 } |
101 | 120 |
102 int ChromeConfigurator::NextCheckDelay() { | 121 int ChromeConfigurator::NextCheckDelay() { |
103 return fast_update_ ? 3 : (2 * kDelayOneHour); | 122 return fast_update_ ? 3 : (2 * kDelayOneHour); |
104 } | 123 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 break; | 173 break; |
155 case kInstallerError: | 174 case kInstallerError: |
156 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.InstallError", val, 100); | 175 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.InstallError", val, 100); |
157 break; | 176 break; |
158 default: | 177 default: |
159 NOTREACHED(); | 178 NOTREACHED(); |
160 break; | 179 break; |
161 } | 180 } |
162 } | 181 } |
163 | 182 |
| 183 ComponentPatcher* ChromeConfigurator::CreateComponentPatcher() { |
| 184 #if defined(OS_WIN) |
| 185 return new ComponentPatcherWin(); |
| 186 #else |
| 187 return new ComponentPatcherCrossPlatform(); |
| 188 #endif |
| 189 } |
| 190 |
| 191 bool ChromeConfigurator::DeltasEnabled() const { |
| 192 return deltas_enabled_; |
| 193 } |
| 194 |
164 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( | 195 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( |
165 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { | 196 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { |
166 return new ChromeConfigurator(cmdline, context_getter); | 197 return new ChromeConfigurator(cmdline, context_getter); |
167 } | 198 } |
OLD | NEW |