Home | History | Annotate | Download | only in util
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_INSTALLER_UTIL_SET_REG_VALUE_WORK_ITEM_H__
      6 #define CHROME_INSTALLER_UTIL_SET_REG_VALUE_WORK_ITEM_H__
      7 
      8 #include <windows.h>
      9 
     10 #include <string>
     11 #include <vector>
     12 
     13 #include "chrome/installer/util/work_item.h"
     14 
     15 // A WorkItem subclass that sets a registry value with REG_SZ, REG_DWORD, or
     16 // REG_QWORD type at the specified path. The value is only set if the target key
     17 // exists.
     18 class SetRegValueWorkItem : public WorkItem {
     19  public:
     20   virtual ~SetRegValueWorkItem();
     21 
     22   virtual bool Do();
     23 
     24   virtual void Rollback();
     25 
     26  private:
     27   friend class WorkItem;
     28 
     29   enum SettingStatus {
     30     // The status before Do is called.
     31     SET_VALUE,
     32     // One possible outcome after Do(). A new value is created under the key.
     33     NEW_VALUE_CREATED,
     34     // One possible outcome after Do(). The previous value under the key has
     35     // been overwritten.
     36     VALUE_OVERWRITTEN,
     37     // One possible outcome after Do(). No change is applied, either
     38     // because we are not allowed to overwrite the previous value, or due to
     39     // some errors like the key does not exist.
     40     VALUE_UNCHANGED,
     41     // The status after Do and Rollback is called.
     42     VALUE_ROLL_BACK
     43   };
     44 
     45   SetRegValueWorkItem(HKEY predefined_root,
     46                       const std::wstring& key_path,
     47                       REGSAM wow64_access,
     48                       const std::wstring& value_name,
     49                       const std::wstring& value_data,
     50                       bool overwrite);
     51 
     52   SetRegValueWorkItem(HKEY predefined_root,
     53                       const std::wstring& key_path,
     54                       REGSAM wow64_access,
     55                       const std::wstring& value_name,
     56                       DWORD value_data,
     57                       bool overwrite);
     58 
     59   SetRegValueWorkItem(HKEY predefined_root,
     60                       const std::wstring& key_path,
     61                       REGSAM wow64_access,
     62                       const std::wstring& value_name,
     63                       int64 value_data,
     64                       bool overwrite);
     65 
     66   // Root key of the target key under which the value is set. The root key can
     67   // only be one of the predefined keys on Windows.
     68   HKEY predefined_root_;
     69 
     70   // Path of the target key under which the value is set.
     71   std::wstring key_path_;
     72 
     73   // Name of the value to be set.
     74   std::wstring value_name_;
     75 
     76   // Whether to overwrite the existing value under the target key.
     77   bool overwrite_;
     78 
     79   // Whether to force 32-bit or 64-bit view of the target key.
     80   REGSAM wow64_access_;
     81 
     82   // Type of data to store
     83   DWORD type_;
     84   std::vector<uint8> value_;
     85   DWORD previous_type_;
     86   std::vector<uint8> previous_value_;
     87 
     88   SettingStatus status_;
     89 };
     90 
     91 #endif  // CHROME_INSTALLER_UTIL_SET_REG_VALUE_WORK_ITEM_H__
     92