summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--remoting/host/clipboard_aura.cc152
-rw-r--r--remoting/host/clipboard_aura.h54
-rw-r--r--remoting/host/clipboard_aura_unittest.cc116
-rw-r--r--remoting/remoting_host.gypi7
-rw-r--r--remoting/remoting_test.gypi2
5 files changed, 1 insertions, 330 deletions
diff --git a/remoting/host/clipboard_aura.cc b/remoting/host/clipboard_aura.cc
deleted file mode 100644
index 2fd3be0..0000000
--- a/remoting/host/clipboard_aura.cc
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "remoting/host/clipboard_aura.h"
-
-#include "base/strings/utf_string_conversions.h"
-#include "base/timer/timer.h"
-#include "content/public/browser/browser_thread.h"
-#include "remoting/base/constants.h"
-#include "remoting/proto/event.pb.h"
-#include "remoting/protocol/clipboard_stub.h"
-#include "ui/base/clipboard/clipboard.h"
-#include "ui/base/clipboard/scoped_clipboard_writer.h"
-
-namespace {
-
-// Clipboard polling interval in milliseconds.
-const int64 kClipboardPollingIntervalMs = 500;
-
-} // namespace
-
-namespace remoting {
-
-class ClipboardAura::Core {
- public:
- Core();
-
- // Mirror the public interface.
- void Start(scoped_ptr<protocol::ClipboardStub> client_clipboard);
- void InjectClipboardEvent(const protocol::ClipboardEvent& event);
- void Stop();
-
- // Overrides the clipboard polling interval for unit test.
- void SetPollingIntervalForTesting(base::TimeDelta polling_interval);
-
- private:
- void CheckClipboardForChanges();
-
- scoped_ptr<protocol::ClipboardStub> client_clipboard_;
- scoped_ptr<base::RepeatingTimer<Core>> clipboard_polling_timer_;
- uint64 current_change_count_;
- base::TimeDelta polling_interval_;
-
- DISALLOW_COPY_AND_ASSIGN(Core);
-};
-
-ClipboardAura::ClipboardAura(
- scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
- : core_(new Core()),
- ui_task_runner_(ui_task_runner) {
-}
-
-ClipboardAura::~ClipboardAura() {
- ui_task_runner_->DeleteSoon(FROM_HERE, core_.release());
-}
-
-void ClipboardAura::Start(
- scoped_ptr<protocol::ClipboardStub> client_clipboard) {
- ui_task_runner_->PostTask(
- FROM_HERE, base::Bind(&Core::Start, base::Unretained(core_.get()),
- base::Passed(&client_clipboard)));
-}
-
-void ClipboardAura::InjectClipboardEvent(
- const protocol::ClipboardEvent& event) {
- ui_task_runner_->PostTask(FROM_HERE,
- base::Bind(&Core::InjectClipboardEvent,
- base::Unretained(core_.get()), event));
-}
-
-void ClipboardAura::Stop() {
- ui_task_runner_->PostTask(
- FROM_HERE, base::Bind(&Core::Stop, base::Unretained(core_.get())));
-};
-
-void ClipboardAura::SetPollingIntervalForTesting(
- base::TimeDelta polling_interval) {
- core_->SetPollingIntervalForTesting(polling_interval);
-}
-
-ClipboardAura::Core::Core()
- : current_change_count_(0),
- polling_interval_(
- base::TimeDelta::FromMilliseconds(kClipboardPollingIntervalMs)) {
-}
-
-void ClipboardAura::Core::Start(
- scoped_ptr<protocol::ClipboardStub> client_clipboard) {
- client_clipboard_.reset(client_clipboard.release());
-
- // Aura doesn't provide a clipboard-changed notification. The only way to
- // detect clipboard changes is by polling.
- clipboard_polling_timer_.reset(new base::RepeatingTimer<Core>());
- clipboard_polling_timer_->Start(
- FROM_HERE, polling_interval_, this,
- &ClipboardAura::Core::CheckClipboardForChanges);
-}
-
-void ClipboardAura::Core::InjectClipboardEvent(
- const protocol::ClipboardEvent& event) {
- // Currently we only handle UTF-8 text.
- if (event.mime_type().compare(kMimeTypeTextUtf8) != 0) {
- return;
- }
-
- ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE);
- clipboard_writer.WriteText(base::UTF8ToUTF16(event.data()));
-
- // Update local change-count to prevent this change from being picked up by
- // CheckClipboardForChanges.
- current_change_count_++;
-}
-
-void ClipboardAura::Core::Stop() {
- clipboard_polling_timer_.reset();
- client_clipboard_.reset();
-}
-
-void ClipboardAura::Core::SetPollingIntervalForTesting(
- base::TimeDelta polling_interval) {
- polling_interval_ = polling_interval;
-}
-
-void ClipboardAura::Core::CheckClipboardForChanges() {
- ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
- uint64 change_count =
- clipboard->GetSequenceNumber(ui::CLIPBOARD_TYPE_COPY_PASTE);
-
- if (change_count == current_change_count_) {
- return;
- }
-
- current_change_count_ = change_count;
-
- protocol::ClipboardEvent event;
- std::string data;
-
- clipboard->ReadAsciiText(ui::CLIPBOARD_TYPE_COPY_PASTE, &data);
- event.set_mime_type(kMimeTypeTextUtf8);
- event.set_data(data);
-
- client_clipboard_->InjectClipboardEvent(event);
-}
-
-scoped_ptr<Clipboard> Clipboard::Create() {
- return make_scoped_ptr(
- new ClipboardAura(content::BrowserThread::GetMessageLoopProxyForThread(
- content::BrowserThread::UI)));
-}
-
-} // namespace remoting
diff --git a/remoting/host/clipboard_aura.h b/remoting/host/clipboard_aura.h
deleted file mode 100644
index 9907fb6d..0000000
--- a/remoting/host/clipboard_aura.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef REMOTING_HOST_CLIPBOARD_AURA_H_
-#define REMOTING_HOST_CLIPBOARD_AURA_H_
-
-#include "base/memory/scoped_ptr.h"
-#include "base/single_thread_task_runner.h"
-#include "remoting/host/clipboard.h"
-
-namespace remoting {
-
-namespace protocol {
-class ClipboardStub;
-} // namespace protocol
-
-// On Chrome OS, the clipboard is managed by aura instead of the underlying
-// native platform (e.g. x11, ozone, etc).
-//
-// This class (1) monitors the aura clipboard for changes and notifies the
-// |client_clipboard|, and (2) provides an interface to inject clipboard event
-// into aura.
-//
-// The public API of this class can be called in any thread as internally it
-// always posts the call to the |ui_task_runner|. On ChromeOS, that should
-// be the UI thread of the browser process.
-//
-class ClipboardAura : public Clipboard {
- public:
- explicit ClipboardAura(
- scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
- ~ClipboardAura() override;
-
- // Clipboard interface.
- void Start(scoped_ptr<protocol::ClipboardStub> client_clipboard) override;
- void InjectClipboardEvent(const protocol::ClipboardEvent& event) override;
- void Stop() override;
-
- // Overrides the clipboard polling interval for unit test.
- void SetPollingIntervalForTesting(base::TimeDelta polling_interval);
-
- private:
- class Core;
-
- scoped_ptr<Core> core_;
- scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
-
- DISALLOW_COPY_AND_ASSIGN(ClipboardAura);
-};
-
-} // namespace remoting
-
-#endif // REMOTING_HOST_CLIPBOARD_AURA_H_
diff --git a/remoting/host/clipboard_aura_unittest.cc b/remoting/host/clipboard_aura_unittest.cc
deleted file mode 100644
index fda6567..0000000
--- a/remoting/host/clipboard_aura_unittest.cc
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "remoting/host/clipboard_aura.h"
-
-#include "base/bind.h"
-#include "base/bind_helpers.h"
-#include "base/message_loop/message_loop.h"
-#include "base/run_loop.h"
-#include "base/strings/utf_string_conversions.h"
-#include "base/test/test_timeouts.h"
-#include "remoting/base/constants.h"
-#include "remoting/proto/event.pb.h"
-#include "remoting/protocol/clipboard_stub.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/base/clipboard/clipboard.h"
-#include "ui/base/clipboard/scoped_clipboard_writer.h"
-
-using testing::_;
-using testing::Eq;
-using testing::InvokeWithoutArgs;
-using testing::Property;
-
-namespace remoting {
-
-namespace {
-
-const base::TimeDelta kTestOverridePollingInterval =
- base::TimeDelta::FromMilliseconds(1);
-
-class ClientClipboard : public protocol::ClipboardStub {
- public:
- ClientClipboard();
- MOCK_METHOD1(InjectClipboardEvent,
- void(const protocol::ClipboardEvent& event));
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ClientClipboard);
-};
-
-ClientClipboard::ClientClipboard() {
-}
-
-} // namespace
-
-class ClipboardAuraTest : public testing::Test {
- public:
- ClipboardAuraTest() {}
- void SetUp() override;
-
- protected:
- base::MessageLoopForUI message_loop_;
- base::RunLoop run_loop_;
- ClientClipboard* client_clipboard_;
- scoped_ptr<ClipboardAura> clipboard_;
-};
-
-void ClipboardAuraTest::SetUp() {
- // Alert the clipboard class to which threads are allowed to access the
- // clipboard.
- std::vector<base::PlatformThreadId> allowed_clipboard_threads;
- allowed_clipboard_threads.push_back(base::PlatformThread::CurrentId());
- ui::Clipboard::SetAllowedThreads(allowed_clipboard_threads);
-
- // Setup the clipboard.
- scoped_refptr<base::SingleThreadTaskRunner> task_runner =
- message_loop_.message_loop_proxy();
- client_clipboard_ = new ClientClipboard();
- clipboard_.reset(new ClipboardAura(task_runner));
- clipboard_->Start(make_scoped_ptr(client_clipboard_));
-
- EXPECT_GT(TestTimeouts::tiny_timeout(), kTestOverridePollingInterval * 10)
- << "The test timeout should be greater than the polling interval";
- clipboard_->SetPollingIntervalForTesting(kTestOverridePollingInterval);
-}
-
-TEST_F(ClipboardAuraTest, WriteToClipboard) {
- protocol::ClipboardEvent event;
- event.set_mime_type(kMimeTypeTextUtf8);
- event.set_data("Test data.");
-
- clipboard_->InjectClipboardEvent(event);
- clipboard_->Stop();
- run_loop_.RunUntilIdle();
-
- std::string clipboard_data;
- ui::Clipboard* aura_clipboard = ui::Clipboard::GetForCurrentThread();
- aura_clipboard->ReadAsciiText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_data);
-
- EXPECT_EQ(clipboard_data, "Test data.")
- << "InjectClipboardEvent should write to aura clipboard";
-}
-
-TEST_F(ClipboardAuraTest, MonitorClipboardChanges) {
- {
- // |clipboard_writer| will write to the clipboard when it goes out of scope.
- ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE);
- clipboard_writer.WriteText(base::UTF8ToUTF16("Test data."));
- }
-
- EXPECT_CALL(*client_clipboard_,
- InjectClipboardEvent(Property(&protocol::ClipboardEvent::data,
- Eq("Test data.")))).Times(1);
-
- message_loop_.PostDelayedTask(
- FROM_HERE,
- base::Bind(&ClipboardAura::Stop, base::Unretained(clipboard_.get())),
- TestTimeouts::tiny_timeout());
- message_loop_.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(),
- TestTimeouts::tiny_timeout());
- message_loop_.Run();
-}
-
-} // namespace remoting
diff --git a/remoting/remoting_host.gypi b/remoting/remoting_host.gypi
index 60e0c38..706f9739 100644
--- a/remoting/remoting_host.gypi
+++ b/remoting/remoting_host.gypi
@@ -90,8 +90,6 @@
'host/client_session.h',
'host/client_session_control.h',
'host/clipboard.h',
- 'host/clipboard_aura.cc',
- 'host/clipboard_aura.h',
'host/clipboard_mac.mm',
'host/clipboard_win.cc',
'host/clipboard_x11.cc',
@@ -339,11 +337,10 @@
'../third_party/skia/include/utils',
],
'sources!' : [
- 'host/clipboard_x11.cc',
+ 'host/policy_hack/policy_watcher_linux.cc',
'host/continue_window_linux.cc',
'host/disconnect_window.cc',
'host/disconnect_window_linux.cc',
- 'host/policy_hack/policy_watcher_linux.cc',
'host/remoting_me2me_host.cc',
]
}, { # chromeos==0
@@ -352,8 +349,6 @@
'host/chromeos/aura_desktop_capturer.h',
'host/chromeos/message_box.cc',
'host/chromeos/message_box.h',
- 'host/clipboard_aura.cc',
- 'host/clipboard_aura.h',
'host/continue_window_chromeos.cc',
'host/disconnect_window_chromeos.cc',
'host/policy_hack/policy_watcher_chromeos.cc',
diff --git a/remoting/remoting_test.gypi b/remoting/remoting_test.gypi
index a016929..456a003 100644
--- a/remoting/remoting_test.gypi
+++ b/remoting/remoting_test.gypi
@@ -139,7 +139,6 @@
'host/chromoting_host_context_unittest.cc',
'host/chromoting_host_unittest.cc',
'host/client_session_unittest.cc',
- 'host/clipboard_aura_unittest.cc',
'host/config_file_watcher_unittest.cc',
'host/daemon_process_unittest.cc',
'host/desktop_process_unittest.cc',
@@ -249,7 +248,6 @@
'sources!': [
'client/plugin/normalizing_input_filter_cros_unittest.cc',
'host/chromeos/aura_desktop_capturer_unittest.cc',
- 'host/clipboard_aura_unittest.cc',
],
}],
['enable_remoting_host == 0', {