OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "remoting/host/pairing_registry_delegate_win.h" | 5 #include "remoting/host/pairing_registry_delegate_win.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 LOG(ERROR) << "Failed to parse '" << value_name << "': " << error_message | 61 LOG(ERROR) << "Failed to parse '" << value_name << "': " << error_message |
62 << " (" << error_code << ")."; | 62 << " (" << error_code << ")."; |
63 return nullptr; | 63 return nullptr; |
64 } | 64 } |
65 | 65 |
66 if (!value->IsType(base::Value::Type::DICTIONARY)) { | 66 if (!value->IsType(base::Value::Type::DICTIONARY)) { |
67 LOG(ERROR) << "Failed to parse '" << value_name << "': not a dictionary."; | 67 LOG(ERROR) << "Failed to parse '" << value_name << "': not a dictionary."; |
68 return nullptr; | 68 return nullptr; |
69 } | 69 } |
70 | 70 |
71 return base::WrapUnique(static_cast<base::DictionaryValue*>(value.release())); | 71 return base::DictionaryValue::From(std::move(value)); |
72 } | 72 } |
73 | 73 |
74 // Serializes |value| into a JSON string and writes it as value |value_name| | 74 // Serializes |value| into a JSON string and writes it as value |value_name| |
75 // under |key|. | 75 // under |key|. |
76 bool WriteValue(base::win::RegKey& key, | 76 bool WriteValue(base::win::RegKey& key, |
77 const wchar_t* value_name, | 77 const wchar_t* value_name, |
78 std::unique_ptr<base::DictionaryValue> value) { | 78 std::unique_ptr<base::DictionaryValue> value) { |
79 std::string value_json_utf8; | 79 std::string value_json_utf8; |
80 JSONStringValueSerializer serializer(&value_json_utf8); | 80 JSONStringValueSerializer serializer(&value_json_utf8); |
81 if (!serializer.Serialize(*value)) { | 81 if (!serializer.Serialize(*value)) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 std::wstring value_name; | 132 std::wstring value_name; |
133 LONG result = unprivileged_.GetValueNameAt(index, &value_name); | 133 LONG result = unprivileged_.GetValueNameAt(index, &value_name); |
134 if (result != ERROR_SUCCESS) { | 134 if (result != ERROR_SUCCESS) { |
135 SetLastError(result); | 135 SetLastError(result); |
136 PLOG(ERROR) << "Cannot get the name of value " << index; | 136 PLOG(ERROR) << "Cannot get the name of value " << index; |
137 continue; | 137 continue; |
138 } | 138 } |
139 | 139 |
140 PairingRegistry::Pairing pairing = Load(base::WideToUTF8(value_name)); | 140 PairingRegistry::Pairing pairing = Load(base::WideToUTF8(value_name)); |
141 if (pairing.is_valid()) | 141 if (pairing.is_valid()) |
142 pairings->Append(pairing.ToValue().release()); | 142 pairings->Append(pairing.ToValue()); |
143 } | 143 } |
144 | 144 |
145 return pairings; | 145 return pairings; |
146 } | 146 } |
147 | 147 |
148 bool PairingRegistryDelegateWin::DeleteAll() { | 148 bool PairingRegistryDelegateWin::DeleteAll() { |
149 if (!privileged_.Valid()) { | 149 if (!privileged_.Valid()) { |
150 LOG(ERROR) << "Cannot delete pairings: the delegate is read-only."; | 150 LOG(ERROR) << "Cannot delete pairings: the delegate is read-only."; |
151 return false; | 151 return false; |
152 } | 152 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 } | 214 } |
215 | 215 |
216 // Convert pairing to JSON. | 216 // Convert pairing to JSON. |
217 std::unique_ptr<base::DictionaryValue> pairing_json = pairing.ToValue(); | 217 std::unique_ptr<base::DictionaryValue> pairing_json = pairing.ToValue(); |
218 | 218 |
219 // Extract the shared secret to a separate dictionary. | 219 // Extract the shared secret to a separate dictionary. |
220 std::unique_ptr<base::Value> secret_key; | 220 std::unique_ptr<base::Value> secret_key; |
221 CHECK(pairing_json->Remove(PairingRegistry::kSharedSecretKey, &secret_key)); | 221 CHECK(pairing_json->Remove(PairingRegistry::kSharedSecretKey, &secret_key)); |
222 std::unique_ptr<base::DictionaryValue> secret_json( | 222 std::unique_ptr<base::DictionaryValue> secret_json( |
223 new base::DictionaryValue()); | 223 new base::DictionaryValue()); |
224 secret_json->Set(PairingRegistry::kSharedSecretKey, secret_key.release()); | 224 secret_json->Set(PairingRegistry::kSharedSecretKey, std::move(secret_key)); |
225 | 225 |
226 // presubmit: allow wstring | 226 // presubmit: allow wstring |
227 std::wstring value_name = base::UTF8ToWide(pairing.client_id()); | 227 std::wstring value_name = base::UTF8ToWide(pairing.client_id()); |
228 | 228 |
229 // Write pairing to the registry. | 229 // Write pairing to the registry. |
230 if (!WriteValue(privileged_, value_name.c_str(), std::move(secret_json)) || | 230 if (!WriteValue(privileged_, value_name.c_str(), std::move(secret_json)) || |
231 !WriteValue(unprivileged_, value_name.c_str(), std::move(pairing_json))) { | 231 !WriteValue(unprivileged_, value_name.c_str(), std::move(pairing_json))) { |
232 return false; | 232 return false; |
233 } | 233 } |
234 | 234 |
(...skipping 28 matching lines...) Expand all Loading... |
263 } | 263 } |
264 | 264 |
265 return true; | 265 return true; |
266 } | 266 } |
267 | 267 |
268 std::unique_ptr<PairingRegistry::Delegate> CreatePairingRegistryDelegate() { | 268 std::unique_ptr<PairingRegistry::Delegate> CreatePairingRegistryDelegate() { |
269 return base::MakeUnique<PairingRegistryDelegateWin>(); | 269 return base::MakeUnique<PairingRegistryDelegateWin>(); |
270 } | 270 } |
271 | 271 |
272 } // namespace remoting | 272 } // namespace remoting |
OLD | NEW |