| 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> |
| 8 |
| 7 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 12 #include "base/values.h" |
| 11 #include "base/win/registry.h" | 13 #include "base/win/registry.h" |
| 12 | 14 |
| 13 namespace remoting { | 15 namespace remoting { |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 SetLastError(result); | 134 SetLastError(result); |
| 133 PLOG(ERROR) << "Cannot get the name of value " << index; | 135 PLOG(ERROR) << "Cannot get the name of value " << index; |
| 134 continue; | 136 continue; |
| 135 } | 137 } |
| 136 | 138 |
| 137 PairingRegistry::Pairing pairing = Load(base::WideToUTF8(value_name)); | 139 PairingRegistry::Pairing pairing = Load(base::WideToUTF8(value_name)); |
| 138 if (pairing.is_valid()) | 140 if (pairing.is_valid()) |
| 139 pairings->Append(pairing.ToValue().release()); | 141 pairings->Append(pairing.ToValue().release()); |
| 140 } | 142 } |
| 141 | 143 |
| 142 return pairings.Pass(); | 144 return pairings; |
| 143 } | 145 } |
| 144 | 146 |
| 145 bool PairingRegistryDelegateWin::DeleteAll() { | 147 bool PairingRegistryDelegateWin::DeleteAll() { |
| 146 if (!privileged_.Valid()) { | 148 if (!privileged_.Valid()) { |
| 147 LOG(ERROR) << "Cannot delete pairings: the delegate is read-only."; | 149 LOG(ERROR) << "Cannot delete pairings: the delegate is read-only."; |
| 148 return false; | 150 return false; |
| 149 } | 151 } |
| 150 | 152 |
| 151 // Enumerate and delete the values in the privileged and unprivileged keys | 153 // Enumerate and delete the values in the privileged and unprivileged keys |
| 152 // separately in case they get out of sync. | 154 // separately in case they get out of sync. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 // Extract the shared secret to a separate dictionary. | 218 // Extract the shared secret to a separate dictionary. |
| 217 scoped_ptr<base::Value> secret_key; | 219 scoped_ptr<base::Value> secret_key; |
| 218 CHECK(pairing_json->Remove(PairingRegistry::kSharedSecretKey, &secret_key)); | 220 CHECK(pairing_json->Remove(PairingRegistry::kSharedSecretKey, &secret_key)); |
| 219 scoped_ptr<base::DictionaryValue> secret_json(new base::DictionaryValue()); | 221 scoped_ptr<base::DictionaryValue> secret_json(new base::DictionaryValue()); |
| 220 secret_json->Set(PairingRegistry::kSharedSecretKey, secret_key.release()); | 222 secret_json->Set(PairingRegistry::kSharedSecretKey, secret_key.release()); |
| 221 | 223 |
| 222 // presubmit: allow wstring | 224 // presubmit: allow wstring |
| 223 std::wstring value_name = base::UTF8ToWide(pairing.client_id()); | 225 std::wstring value_name = base::UTF8ToWide(pairing.client_id()); |
| 224 | 226 |
| 225 // Write pairing to the registry. | 227 // Write pairing to the registry. |
| 226 if (!WriteValue(privileged_, value_name.c_str(), secret_json.Pass()) || | 228 if (!WriteValue(privileged_, value_name.c_str(), std::move(secret_json)) || |
| 227 !WriteValue(unprivileged_, value_name.c_str(), pairing_json.Pass())) { | 229 !WriteValue(unprivileged_, value_name.c_str(), std::move(pairing_json))) { |
| 228 return false; | 230 return false; |
| 229 } | 231 } |
| 230 | 232 |
| 231 return true; | 233 return true; |
| 232 } | 234 } |
| 233 | 235 |
| 234 bool PairingRegistryDelegateWin::Delete(const std::string& client_id) { | 236 bool PairingRegistryDelegateWin::Delete(const std::string& client_id) { |
| 235 if (!privileged_.Valid()) { | 237 if (!privileged_.Valid()) { |
| 236 LOG(ERROR) << "Cannot delete pairing entry '" << client_id | 238 LOG(ERROR) << "Cannot delete pairing entry '" << client_id |
| 237 << "': the delegate is read-only."; | 239 << "': the delegate is read-only."; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 259 } | 261 } |
| 260 | 262 |
| 261 return true; | 263 return true; |
| 262 } | 264 } |
| 263 | 265 |
| 264 scoped_ptr<PairingRegistry::Delegate> CreatePairingRegistryDelegate() { | 266 scoped_ptr<PairingRegistry::Delegate> CreatePairingRegistryDelegate() { |
| 265 return make_scoped_ptr(new PairingRegistryDelegateWin()); | 267 return make_scoped_ptr(new PairingRegistryDelegateWin()); |
| 266 } | 268 } |
| 267 | 269 |
| 268 } // namespace remoting | 270 } // namespace remoting |
| OLD | NEW |