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 "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 PairingRegistry::Pairing::~Pairing() { | 42 PairingRegistry::Pairing::~Pairing() { |
43 } | 43 } |
44 | 44 |
45 PairingRegistry::Pairing PairingRegistry::Pairing::Create( | 45 PairingRegistry::Pairing PairingRegistry::Pairing::Create( |
46 const std::string& client_name) { | 46 const std::string& client_name) { |
47 base::Time created_time = base::Time::Now(); | 47 base::Time created_time = base::Time::Now(); |
48 std::string client_id = base::GenerateGUID(); | 48 std::string client_id = base::GenerateGUID(); |
49 std::string shared_secret; | 49 std::string shared_secret; |
50 char buffer[kKeySize]; | 50 char buffer[kKeySize]; |
51 crypto::RandBytes(buffer, arraysize(buffer)); | 51 crypto::RandBytes(buffer, arraysize(buffer)); |
52 if (!base::Base64Encode(base::StringPiece(buffer, arraysize(buffer)), | 52 base::Base64Encode(base::StringPiece(buffer, arraysize(buffer)), |
53 &shared_secret)) { | 53 &shared_secret); |
54 LOG(FATAL) << "Base64Encode failed."; | |
55 } | |
56 return Pairing(created_time, client_name, client_id, shared_secret); | 54 return Pairing(created_time, client_name, client_id, shared_secret); |
57 } | 55 } |
58 | 56 |
59 PairingRegistry::Pairing PairingRegistry::Pairing::CreateFromValue( | 57 PairingRegistry::Pairing PairingRegistry::Pairing::CreateFromValue( |
60 const base::DictionaryValue& pairing) { | 58 const base::DictionaryValue& pairing) { |
61 std::string client_name, client_id; | 59 std::string client_name, client_id; |
62 double created_time_value; | 60 double created_time_value; |
63 if (pairing.GetDouble(kCreatedTimeKey, &created_time_value) && | 61 if (pairing.GetDouble(kCreatedTimeKey, &created_time_value) && |
64 pairing.GetString(kClientNameKey, &client_name) && | 62 pairing.GetString(kClientNameKey, &client_name) && |
65 pairing.GetString(kClientIdKey, &client_id)) { | 63 pairing.GetString(kClientIdKey, &client_id)) { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 291 |
294 void PairingRegistry::ServiceNextRequest() { | 292 void PairingRegistry::ServiceNextRequest() { |
295 if (pending_requests_.empty()) | 293 if (pending_requests_.empty()) |
296 return; | 294 return; |
297 | 295 |
298 PostTask(delegate_task_runner_, FROM_HERE, pending_requests_.front()); | 296 PostTask(delegate_task_runner_, FROM_HERE, pending_requests_.front()); |
299 } | 297 } |
300 | 298 |
301 } // namespace protocol | 299 } // namespace protocol |
302 } // namespace remoting | 300 } // namespace remoting |
OLD | NEW |