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 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 | 16 |
| 17 namespace base { |
| 18 class TaskRunner; |
| 19 } // namespace base |
| 20 |
17 namespace remoting { | 21 namespace remoting { |
18 namespace protocol { | 22 namespace protocol { |
19 | 23 |
20 // TODO(jamiewalch): This class is little more than a wrapper around the | 24 // TODO(jamiewalch): This class is little more than a wrapper around the |
21 // Pairing and Delegate classes. Refactor it away. | 25 // Pairing and Delegate classes. Refactor it away. |
22 | 26 |
23 // PairingRegistry holds information about paired clients to support | 27 // PairingRegistry holds information about paired clients to support |
24 // PIN-less authentication. For each paired client, the registry holds | 28 // PIN-less authentication. For each paired client, the registry holds |
25 // the following information: | 29 // the following information: |
26 // * The name of the client. This is supplied by the client and is not | 30 // * The name of the client. This is supplied by the client and is not |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 const AddPairingCallback& callback) = 0; | 85 const AddPairingCallback& callback) = 0; |
82 | 86 |
83 // Retrieve the Pairing for the specified client id. If none is found, | 87 // Retrieve the Pairing for the specified client id. If none is found, |
84 // invoke the callback with a default pairing. Must not block. | 88 // invoke the callback with a default pairing. Must not block. |
85 virtual void GetPairing(const std::string& client_id, | 89 virtual void GetPairing(const std::string& client_id, |
86 const GetPairingCallback& callback) = 0; | 90 const GetPairingCallback& callback) = 0; |
87 }; | 91 }; |
88 | 92 |
89 explicit PairingRegistry(scoped_ptr<Delegate> delegate); | 93 explicit PairingRegistry(scoped_ptr<Delegate> delegate); |
90 | 94 |
91 // Create a pairing for a new client and save it to disk. | 95 // Creates a pairing for a new client and saves it to disk. |
92 Pairing CreatePairing(const std::string& client_name); | 96 Pairing CreatePairing(const std::string& client_name); |
93 | 97 |
94 // Get the pairing for the specified client id. See the corresponding | 98 // Gets the pairing for the specified client id. See the corresponding |
95 // Delegate method for details. | 99 // Delegate method for details. |
96 void GetPairing(const std::string& client_id, | 100 void GetPairing(const std::string& client_id, |
97 const GetPairingCallback& callback); | 101 const GetPairingCallback& callback); |
98 | 102 |
| 103 // Returns a platform-specific Delegate that will save to permanent storage |
| 104 // using the specified TaskRunner. Returns NULL on platforms that don't |
| 105 // support pairing. |
| 106 static scoped_ptr<Delegate> CreateDelegate( |
| 107 scoped_refptr<base::TaskRunner> task_runner); |
| 108 |
99 private: | 109 private: |
100 friend class base::RefCountedThreadSafe<PairingRegistry>; | 110 friend class base::RefCountedThreadSafe<PairingRegistry>; |
101 | 111 |
102 virtual ~PairingRegistry(); | 112 virtual ~PairingRegistry(); |
103 | 113 |
104 scoped_ptr<Delegate> delegate_; | 114 scoped_ptr<Delegate> delegate_; |
105 | 115 |
106 DISALLOW_COPY_AND_ASSIGN(PairingRegistry); | 116 DISALLOW_COPY_AND_ASSIGN(PairingRegistry); |
107 }; | 117 }; |
108 | 118 |
109 // Temporary delegate that just logs NOTIMPLEMENTED for Load/Save. | |
110 // TODO(jamiewalch): Delete once Delegates are implemented for all platforms. | |
111 class NotImplementedPairingRegistryDelegate : public PairingRegistry::Delegate { | |
112 public: | |
113 virtual void AddPairing( | |
114 const PairingRegistry::Pairing& paired_clients, | |
115 const PairingRegistry::AddPairingCallback& callback) OVERRIDE; | |
116 virtual void GetPairing( | |
117 const std::string& client_id, | |
118 const PairingRegistry::GetPairingCallback& callback) OVERRIDE; | |
119 }; | |
120 | |
121 } // namespace protocol | 119 } // namespace protocol |
122 } // namespace remoting | 120 } // namespace remoting |
123 | 121 |
124 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ | 122 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ |
OLD | NEW |