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

Side by Side Diff: components/policy/core/common/preg_parser_win.cc

Issue 1902633006: Convert //components/policy from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and use namespace alias Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "components/policy/core/common/preg_parser_win.h" 5 #include "components/policy/core/common/preg_parser_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <functional> 12 #include <functional>
13 #include <iterator> 13 #include <iterator>
14 #include <utility> 14 #include <utility>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
18 #include "base/files/memory_mapped_file.h" 18 #include "base/files/memory_mapped_file.h"
19 #include "base/i18n/case_conversion.h" 19 #include "base/i18n/case_conversion.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/macros.h" 21 #include "base/macros.h"
22 #include "base/memory/ptr_util.h"
22 #include "base/strings/string16.h" 23 #include "base/strings/string16.h"
23 #include "base/strings/string_split.h" 24 #include "base/strings/string_split.h"
24 #include "base/strings/string_util.h" 25 #include "base/strings/string_util.h"
25 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
26 #include "base/sys_byteorder.h" 27 #include "base/sys_byteorder.h"
27 #include "base/values.h" 28 #include "base/values.h"
28 #include "components/policy/core/common/policy_load_status.h" 29 #include "components/policy/core/common/policy_load_status.h"
29 #include "components/policy/core/common/registry_dict_win.h" 30 #include "components/policy/core/common/registry_dict_win.h"
30 31
31 namespace policy { 32 namespace policy {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 reinterpret_cast<const base::char16*>(data.data()); 113 reinterpret_cast<const base::char16*>(data.data());
113 base::string16 result; 114 base::string16 result;
114 std::transform(chars, chars + len - 1, std::back_inserter(result), 115 std::transform(chars, chars + len - 1, std::back_inserter(result),
115 std::ptr_fun(base::ByteSwapToLE16)); 116 std::ptr_fun(base::ByteSwapToLE16));
116 return base::UTF16ToUTF8(result); 117 return base::UTF16ToUTF8(result);
117 } 118 }
118 119
119 // Decodes a value from a PReg file given as a uint8_t vector. 120 // Decodes a value from a PReg file given as a uint8_t vector.
120 bool DecodePRegValue(uint32_t type, 121 bool DecodePRegValue(uint32_t type,
121 const std::vector<uint8_t>& data, 122 const std::vector<uint8_t>& data,
122 scoped_ptr<base::Value>* value) { 123 std::unique_ptr<base::Value>* value) {
123 switch (type) { 124 switch (type) {
124 case REG_SZ: 125 case REG_SZ:
125 case REG_EXPAND_SZ: 126 case REG_EXPAND_SZ:
126 value->reset(new base::StringValue(DecodePRegStringValue(data))); 127 value->reset(new base::StringValue(DecodePRegStringValue(data)));
127 return true; 128 return true;
128 case REG_DWORD_LITTLE_ENDIAN: 129 case REG_DWORD_LITTLE_ENDIAN:
129 case REG_DWORD_BIG_ENDIAN: 130 case REG_DWORD_BIG_ENDIAN:
130 if (data.size() == sizeof(uint32_t)) { 131 if (data.size() == sizeof(uint32_t)) {
131 uint32_t val = *reinterpret_cast<const uint32_t*>(data.data()); 132 uint32_t val = *reinterpret_cast<const uint32_t*>(data.data());
132 if (type == REG_DWORD_BIG_ENDIAN) 133 if (type == REG_DWORD_BIG_ENDIAN)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 166
166 for (const base::string16& entry : 167 for (const base::string16& entry :
167 base::SplitString(key_name, kRegistryPathSeparator, 168 base::SplitString(key_name, kRegistryPathSeparator,
168 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { 169 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
169 if (entry.empty()) 170 if (entry.empty())
170 continue; 171 continue;
171 const std::string name = base::UTF16ToUTF8(entry); 172 const std::string name = base::UTF16ToUTF8(entry);
172 RegistryDict* subdict = dict->GetKey(name); 173 RegistryDict* subdict = dict->GetKey(name);
173 if (!subdict) { 174 if (!subdict) {
174 subdict = new RegistryDict(); 175 subdict = new RegistryDict();
175 dict->SetKey(name, make_scoped_ptr(subdict)); 176 dict->SetKey(name, base::WrapUnique(subdict));
176 } 177 }
177 dict = subdict; 178 dict = subdict;
178 } 179 }
179 180
180 if (value.empty()) 181 if (value.empty())
181 return; 182 return;
182 183
183 std::string value_name(base::UTF16ToUTF8(value)); 184 std::string value_name(base::UTF16ToUTF8(value));
184 if (!base::StartsWith(value_name, kActionTriggerPrefix, 185 if (!base::StartsWith(value_name, kActionTriggerPrefix,
185 base::CompareCase::SENSITIVE)) { 186 base::CompareCase::SENSITIVE)) {
186 scoped_ptr<base::Value> value; 187 std::unique_ptr<base::Value> value;
187 if (DecodePRegValue(type, data, &value)) 188 if (DecodePRegValue(type, data, &value))
188 dict->SetValue(value_name, std::move(value)); 189 dict->SetValue(value_name, std::move(value));
189 return; 190 return;
190 } 191 }
191 192
192 std::string action_trigger(base::ToLowerASCII(value_name.substr( 193 std::string action_trigger(base::ToLowerASCII(value_name.substr(
193 arraysize(kActionTriggerPrefix) - 1))); 194 arraysize(kActionTriggerPrefix) - 1)));
194 if (action_trigger == kActionTriggerDeleteValues) { 195 if (action_trigger == kActionTriggerDeleteValues) {
195 for (const std::string& value : 196 for (const std::string& value :
196 base::SplitString(DecodePRegStringValue(data), ";", 197 base::SplitString(DecodePRegStringValue(data), ";",
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 311
311 LOG(ERROR) << "Error parsing " << file_path.value() << " at offset " 312 LOG(ERROR) << "Error parsing " << file_path.value() << " at offset "
312 << reinterpret_cast<const uint8_t*>(cursor - 1) - 313 << reinterpret_cast<const uint8_t*>(cursor - 1) -
313 mapped_file.data(); 314 mapped_file.data();
314 status->Add(POLICY_LOAD_STATUS_PARSE_ERROR); 315 status->Add(POLICY_LOAD_STATUS_PARSE_ERROR);
315 return false; 316 return false;
316 } 317 }
317 318
318 } // namespace preg_parser 319 } // namespace preg_parser
319 } // namespace policy 320 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/preg_parser_win.h ('k') | components/policy/core/common/preg_parser_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698