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 #ifndef REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ | 5 #ifndef REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ |
6 #define REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ | 6 #define REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 public: | 30 public: |
31 struct Pairing { | 31 struct Pairing { |
32 std::string client_id; | 32 std::string client_id; |
33 std::string client_name; | 33 std::string client_name; |
34 std::string shared_secret; | 34 std::string shared_secret; |
35 }; | 35 }; |
36 | 36 |
37 // Mapping from client id to pairing information. | 37 // Mapping from client id to pairing information. |
38 typedef std::map<std::string, Pairing> PairedClients; | 38 typedef std::map<std::string, Pairing> PairedClients; |
39 | 39 |
| 40 // Delegate::GetPairing callback. |
| 41 typedef base::Callback<void(Pairing)> GetPairingCallback; |
| 42 |
40 // Interface representing the persistent storage back-end. | 43 // Interface representing the persistent storage back-end. |
41 class Delegate { | 44 class Delegate { |
42 public: | 45 public: |
43 virtual ~Delegate() {} | 46 virtual ~Delegate() {} |
44 | 47 |
45 // Save pairing information to persistent storage. Must not block. | 48 // Add pairing information to persistent storage. Must not block. |
46 virtual void Save(const PairedClients& paired_clients) = 0; | 49 virtual void AddPairing(const Pairing& new_paired_client) = 0; |
| 50 |
| 51 // Retrieve the Pairing for the specified client id. If none is |
| 52 // found, invoke the callback with a Pairing in which (at least) |
| 53 // the shared_secret is empty. |
| 54 virtual void GetPairing(const std::string& client_id, |
| 55 const GetPairingCallback& callback) = 0; |
47 }; | 56 }; |
48 | 57 |
49 explicit PairingRegistry(scoped_ptr<Delegate> delegate, | 58 explicit PairingRegistry(scoped_ptr<Delegate> delegate); |
50 const PairedClients& paired_clients); | |
51 | 59 |
52 // Create a pairing for a new client and save it to disk. | 60 // Create a pairing for a new client and save it to disk. |
53 const Pairing& CreatePairing(const std::string& client_name); | 61 Pairing CreatePairing(const std::string& client_name); |
54 | 62 |
55 // Look up the shared secret for the specified client id. Returns an empty | 63 // Get the pairing for the specified client id. See the corresponding |
56 // string if the client id is not known. | 64 // Delegate method for details. |
57 std::string GetSecret(const std::string &client_id) const; | 65 void GetPairing(const std::string& client_id, |
| 66 const GetPairingCallback& callback); |
58 | 67 |
59 private: | 68 private: |
60 friend class base::RefCountedThreadSafe<PairingRegistry>; | 69 friend class base::RefCountedThreadSafe<PairingRegistry>; |
61 | 70 |
62 virtual ~PairingRegistry(); | 71 virtual ~PairingRegistry(); |
63 | 72 |
64 scoped_ptr<Delegate> delegate_; | 73 scoped_ptr<Delegate> delegate_; |
65 PairedClients paired_clients_; | |
66 | 74 |
67 DISALLOW_COPY_AND_ASSIGN(PairingRegistry); | 75 DISALLOW_COPY_AND_ASSIGN(PairingRegistry); |
68 }; | 76 }; |
69 | 77 |
70 // Temporary delegate that just logs NOTIMPLEMENTED for Load/Save. | 78 // Temporary delegate that just logs NOTIMPLEMENTED for Load/Save. |
71 // TODO(jamiewalch): Delete once Delegates are implemented for all platforms. | 79 // TODO(jamiewalch): Delete once Delegates are implemented for all platforms. |
72 class NotImplementedPairingRegistryDelegate : public PairingRegistry::Delegate { | 80 class NotImplementedPairingRegistryDelegate : public PairingRegistry::Delegate { |
73 public: | 81 public: |
74 virtual void Save( | 82 virtual void AddPairing( |
75 const PairingRegistry::PairedClients& paired_clients) OVERRIDE; | 83 const PairingRegistry::Pairing& paired_clients) OVERRIDE; |
| 84 virtual void GetPairing( |
| 85 const std::string& client_id, |
| 86 const PairingRegistry::GetPairingCallback& callback) OVERRIDE; |
76 }; | 87 }; |
77 | 88 |
78 } // namespace protocol | 89 } // namespace protocol |
79 } // namespace remoting | 90 } // namespace remoting |
80 | 91 |
81 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ | 92 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ |
OLD | NEW |