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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
// Copyright (c) 2010 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/installer/util/channel_info.h"
#include "base/logging.h"
#include "base/win/registry.h"
#include "chrome/installer/util/google_update_constants.h"
using base::win::RegKey;
namespace {
const wchar_t kChannelBeta[] = L"beta";
const wchar_t kChannelDev[] = L"dev";
const wchar_t kModCeee[] = L"-CEEE";
const wchar_t kModFullInstall[] = L"-full";
const wchar_t kModMultiInstall[] = L"-multi";
const wchar_t* const kChannels[] = {
kChannelBeta,
kChannelDev
};
const wchar_t* const kModifiers[] = {
kModCeee,
kModFullInstall,
kModMultiInstall
};
} // namespace
namespace installer_util {
// static
bool ChannelInfo::HasModifier(const wchar_t* modifier,
const std::wstring& ap_value) {
DCHECK(modifier);
return ap_value.find(modifier) != std::wstring::npos;
}
// Returns true if |ap_value| is modified.
// static
bool ChannelInfo::SetModifier(const wchar_t* modifier,
bool set,
std::wstring* ap_value) {
DCHECK(modifier);
DCHECK(ap_value);
std::wstring::size_type position = ap_value->find(modifier);
if (set) {
if (position == std::wstring::npos) {
ap_value->append(modifier);
return true;
}
} else {
if (position != std::wstring::npos) {
ap_value->erase(position, std::wstring::traits_type::length(modifier));
return true;
}
}
return false;
}
bool ChannelInfo::Initialize(const RegKey& key) {
return key.ReadValue(google_update::kRegApField, &value_);
}
bool ChannelInfo::Write(RegKey* key) const {
return key->WriteValue(google_update::kRegApField, value_.c_str());
}
bool ChannelInfo::GetChannelName(std::wstring* channel_name) const {
DCHECK(channel_name);
if (value_.empty()) {
channel_name->erase();
return true;
} else {
for (const wchar_t* const* scan = &kChannels[0],
*const* end = &kChannels[arraysize(kChannels)]; scan != end;
++scan) {
if (value_.find(*scan) != std::wstring::npos) {
channel_name->assign(*scan);
return true;
}
}
// There may be modifiers present. Strip them off and see if we're left
// with the empty string (stable channel).
std::wstring tmp_value = value_;
for (const wchar_t* const* scan = &kModifiers[0],
*const *end = &kModifiers[arraysize(kModifiers)]; scan != end;
++scan) {
SetModifier(*scan, false, &tmp_value);
}
if (tmp_value.empty()) {
channel_name->erase();
return true;
}
}
return false;
}
bool ChannelInfo::IsCeee() const {
return HasModifier(kModCeee, value_);
}
bool ChannelInfo::SetCeee(bool value) {
return SetModifier(kModCeee, value, &value_);
}
bool ChannelInfo::IsFullInstall() const {
return HasModifier(kModFullInstall, value_);
}
bool ChannelInfo::SetFullInstall(bool value) {
return SetModifier(kModFullInstall, value, &value_);
}
bool ChannelInfo::IsMultiInstall() const {
return HasModifier(kModMultiInstall, value_);
}
bool ChannelInfo::SetMultiInstall(bool value) {
return SetModifier(kModMultiInstall, value, &value_);
}
} // namespace installer_util
|