| 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/protocol/pairing_registry.h" | 5 #include "remoting/protocol/pairing_registry.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 std::string shared_secret; | 72 std::string shared_secret; |
| 73 pairing.GetString(kSharedSecretKey, &shared_secret); | 73 pairing.GetString(kSharedSecretKey, &shared_secret); |
| 74 base::Time created_time = base::Time::FromJsTime(created_time_value); | 74 base::Time created_time = base::Time::FromJsTime(created_time_value); |
| 75 return Pairing(created_time, client_name, client_id, shared_secret); | 75 return Pairing(created_time, client_name, client_id, shared_secret); |
| 76 } | 76 } |
| 77 | 77 |
| 78 LOG(ERROR) << "Failed to load pairing information: unexpected format."; | 78 LOG(ERROR) << "Failed to load pairing information: unexpected format."; |
| 79 return Pairing(); | 79 return Pairing(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 scoped_ptr<base::DictionaryValue> PairingRegistry::Pairing::ToValue() const { | 82 std::unique_ptr<base::DictionaryValue> PairingRegistry::Pairing::ToValue() |
| 83 scoped_ptr<base::DictionaryValue> pairing(new base::DictionaryValue()); | 83 const { |
| 84 std::unique_ptr<base::DictionaryValue> pairing(new base::DictionaryValue()); |
| 84 pairing->SetDouble(kCreatedTimeKey, created_time().ToJsTime()); | 85 pairing->SetDouble(kCreatedTimeKey, created_time().ToJsTime()); |
| 85 pairing->SetString(kClientNameKey, client_name()); | 86 pairing->SetString(kClientNameKey, client_name()); |
| 86 pairing->SetString(kClientIdKey, client_id()); | 87 pairing->SetString(kClientIdKey, client_id()); |
| 87 if (!shared_secret().empty()) | 88 if (!shared_secret().empty()) |
| 88 pairing->SetString(kSharedSecretKey, shared_secret()); | 89 pairing->SetString(kSharedSecretKey, shared_secret()); |
| 89 return pairing; | 90 return pairing; |
| 90 } | 91 } |
| 91 | 92 |
| 92 bool PairingRegistry::Pairing::operator==(const Pairing& other) const { | 93 bool PairingRegistry::Pairing::operator==(const Pairing& other) const { |
| 93 return created_time_ == other.created_time_ && | 94 return created_time_ == other.created_time_ && |
| 94 client_id_ == other.client_id_ && | 95 client_id_ == other.client_id_ && |
| 95 client_name_ == other.client_name_ && | 96 client_name_ == other.client_name_ && |
| 96 shared_secret_ == other.shared_secret_; | 97 shared_secret_ == other.shared_secret_; |
| 97 } | 98 } |
| 98 | 99 |
| 99 bool PairingRegistry::Pairing::is_valid() const { | 100 bool PairingRegistry::Pairing::is_valid() const { |
| 100 // |shared_secret_| is optional. It will be empty on Windows because the | 101 // |shared_secret_| is optional. It will be empty on Windows because the |
| 101 // privileged registry key can only be read in the elevated host process. | 102 // privileged registry key can only be read in the elevated host process. |
| 102 return !client_id_.empty(); | 103 return !client_id_.empty(); |
| 103 } | 104 } |
| 104 | 105 |
| 105 PairingRegistry::PairingRegistry( | 106 PairingRegistry::PairingRegistry( |
| 106 scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner, | 107 scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner, |
| 107 scoped_ptr<Delegate> delegate) | 108 std::unique_ptr<Delegate> delegate) |
| 108 : caller_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 109 : caller_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 109 delegate_task_runner_(delegate_task_runner), | 110 delegate_task_runner_(delegate_task_runner), |
| 110 delegate_(std::move(delegate)) { | 111 delegate_(std::move(delegate)) { |
| 111 DCHECK(delegate_); | 112 DCHECK(delegate_); |
| 112 } | 113 } |
| 113 | 114 |
| 114 PairingRegistry::Pairing PairingRegistry::CreatePairing( | 115 PairingRegistry::Pairing PairingRegistry::CreatePairing( |
| 115 const std::string& client_name) { | 116 const std::string& client_name) { |
| 116 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 117 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 117 | 118 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 this, DoneCallback()); | 188 this, DoneCallback()); |
| 188 base::Closure request = base::Bind( | 189 base::Closure request = base::Bind( |
| 189 &PairingRegistry::DoSave, this, pairing, wrapped_callback); | 190 &PairingRegistry::DoSave, this, pairing, wrapped_callback); |
| 190 ServiceOrQueueRequest(request); | 191 ServiceOrQueueRequest(request); |
| 191 } | 192 } |
| 192 | 193 |
| 193 void PairingRegistry::DoLoadAll( | 194 void PairingRegistry::DoLoadAll( |
| 194 const protocol::PairingRegistry::GetAllPairingsCallback& callback) { | 195 const protocol::PairingRegistry::GetAllPairingsCallback& callback) { |
| 195 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 196 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
| 196 | 197 |
| 197 scoped_ptr<base::ListValue> pairings = delegate_->LoadAll(); | 198 std::unique_ptr<base::ListValue> pairings = delegate_->LoadAll(); |
| 198 PostTask(caller_task_runner_, FROM_HERE, base::Bind(callback, | 199 PostTask(caller_task_runner_, FROM_HERE, base::Bind(callback, |
| 199 base::Passed(&pairings))); | 200 base::Passed(&pairings))); |
| 200 } | 201 } |
| 201 | 202 |
| 202 void PairingRegistry::DoDeleteAll( | 203 void PairingRegistry::DoDeleteAll( |
| 203 const protocol::PairingRegistry::DoneCallback& callback) { | 204 const protocol::PairingRegistry::DoneCallback& callback) { |
| 204 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 205 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
| 205 | 206 |
| 206 bool success = delegate_->DeleteAll(); | 207 bool success = delegate_->DeleteAll(); |
| 207 PostTask(caller_task_runner_, FROM_HERE, base::Bind(callback, success)); | 208 PostTask(caller_task_runner_, FROM_HERE, base::Bind(callback, success)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 247 |
| 247 void PairingRegistry::InvokeGetPairingCallbackAndScheduleNext( | 248 void PairingRegistry::InvokeGetPairingCallbackAndScheduleNext( |
| 248 const GetPairingCallback& callback, Pairing pairing) { | 249 const GetPairingCallback& callback, Pairing pairing) { |
| 249 callback.Run(pairing); | 250 callback.Run(pairing); |
| 250 pending_requests_.pop(); | 251 pending_requests_.pop(); |
| 251 ServiceNextRequest(); | 252 ServiceNextRequest(); |
| 252 } | 253 } |
| 253 | 254 |
| 254 void PairingRegistry::InvokeGetAllPairingsCallbackAndScheduleNext( | 255 void PairingRegistry::InvokeGetAllPairingsCallbackAndScheduleNext( |
| 255 const GetAllPairingsCallback& callback, | 256 const GetAllPairingsCallback& callback, |
| 256 scoped_ptr<base::ListValue> pairings) { | 257 std::unique_ptr<base::ListValue> pairings) { |
| 257 callback.Run(std::move(pairings)); | 258 callback.Run(std::move(pairings)); |
| 258 pending_requests_.pop(); | 259 pending_requests_.pop(); |
| 259 ServiceNextRequest(); | 260 ServiceNextRequest(); |
| 260 } | 261 } |
| 261 | 262 |
| 262 void PairingRegistry::SanitizePairings(const GetAllPairingsCallback& callback, | 263 void PairingRegistry::SanitizePairings( |
| 263 scoped_ptr<base::ListValue> pairings) { | 264 const GetAllPairingsCallback& callback, |
| 265 std::unique_ptr<base::ListValue> pairings) { |
| 264 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 266 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 265 | 267 |
| 266 scoped_ptr<base::ListValue> sanitized_pairings(new base::ListValue()); | 268 std::unique_ptr<base::ListValue> sanitized_pairings(new base::ListValue()); |
| 267 for (size_t i = 0; i < pairings->GetSize(); ++i) { | 269 for (size_t i = 0; i < pairings->GetSize(); ++i) { |
| 268 base::DictionaryValue* pairing_json; | 270 base::DictionaryValue* pairing_json; |
| 269 if (!pairings->GetDictionary(i, &pairing_json)) { | 271 if (!pairings->GetDictionary(i, &pairing_json)) { |
| 270 LOG(WARNING) << "A pairing entry is not a dictionary."; | 272 LOG(WARNING) << "A pairing entry is not a dictionary."; |
| 271 continue; | 273 continue; |
| 272 } | 274 } |
| 273 | 275 |
| 274 // Parse the pairing data. | 276 // Parse the pairing data. |
| 275 Pairing pairing = Pairing::CreateFromValue(*pairing_json); | 277 Pairing pairing = Pairing::CreateFromValue(*pairing_json); |
| 276 if (!pairing.is_valid()) { | 278 if (!pairing.is_valid()) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 300 | 302 |
| 301 void PairingRegistry::ServiceNextRequest() { | 303 void PairingRegistry::ServiceNextRequest() { |
| 302 if (pending_requests_.empty()) | 304 if (pending_requests_.empty()) |
| 303 return; | 305 return; |
| 304 | 306 |
| 305 PostTask(delegate_task_runner_, FROM_HERE, pending_requests_.front()); | 307 PostTask(delegate_task_runner_, FROM_HERE, pending_requests_.front()); |
| 306 } | 308 } |
| 307 | 309 |
| 308 } // namespace protocol | 310 } // namespace protocol |
| 309 } // namespace remoting | 311 } // namespace remoting |
| OLD | NEW |