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 #ifndef CHROME_INSTALLER_UTIL_CHANNEL_INFO_H_ | 5 #ifndef CHROME_INSTALLER_UTIL_CHANNEL_INFO_H_ |
6 #define CHROME_INSTALLER_UTIL_CHANNEL_INFO_H_ | 6 #define CHROME_INSTALLER_UTIL_CHANNEL_INFO_H_ |
7 | 7 |
8 #include <string> | 8 #include "base/strings/string16.h" |
9 | 9 |
10 namespace base { | 10 namespace base { |
11 namespace win { | 11 namespace win { |
12 class RegKey; | 12 class RegKey; |
13 } | 13 } |
14 } | 14 } |
15 | 15 |
16 namespace installer { | 16 namespace installer { |
17 | 17 |
18 // A helper class for parsing and modifying the Google Update additional | 18 // A helper class for parsing and modifying the Google Update additional |
19 // parameter ("ap") client state value for a product. | 19 // parameter ("ap") client state value for a product. |
20 class ChannelInfo { | 20 class ChannelInfo { |
21 public: | 21 public: |
22 | 22 |
23 // Initialize an instance from the "ap" value in a given registry key. | 23 // Initialize an instance from the "ap" value in a given registry key. |
24 // Returns false if the value is present but could not be read from the | 24 // Returns false if the value is present but could not be read from the |
25 // registry. Returns true if the value was not present or could be read. | 25 // registry. Returns true if the value was not present or could be read. |
26 // Also returns true if the key is not valid. | 26 // Also returns true if the key is not valid. |
27 // An absent "ap" value is treated identically to an empty "ap" value. | 27 // An absent "ap" value is treated identically to an empty "ap" value. |
28 bool Initialize(const base::win::RegKey& key); | 28 bool Initialize(const base::win::RegKey& key); |
29 | 29 |
30 // Writes the info to the "ap" value in a given registry key. | 30 // Writes the info to the "ap" value in a given registry key. |
31 // Returns false if the value could not be written to the registry. | 31 // Returns false if the value could not be written to the registry. |
32 bool Write(base::win::RegKey* key) const; | 32 bool Write(base::win::RegKey* key) const; |
33 | 33 |
34 const std::wstring& value() const { return value_; } | 34 const base::string16& value() const { return value_; } |
35 void set_value(const std::wstring& value) { value_ = value; } | 35 |
| 36 // This should be the only point way to modify |value_|, since we may need |
| 37 // to audit |value| and remove deprecated modifiers. |
| 38 void set_value(const base::string16& value); |
| 39 |
36 bool Equals(const ChannelInfo& other) const { | 40 bool Equals(const ChannelInfo& other) const { |
37 return value_ == other.value_; | 41 return value_ == other.value_; |
38 } | 42 } |
39 | 43 |
40 // Determines the update channel for the value. Possible |channel_name| | 44 // Determines the update channel for the value. Possible |channel_name| |
41 // results are the empty string (stable channel), "beta", and "dev". Returns | 45 // results are the empty string (stable channel), "beta", and "dev". Returns |
42 // false (without modifying |channel_name|) if the channel could not be | 46 // false (without modifying |channel_name|) if the channel could not be |
43 // determined. | 47 // determined. |
44 bool GetChannelName(std::wstring* channel_name) const; | 48 bool GetChannelName(base::string16* channel_name) const; |
45 | 49 |
46 // Returns true if the -chrome modifier is present in the value. | 50 // Returns true if the -chrome modifier is present in the value. |
47 bool IsChrome() const; | 51 bool IsChrome() const; |
48 | 52 |
49 // Adds or removes the -chrome modifier, returning true if the value is | 53 // Adds or removes the -chrome modifier, returning true if the value is |
50 // modified. | 54 // modified. |
51 bool SetChrome(bool value); | 55 bool SetChrome(bool value); |
52 | 56 |
53 // Returns true if the -chromeframe modifier is present in the value. | 57 // Returns true if the -chromeframe modifier is present in the value. |
54 bool IsChromeFrame() const; | 58 bool IsChromeFrame() const; |
55 | 59 |
56 // Adds or removes the -chromeframe modifier, returning true if the value is | 60 // Adds or removes the -chromeframe modifier, returning true if the value is |
57 // modified. | 61 // modified. |
58 bool SetChromeFrame(bool value); | 62 bool SetChromeFrame(bool value); |
59 | 63 |
60 // Returns true if the -applauncher modifier is present in the value. | 64 // (Deprecated) Returns true if the -applauncher modifier is present in the |
| 65 // value. |
61 bool IsAppLauncher() const; | 66 bool IsAppLauncher() const; |
62 | 67 |
63 // Adds or removes the -applauncher modifier, returning true if the value is | 68 // (Deprecated) Adds or removes the -applauncher modifier, returning true if |
64 // modified. | 69 // the value is modified. |
65 bool SetAppLauncher(bool value); | 70 bool SetAppLauncher(bool value); |
66 | 71 |
67 // Returns true if the -multi modifier is present in the value. | 72 // Returns true if the -multi modifier is present in the value. |
68 bool IsMultiInstall() const; | 73 bool IsMultiInstall() const; |
69 | 74 |
70 // Adds or removes the -multi modifier, returning true if the value is | 75 // Adds or removes the -multi modifier, returning true if the value is |
71 // modified. | 76 // modified. |
72 bool SetMultiInstall(bool value); | 77 bool SetMultiInstall(bool value); |
73 | 78 |
74 // Returns true if the -readymode modifier is present in the value. | 79 // Returns true if the -readymode modifier is present in the value. |
75 bool IsReadyMode() const; | 80 bool IsReadyMode() const; |
76 | 81 |
77 // Adds or removes the -readymode modifier, returning true if the value is | 82 // Adds or removes the -readymode modifier, returning true if the value is |
78 // modified. | 83 // modified. |
79 bool SetReadyMode(bool value); | 84 bool SetReadyMode(bool value); |
80 | 85 |
81 // Adds the -stage: modifier with the given string (if |stage| is non-NULL) or | 86 // Adds the -stage: modifier with the given string (if |stage| is non-NULL) or |
82 // removes the -stage: modifier (otherwise), returning true if the value is | 87 // removes the -stage: modifier (otherwise), returning true if the value is |
83 // modified. | 88 // modified. |
84 bool SetStage(const wchar_t* stage); | 89 bool SetStage(const wchar_t* stage); |
85 | 90 |
86 // Returns the string identifying the current stage, or an empty string if the | 91 // Returns the string identifying the current stage, or an empty string if the |
87 // -stage: modifier is not present in the value. | 92 // -stage: modifier is not present in the value. |
88 std::wstring GetStage() const; | 93 base::string16 GetStage() const; |
89 | 94 |
90 // Returns true if the -full suffix is present in the value. | 95 // Returns true if the -full suffix is present in the value. |
91 bool HasFullSuffix() const; | 96 bool HasFullSuffix() const; |
92 | 97 |
93 // Adds or removes the -full suffix, returning true if the value is | 98 // Adds or removes the -full suffix, returning true if the value is |
94 // modified. | 99 // modified. |
95 bool SetFullSuffix(bool value); | 100 bool SetFullSuffix(bool value); |
96 | 101 |
97 // Returns true if the -multifail suffix is present in the value. | 102 // Returns true if the -multifail suffix is present in the value. |
98 bool HasMultiFailSuffix() const; | 103 bool HasMultiFailSuffix() const; |
99 | 104 |
100 // Adds or removes the -multifail suffix, returning true if the value is | 105 // Adds or removes the -multifail suffix, returning true if the value is |
101 // modified. | 106 // modified. |
102 bool SetMultiFailSuffix(bool value); | 107 bool SetMultiFailSuffix(bool value); |
103 | 108 |
104 // Adds or removes the -migrating suffix, returning true if the value is | 109 // Adds or removes the -migrating suffix, returning true if the value is |
105 // modified. | 110 // modified. |
106 bool SetMigratingSuffix(bool value); | 111 bool SetMigratingSuffix(bool value); |
107 | 112 |
108 // Returns true if the -migrating suffix is present in the value. | 113 // Returns true if the -migrating suffix is present in the value. |
109 bool HasMigratingSuffix() const; | 114 bool HasMigratingSuffix() const; |
110 | 115 |
111 // Removes all modifiers and suffixes. For example, 2.0-dev-multi-chrome-full | 116 // Removes all modifiers and suffixes. For example, 2.0-dev-multi-chrome-full |
112 // becomes 2.0-dev. Returns true if the value is modified. | 117 // becomes 2.0-dev. Returns true if the value is modified. |
113 bool RemoveAllModifiersAndSuffixes(); | 118 bool RemoveAllModifiersAndSuffixes(); |
114 | 119 |
115 private: | 120 private: |
116 std::wstring value_; | 121 base::string16 value_; |
117 }; // class ChannelInfo | 122 }; // class ChannelInfo |
118 | 123 |
119 } // namespace installer | 124 } // namespace installer |
120 | 125 |
121 #endif // CHROME_INSTALLER_UTIL_CHANNEL_INFO_H_ | 126 #endif // CHROME_INSTALLER_UTIL_CHANNEL_INFO_H_ |
OLD | NEW |