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