Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: remoting/protocol/pairing_registry.h

Issue 19714002: Add serialization to PairingRegistry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 // Private implementation functions for each of the public methods. These
135 // are queued as closures by the corresponding public method if there is
136 // a request being serviced when it is called. The |callback| parameters
137 // include the original caller-supplied callback wrapped in one of the
138 // Invoke*CallbackAndScheduleNext methods defined below.
139 void SavePairingAndScheduleNext(Pairing pairing,
Jamie 2013/07/18 00:15:07 I'm not convinced by the naming of these methods.
140 const SaveCallback& callback);
141 void GetPairingAndScheduleNext(const std::string& client_id,
142 const GetPairingCallback& callback);
143 void GetAllPairingsAndScheduleNext(const GetAllPairingsCallback& callback);
144 void DeletePairingAndScheduleNext(const std::string& client_id,
145 const SaveCallback& callback);
146 void ClearAllPairingsAndScheduleNext(const SaveCallback& callback);
147
148 // Worker functions for each of the public methods, passed as a callback to
149 // the delegate.
131 void MergePairingAndSave(const Pairing& pairing, 150 void MergePairingAndSave(const Pairing& pairing,
151 const SaveCallback& callback,
132 const std::string& pairings_json); 152 const std::string& pairings_json);
133 void DoGetPairing(const std::string& client_id, 153 void DoGetPairing(const std::string& client_id,
134 const GetPairingCallback& callback, 154 const GetPairingCallback& callback,
135 const std::string& pairings_json); 155 const std::string& pairings_json);
136 void SanitizePairings(const GetAllPairingsCallback& callback, 156 void SanitizePairings(const GetAllPairingsCallback& callback,
137 const std::string& pairings_json); 157 const std::string& pairings_json);
138 void DoDeletePairing(const std::string& client_id, 158 void DoDeletePairing(const std::string& client_id,
139 const SaveCallback& callback, 159 const SaveCallback& callback,
140 const std::string& pairings_json); 160 const std::string& pairings_json);
141 161
162 // "Trampoline" callbacks that schedule the next pending request and then
163 // invoke the original caller-supplied callback.
164 void InvokeLoadCallbackAndScheduleNext(
165 const LoadCallback& callback, const std::string& pairings_json);
166 void InvokeSaveCallbackAndScheduleNext(
167 const SaveCallback& callback, bool success);
168 void InvokeGetPairingCallbackAndScheduleNext(
169 const GetPairingCallback& callback, Pairing pairing);
170 void InvokeGetAllPairingsCallbackAndScheduleNext(
171 const GetAllPairingsCallback& callback,
172 scoped_ptr<base::ListValue> pairings);
173
174 // Queue management methods.
175 void ServiceOrQueueRequest(const base::Closure& request);
176 void ServiceNextRequest();
177
142 // Translate between the structured and serialized forms of the pairing data. 178 // Translate between the structured and serialized forms of the pairing data.
143 static PairedClients DecodeJson(const std::string& pairings_json); 179 static PairedClients DecodeJson(const std::string& pairings_json);
144 static std::string EncodeJson(const PairedClients& clients); 180 static std::string EncodeJson(const PairedClients& clients);
145 static scoped_ptr<base::ListValue> ConvertToListValue( 181 static scoped_ptr<base::ListValue> ConvertToListValue(
146 const PairedClients& clients, 182 const PairedClients& clients,
147 bool include_shared_secrets); 183 bool include_shared_secrets);
148 184
149 scoped_ptr<Delegate> delegate_; 185 scoped_ptr<Delegate> delegate_;
150 186
187 std::queue<base::Closure> pending_requests_;
188 bool servicing_request_;
Lambros 2013/07/18 20:34:51 Suggestion: if you keep the currently-serviced req
Jamie 2013/07/18 22:44:56 Done.
189
151 DISALLOW_COPY_AND_ASSIGN(PairingRegistry); 190 DISALLOW_COPY_AND_ASSIGN(PairingRegistry);
152 }; 191 };
153 192
154 } // namespace protocol 193 } // namespace protocol
155 } // namespace remoting 194 } // namespace remoting
156 195
157 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ 196 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/protocol/pairing_registry.cc » ('j') | remoting/protocol/pairing_registry_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698