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

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

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: rebased 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
« no previous file with comments | « remoting/protocol/protocol_mock_objects.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "remoting/protocol/protocol_mock_objects.h" 5 #include "remoting/protocol/protocol_mock_objects.h"
6 6
7 #include "base/logging.h"
8 #include "base/thread_task_runner_handle.h"
9
7 namespace remoting { 10 namespace remoting {
8 namespace protocol { 11 namespace protocol {
9 12
10 MockConnectionToClient::MockConnectionToClient( 13 MockConnectionToClient::MockConnectionToClient(
11 Session* session, 14 Session* session,
12 HostStub* host_stub) 15 HostStub* host_stub)
13 : ConnectionToClient(session) { 16 : ConnectionToClient(session) {
14 set_host_stub(host_stub); 17 set_host_stub(host_stub);
15 } 18 }
16 19
(...skipping 24 matching lines...) Expand all
41 MockVideoStub::~MockVideoStub() {} 44 MockVideoStub::~MockVideoStub() {}
42 45
43 MockSession::MockSession() {} 46 MockSession::MockSession() {}
44 47
45 MockSession::~MockSession() {} 48 MockSession::~MockSession() {}
46 49
47 MockSessionManager::MockSessionManager() {} 50 MockSessionManager::MockSessionManager() {}
48 51
49 MockSessionManager::~MockSessionManager() {} 52 MockSessionManager::~MockSessionManager() {}
50 53
51 MockPairingRegistryDelegate::MockPairingRegistryDelegate() 54 MockPairingRegistryDelegate::MockPairingRegistryDelegate() {
52 : run_save_callback_automatically_(true) {
53 } 55 }
54 56
55 MockPairingRegistryDelegate::~MockPairingRegistryDelegate() { 57 MockPairingRegistryDelegate::~MockPairingRegistryDelegate() {
56 } 58 }
57 59
58 void MockPairingRegistryDelegate::Save( 60 scoped_ptr<base::ListValue> MockPairingRegistryDelegate::LoadAll() {
59 const std::string& pairings_json, 61 scoped_ptr<base::ListValue> result(new base::ListValue());
60 const PairingRegistry::SaveCallback& callback) { 62 for (Pairings::const_iterator i = pairings_.begin(); i != pairings_.end();
61 EXPECT_TRUE(load_callback_.is_null()); 63 ++i) {
62 EXPECT_TRUE(save_callback_.is_null()); 64 result->Append(i->second.ToValue().release());
63 if (run_save_callback_automatically_) { 65 }
64 SetPairingsJsonAndRunCallback(pairings_json, callback); 66 return result.Pass();
67 }
68
69 bool MockPairingRegistryDelegate::DeleteAll() {
70 pairings_.clear();
71 return true;
72 }
73
74 protocol::PairingRegistry::Pairing MockPairingRegistryDelegate::Load(
75 const std::string& client_id) {
76 Pairings::const_iterator i = pairings_.find(client_id);
77 if (i != pairings_.end()) {
78 return i->second;
65 } else { 79 } else {
66 save_callback_ = base::Bind( 80 return protocol::PairingRegistry::Pairing();
67 &MockPairingRegistryDelegate::SetPairingsJsonAndRunCallback,
68 base::Unretained(this), pairings_json, callback);
69 } 81 }
70 } 82 }
71 83
72 void MockPairingRegistryDelegate::SetPairingsJsonAndRunCallback( 84 bool MockPairingRegistryDelegate::Save(
73 const std::string& pairings_json, 85 const protocol::PairingRegistry::Pairing& pairing) {
74 const PairingRegistry::SaveCallback& callback) { 86 pairings_[pairing.client_id()] = pairing;
75 pairings_json_ = pairings_json; 87 return true;
76 if (!callback.is_null()) {
77 callback.Run(true);
78 }
79 } 88 }
80 89
81 void MockPairingRegistryDelegate::Load( 90 bool MockPairingRegistryDelegate::Delete(const std::string& client_id) {
82 const PairingRegistry::LoadCallback& callback) { 91 pairings_.erase(client_id);
83 EXPECT_TRUE(load_callback_.is_null()); 92 return true;
84 EXPECT_TRUE(save_callback_.is_null());
85 load_callback_ = base::Bind(callback, pairings_json_);
86 } 93 }
87 94
88 void MockPairingRegistryDelegate::RunCallback() { 95 SynchronousPairingRegistry::SynchronousPairingRegistry(
89 if (!load_callback_.is_null()) { 96 scoped_ptr<Delegate> delegate)
90 EXPECT_TRUE(save_callback_.is_null()); 97 : PairingRegistry(base::ThreadTaskRunnerHandle::Get(), delegate.Pass()) {
91 base::Closure load_callback = load_callback_; 98 }
92 load_callback_.Reset(); 99
93 load_callback.Run(); 100 SynchronousPairingRegistry::~SynchronousPairingRegistry() {
94 } else if (!save_callback_.is_null()) { 101 }
95 EXPECT_TRUE(load_callback_.is_null()); 102
96 base::Closure save_callback = save_callback_; 103 void SynchronousPairingRegistry::PostTask(
97 save_callback_.Reset(); 104 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
98 save_callback.Run(); 105 const tracked_objects::Location& from_here,
99 } else { 106 const base::Closure& task) {
100 ADD_FAILURE() << "RunCallback called without any callbacks set."; 107 DCHECK(task_runner->BelongsToCurrentThread());
101 } 108 task.Run();
102 } 109 }
103 110
104 } // namespace protocol 111 } // namespace protocol
105 } // namespace remoting 112 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/protocol_mock_objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698