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 <queue> |
9 #include <string> | 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/callback.h" | 13 #include "base/callback.h" |
13 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
16 #include "base/threading/non_thread_safe.h" | 17 #include "base/threading/non_thread_safe.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 | 19 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 void ClearAllPairings(const SaveCallback& callback); | 121 void ClearAllPairings(const SaveCallback& callback); |
121 | 122 |
122 private: | 123 private: |
123 FRIEND_TEST_ALL_PREFIXES(PairingRegistryTest, AddPairing); | 124 FRIEND_TEST_ALL_PREFIXES(PairingRegistryTest, AddPairing); |
124 FRIEND_TEST_ALL_PREFIXES(PairingRegistryTest, GetAllPairingsJSON); | 125 FRIEND_TEST_ALL_PREFIXES(PairingRegistryTest, GetAllPairingsJSON); |
125 friend class NegotiatingAuthenticatorTest; | 126 friend class NegotiatingAuthenticatorTest; |
126 friend class base::RefCountedThreadSafe<PairingRegistry>; | 127 friend class base::RefCountedThreadSafe<PairingRegistry>; |
127 | 128 |
128 virtual ~PairingRegistry(); | 129 virtual ~PairingRegistry(); |
129 | 130 |
| 131 // Helper method for unit tests. |
130 void AddPairing(const Pairing& pairing); | 132 void AddPairing(const Pairing& pairing); |
| 133 |
| 134 // Worker functions for each of the public methods, passed as a callback to |
| 135 // the delegate. |
131 void MergePairingAndSave(const Pairing& pairing, | 136 void MergePairingAndSave(const Pairing& pairing, |
| 137 const SaveCallback& callback, |
132 const std::string& pairings_json); | 138 const std::string& pairings_json); |
133 void DoGetPairing(const std::string& client_id, | 139 void DoGetPairing(const std::string& client_id, |
134 const GetPairingCallback& callback, | 140 const GetPairingCallback& callback, |
135 const std::string& pairings_json); | 141 const std::string& pairings_json); |
136 void SanitizePairings(const GetAllPairingsCallback& callback, | 142 void SanitizePairings(const GetAllPairingsCallback& callback, |
137 const std::string& pairings_json); | 143 const std::string& pairings_json); |
138 void DoDeletePairing(const std::string& client_id, | 144 void DoDeletePairing(const std::string& client_id, |
139 const SaveCallback& callback, | 145 const SaveCallback& callback, |
140 const std::string& pairings_json); | 146 const std::string& pairings_json); |
141 | 147 |
| 148 // "Trampoline" callbacks that schedule the next pending request and then |
| 149 // invoke the original caller-supplied callback. |
| 150 void InvokeLoadCallbackAndScheduleNext( |
| 151 const LoadCallback& callback, const std::string& pairings_json); |
| 152 void InvokeSaveCallbackAndScheduleNext( |
| 153 const SaveCallback& callback, bool success); |
| 154 void InvokeGetPairingCallbackAndScheduleNext( |
| 155 const GetPairingCallback& callback, Pairing pairing); |
| 156 void InvokeGetAllPairingsCallbackAndScheduleNext( |
| 157 const GetAllPairingsCallback& callback, |
| 158 scoped_ptr<base::ListValue> pairings); |
| 159 |
| 160 // Queue management methods. |
| 161 void ServiceOrQueueRequest(const base::Closure& request); |
| 162 void ServiceNextRequest(); |
| 163 |
142 // Translate between the structured and serialized forms of the pairing data. | 164 // Translate between the structured and serialized forms of the pairing data. |
143 static PairedClients DecodeJson(const std::string& pairings_json); | 165 static PairedClients DecodeJson(const std::string& pairings_json); |
144 static std::string EncodeJson(const PairedClients& clients); | 166 static std::string EncodeJson(const PairedClients& clients); |
145 static scoped_ptr<base::ListValue> ConvertToListValue( | 167 static scoped_ptr<base::ListValue> ConvertToListValue( |
146 const PairedClients& clients, | 168 const PairedClients& clients, |
147 bool include_shared_secrets); | 169 bool include_shared_secrets); |
148 | 170 |
149 scoped_ptr<Delegate> delegate_; | 171 scoped_ptr<Delegate> delegate_; |
150 | 172 |
| 173 std::queue<base::Closure> pending_requests_; |
| 174 |
151 DISALLOW_COPY_AND_ASSIGN(PairingRegistry); | 175 DISALLOW_COPY_AND_ASSIGN(PairingRegistry); |
152 }; | 176 }; |
153 | 177 |
154 } // namespace protocol | 178 } // namespace protocol |
155 } // namespace remoting | 179 } // namespace remoting |
156 | 180 |
157 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ | 181 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ |
OLD | NEW |