1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/component_updater/component_updater_service.h"
#include <algorithm>
#include <string>
#include <vector>
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/string_util.h"
#include "chrome/common/chrome_switches.h"
#include "net/url_request/url_request_context_getter.h"
namespace {
// Default time constants.
const int kDelayOneMinute = 60;
const int kDelayOneHour = kDelayOneMinute * 60;
// Debug values you can pass to --component-updater-debug=<value>.
const char kDebugFastUpdate[] = "fast-update";
const char kDebugOutOfProcess[] = "out-of-process";
bool HasDebugValue(const std::vector<std::string>& vec, const char* test) {
if (vec.empty())
return 0;
return (std::find(vec.begin(), vec.end(), test) != vec.end());
}
} // namespace
class ChromeConfigurator : public ComponentUpdateService::Configurator {
public:
ChromeConfigurator(const CommandLine* cmdline,
net::URLRequestContextGetter* url_request_getter);
virtual ~ChromeConfigurator() {}
virtual int InitialDelay() OVERRIDE;
virtual int NextCheckDelay() OVERRIDE;
virtual int StepDelay() OVERRIDE;
virtual int MinimumReCheckWait() OVERRIDE;
virtual GURL UpdateUrl() OVERRIDE;
virtual size_t UrlSizeLimit() OVERRIDE;
virtual net::URLRequestContextGetter* RequestContext() OVERRIDE;
virtual bool InProcess() OVERRIDE;
private:
net::URLRequestContextGetter* url_request_getter_;
bool fast_update_;
bool out_of_process_;
};
ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline,
net::URLRequestContextGetter* url_request_getter)
: url_request_getter_(url_request_getter) {
// Parse comma-delimited debug flags.
std::vector<std::string> debug_values;
Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdaterDebug),
",", &debug_values);
fast_update_ = HasDebugValue(debug_values, kDebugFastUpdate);
out_of_process_ = HasDebugValue(debug_values, kDebugOutOfProcess);
}
int ChromeConfigurator::InitialDelay() {
return fast_update_ ? 1 : (6 * kDelayOneMinute);
}
int ChromeConfigurator::NextCheckDelay() {
return fast_update_ ? 3 : (4 * kDelayOneHour);
}
int ChromeConfigurator::StepDelay() {
return fast_update_ ? 1 : 4;
}
int ChromeConfigurator::MinimumReCheckWait() {
return fast_update_ ? 30 : (6 * kDelayOneHour);
}
GURL ChromeConfigurator::UpdateUrl() {
return GURL("http://clients2.google.com/service/update2/crx");
}
size_t ChromeConfigurator::UrlSizeLimit() {
return 1024ul;
}
net::URLRequestContextGetter* ChromeConfigurator::RequestContext() {
return url_request_getter_;
}
bool ChromeConfigurator::InProcess() {
return !out_of_process_;
}
ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator(
const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) {
return new ChromeConfigurator(cmdline, context_getter);
}
|