OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "chrome/installer/setup/user_hive_visitor.h" | 5 #include "chrome/installer/setup/user_hive_visitor.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
| 10 #include "base/base32.h" |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
14 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/rand_util.h" | 17 #include "base/rand_util.h" |
17 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
18 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
20 #include "base/win/registry.h" | 21 #include "base/win/registry.h" |
21 #include "chrome/installer/setup/setup_util.h" | 22 #include "chrome/installer/setup/setup_util.h" |
22 #include "components/base32/base32.h" | |
23 | 23 |
24 namespace installer { | 24 namespace installer { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 // A helper for loading and opening a hive into a random subkey of | 28 // A helper for loading and opening a hive into a random subkey of |
29 // HKEY_LOCAL_MACHINE. | 29 // HKEY_LOCAL_MACHINE. |
30 class ScopedUserHive { | 30 class ScopedUserHive { |
31 public: | 31 public: |
32 explicit ScopedUserHive(const base::FilePath& hive_file); | 32 explicit ScopedUserHive(const base::FilePath& hive_file); |
(...skipping 13 matching lines...) Expand all Loading... |
46 // The loaded key. | 46 // The loaded key. |
47 base::win::RegKey key_; | 47 base::win::RegKey key_; |
48 | 48 |
49 DISALLOW_COPY_AND_ASSIGN(ScopedUserHive); | 49 DISALLOW_COPY_AND_ASSIGN(ScopedUserHive); |
50 }; | 50 }; |
51 | 51 |
52 ScopedUserHive::ScopedUserHive(const base::FilePath& hive_file) { | 52 ScopedUserHive::ScopedUserHive(const base::FilePath& hive_file) { |
53 // Generate a random name for the key at which the file will be loaded. | 53 // Generate a random name for the key at which the file will be loaded. |
54 std::string buffer = base::RandBytesAsString(10); | 54 std::string buffer = base::RandBytesAsString(10); |
55 subkey_name_ = base::ASCIIToUTF16( | 55 subkey_name_ = base::ASCIIToUTF16( |
56 base32::Base32Encode(buffer, base32::Base32EncodePolicy::OMIT_PADDING)); | 56 base::Base32Encode(buffer, base::Base32EncodePolicy::OMIT_PADDING)); |
57 DCHECK_EQ(16U, subkey_name_.size()); | 57 DCHECK_EQ(16U, subkey_name_.size()); |
58 | 58 |
59 LONG result = ::RegLoadKey(HKEY_LOCAL_MACHINE, subkey_name_.c_str(), | 59 LONG result = ::RegLoadKey(HKEY_LOCAL_MACHINE, subkey_name_.c_str(), |
60 hive_file.value().c_str()); | 60 hive_file.value().c_str()); |
61 if (result != ERROR_SUCCESS) { | 61 if (result != ERROR_SUCCESS) { |
62 // Clear subkey_name_ since the load failed so that an unload will not be | 62 // Clear subkey_name_ since the load failed so that an unload will not be |
63 // attempted in the dtor. | 63 // attempted in the dtor. |
64 subkey_name_.clear(); | 64 subkey_name_.clear(); |
65 ::SetLastError(result); | 65 ::SetLastError(result); |
66 PLOG(ERROR) << "Failed loading user hive file \"" << hive_file.value() | 66 PLOG(ERROR) << "Failed loading user hive file \"" << hive_file.value() |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 ScopedUserHive user_hive(hive_file); | 159 ScopedUserHive user_hive(hive_file); |
160 if (user_hive.valid()) { | 160 if (user_hive.valid()) { |
161 VLOG(1) << "Loaded and opened hive for sid \"" << sid << "\""; | 161 VLOG(1) << "Loaded and opened hive for sid \"" << sid << "\""; |
162 if (!visitor.Run(sid, user_hive.key())) | 162 if (!visitor.Run(sid, user_hive.key())) |
163 break; | 163 break; |
164 } | 164 } |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
168 } // namespace installer | 168 } // namespace installer |
OLD | NEW |