Home | History | Annotate | Download | only in util
      1 // Copyright (c) 2009 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 // This file declares helper methods used to schedule files for deletion
      6 // on next reboot.
      7 
      8 #ifndef CHROME_INSTALLER_UTIL_DELETE_AFTER_REBOOT_HELPER_H_
      9 #define CHROME_INSTALLER_UTIL_DELETE_AFTER_REBOOT_HELPER_H_
     10 
     11 #include <string>
     12 #include <vector>
     13 
     14 #include <windows.h>
     15 
     16 // Used by the unit tests.
     17 extern const wchar_t kSessionManagerKey[];
     18 extern const wchar_t kPendingFileRenameOps[];
     19 
     20 typedef std::pair<std::wstring, std::wstring> PendingMove;
     21 
     22 // Attempts to schedule only the item at path for deletion.
     23 bool ScheduleFileSystemEntityForDeletion(const wchar_t* path);
     24 
     25 // Attempts to recursively schedule the directory for deletion.
     26 bool ScheduleDirectoryForDeletion(const wchar_t* dir_name);
     27 
     28 // Removes all pending moves that are registered for |directory| and all
     29 // elements contained in |directory|.
     30 bool RemoveFromMovesPendingReboot(const wchar_t* directory);
     31 
     32 // Retrieves the list of pending renames from the registry and returns a vector
     33 // containing pairs of strings that represent the operations. If the list
     34 // contains only deletes then every other element will be an empty string
     35 // as per http://msdn.microsoft.com/en-us/library/aa365240(VS.85).aspx.
     36 HRESULT GetPendingMovesValue(std::vector<PendingMove>* pending_moves);
     37 
     38 // This returns true if |short_form_needle| is contained in |reg_path| where
     39 // |short_form_needle| is a file system path that has been shortened by
     40 // GetShortPathName and |reg_path| is a path stored in the
     41 // PendingFileRenameOperations key.
     42 bool MatchPendingDeletePath(const std::wstring& short_form_needle,
     43                             const std::wstring& reg_path);
     44 
     45 // Converts the strings found in |buffer| to a list of PendingMoves that is
     46 // returned in |value|.
     47 // |buffer| points to a series of pairs of null-terminated wchar_t strings
     48 // followed by a terminating null character.
     49 // |byte_count| is the length of |buffer| in bytes.
     50 // |value| is a pointer to an empty vector of PendingMoves (string pairs).
     51 // On success, this vector contains all of the string pairs extracted from
     52 // |buffer|.
     53 // Returns S_OK on success, E_INVALIDARG if buffer does not meet the above
     54 // specification.
     55 HRESULT MultiSZBytesToStringArray(const char* buffer, size_t byte_count,
     56                                   std::vector<PendingMove>* value);
     57 
     58 // The inverse of MultiSZBytesToStringArray, this function converts a list
     59 // of string pairs into a byte array format suitable for writing to the
     60 // kPendingFileRenameOps registry value. It concatenates the strings and
     61 // appends an additional terminating null character.
     62 void StringArrayToMultiSZBytes(const std::vector<PendingMove>& strings,
     63                                std::vector<char>* buffer);
     64 
     65 // A helper function for the win32 GetShortPathName that more conveniently
     66 // returns a correctly sized wstring. Note that if |path| is not present on the
     67 // file system then GetShortPathName will return |path| unchanged, unlike the
     68 // win32 GetShortPathName which will return an error.
     69 std::wstring GetShortPathName(const wchar_t* path);
     70 
     71 #endif  // CHROME_INSTALLER_UTIL_DELETE_AFTER_REBOOT_HELPER_H_
     72