Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: chrome/browser/component_updater/component_updater_configurator.cc

Issue 15908002: Differential updates for components. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: really removing the lzma files this time. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 kDebugFastUpdate[] = "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 kDebugOutOfProcess[] = "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 kDebugRequestParam[] = "test-request";
33 39
34 // The urls from which an update manifest can be fetched. 40 // The urls from which an update manifest can be fetched.
35 const char* kUrlSources[] = { 41 const char* kUrlSources[] = {
36 "http://clients2.google.com/service/update2/crx", // BANDAID 42 "http://clients2.google.com/service/update2/crx", // BANDAID
37 "http://omaha.google.com/service/update2/crx", // CWS_PUBLIC 43 "http://omaha.google.com/service/update2/crx", // CWS_PUBLIC
38 "http://omaha.sandbox.google.com/service/update2/crx" // CWS_SANDBOX 44 "http://omaha.sandbox.google.com/service/update2/crx", // CWS_SANDBOX
39 }; 45 };
40 46
47 // The url to send the completion pings to. Completion pings are sent when
48 // updates have completed, either successfully or with errors.
49 const char kUrlPing[] = "http://tools.google.com/service/update2";
50
41 bool HasDebugValue(const std::vector<std::string>& vec, const char* test) { 51 bool HasDebugValue(const std::vector<std::string>& vec, const char* test) {
42 if (vec.empty()) 52 if (vec.empty())
43 return 0; 53 return 0;
44 return (std::find(vec.begin(), vec.end(), test) != vec.end()); 54 return (std::find(vec.begin(), vec.end(), test) != vec.end());
45 } 55 }
46 56
47 } // namespace 57 } // namespace
48 58
49 class ChromeConfigurator : public ComponentUpdateService::Configurator { 59 class ChromeConfigurator : public ComponentUpdateService::Configurator {
50 public: 60 public:
51 ChromeConfigurator(const CommandLine* cmdline, 61 ChromeConfigurator(const CommandLine* cmdline,
52 net::URLRequestContextGetter* url_request_getter); 62 net::URLRequestContextGetter* url_request_getter);
53 63
54 virtual ~ChromeConfigurator() {} 64 virtual ~ChromeConfigurator() {}
55 65
56 virtual int InitialDelay() OVERRIDE; 66 virtual int InitialDelay() OVERRIDE;
57 virtual int NextCheckDelay() OVERRIDE; 67 virtual int NextCheckDelay() OVERRIDE;
58 virtual int StepDelay() OVERRIDE; 68 virtual int StepDelay() OVERRIDE;
59 virtual int MinimumReCheckWait() OVERRIDE; 69 virtual int MinimumReCheckWait() OVERRIDE;
60 virtual int OnDemandDelay() OVERRIDE; 70 virtual int OnDemandDelay() OVERRIDE;
61 virtual GURL UpdateUrl(CrxComponent::UrlSource source) OVERRIDE; 71 virtual GURL UpdateUrl(CrxComponent::UrlSource source) OVERRIDE;
72 virtual GURL PingUrl() OVERRIDE;
62 virtual const char* ExtraRequestParams() OVERRIDE; 73 virtual const char* ExtraRequestParams() OVERRIDE;
63 virtual size_t UrlSizeLimit() OVERRIDE; 74 virtual size_t UrlSizeLimit() OVERRIDE;
64 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; 75 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE;
65 virtual bool InProcess() OVERRIDE; 76 virtual bool InProcess() OVERRIDE;
66 virtual void OnEvent(Events event, int val) OVERRIDE; 77 virtual void OnEvent(Events event, int val) OVERRIDE;
78 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE;
79 virtual bool PingsEnabled() const OVERRIDE;
cpu_(ooo_6.6-7.5) 2013/06/17 20:27:01 I feel we have duplicated state here, I propose th
waffles 2013/06/17 23:51:07 Done.
80 virtual bool DeltasEnabled() const OVERRIDE;
67 81
68 private: 82 private:
69 net::URLRequestContextGetter* url_request_getter_; 83 net::URLRequestContextGetter* url_request_getter_;
70 std::string extra_info_; 84 std::string extra_info_;
71 bool fast_update_; 85 bool fast_update_;
72 bool out_of_process_; 86 bool out_of_process_;
87 bool pings_enabled_;
88 bool deltas_enabled_;
73 }; 89 };
74 90
75 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, 91 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline,
76 net::URLRequestContextGetter* url_request_getter) 92 net::URLRequestContextGetter* url_request_getter)
77 : url_request_getter_(url_request_getter), 93 : url_request_getter_(url_request_getter),
78 extra_info_(chrome::OmahaQueryParams::Get( 94 extra_info_(chrome::OmahaQueryParams::Get(
79 chrome::OmahaQueryParams::CHROME)) { 95 chrome::OmahaQueryParams::CHROME)),
96 pings_enabled_(false),
robertshield 2013/06/17 17:47:00 don't need these in the initializer list if they a
Sorin Jianu 2013/06/17 22:21:09 We prefer to initialize any member in all cases ev
robertshield 2013/06/18 13:27:07 Sounds good. In that case, please initialize fast_
Sorin Jianu 2013/06/18 17:00:11 Done.
97 deltas_enabled_(false) {
80 // Parse comma-delimited debug flags. 98 // Parse comma-delimited debug flags.
81 std::vector<std::string> debug_values; 99 std::vector<std::string> debug_values;
82 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdaterDebug), 100 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdaterDebug),
83 ",", &debug_values); 101 ",", &debug_values);
84 fast_update_ = HasDebugValue(debug_values, kDebugFastUpdate); 102 fast_update_ = HasDebugValue(debug_values, kDebugFastUpdate);
85 out_of_process_ = HasDebugValue(debug_values, kDebugOutOfProcess); 103 out_of_process_ = HasDebugValue(debug_values, kDebugOutOfProcess);
86 104
105 // Parse other command-ling flags.
106 pings_enabled_ = cmdline->HasSwitch(switches::kEnableComponentUpdatePings);
107 #if defined(OS_WIN)
108 deltas_enabled_ = cmdline->HasSwitch(switches::kEnableComponentUpdateDeltas);
cpu_(ooo_6.6-7.5) 2013/06/17 20:27:01 if deltas enabled are an option, it does not seem
Sorin Jianu 2013/06/17 22:21:09 People could turn on deltas on platforms that we d
109 #else
110 deltas_enabled_ = false;
111 #endif
112
87 // Make the extra request params, they are necessary so omaha does 113 // Make the extra request params, they are necessary so omaha does
88 // not deliver components that are going to be rejected at install time. 114 // not deliver components that are going to be rejected at install time.
89 #if defined(OS_WIN) 115 #if defined(OS_WIN)
90 if (base::win::OSInfo::GetInstance()->wow64_status() == 116 if (base::win::OSInfo::GetInstance()->wow64_status() ==
91 base::win::OSInfo::WOW64_ENABLED) 117 base::win::OSInfo::WOW64_ENABLED)
92 extra_info_ += "&wow64=1"; 118 extra_info_ += "&wow64=1";
93 #endif 119 #endif
94 if (HasDebugValue(debug_values, kDebugRequestParam)) 120 if (HasDebugValue(debug_values, kDebugRequestParam))
95 extra_info_ += "&testrequest=1"; 121 extra_info_ += "&testrequest=1";
96 } 122 }
(...skipping 15 matching lines...) Expand all
112 } 138 }
113 139
114 int ChromeConfigurator::OnDemandDelay() { 140 int ChromeConfigurator::OnDemandDelay() {
115 return fast_update_ ? 2 : (30 * kDelayOneMinute); 141 return fast_update_ ? 2 : (30 * kDelayOneMinute);
116 } 142 }
117 143
118 GURL ChromeConfigurator::UpdateUrl(CrxComponent::UrlSource source) { 144 GURL ChromeConfigurator::UpdateUrl(CrxComponent::UrlSource source) {
119 return GURL(kUrlSources[source]); 145 return GURL(kUrlSources[source]);
120 } 146 }
121 147
148 GURL ChromeConfigurator::PingUrl() {
149 return GURL(kUrlPing);
150 }
151
122 const char* ChromeConfigurator::ExtraRequestParams() { 152 const char* ChromeConfigurator::ExtraRequestParams() {
123 return extra_info_.c_str(); 153 return extra_info_.c_str();
124 } 154 }
125 155
126 size_t ChromeConfigurator::UrlSizeLimit() { 156 size_t ChromeConfigurator::UrlSizeLimit() {
127 return 1024ul; 157 return 1024ul;
128 } 158 }
129 159
130 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() { 160 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() {
131 return url_request_getter_; 161 return url_request_getter_;
(...skipping 22 matching lines...) Expand all
154 break; 184 break;
155 case kInstallerError: 185 case kInstallerError:
156 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.InstallError", val, 100); 186 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.InstallError", val, 100);
157 break; 187 break;
158 default: 188 default:
159 NOTREACHED(); 189 NOTREACHED();
160 break; 190 break;
161 } 191 }
162 } 192 }
163 193
194 ComponentPatcher* ChromeConfigurator::CreateComponentPatcher() {
195 #if defined(OS_WIN)
196 return new ComponentPatcherWin();
cpu_(ooo_6.6-7.5) 2013/06/17 20:27:01 this DI is nice but I do wonder if the configurato
Sorin Jianu 2013/06/17 22:21:09 Right on, I needed this primarily for DI and this
197 #else
198 return new ComponentPatcherCrossPlatform();
199 #endif
200 }
201
202 bool ChromeConfigurator::DeltasEnabled() const {
203 return deltas_enabled_;
204 }
205
206 bool ChromeConfigurator::PingsEnabled() const {
207 return pings_enabled_;
208 }
209
164 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( 210 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator(
165 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { 211 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) {
166 return new ChromeConfigurator(cmdline, context_getter); 212 return new ChromeConfigurator(cmdline, context_getter);
167 } 213 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698