Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chrome/installer/setup/user_hive_visitor.cc

Issue 2017123002: Adds a base32 component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Migrates installer/setup/user_hive_visitor.cc to use base32 component Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/installer/setup/DEPS ('k') | chrome/installer/util/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 8 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
12 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/rand_util.h" 16 #include "base/rand_util.h"
16 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
17 #include "base/strings/string_piece.h" 18 #include "base/strings/string_piece.h"
19 #include "base/strings/utf_string_conversions.h"
18 #include "base/win/registry.h" 20 #include "base/win/registry.h"
19 #include "chrome/installer/setup/setup_util.h" 21 #include "chrome/installer/setup/setup_util.h"
20 #include "chrome/installer/util/shell_util.h" 22 #include "components/base32/base32.h"
21 23
22 namespace installer { 24 namespace installer {
23 25
24 namespace { 26 namespace {
25 27
26 // 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
27 // HKEY_LOCAL_MACHINE. 29 // HKEY_LOCAL_MACHINE.
28 class ScopedUserHive { 30 class ScopedUserHive {
29 public: 31 public:
30 explicit ScopedUserHive(const base::FilePath& hive_file); 32 explicit ScopedUserHive(const base::FilePath& hive_file);
(...skipping 11 matching lines...) Expand all
42 base::string16 subkey_name_; 44 base::string16 subkey_name_;
43 45
44 // The loaded key. 46 // The loaded key.
45 base::win::RegKey key_; 47 base::win::RegKey key_;
46 48
47 DISALLOW_COPY_AND_ASSIGN(ScopedUserHive); 49 DISALLOW_COPY_AND_ASSIGN(ScopedUserHive);
48 }; 50 };
49 51
50 ScopedUserHive::ScopedUserHive(const base::FilePath& hive_file) { 52 ScopedUserHive::ScopedUserHive(const base::FilePath& hive_file) {
51 // 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.
52 uint8_t buffer[10] = {}; 54 std::string buffer = base::RandBytesAsString(10);
53 base::RandBytes(&buffer[0], arraysize(buffer)); 55 subkey_name_ = base::ASCIIToUTF16(
54 subkey_name_ = ShellUtil::ByteArrayToBase32(&buffer[0], arraysize(buffer)); 56 base32::Base32Encode(buffer, base32::Base32EncodePolicy::OMIT_PADDING));
55 DCHECK_EQ(16U, subkey_name_.size()); 57 DCHECK_EQ(16U, subkey_name_.size());
56 58
57 LONG result = ::RegLoadKey(HKEY_LOCAL_MACHINE, subkey_name_.c_str(), 59 LONG result = ::RegLoadKey(HKEY_LOCAL_MACHINE, subkey_name_.c_str(),
58 hive_file.value().c_str()); 60 hive_file.value().c_str());
59 if (result != ERROR_SUCCESS) { 61 if (result != ERROR_SUCCESS) {
60 // 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
61 // attempted in the dtor. 63 // attempted in the dtor.
62 subkey_name_.clear(); 64 subkey_name_.clear();
63 ::SetLastError(result); 65 ::SetLastError(result);
64 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
157 ScopedUserHive user_hive(hive_file); 159 ScopedUserHive user_hive(hive_file);
158 if (user_hive.valid()) { 160 if (user_hive.valid()) {
159 VLOG(1) << "Loaded and opened hive for sid \"" << sid << "\""; 161 VLOG(1) << "Loaded and opened hive for sid \"" << sid << "\"";
160 if (!visitor.Run(sid, user_hive.key())) 162 if (!visitor.Run(sid, user_hive.key()))
161 break; 163 break;
162 } 164 }
163 } 165 }
164 } 166 }
165 167
166 } // namespace installer 168 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/setup/DEPS ('k') | chrome/installer/util/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698