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

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

Issue 21128006: Refactored PairingRegistry::Delegate such that it can retrieve/modify for a single client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_PROTOCOL_MOCK_OBJECTS_H_ 5 #ifndef REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_
6 #define REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_ 6 #define REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_
7 7
8 #include <map>
8 #include <string> 9 #include <string>
9 10
11 #include "base/values.h"
10 #include "net/base/ip_endpoint.h" 12 #include "net/base/ip_endpoint.h"
11 #include "remoting/proto/internal.pb.h" 13 #include "remoting/proto/internal.pb.h"
12 #include "remoting/proto/video.pb.h" 14 #include "remoting/proto/video.pb.h"
13 #include "remoting/protocol/authenticator.h" 15 #include "remoting/protocol/authenticator.h"
14 #include "remoting/protocol/client_stub.h" 16 #include "remoting/protocol/client_stub.h"
15 #include "remoting/protocol/clipboard_stub.h" 17 #include "remoting/protocol/clipboard_stub.h"
16 #include "remoting/protocol/connection_to_client.h" 18 #include "remoting/protocol/connection_to_client.h"
17 #include "remoting/protocol/host_stub.h" 19 #include "remoting/protocol/host_stub.h"
18 #include "remoting/protocol/input_stub.h" 20 #include "remoting/protocol/input_stub.h"
19 #include "remoting/protocol/pairing_registry.h" 21 #include "remoting/protocol/pairing_registry.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 private: 206 private:
205 DISALLOW_COPY_AND_ASSIGN(MockSessionManager); 207 DISALLOW_COPY_AND_ASSIGN(MockSessionManager);
206 }; 208 };
207 209
208 // Simple delegate that caches information on paired clients in memory. 210 // Simple delegate that caches information on paired clients in memory.
209 class MockPairingRegistryDelegate : public PairingRegistry::Delegate { 211 class MockPairingRegistryDelegate : public PairingRegistry::Delegate {
210 public: 212 public:
211 MockPairingRegistryDelegate(); 213 MockPairingRegistryDelegate();
212 virtual ~MockPairingRegistryDelegate(); 214 virtual ~MockPairingRegistryDelegate();
213 215
214 const std::string& pairings_json() const { 216 // PairingRegistry::Delegate implementation.
215 return pairings_json_; 217 virtual void LoadAll(
216 } 218 const protocol::PairingRegistry::GetAllPairingsCallback& callback)
219 OVERRIDE;
220 virtual void DeleteAll(
221 const protocol::PairingRegistry::DoneCallback& callback) OVERRIDE;
222 virtual void Load(
223 const std::string& client_id,
224 const protocol::PairingRegistry::GetPairingCallback& callback) OVERRIDE;
225 virtual void Save(
226 const protocol::PairingRegistry::Pairing& pairing,
227 const protocol::PairingRegistry::DoneCallback& callback) OVERRIDE;
228 virtual void Delete(
229 const std::string& client_id,
230 const protocol::PairingRegistry::DoneCallback& callback) OVERRIDE;
217 231
218 // PairingRegistry::Delegate implementation. 232 // Run |pending_callback_| if set. Keeps running until |pending_callback_| is
219 virtual void Save( 233 // not set. This is needed for the case when a callback in turn sets
220 const std::string& pairings_json, 234 // |pending_callback_|.
221 const PairingRegistry::SaveCallback& callback) OVERRIDE; 235 void DrainCallbacks();
222 virtual void Load(
223 const PairingRegistry::LoadCallback& callback) OVERRIDE;
224
225 // By default, the Save method runs its callback automatically because the
226 // negotiating authenticator unit test does not provide any hooks to do it
227 // manually. For unit tests that need to verify correct behaviour under
228 // asynchronous conditions, use this method to disable this feature and call
229 // RunCallback as appropriate.
230 void set_run_save_callback_automatically(
231 bool run_save_callback_automatically) {
232 run_save_callback_automatically_ = run_save_callback_automatically;
233 }
234
235 bool HasCallback() const {
236 return !load_callback_.is_null() || !save_callback_.is_null();
237 }
238
239 // Run either the save or the load callback (whichever was set most recently;
240 // it is an error for both of these to be set at the same time).
241 void RunCallback();
242 236
243 private: 237 private:
244 void SetPairingsJsonAndRunCallback( 238 void DoLoadAll(
245 const std::string& pairings_json, 239 const protocol::PairingRegistry::GetAllPairingsCallback& callback);
246 const PairingRegistry::SaveCallback& callback); 240 void DoDeleteAll(
241 const protocol::PairingRegistry::DoneCallback& callback);
242 void DoLoad(
243 const std::string& client_id,
244 const protocol::PairingRegistry::GetPairingCallback& callback);
245 void DoSave(
246 const protocol::PairingRegistry::Pairing& pairing,
247 const protocol::PairingRegistry::DoneCallback& callback);
248 void DoDelete(
249 const std::string& client_id,
250 const protocol::PairingRegistry::DoneCallback& callback);
247 251
248 base::Closure load_callback_; 252 base::Closure pending_callback_;
249 base::Closure save_callback_; 253
250 std::string pairings_json_; 254 typedef std::map<std::string, protocol::PairingRegistry::Pairing> Pairings;
251 bool run_save_callback_automatically_; 255 Pairings pairings_;
252 }; 256 };
253 257
254 } // namespace protocol 258 } // namespace protocol
255 } // namespace remoting 259 } // namespace remoting
256 260
257 #endif // REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_ 261 #endif // REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698