15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_INSTALLER_UTIL_CHANNEL_INFO_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_INSTALLER_UTIL_CHANNEL_INFO_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace win {
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RegKey;
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace installer {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A helper class for parsing and modifying the Google Update additional
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// parameter ("ap") client state value for a product.
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ChannelInfo {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initialize an instance from the "ap" value in a given registry key.
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns false if the value is present but could not be read from the
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // registry. Returns true if the value was not present or could be read.
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Also returns true if the key is not valid.
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // An absent "ap" value is treated identically to an empty "ap" value.
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool Initialize(const base::win::RegKey& key);
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Writes the info to the "ap" value in a given registry key.
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns false if the value could not be written to the registry.
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool Write(base::win::RegKey* key) const;
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const std::wstring& value() const { return value_; }
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_value(const std::wstring& value) { value_ = value; }
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool Equals(const ChannelInfo& other) const {
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return value_ == other.value_;
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Determines the update channel for the value.  Possible |channel_name|
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // results are the empty string (stable channel), "beta", and "dev".  Returns
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // false (without modifying |channel_name|) if the channel could not be
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // determined.
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetChannelName(std::wstring* channel_name) const;
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the -chrome modifier is present in the value.
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool IsChrome() const;
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds or removes the -chrome modifier, returning true if the value is
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // modified.
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetChrome(bool value);
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the -chromeframe modifier is present in the value.
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool IsChromeFrame() const;
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds or removes the -chromeframe modifier, returning true if the value is
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // modified.
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetChromeFrame(bool value);
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the -applauncher modifier is present in the value.
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool IsAppLauncher() const;
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds or removes the -applauncher modifier, returning true if the value is
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // modified.
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetAppLauncher(bool value);
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the -multi modifier is present in the value.
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool IsMultiInstall() const;
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds or removes the -multi modifier, returning true if the value is
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // modified.
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetMultiInstall(bool value);
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the -readymode modifier is present in the value.
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool IsReadyMode() const;
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds or removes the -readymode modifier, returning true if the value is
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // modified.
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetReadyMode(bool value);
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds the -stage: modifier with the given string (if |stage| is non-NULL) or
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // removes the -stage: modifier (otherwise), returning true if the value is
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // modified.
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetStage(const wchar_t* stage);
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the string identifying the current stage, or an empty string if the
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // -stage: modifier is not present in the value.
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::wstring GetStage() const;
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the -full suffix is present in the value.
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool HasFullSuffix() const;
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds or removes the -full suffix, returning true if the value is
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // modified.
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetFullSuffix(bool value);
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the -multifail suffix is present in the value.
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool HasMultiFailSuffix() const;
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds or removes the -multifail suffix, returning true if the value is
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // modified.
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetMultiFailSuffix(bool value);
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Adds or removes the -migrating suffix, returning true if the value is
10568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // modified.
10668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  bool SetMigratingSuffix(bool value);
10768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
10868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Returns true if the -migrating suffix is present in the value.
10968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  bool HasMigratingSuffix() const;
11068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
111558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // Removes all modifiers and suffixes. For example, 2.0-dev-multi-chrome-full
112558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // becomes 2.0-dev. Returns true if the value is modified.
113558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  bool RemoveAllModifiersAndSuffixes();
114558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::wstring value_;
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};  // class ChannelInfo
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace installer
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_INSTALLER_UTIL_CHANNEL_INFO_H_
122