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. |
rmsousa
2013/06/13 04:26:19
This interface isn't safe anymore, now that there
Jamie
2013/06/13 17:22:15
The client will never show pairing information, on
| |
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 found, | |
52 // invoke the callback with a callback in which the client_id is empty. | |
rmsousa
2013/06/13 04:26:19
nit: it says client_id is empty in the description
Jamie
2013/06/13 17:22:15
Done.
| |
53 virtual void GetPairing(const std::string& client_id, | |
54 const GetPairingCallback& callback) = 0; | |
47 }; | 55 }; |
48 | 56 |
49 explicit PairingRegistry(scoped_ptr<Delegate> delegate, | 57 explicit PairingRegistry(scoped_ptr<Delegate> delegate); |
50 const PairedClients& paired_clients); | |
51 | 58 |
52 // Create a pairing for a new client and save it to disk. | 59 // Create a pairing for a new client and save it to disk. |
53 const Pairing& CreatePairing(const std::string& client_name); | 60 Pairing CreatePairing(const std::string& client_name); |
54 | 61 |
55 // Look up the shared secret for the specified client id. Returns an empty | 62 // Get the pairing for the specified client id. See the corresponding |
56 // string if the client id is not known. | 63 // Delegate method for details. |
57 std::string GetSecret(const std::string &client_id) const; | 64 void GetPairing(const std::string& client_id, |
65 const GetPairingCallback& callback); | |
58 | 66 |
59 private: | 67 private: |
60 friend class base::RefCountedThreadSafe<PairingRegistry>; | 68 friend class base::RefCountedThreadSafe<PairingRegistry>; |
61 | 69 |
62 virtual ~PairingRegistry(); | 70 virtual ~PairingRegistry(); |
63 | 71 |
64 scoped_ptr<Delegate> delegate_; | 72 scoped_ptr<Delegate> delegate_; |
65 PairedClients paired_clients_; | |
66 | 73 |
67 DISALLOW_COPY_AND_ASSIGN(PairingRegistry); | 74 DISALLOW_COPY_AND_ASSIGN(PairingRegistry); |
68 }; | 75 }; |
69 | 76 |
70 // Temporary delegate that just logs NOTIMPLEMENTED for Load/Save. | 77 // Temporary delegate that just logs NOTIMPLEMENTED for Load/Save. |
71 // TODO(jamiewalch): Delete once Delegates are implemented for all platforms. | 78 // TODO(jamiewalch): Delete once Delegates are implemented for all platforms. |
72 class NotImplementedPairingRegistryDelegate : public PairingRegistry::Delegate { | 79 class NotImplementedPairingRegistryDelegate : public PairingRegistry::Delegate { |
73 public: | 80 public: |
74 virtual void Save( | 81 virtual void AddPairing( |
75 const PairingRegistry::PairedClients& paired_clients) OVERRIDE; | 82 const PairingRegistry::Pairing& paired_clients) OVERRIDE; |
83 virtual void GetPairing( | |
84 const std::string& client_id, | |
85 const PairingRegistry::GetPairingCallback& callback) OVERRIDE; | |
76 }; | 86 }; |
77 | 87 |
78 } // namespace protocol | 88 } // namespace protocol |
79 } // namespace remoting | 89 } // namespace remoting |
80 | 90 |
81 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ | 91 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ |
OLD | NEW |