15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "remoting/protocol/protocol_mock_objects.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/logging.h"
8a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/thread_task_runner_handle.h"
9a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace remoting {
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace protocol {
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockConnectionToClient::MockConnectionToClient(
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Session* session,
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    HostStub* host_stub)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : ConnectionToClient(session) {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  set_host_stub(host_stub);
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockConnectionToClient::~MockConnectionToClient() {}
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockConnectionToClientEventHandler::MockConnectionToClientEventHandler() {}
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockConnectionToClientEventHandler::~MockConnectionToClientEventHandler() {}
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockClipboardStub::MockClipboardStub() {}
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockClipboardStub::~MockClipboardStub() {}
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockInputStub::MockInputStub() {}
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockInputStub::~MockInputStub() {}
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockHostStub::MockHostStub() {}
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockHostStub::~MockHostStub() {}
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockClientStub::MockClientStub() {}
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockClientStub::~MockClientStub() {}
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockVideoStub::MockVideoStub() {}
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockVideoStub::~MockVideoStub() {}
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockSession::MockSession() {}
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockSession::~MockSession() {}
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockSessionManager::MockSessionManager() {}
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockSessionManager::~MockSessionManager() {}
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
54a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)MockPairingRegistryDelegate::MockPairingRegistryDelegate() {
557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)MockPairingRegistryDelegate::~MockPairingRegistryDelegate() {
587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
60a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)scoped_ptr<base::ListValue> MockPairingRegistryDelegate::LoadAll() {
61a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  scoped_ptr<base::ListValue> result(new base::ListValue());
62a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  for (Pairings::const_iterator i = pairings_.begin(); i != pairings_.end();
63a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)       ++i) {
64a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    result->Append(i->second.ToValue().release());
65ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  }
66a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  return result.Pass();
67a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
68a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
69a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)bool MockPairingRegistryDelegate::DeleteAll() {
70a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  pairings_.clear();
71a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  return true;
72ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch}
73ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
74a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)protocol::PairingRegistry::Pairing MockPairingRegistryDelegate::Load(
75a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    const std::string& client_id) {
76a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  Pairings::const_iterator i = pairings_.find(client_id);
77a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (i != pairings_.end()) {
78a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    return i->second;
79a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  } else {
80a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    return protocol::PairingRegistry::Pairing();
817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
84a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)bool MockPairingRegistryDelegate::Save(
85a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    const protocol::PairingRegistry::Pairing& pairing) {
86a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  pairings_[pairing.client_id()] = pairing;
87a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  return true;
887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
90a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)bool MockPairingRegistryDelegate::Delete(const std::string& client_id) {
91a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  pairings_.erase(client_id);
92a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  return true;
93a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
94a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
95a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)SynchronousPairingRegistry::SynchronousPairingRegistry(
96a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    scoped_ptr<Delegate> delegate)
97a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    : PairingRegistry(base::ThreadTaskRunnerHandle::Get(), delegate.Pass()) {
98a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
99a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
100a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)SynchronousPairingRegistry::~SynchronousPairingRegistry() {
101a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
102a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
103a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)void SynchronousPairingRegistry::PostTask(
104a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
105a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    const tracked_objects::Location& from_here,
106a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    const base::Closure& task) {
107a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  DCHECK(task_runner->BelongsToCurrentThread());
108a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  task.Run();
1097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
1107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace protocol
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace remoting
113