diff options
author | dmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-04 22:44:11 +0000 |
---|---|---|
committer | dmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-04 22:44:11 +0000 |
commit | 0b7e42805341699a240997b202d4d23aed4b458b (patch) | |
tree | 44b31edf61ace0f552a113dd56368768d9774598 | |
parent | 167d52bbfbfc80f2232474eddfeb8bc587008d71 (diff) | |
download | chromium_src-0b7e42805341699a240997b202d4d23aed4b458b.zip chromium_src-0b7e42805341699a240997b202d4d23aed4b458b.tar.gz chromium_src-0b7e42805341699a240997b202d4d23aed4b458b.tar.bz2 |
Clean up remoting project
Cleaned up some file names so it simplifies our project, and gets us more inline with chromium standards.
Removed several unnecessary headers that were cluttering the remoting namespace.
Simplified some of the double pimpl implementations that we had on Linux to hide X11 stuff.
Got HostAuthentication working reasonably well as a mock.
BUG=NONE
TEST=BUILD
Review URL: http://codereview.chromium.org/6780014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80385 0039d316-1c4b-4281-b951-d872f2087c98
43 files changed, 723 insertions, 1036 deletions
diff --git a/remoting/host/capturer_gdi.h b/remoting/host/capturer_gdi.h deleted file mode 100644 index fb8f157..0000000 --- a/remoting/host/capturer_gdi.h +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (c) 2011 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_CAPTURER_GDI_H_ -#define REMOTING_HOST_CAPTURER_GDI_H_ - -#include <windows.h> -typedef HBITMAP BitmapRef; -#include "base/memory/scoped_ptr.h" -#include "remoting/host/capturer.h" -#include "remoting/host/capturer_helper.h" - -namespace remoting { - -class Differ; - -// CapturerGdi captures 32bit RGB using GDI. -// -// CapturerGdi is double-buffered as required by Capturer. See -// remoting/host/capturer.h. -class CapturerGdi : public Capturer { - public: - CapturerGdi(); - virtual ~CapturerGdi(); - - // Capturer interface. - virtual void ScreenConfigurationChanged(); - virtual media::VideoFrame::Format pixel_format() const; - virtual void ClearInvalidRects(); - virtual void InvalidateRects(const InvalidRects& inval_rects); - virtual void InvalidateScreen(const gfx::Size& size); - virtual void InvalidateFullScreen(); - virtual void CaptureInvalidRects(CaptureCompletedCallback* callback); - virtual const gfx::Size& size_most_recent() const; - - private: - struct VideoFrameBuffer { - VideoFrameBuffer(void* data, const gfx::Size& size, int bytes_per_pixel, - int bytes_per_row) - : data(data), size(size), bytes_per_pixel(bytes_per_pixel), - bytes_per_row(bytes_per_row) { - } - VideoFrameBuffer() { - data = 0; - size = gfx::Size(0, 0); - bytes_per_pixel = 0; - bytes_per_row = 0; - } - void* data; - gfx::Size size; - int bytes_per_pixel; - int bytes_per_row; - }; - - // Make sure that the current buffer has the same size as the screen. - void UpdateBufferCapture(const gfx::Size& size); - - // Allocate memory for a buffer of a given size, freeing any memory previously - // allocated for that buffer. - void ReallocateBuffer(int buffer_index, const gfx::Size& size); - - void CalculateInvalidRects(); - void CaptureRects(const InvalidRects& rects, - CaptureCompletedCallback* callback); - - void ReleaseBuffers(); - // Generates an image in the current buffer. - void CaptureImage(); - - // Gets the current screen size and calls ScreenConfigurationChanged - // if the screen size has changed. - void MaybeChangeScreenConfiguration(); - - // Gets the screen size. - gfx::Size GetScreenSize(); - - // A thread-safe list of invalid rectangles, and the size of the most - // recently captured screen. - CapturerHelper helper; - - // There are two buffers for the screen images, as required by Capturer. - static const int kNumBuffers = 2; - VideoFrameBuffer buffers_[kNumBuffers]; - - // Gdi specific information about screen. - HDC desktop_dc_; - HDC memory_dc_; - HBITMAP target_bitmap_[kNumBuffers]; - - // The screen size attached to the device contexts through which the screen - // is captured. - gfx::Size dc_size_; - - // The current buffer with valid data for reading. - int current_buffer_; - - // Format of pixels returned in buffer. - media::VideoFrame::Format pixel_format_; - - // Class to calculate the difference between two screen bitmaps. - scoped_ptr<Differ> differ_; - - // True if we should force a fullscreen capture. - bool capture_fullscreen_; - - DISALLOW_COPY_AND_ASSIGN(CapturerGdi); -}; - -} // namespace remoting - -#endif // REMOTING_HOST_CAPTURER_GDI_H_ diff --git a/remoting/host/capturer_linux.cc b/remoting/host/capturer_linux.cc index 71de8fd..6aaff4e 100644 --- a/remoting/host/capturer_linux.cc +++ b/remoting/host/capturer_linux.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "remoting/host/capturer_linux.h" +#include "remoting/host/capturer.h" #include <X11/Xlib.h> #include <X11/Xutil.h> @@ -10,33 +10,36 @@ #include <set> +#include "base/basictypes.h" #include "base/logging.h" +#include "base/memory/scoped_ptr.h" #include "remoting/base/types.h" #include "remoting/host/capturer_helper.h" #include "remoting/host/x_server_pixel_buffer.h" namespace remoting { -// Private Implementation pattern to avoid leaking the X11 types into the header -// file. -class CapturerLinuxPimpl : public Capturer { +namespace { + +// A class to perform capturing for Linux. +class CapturerLinux : public Capturer { public: - CapturerLinuxPimpl(); - virtual ~CapturerLinuxPimpl(); + CapturerLinux(); + virtual ~CapturerLinux(); - bool Init(); // TODO(ajwong): Do we really want this to be synchronous? // Capturer interface. - virtual void ScreenConfigurationChanged(); - virtual media::VideoFrame::Format pixel_format() const; - virtual void ClearInvalidRects(); - virtual void InvalidateRects(const InvalidRects& inval_rects); - virtual void InvalidateScreen(const gfx::Size& size); - virtual void InvalidateFullScreen(); - virtual void CaptureInvalidRects(CaptureCompletedCallback* callback); - virtual const gfx::Size& size_most_recent() const; + virtual void ScreenConfigurationChanged() OVERRIDE; + virtual media::VideoFrame::Format pixel_format() const OVERRIDE; + virtual void ClearInvalidRects() OVERRIDE; + virtual void InvalidateRects(const InvalidRects& inval_rects) OVERRIDE; + virtual void InvalidateScreen(const gfx::Size& size) OVERRIDE; + virtual void InvalidateFullScreen() OVERRIDE; + virtual void CaptureInvalidRects(CaptureCompletedCallback* callback) OVERRIDE; + virtual const gfx::Size& size_most_recent() const OVERRIDE; private: + bool Init(); // TODO(ajwong): Do we really want this to be synchronous? void CalculateInvalidRects(); void CaptureRects(const InvalidRects& rects, Capturer::CaptureCompletedCallback* callback); @@ -84,51 +87,11 @@ class CapturerLinuxPimpl : public Capturer { // Last capture buffer used. uint8* last_buffer_; + + DISALLOW_COPY_AND_ASSIGN(CapturerLinux); }; CapturerLinux::CapturerLinux() - : pimpl_(new CapturerLinuxPimpl()) { - // TODO(ajwong): This should be moved into an Init() method on Capturer - // itself. Then we can remove the CHECK. - CHECK(pimpl_->Init()); -} - -CapturerLinux::~CapturerLinux() { -} - -void CapturerLinux::ScreenConfigurationChanged() { - pimpl_->ScreenConfigurationChanged(); -} - -media::VideoFrame::Format CapturerLinux::pixel_format() const { - return pimpl_->pixel_format(); -} - -void CapturerLinux::ClearInvalidRects() { - pimpl_->ClearInvalidRects(); -} - -void CapturerLinux::InvalidateRects(const InvalidRects& inval_rects) { - pimpl_->InvalidateRects(inval_rects); -} - -void CapturerLinux::InvalidateScreen(const gfx::Size& size) { - pimpl_->InvalidateScreen(size); -} - -void CapturerLinux::InvalidateFullScreen() { - pimpl_->InvalidateFullScreen(); -} - -void CapturerLinux::CaptureInvalidRects(CaptureCompletedCallback* callback) { - pimpl_->CaptureInvalidRects(callback); -} - -const gfx::Size& CapturerLinux::size_most_recent() const { - return pimpl_->size_most_recent(); -} - -CapturerLinuxPimpl::CapturerLinuxPimpl() : display_(NULL), gc_(NULL), root_window_(BadValue), @@ -145,9 +108,10 @@ CapturerLinuxPimpl::CapturerLinuxPimpl() for (int i = 0; i < kNumBuffers; i++) { buffers_[i] = NULL; } + CHECK(Init()); } -CapturerLinuxPimpl::~CapturerLinuxPimpl() { +CapturerLinux::~CapturerLinux() { DeinitXlib(); for (int i = 0; i < kNumBuffers; i++) { @@ -156,7 +120,7 @@ CapturerLinuxPimpl::~CapturerLinuxPimpl() { } } -bool CapturerLinuxPimpl::Init() { +bool CapturerLinux::Init() { // TODO(ajwong): We should specify the display string we are attaching to // in the constructor. display_ = XOpenDisplay(NULL); @@ -216,32 +180,32 @@ bool CapturerLinuxPimpl::Init() { return true; } -void CapturerLinuxPimpl::ScreenConfigurationChanged() { +void CapturerLinux::ScreenConfigurationChanged() { // TODO(ajwong): Support resolution changes. NOTIMPLEMENTED(); } -media::VideoFrame::Format CapturerLinuxPimpl::pixel_format() const { +media::VideoFrame::Format CapturerLinux::pixel_format() const { return pixel_format_; } -void CapturerLinuxPimpl::ClearInvalidRects() { +void CapturerLinux::ClearInvalidRects() { helper_.ClearInvalidRects(); } -void CapturerLinuxPimpl::InvalidateRects(const InvalidRects& inval_rects) { +void CapturerLinux::InvalidateRects(const InvalidRects& inval_rects) { helper_.InvalidateRects(inval_rects); } -void CapturerLinuxPimpl::InvalidateScreen(const gfx::Size& size) { +void CapturerLinux::InvalidateScreen(const gfx::Size& size) { helper_.InvalidateScreen(size); } -void CapturerLinuxPimpl::InvalidateFullScreen() { +void CapturerLinux::InvalidateFullScreen() { helper_.InvalidateFullScreen(); } -void CapturerLinuxPimpl::CaptureInvalidRects( +void CapturerLinux::CaptureInvalidRects( CaptureCompletedCallback* callback) { CalculateInvalidRects(); @@ -251,7 +215,7 @@ void CapturerLinuxPimpl::CaptureInvalidRects( CaptureRects(rects, callback); } -void CapturerLinuxPimpl::CalculateInvalidRects() { +void CapturerLinux::CalculateInvalidRects() { if (helper_.IsCaptureFullScreen(gfx::Size(width_, height_))) capture_fullscreen_ = true; @@ -294,7 +258,7 @@ void CapturerLinuxPimpl::CalculateInvalidRects() { } } -void CapturerLinuxPimpl::CaptureRects( +void CapturerLinux::CaptureRects( const InvalidRects& rects, Capturer::CaptureCompletedCallback* callback) { scoped_ptr<CaptureCompletedCallback> callback_deleter(callback); @@ -354,7 +318,7 @@ void CapturerLinuxPimpl::CaptureRects( callback->Run(capture_data); } -void CapturerLinuxPimpl::DeinitXlib() { +void CapturerLinux::DeinitXlib() { if (gc_) { XFreeGC(display_, gc_); gc_ = NULL; @@ -366,7 +330,7 @@ void CapturerLinuxPimpl::DeinitXlib() { } } -void CapturerLinuxPimpl::FastBlit(uint8* image, const gfx::Rect& rect, +void CapturerLinux::FastBlit(uint8* image, const gfx::Rect& rect, CaptureData* capture_data) { uint8* src_pos = image; int src_stride = x_server_pixel_buffer_.GetStride(); @@ -388,7 +352,7 @@ void CapturerLinuxPimpl::FastBlit(uint8* image, const gfx::Rect& rect, } } -void CapturerLinuxPimpl::SlowBlit(uint8* image, const gfx::Rect& rect, +void CapturerLinux::SlowBlit(uint8* image, const gfx::Rect& rect, CaptureData* capture_data) { DataPlanes planes = capture_data->data_planes(); uint8* dst_buffer = planes.data[0]; @@ -439,10 +403,12 @@ void CapturerLinuxPimpl::SlowBlit(uint8* image, const gfx::Rect& rect, } } -const gfx::Size& CapturerLinuxPimpl::size_most_recent() const { +const gfx::Size& CapturerLinux::size_most_recent() const { return helper_.size_most_recent(); } +} // namespace + // static Capturer* Capturer::Create() { return new CapturerLinux(); diff --git a/remoting/host/capturer_linux.h b/remoting/host/capturer_linux.h deleted file mode 100644 index f0ef413..0000000 --- a/remoting/host/capturer_linux.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2011 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_CAPTURER_LINUX_H_ -#define REMOTING_HOST_CAPTURER_LINUX_H_ - -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" -#include "remoting/host/capturer.h" - -namespace remoting { - -class CapturerLinuxPimpl; - -// A class to perform capturing for Linux. -class CapturerLinux : public Capturer { - public: - CapturerLinux(); - virtual ~CapturerLinux(); - - // Capturer interface. - virtual void ScreenConfigurationChanged(); - virtual media::VideoFrame::Format pixel_format() const; - virtual void ClearInvalidRects(); - virtual void InvalidateRects(const InvalidRects& inval_rects); - virtual void InvalidateScreen(const gfx::Size& size); - virtual void InvalidateFullScreen(); - virtual void CaptureInvalidRects(CaptureCompletedCallback* callback); - virtual const gfx::Size& size_most_recent() const; - - private: - friend class CapturerLinuxPimpl; - - scoped_ptr<CapturerLinuxPimpl> pimpl_; - DISALLOW_COPY_AND_ASSIGN(CapturerLinux); -}; - -} // namespace remoting - -#endif // REMOTING_HOST_CAPTURER_LINUX_H_ diff --git a/remoting/host/capturer_linux_unittest.cc b/remoting/host/capturer_linux_unittest.cc index 7b94b56..1205ec3 100644 --- a/remoting/host/capturer_linux_unittest.cc +++ b/remoting/host/capturer_linux_unittest.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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 "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" namespace remoting { diff --git a/remoting/host/capturer_mac.cc b/remoting/host/capturer_mac.cc index d13a5f5..6eb446d 100644 --- a/remoting/host/capturer_mac.cc +++ b/remoting/host/capturer_mac.cc @@ -2,15 +2,81 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/logging.h" -#include "remoting/host/capturer_mac.h" +#include "remoting/host/capturer.h" + +#include <ApplicationServices/ApplicationServices.h> +#include <OpenGL/CGLMacro.h> +#include <OpenGL/OpenGL.h> #include <stddef.h> -#include <OpenGL/CGLMacro.h> +#include "base/logging.h" +#include "base/memory/scoped_ptr.h" +#include "remoting/host/capturer_helper.h" namespace remoting { +namespace { +// A class to perform capturing for mac. +class CapturerMac : public Capturer { + public: + CapturerMac(); + virtual ~CapturerMac(); + + // Capturer interface. + virtual void ScreenConfigurationChanged() OVERRIDE; + virtual media::VideoFrame::Format pixel_format() const OVERRIDE; + virtual void ClearInvalidRects() OVERRIDE; + virtual void InvalidateRects(const InvalidRects& inval_rects) OVERRIDE; + virtual void InvalidateScreen(const gfx::Size& size) OVERRIDE; + virtual void InvalidateFullScreen() OVERRIDE; + virtual void CaptureInvalidRects(CaptureCompletedCallback* callback) OVERRIDE; + virtual const gfx::Size& size_most_recent() const OVERRIDE; + + private: + void CaptureRects(const InvalidRects& rects, + CaptureCompletedCallback* callback); + + void ScreenRefresh(CGRectCount count, const CGRect *rect_array); + void ScreenUpdateMove(CGScreenUpdateMoveDelta delta, + size_t count, + const CGRect *rect_array); + static void ScreenRefreshCallback(CGRectCount count, + const CGRect *rect_array, + void *user_parameter); + static void ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, + size_t count, + const CGRect *rect_array, + void *user_parameter); + static void DisplaysReconfiguredCallback(CGDirectDisplayID display, + CGDisplayChangeSummaryFlags flags, + void *user_parameter); + + void ReleaseBuffers(); + CGLContextObj cgl_context_; + static const int kNumBuffers = 2; + scoped_array<uint8> buffers_[kNumBuffers]; + scoped_array<uint8> flip_buffer_; + + // A thread-safe list of invalid rectangles, and the size of the most + // recently captured screen. + CapturerHelper helper_; + + // Screen size. + int width_; + int height_; + + int bytes_per_row_; + + // The current buffer with valid data for reading. + int current_buffer_; + + // Format of pixels returned in buffer. + media::VideoFrame::Format pixel_format_; + + DISALLOW_COPY_AND_ASSIGN(CapturerMac); +}; + CapturerMac::CapturerMac() : cgl_context_(NULL), width_(0), @@ -195,6 +261,8 @@ void CapturerMac::DisplaysReconfiguredCallback( } } +} // namespace + // static Capturer* Capturer::Create() { return new CapturerMac(); diff --git a/remoting/host/capturer_mac.h b/remoting/host/capturer_mac.h deleted file mode 100644 index ee42882..0000000 --- a/remoting/host/capturer_mac.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) 2011 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_CAPTURER_MAC_H_ -#define REMOTING_HOST_CAPTURER_MAC_H_ - -#include "remoting/host/capturer.h" -#include "remoting/host/capturer_helper.h" -#include <ApplicationServices/ApplicationServices.h> -#include <OpenGL/OpenGL.h> -#include "base/memory/scoped_ptr.h" - -namespace remoting { - -// A class to perform capturing for mac. -class CapturerMac : public Capturer { - public: - CapturerMac(); - virtual ~CapturerMac(); - - // Capturer interface. - virtual void ScreenConfigurationChanged(); - virtual media::VideoFrame::Format pixel_format() const; - virtual void ClearInvalidRects(); - virtual void InvalidateRects(const InvalidRects& inval_rects); - virtual void InvalidateScreen(const gfx::Size& size); - virtual void InvalidateFullScreen(); - virtual void CaptureInvalidRects(CaptureCompletedCallback* callback); - virtual const gfx::Size& size_most_recent() const; - - private: - void CaptureRects(const InvalidRects& rects, - CaptureCompletedCallback* callback); - - void ScreenRefresh(CGRectCount count, const CGRect *rect_array); - void ScreenUpdateMove(CGScreenUpdateMoveDelta delta, - size_t count, - const CGRect *rect_array); - static void ScreenRefreshCallback(CGRectCount count, - const CGRect *rect_array, - void *user_parameter); - static void ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, - size_t count, - const CGRect *rect_array, - void *user_parameter); - static void DisplaysReconfiguredCallback(CGDirectDisplayID display, - CGDisplayChangeSummaryFlags flags, - void *user_parameter); - - void ReleaseBuffers(); - CGLContextObj cgl_context_; - static const int kNumBuffers = 2; - scoped_array<uint8> buffers_[kNumBuffers]; - scoped_array<uint8> flip_buffer_; - - // A thread-safe list of invalid rectangles, and the size of the most - // recently captured screen. - CapturerHelper helper_; - - // Screen size. - int width_; - int height_; - - int bytes_per_row_; - - // The current buffer with valid data for reading. - int current_buffer_; - - // Format of pixels returned in buffer. - media::VideoFrame::Format pixel_format_; - - DISALLOW_COPY_AND_ASSIGN(CapturerMac); -}; - -} // namespace remoting - -#endif // REMOTING_HOST_CAPTURER_MAC_H_ diff --git a/remoting/host/capturer_mac_unittest.cc b/remoting/host/capturer_mac_unittest.cc index 4ca85f5..ca277c5 100644 --- a/remoting/host/capturer_mac_unittest.cc +++ b/remoting/host/capturer_mac_unittest.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "remoting/host/capturer.h" + #include <ApplicationServices/ApplicationServices.h> #include <iostream> @@ -9,22 +11,21 @@ #include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "remoting/base/types.h" -#include "remoting/host/capturer_mac.h" -#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" namespace remoting { class CapturerMacTest : public testing::Test { protected: virtual void SetUp() { - capturer_.reset(new CapturerMac()); + capturer_.reset(Capturer::Create()); } void AddDirtyRect() { rects_.insert(gfx::Rect(0, 0, 10, 10)); } - scoped_ptr<CapturerMac> capturer_; + scoped_ptr<Capturer> capturer_; InvalidRects rects_; }; diff --git a/remoting/host/capturer_gdi.cc b/remoting/host/capturer_win.cc index 8e50bde..b5fe81e 100644 --- a/remoting/host/capturer_gdi.cc +++ b/remoting/host/capturer_win.cc @@ -2,13 +2,111 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "remoting/host/capturer_gdi.h" -#include "remoting/host/differ.h" +#include "remoting/host/capturer.h" + +#include <windows.h> +#include "base/memory/scoped_ptr.h" +#include "remoting/host/capturer_helper.h" +#include "remoting/host/differ.h" #include "ui/gfx/rect.h" namespace remoting { +namespace { + +// CapturerGdi captures 32bit RGB using GDI. +// +// CapturerGdi is double-buffered as required by Capturer. See +// remoting/host/capturer.h. +class CapturerGdi : public Capturer { + public: + CapturerGdi(); + virtual ~CapturerGdi(); + + // Capturer interface. + virtual void ScreenConfigurationChanged() OVERRIDE; + virtual media::VideoFrame::Format pixel_format() const OVERRIDE; + virtual void ClearInvalidRects() OVERRIDE; + virtual void InvalidateRects(const InvalidRects& inval_rects) OVERRIDE; + virtual void InvalidateScreen(const gfx::Size& size) OVERRIDE; + virtual void InvalidateFullScreen() OVERRIDE; + virtual void CaptureInvalidRects(CaptureCompletedCallback* callback) OVERRIDE; + virtual const gfx::Size& size_most_recent() const OVERRIDE; + + private: + struct VideoFrameBuffer { + VideoFrameBuffer(void* data, const gfx::Size& size, int bytes_per_pixel, + int bytes_per_row) + : data(data), size(size), bytes_per_pixel(bytes_per_pixel), + bytes_per_row(bytes_per_row) { + } + VideoFrameBuffer() { + data = 0; + size = gfx::Size(0, 0); + bytes_per_pixel = 0; + bytes_per_row = 0; + } + void* data; + gfx::Size size; + int bytes_per_pixel; + int bytes_per_row; + }; + + // Make sure that the current buffer has the same size as the screen. + void UpdateBufferCapture(const gfx::Size& size); + + // Allocate memory for a buffer of a given size, freeing any memory previously + // allocated for that buffer. + void ReallocateBuffer(int buffer_index, const gfx::Size& size); + + void CalculateInvalidRects(); + void CaptureRects(const InvalidRects& rects, + CaptureCompletedCallback* callback); + + void ReleaseBuffers(); + // Generates an image in the current buffer. + void CaptureImage(); + + // Gets the current screen size and calls ScreenConfigurationChanged + // if the screen size has changed. + void MaybeChangeScreenConfiguration(); + + // Gets the screen size. + gfx::Size GetScreenSize(); + + // A thread-safe list of invalid rectangles, and the size of the most + // recently captured screen. + CapturerHelper helper; + + // There are two buffers for the screen images, as required by Capturer. + static const int kNumBuffers = 2; + VideoFrameBuffer buffers_[kNumBuffers]; + + // Gdi specific information about screen. + HDC desktop_dc_; + HDC memory_dc_; + HBITMAP target_bitmap_[kNumBuffers]; + + // The screen size attached to the device contexts through which the screen + // is captured. + gfx::Size dc_size_; + + // The current buffer with valid data for reading. + int current_buffer_; + + // Format of pixels returned in buffer. + media::VideoFrame::Format pixel_format_; + + // Class to calculate the difference between two screen bitmaps. + scoped_ptr<Differ> differ_; + + // True if we should force a fullscreen capture. + bool capture_fullscreen_; + + DISALLOW_COPY_AND_ASSIGN(CapturerGdi); +}; + // 3780 pixels per meter is equivalent to 96 DPI, typical on desktop monitors. static const int kPixelsPerMeter = 3780; // 32 bit RGBA is 4 bytes per pixel. @@ -229,6 +327,8 @@ gfx::Size CapturerGdi::GetScreenSize() { GetSystemMetrics(SM_CYSCREEN)); } +} // namespace + // static Capturer* Capturer::Create() { return new CapturerGdi(); diff --git a/remoting/host/capturer_gdi_unittest.cc b/remoting/host/capturer_win_unittest.cc index 850a4a6..bec0766 100644 --- a/remoting/host/capturer_gdi_unittest.cc +++ b/remoting/host/capturer_win_unittest.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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 "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" namespace remoting { diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc index ae5ef68..d604d52 100644 --- a/remoting/host/chromoting_host.cc +++ b/remoting/host/chromoting_host.cc @@ -4,9 +4,6 @@ #include "remoting/host/chromoting_host.h" -#include "base/bind.h" -#include "base/stl_util-inl.h" -#include "base/task.h" #include "build/build_config.h" #include "remoting/base/constants.h" #include "remoting/base/encoder.h" @@ -38,11 +35,11 @@ namespace remoting { ChromotingHost* ChromotingHost::Create(ChromotingHostContext* context, MutableHostConfig* config) { Capturer* capturer = Capturer::Create(); - InputStub* input_stub = CreateEventExecutor(context->ui_message_loop(), - capturer); + EventExecutor* event_executor = + EventExecutor::Create(context->ui_message_loop(), capturer); Curtain* curtain = Curtain::Create(); return Create(context, config, - new DesktopEnvironment(capturer, input_stub, curtain)); + new DesktopEnvironment(capturer, event_executor, curtain)); } // static @@ -332,9 +329,9 @@ void ChromotingHost::OnNewClientSession( // Create a client object. ClientSession* client = new ClientSession( this, - base::Bind(UserAuthenticator::Create), + UserAuthenticator::Create(), connection, - desktop_environment_->input_stub()); + desktop_environment_->event_executor()); connection->set_host_stub(client); connection->set_input_stub(client); diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc index 6fa50a1..51093b5 100644 --- a/remoting/host/chromoting_host_unittest.cc +++ b/remoting/host/chromoting_host_unittest.cc @@ -10,7 +10,6 @@ #include "remoting/host/chromoting_host_context.h" #include "remoting/host/host_mock_objects.h" #include "remoting/host/in_memory_host_config.h" -#include "remoting/host/user_authenticator_fake.h" #include "remoting/proto/video.pb.h" #include "remoting/protocol/protocol_mock_objects.h" #include "remoting/protocol/session_config.h" @@ -23,7 +22,6 @@ using ::remoting::protocol::MockClientStub; using ::remoting::protocol::MockConnectionToClient; using ::remoting::protocol::MockConnectionToClientEventHandler; using ::remoting::protocol::MockHostStub; -using ::remoting::protocol::MockInputStub; using ::remoting::protocol::MockSession; using ::remoting::protocol::MockVideoStub; using ::remoting::protocol::SessionConfig; @@ -43,10 +41,6 @@ namespace remoting { namespace { -UserAuthenticator* MakeUserAuthenticator() { - return new UserAuthenticatorFake(); -} - void PostQuitTask(MessageLoop* message_loop) { message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); } @@ -90,22 +84,19 @@ class ChromotingHostTest : public testing::Test { Capturer* capturer = new CapturerFake(); host_stub_ = new MockHostStub(); host_stub2_ = new MockHostStub(); - input_stub_ = new MockInputStub(); - input_stub2_ = new MockInputStub(); + event_executor_ = new MockEventExecutor(); + event_executor2_ = new MockEventExecutor(); curtain_ = new MockCurtain(); DesktopEnvironment* desktop = - new DesktopEnvironment(capturer, input_stub_, curtain_); + new DesktopEnvironment(capturer, event_executor_, curtain_); host_ = ChromotingHost::Create(&context_, config_, desktop); - credentials_good_.set_type(protocol::PASSWORD); - credentials_good_.set_username("user"); - credentials_good_.set_credential("password"); - credentials_bad_.set_type(protocol::PASSWORD); - credentials_bad_.set_username(UserAuthenticatorFake::fail_username()); - credentials_bad_.set_credential(UserAuthenticatorFake::fail_password()); + credentials_.set_type(protocol::PASSWORD); + credentials_.set_username("user"); + credentials_.set_credential("password"); connection_ = new MockConnectionToClient( - &message_loop_, &handler_, host_stub_, input_stub_); + &message_loop_, &handler_, host_stub_, event_executor_); connection2_ = new MockConnectionToClient( - &message_loop_, &handler_, host_stub2_, input_stub2_); + &message_loop_, &handler_, host_stub2_, event_executor2_); session_ = new MockSession(); session2_ = new MockSession(); session_config_.reset(SessionConfig::CreateDefault()); @@ -151,20 +142,20 @@ class ChromotingHostTest : public testing::Test { .Times(AnyNumber()); } - virtual void TearDown() { - } - // Helper method to pretend a client is connected to ChromotingHost. void SimulateClientConnection(int connection_index, bool authenticate) { scoped_refptr<MockConnectionToClient> connection = (connection_index == 0) ? connection_ : connection2_; - protocol::LocalLoginCredentials& credentials = - authenticate ? credentials_good_ : credentials_bad_; + + MockUserAuthenticator *user_authenticator = new MockUserAuthenticator; + EXPECT_CALL(*user_authenticator, Authenticate(_, _)) + .WillOnce(Return(authenticate)); + scoped_refptr<ClientSession> client = new ClientSession( host_.get(), - base::Bind(MakeUserAuthenticator), + user_authenticator, connection, - input_stub_); + event_executor_); connection->set_host_stub(client.get()); context_.network_message_loop()->PostTask( @@ -181,7 +172,7 @@ class ChromotingHostTest : public testing::Test { FROM_HERE, NewRunnableMethod(client.get(), &ClientSession::BeginSessionRequest, - &credentials, + &credentials_, NewRunnableFunction(&DummyDoneTask))); } @@ -200,15 +191,14 @@ class ChromotingHostTest : public testing::Test { scoped_refptr<ChromotingHost> host_; scoped_refptr<InMemoryHostConfig> config_; MockChromotingHostContext context_; - protocol::LocalLoginCredentials credentials_good_; - protocol::LocalLoginCredentials credentials_bad_; + protocol::LocalLoginCredentials credentials_; scoped_refptr<MockConnectionToClient> connection_; scoped_refptr<MockSession> session_; scoped_ptr<SessionConfig> session_config_; MockVideoStub video_stub_; MockClientStub client_stub_; MockHostStub* host_stub_; - MockInputStub* input_stub_; + MockEventExecutor* event_executor_; MockCurtain* curtain_; scoped_refptr<MockConnectionToClient> connection2_; scoped_refptr<MockSession> session2_; @@ -216,7 +206,7 @@ class ChromotingHostTest : public testing::Test { MockVideoStub video_stub2_; MockClientStub client_stub2_; MockHostStub* host_stub2_; - MockInputStub* input_stub2_; + MockEventExecutor* event_executor2_; }; TEST_F(ChromotingHostTest, StartAndShutdown) { @@ -236,19 +226,20 @@ TEST_F(ChromotingHostTest, Connect) { // When the video packet is received we first shutdown ChromotingHost // then execute the done task. - InSequence s; - EXPECT_CALL(*curtain_, EnableCurtainMode(true)) - .Times(1); - EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) - .WillOnce(DoAll( - InvokeWithoutArgs(host_.get(), &ChromotingHost::Shutdown), - RunDoneTask())) - .RetiresOnSaturation(); - EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) - .Times(AnyNumber()); - EXPECT_CALL(*connection_.get(), Disconnect()) - .RetiresOnSaturation(); - + { + InSequence s; + EXPECT_CALL(*curtain_, EnableCurtainMode(true)) + .Times(1); + EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) + .WillOnce(DoAll( + InvokeWithoutArgs(host_.get(), &ChromotingHost::Shutdown), + RunDoneTask())) + .RetiresOnSaturation(); + EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) + .Times(AnyNumber()); + EXPECT_CALL(*connection_.get(), Disconnect()) + .RetiresOnSaturation(); + } SimulateClientConnection(0, true); message_loop_.Run(); } @@ -362,8 +353,7 @@ TEST_F(ChromotingHostTest, CurtainModeFail) { host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); EXPECT_CALL(client_stub_, BeginSessionResponse(_, _)) - .Times(1) - .WillRepeatedly(RunDoneTask()); + .WillOnce(RunDoneTask()); // Ensure that curtain mode is not activated if a connection does not // authenticate. @@ -380,19 +370,17 @@ TEST_F(ChromotingHostTest, CurtainModeFailSecond) { host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); EXPECT_CALL(client_stub_, BeginSessionResponse(_, _)) - .Times(1) - .WillRepeatedly(RunDoneTask()); + .WillOnce(RunDoneTask()); EXPECT_CALL(client_stub2_, BeginSessionResponse(_, _)) - .Times(1) - .WillRepeatedly(RunDoneTask()); + .WillOnce(RunDoneTask()); + // When a video packet is received we connect the second mock // connection. { InSequence s; EXPECT_CALL(*curtain_, EnableCurtainMode(true)) - .Times(1) .WillOnce(QuitMainMessageLoop(&message_loop_)); EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) .WillOnce(DoAll( diff --git a/remoting/host/client_session.cc b/remoting/host/client_session.cc index b946a0a..1e678ff 100644 --- a/remoting/host/client_session.cc +++ b/remoting/host/client_session.cc @@ -4,7 +4,6 @@ #include "remoting/host/client_session.h" -#include "base/memory/scoped_ptr.h" #include "base/task.h" #include "media/base/callback.h" #include "remoting/host/user_authenticator.h" @@ -14,11 +13,11 @@ namespace remoting { ClientSession::ClientSession( EventHandler* event_handler, - const base::Callback<UserAuthenticatorFactory>& auth_factory, + UserAuthenticator* user_authenticator, scoped_refptr<protocol::ConnectionToClient> connection, protocol::InputStub* input_stub) : event_handler_(event_handler), - auth_factory_(auth_factory), + user_authenticator_(user_authenticator), connection_(connection), input_stub_(input_stub), authenticated_(false) { @@ -45,11 +44,10 @@ void ClientSession::BeginSessionRequest( media::AutoTaskRunner done_runner(done); bool success = false; - scoped_ptr<UserAuthenticator> authenticator(auth_factory_.Run()); switch (credentials->type()) { case protocol::PASSWORD: - success = authenticator->Authenticate(credentials->username(), - credentials->credential()); + success = user_authenticator_->Authenticate(credentials->username(), + credentials->credential()); break; default: diff --git a/remoting/host/client_session.h b/remoting/host/client_session.h index e5ef81a..131cc70 100644 --- a/remoting/host/client_session.h +++ b/remoting/host/client_session.h @@ -34,10 +34,8 @@ class ClientSession : public protocol::HostStub, scoped_refptr<protocol::ConnectionToClient> client) = 0; }; - typedef UserAuthenticator* UserAuthenticatorFactory(); - ClientSession(EventHandler* event_handler, - const base::Callback<UserAuthenticatorFactory>& auth_factory, + UserAuthenticator* user_authenticator, scoped_refptr<protocol::ConnectionToClient> connection, protocol::InputStub* input_stub); @@ -69,7 +67,7 @@ class ClientSession : public protocol::HostStub, EventHandler* event_handler_; // A factory for user authenticators. - base::Callback<UserAuthenticatorFactory> auth_factory_; + scoped_ptr<UserAuthenticator> user_authenticator_; // The connection to the client. scoped_refptr<protocol::ConnectionToClient> connection_; diff --git a/remoting/host/client_session_unittest.cc b/remoting/host/client_session_unittest.cc index 5ce97af..bd6860a 100644 --- a/remoting/host/client_session_unittest.cc +++ b/remoting/host/client_session_unittest.cc @@ -2,10 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/bind.h" #include "remoting/host/client_session.h" #include "remoting/host/host_mock_objects.h" -#include "remoting/host/user_authenticator_fake.h" #include "remoting/protocol/protocol_mock_objects.h" #include "testing/gtest/include/gtest/gtest.h" @@ -13,10 +11,6 @@ namespace remoting { namespace { -UserAuthenticator* MakeUserAuthenticator() { - return new UserAuthenticatorFake(); -} - // A task that does nothing. class DummyTask : public Task { public: @@ -33,41 +27,37 @@ using protocol::MockInputStub; using testing::_; using testing::DeleteArg; using testing::InSequence; +using testing::Return; class ClientSessionTest : public testing::Test { public: - ClientSessionTest() { - } + ClientSessionTest() {} virtual void SetUp() { connection_ = new MockConnectionToClient(&message_loop_, &connection_event_handler_, &host_stub_, &input_stub_); - client_session_ = new ClientSession(&session_event_handler_, - base::Bind(MakeUserAuthenticator), - connection_, - &input_stub_); - credentials_.set_type(protocol::PASSWORD); - credentials_.set_username("user"); - credentials_.set_credential("password"); + user_authenticator_ = new MockUserAuthenticator(); + client_session_ = new ClientSession( + &session_event_handler_, + user_authenticator_, + connection_, + &input_stub_); ON_CALL(input_stub_, InjectKeyEvent(_, _)).WillByDefault(DeleteArg<1>()); ON_CALL(input_stub_, InjectMouseEvent(_, _)).WillByDefault(DeleteArg<1>()); } - virtual void TearDown() { - } - protected: MessageLoop message_loop_; MockConnectionToClientEventHandler connection_event_handler_; MockHostStub host_stub_; MockInputStub input_stub_; MockClientSessionEventHandler session_event_handler_; + MockUserAuthenticator* user_authenticator_; scoped_refptr<MockConnectionToClient> connection_; scoped_refptr<ClientSession> client_session_; - protocol::LocalLoginCredentials credentials_; }; TEST_F(ClientSessionTest, InputStubFilter) { @@ -95,11 +85,14 @@ TEST_F(ClientSessionTest, InputStubFilter) { mouse_event3.set_x(300); mouse_event3.set_y(301); - credentials_.set_type(protocol::PASSWORD); - credentials_.set_username("user"); - credentials_.set_credential("password"); + protocol::LocalLoginCredentials credentials; + credentials.set_type(protocol::PASSWORD); + credentials.set_username("user"); + credentials.set_credential("password"); InSequence s; + EXPECT_CALL(*user_authenticator_, Authenticate(_, _)) + .WillOnce(Return(true)); EXPECT_CALL(session_event_handler_, LocalLoginSucceeded(_)); EXPECT_CALL(input_stub_, InjectKeyEvent(&key_event2, _)); EXPECT_CALL(input_stub_, InjectMouseEvent(&mouse_event2, _)); @@ -109,7 +102,7 @@ TEST_F(ClientSessionTest, InputStubFilter) { // because the client isn't authenticated yet. client_session_->InjectKeyEvent(&key_event1, new DummyTask()); client_session_->InjectMouseEvent(&mouse_event1, new DummyTask()); - client_session_->BeginSessionRequest(&credentials_, new DummyTask()); + client_session_->BeginSessionRequest(&credentials, new DummyTask()); // These events should get through to the input stub. client_session_->InjectKeyEvent(&key_event2, new DummyTask()); client_session_->InjectMouseEvent(&mouse_event2, new DummyTask()); diff --git a/remoting/host/curtain_linux.cc b/remoting/host/curtain_linux.cc index c38df01..3bf7deb 100644 --- a/remoting/host/curtain_linux.cc +++ b/remoting/host/curtain_linux.cc @@ -2,15 +2,30 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "remoting/host/curtain_linux.h" +#include "remoting/host/curtain.h" + +#include "base/basictypes.h" +#include "base/compiler_specific.h" #include "base/logging.h" namespace remoting { +namespace { + +class CurtainLinux : public Curtain { + public: + CurtainLinux() {} + virtual void EnableCurtainMode(bool enable) OVERRIDE; + private: + DISALLOW_COPY_AND_ASSIGN(CurtainLinux); +}; + void CurtainLinux::EnableCurtainMode(bool enable) { NOTIMPLEMENTED(); } +} // namespace + Curtain* Curtain::Create() { return new CurtainLinux(); } diff --git a/remoting/host/curtain_linux.h b/remoting/host/curtain_linux.h deleted file mode 100644 index 270f825..0000000 --- a/remoting/host/curtain_linux.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2011 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_CURTAIN_LINUX_H_ -#define REMOTING_HOST_CURTAIN_LINUX_H_ - -#include "remoting/host/curtain.h" -#include "base/compiler_specific.h" - -namespace remoting { - -class CurtainLinux : public Curtain { - public: - virtual void EnableCurtainMode(bool enable) OVERRIDE; -}; - -} // namespace remoting - -#endif // REMOTING_HOST_CURTAIN_LINUX_H_ diff --git a/remoting/host/curtain_mac.cc b/remoting/host/curtain_mac.cc index 0055e68..b6c741a 100644 --- a/remoting/host/curtain_mac.cc +++ b/remoting/host/curtain_mac.cc @@ -2,15 +2,31 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "remoting/host/curtain_mac.h" +#include "remoting/host/curtain.h" + +#include "base/basictypes.h" +#include "base/compiler_specific.h" #include "base/logging.h" namespace remoting { +namespace { + +class CurtainMac : public Curtain { + public: + CurtainMac() {} + virtual void EnableCurtainMode(bool enable) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(CurtainMac); +}; + void CurtainMac::EnableCurtainMode(bool enable) { NOTIMPLEMENTED(); } +} // namespace + Curtain* Curtain::Create() { return new CurtainMac(); } diff --git a/remoting/host/curtain_mac.h b/remoting/host/curtain_mac.h deleted file mode 100644 index 6bb95a6..0000000 --- a/remoting/host/curtain_mac.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2011 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_CURTAIN_MAC_H_ -#define REMOTING_HOST_CURTAIN_MAC_H_ - -#include "remoting/host/curtain.h" -#include "base/compiler_specific.h" - -namespace remoting { - -class CurtainMac : public Curtain { - public: - virtual void EnableCurtainMode(bool enable) OVERRIDE; -}; - -} // namespace remoting - -#endif // REMOTING_HOST_CURTAIN_MAC_H_ diff --git a/remoting/host/curtain_win.cc b/remoting/host/curtain_win.cc index 30a9868..25168f7 100644 --- a/remoting/host/curtain_win.cc +++ b/remoting/host/curtain_win.cc @@ -2,15 +2,31 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "remoting/host/curtain_win.h" +#include "remoting/host/curtain.h" + +#include "base/basictypes.h" +#include "base/compiler_specific.h" #include "base/logging.h" namespace remoting { +namespace { + +class CurtainWin : public Curtain { + public: + CurtainWin() {} + virtual void EnableCurtainMode(bool enable) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(CurtainWin); +}; + void CurtainWin::EnableCurtainMode(bool enable) { NOTIMPLEMENTED(); } +} // namespace + Curtain* Curtain::Create() { return new CurtainWin(); } diff --git a/remoting/host/curtain_win.h b/remoting/host/curtain_win.h deleted file mode 100644 index d22385a..0000000 --- a/remoting/host/curtain_win.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2011 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_CURTAIN_WIN_H_ -#define REMOTING_HOST_CURTAIN_WIN_H_ - -#include "remoting/host/curtain.h" -#include "base/compiler_specific.h" - -namespace remoting { - -class CurtainWin : public Curtain { - public: - virtual void EnableCurtainMode(bool enable) OVERRIDE; -}; - -} // namespace remoting - -#endif // REMOTING_HOST_CURTAIN_WIN_H_ diff --git a/remoting/host/desktop_environment.cc b/remoting/host/desktop_environment.cc index cae6016..3fb128a 100644 --- a/remoting/host/desktop_environment.cc +++ b/remoting/host/desktop_environment.cc @@ -6,17 +6,15 @@ #include "remoting/host/capturer.h" #include "remoting/host/curtain.h" -#include "remoting/protocol/input_stub.h" - -using remoting::protocol::InputStub; +#include "remoting/host/event_executor.h" namespace remoting { DesktopEnvironment::DesktopEnvironment(Capturer* capturer, - InputStub* input_stub, + EventExecutor* event_executor, Curtain* curtain) : capturer_(capturer), - input_stub_(input_stub), + event_executor_(event_executor), curtain_(curtain) { } diff --git a/remoting/host/desktop_environment.h b/remoting/host/desktop_environment.h index afb148a..03f3bc8 100644 --- a/remoting/host/desktop_environment.h +++ b/remoting/host/desktop_environment.h @@ -10,30 +10,27 @@ namespace remoting { -namespace protocol { -class InputStub; -} // namespace protocol - class Capturer; class Curtain; +class EventExecutor; class DesktopEnvironment { public: // DesktopEnvironment takes ownership of all the objects passed the ctor. - DesktopEnvironment(Capturer* capturer, protocol::InputStub* input_stub, + DesktopEnvironment(Capturer* capturer, EventExecutor* event_executor, Curtain* curtain); virtual ~DesktopEnvironment(); Capturer* capturer() const { return capturer_.get(); } - protocol::InputStub* input_stub() const { return input_stub_.get(); } + EventExecutor* event_executor() const { return event_executor_.get(); } Curtain* curtain() const { return curtain_.get(); } private: // Capturer to be used by ScreenRecorder. scoped_ptr<Capturer> capturer_; - // InputStub in the host executes input events received from the client. - scoped_ptr<protocol::InputStub> input_stub_; + // Executes input events received from the client. + scoped_ptr<EventExecutor> event_executor_; // Curtain ensures privacy for the remote user. scoped_ptr<Curtain> curtain_; diff --git a/remoting/host/event_executor.h b/remoting/host/event_executor.h index f99339b..449c670 100644 --- a/remoting/host/event_executor.h +++ b/remoting/host/event_executor.h @@ -1,23 +1,24 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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_EVENT_EXECUTOR_H_ #define REMOTING_HOST_EVENT_EXECUTOR_H_ +#include "remoting/protocol/input_stub.h" + class MessageLoopForUI; namespace remoting { class Capturer; -namespace protocol { -class InputStub; -} // namespace protocol - -// Creates default event executor for the current platform. -protocol::InputStub* CreateEventExecutor(MessageLoopForUI* message_loop, - Capturer* capturer); +class EventExecutor : public protocol::InputStub { + public: + // Creates default event executor for the current platform. + static EventExecutor* Create(MessageLoopForUI* message_loop, + Capturer* capturer); +}; } // namespace remoting diff --git a/remoting/host/event_executor_linux.cc b/remoting/host/event_executor_linux.cc index e41f0bf..efbdcd9 100644 --- a/remoting/host/event_executor_linux.cc +++ b/remoting/host/event_executor_linux.cc @@ -1,14 +1,16 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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/event_executor_linux.h" +#include "remoting/host/event_executor.h" #include <X11/Xlib.h> #include <X11/XF86keysym.h> #include <X11/keysym.h> #include <X11/extensions/XTest.h> +#include "base/basictypes.h" +#include "base/compiler_specific.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/task.h" @@ -19,8 +21,35 @@ namespace remoting { using protocol::MouseEvent; using protocol::KeyEvent; -static int MouseButtonToX11ButtonNumber( - protocol::MouseEvent::MouseButton button) { +namespace { + +// A class to generate events on Linux. +class EventExecutorLinux : public EventExecutor { + public: + EventExecutorLinux(MessageLoopForUI* message_loop, Capturer* capturer); + virtual ~EventExecutorLinux() {}; + + virtual void InjectKeyEvent(const KeyEvent* event, Task* done) OVERRIDE; + virtual void InjectMouseEvent(const MouseEvent* event, Task* done) OVERRIDE; + + private: + bool Init(); + MessageLoopForUI* message_loop_; + Capturer* capturer_; + + // X11 graphics context. + Display* display_; + Window root_window_; + int width_; + int height_; + + int test_event_base_; + int test_error_base_; + + DISALLOW_COPY_AND_ASSIGN(EventExecutorLinux); +}; + +int MouseButtonToX11ButtonNumber(MouseEvent::MouseButton button) { switch (button) { case MouseEvent::BUTTON_LEFT: return 1; @@ -196,7 +225,7 @@ const int kUsVkeyToKeysym[256] = { /* VKEY_NONAME */ -1, /* VKEY_PA1 */ -1, /* VKEY_OEM_CLEAR */ -1, -1 }; -static int ChromotocolKeycodeToX11Keysym(int32_t keycode) { +int ChromotocolKeycodeToX11Keysym(int32_t keycode) { if (keycode < 0 || keycode > 255) { return -1; } @@ -204,41 +233,18 @@ static int ChromotocolKeycodeToX11Keysym(int32_t keycode) { return kUsVkeyToKeysym[keycode]; } -class EventExecutorLinuxPimpl { - public: - explicit EventExecutorLinuxPimpl(EventExecutorLinux* executor, - Display* display); - - bool Init(); // TODO(ajwong): Do we really want this to be synchronous? - - void HandleMouse(const MouseEvent* message); - void HandleKey(const KeyEvent* key_event); - - private: - // Reference to containing class so we can access friend functions. - // Not owned. - EventExecutorLinux* executor_; - - // X11 graphics context. - Display* display_; - Window root_window_; - int width_; - int height_; - - int test_event_base_; - int test_error_base_; -}; - -EventExecutorLinuxPimpl::EventExecutorLinuxPimpl(EventExecutorLinux* executor, - Display* display) - : executor_(executor), - display_(display), +EventExecutorLinux::EventExecutorLinux( + MessageLoopForUI* message_loop, Capturer* capturer) + : message_loop_(message_loop), + capturer_(capturer), + display_(message_loop->GetDisplay()), root_window_(BadValue), width_(0), height_(0) { + CHECK(Init()); } -bool EventExecutorLinuxPimpl::Init() { +bool EventExecutorLinux::Init() { CHECK(display_); root_window_ = RootWindow(display_, DefaultScreen(display_)); @@ -267,16 +273,22 @@ bool EventExecutorLinuxPimpl::Init() { width_ = root_attr.width; height_ = root_attr.height; - return true; } -void EventExecutorLinuxPimpl::HandleKey(const KeyEvent* key_event) { +void EventExecutorLinux::InjectKeyEvent(const KeyEvent* event, Task* done) { + if (MessageLoop::current() != message_loop_) { + message_loop_->PostTask( + FROM_HERE, + NewRunnableMethod(this, &EventExecutorLinux::InjectKeyEvent, + event, done)); + return; + } // TODO(ajwong): This will only work for QWERTY keyboards. - int keysym = ChromotocolKeycodeToX11Keysym(key_event->keycode()); + int keysym = ChromotocolKeycodeToX11Keysym(event->keycode()); if (keysym == -1) { - LOG(WARNING) << "Ignoring unknown key: " << key_event->keycode(); + LOG(WARNING) << "Ignoring unknown key: " << event->keycode(); return; } @@ -284,17 +296,28 @@ void EventExecutorLinuxPimpl::HandleKey(const KeyEvent* key_event) { int keycode = XKeysymToKeycode(display_, keysym); if (keycode == 0) { LOG(WARNING) << "Ignoring undefined keysym: " << keysym - << " for key: " << key_event->keycode(); + << " for key: " << event->keycode(); return; } - VLOG(3) << "Got pepper key: " << key_event->keycode() + VLOG(3) << "Got pepper key: " << event->keycode() << " sending keysym: " << keysym << " to keycode: " << keycode; - XTestFakeKeyEvent(display_, keycode, key_event->pressed(), CurrentTime); + XTestFakeKeyEvent(display_, keycode, event->pressed(), CurrentTime); + + done->Run(); + delete done; } -void EventExecutorLinuxPimpl::HandleMouse(const MouseEvent* event) { +void EventExecutorLinux::InjectMouseEvent(const MouseEvent* event, + Task* done) { + if (MessageLoop::current() != message_loop_) { + message_loop_->PostTask( + FROM_HERE, + NewRunnableMethod(this, &EventExecutorLinux::InjectMouseEvent, + event, done)); + return; + } if (event->has_x() && event->has_y()) { if (event->x() < 0 || event->y() < 0 || event->x() > width_ || event->y() > height_) { @@ -329,49 +352,19 @@ void EventExecutorLinuxPimpl::HandleMouse(const MouseEvent* event) { if (event->has_wheel_offset_x() && event->has_wheel_offset_y()) { NOTIMPLEMENTED() << "No scroll wheel support yet."; } -} - -EventExecutorLinux::EventExecutorLinux( - MessageLoopForUI* message_loop, Capturer* capturer) - : message_loop_(message_loop), - capturer_(capturer), - pimpl_(new EventExecutorLinuxPimpl(this, message_loop->GetDisplay())) { - CHECK(pimpl_->Init()); -} - -EventExecutorLinux::~EventExecutorLinux() { -} -void EventExecutorLinux::InjectKeyEvent(const KeyEvent* event, Task* done) { - if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod(this, &EventExecutorLinux::InjectKeyEvent, - event, done)); - return; - } - pimpl_->HandleKey(event); done->Run(); delete done; } -void EventExecutorLinux::InjectMouseEvent(const MouseEvent* event, - Task* done) { - if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod(this, &EventExecutorLinux::InjectMouseEvent, - event, done)); - return; - } - pimpl_->HandleMouse(event); - done->Run(); - delete done; -} +} // namespace -protocol::InputStub* CreateEventExecutor(MessageLoopForUI* message_loop, - Capturer* capturer) { +EventExecutor* EventExecutor::Create(MessageLoopForUI* message_loop, + Capturer* capturer) { return new EventExecutorLinux(message_loop, capturer); } } // namespace remoting + +DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::EventExecutorLinux); + diff --git a/remoting/host/event_executor_linux.h b/remoting/host/event_executor_linux.h deleted file mode 100644 index 64ce94e..0000000 --- a/remoting/host/event_executor_linux.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2011 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_EVENT_EXECUTOR_LINUX_H_ -#define REMOTING_HOST_EVENT_EXECUTOR_LINUX_H_ - -#include <vector> - -#include "base/task.h" -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" -#include "remoting/host/event_executor.h" -#include "remoting/protocol/input_stub.h" - -namespace remoting { - -class EventExecutorLinuxPimpl; - -// A class to generate events on Linux. -class EventExecutorLinux : public protocol::InputStub { - public: - EventExecutorLinux(MessageLoopForUI* message_loop, - Capturer* capturer); - virtual ~EventExecutorLinux(); - - virtual void InjectKeyEvent(const protocol::KeyEvent* event, Task* done); - virtual void InjectMouseEvent(const protocol::MouseEvent* event, Task* done); - - private: - MessageLoopForUI* message_loop_; - Capturer* capturer_; - scoped_ptr<EventExecutorLinuxPimpl> pimpl_; - - DISALLOW_COPY_AND_ASSIGN(EventExecutorLinux); -}; - -} // namespace remoting - -DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::EventExecutorLinux); - -#endif // REMOTING_HOST_EVENT_EXECUTOR_LINUX_H_ diff --git a/remoting/host/event_executor_mac.cc b/remoting/host/event_executor_mac.cc index 808f964..e38f514 100644 --- a/remoting/host/event_executor_mac.cc +++ b/remoting/host/event_executor_mac.cc @@ -1,24 +1,46 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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/event_executor_mac.h" +#include "remoting/host/event_executor.h" #include <ApplicationServices/ApplicationServices.h> #include <Carbon/Carbon.h> +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/mac/scoped_cftyperef.h" #include "base/message_loop.h" #include "base/task.h" -#include "base/mac/scoped_cftyperef.h" #include "remoting/host/capturer.h" -#include "remoting/protocol/message_decoder.h" #include "remoting/proto/internal.pb.h" +#include "remoting/protocol/message_decoder.h" namespace remoting { +namespace { + using protocol::MouseEvent; using protocol::KeyEvent; +// A class to generate events on Mac. +class EventExecutorMac : public EventExecutor { + public: + EventExecutorMac(MessageLoopForUI* message_loop, Capturer* capturer); + virtual ~EventExecutorMac() {} + + virtual void InjectKeyEvent(const KeyEvent* event, Task* done) OVERRIDE; + virtual void InjectMouseEvent(const MouseEvent* event, Task* done) OVERRIDE; + + private: + MessageLoopForUI* message_loop_; + Capturer* capturer_; + int last_x_, last_y_; + int modifiers_, mouse_buttons_; + + DISALLOW_COPY_AND_ASSIGN(EventExecutorMac); +}; + EventExecutorMac::EventExecutorMac( MessageLoopForUI* message_loop, Capturer* capturer) : message_loop_(message_loop), @@ -26,9 +48,6 @@ EventExecutorMac::EventExecutorMac( mouse_buttons_(0) { } -EventExecutorMac::~EventExecutorMac() { -} - // Hard-coded mapping from Virtual Key codes to Mac KeySyms. // This mapping is only valid if both client and host are using a // US English keyboard layout. @@ -287,8 +306,10 @@ void EventExecutorMac::InjectMouseEvent(const MouseEvent* event, Task* done) { delete done; } -protocol::InputStub* CreateEventExecutor(MessageLoopForUI* message_loop, - Capturer* capturer) { +} // namespace + +EventExecutor* EventExecutor::Create(MessageLoopForUI* message_loop, + Capturer* capturer) { return new EventExecutorMac(message_loop, capturer); } diff --git a/remoting/host/event_executor_mac.h b/remoting/host/event_executor_mac.h deleted file mode 100644 index 4f84aef..0000000 --- a/remoting/host/event_executor_mac.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2010 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_EVENT_EXECUTOR_MAC_H_ -#define REMOTING_HOST_EVENT_EXECUTOR_MAC_H_ - -#include <vector> - -#include "base/basictypes.h" -#include "remoting/host/event_executor.h" -#include "remoting/protocol/input_stub.h" - -namespace remoting { - -// A class to generate events on Mac. -class EventExecutorMac : public protocol::InputStub { - public: - EventExecutorMac(MessageLoopForUI* message_loop, Capturer* capturer); - virtual ~EventExecutorMac(); - - virtual void InjectKeyEvent(const protocol::KeyEvent* event, Task* done); - virtual void InjectMouseEvent(const protocol::MouseEvent* event, Task* done); - - private: - MessageLoopForUI* message_loop_; - Capturer* capturer_; - int last_x_, last_y_; - int modifiers_, mouse_buttons_; - - DISALLOW_COPY_AND_ASSIGN(EventExecutorMac); -}; - -} // namespace remoting - -#endif // REMOTING_HOST_EVENT_EXECUTOR_MAC_H_ diff --git a/remoting/host/event_executor_win.cc b/remoting/host/event_executor_win.cc index b87119d..53c550a 100644 --- a/remoting/host/event_executor_win.cc +++ b/remoting/host/event_executor_win.cc @@ -1,13 +1,13 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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/event_executor_win.h" +#include "remoting/host/event_executor.h" #include <windows.h> +#include "base/compiler_specific.h" #include "base/message_loop.h" -#include "base/stl_util-inl.h" #include "remoting/host/capturer.h" #include "remoting/proto/event.pb.h" #include "ui/base/keycodes/keyboard_codes.h" @@ -17,15 +17,33 @@ namespace remoting { using protocol::MouseEvent; using protocol::KeyEvent; -EventExecutorWin::EventExecutorWin( - MessageLoopForUI* message_loop, Capturer* capturer) +namespace { + +// A class to generate events on Windows. +class EventExecutorWin : public EventExecutor { + public: + EventExecutorWin(MessageLoopForUI* message_loop, Capturer* capturer); + virtual ~EventExecutorWin() {} + + virtual void InjectKeyEvent(const KeyEvent* event, Task* done) OVERRIDE; + virtual void InjectMouseEvent(const MouseEvent* event, Task* done) OVERRIDE; + + private: + void HandleKey(const KeyEvent* event); + void HandleMouse(const MouseEvent* event); + + MessageLoopForUI* message_loop_; + Capturer* capturer_; + + DISALLOW_COPY_AND_ASSIGN(EventExecutorWin); +}; + +EventExecutorWin::EventExecutorWin(MessageLoopForUI* message_loop, + Capturer* capturer) : message_loop_(message_loop), capturer_(capturer) { } -EventExecutorWin::~EventExecutorWin() { -} - void EventExecutorWin::InjectKeyEvent(const KeyEvent* event, Task* done) { if (MessageLoop::current() != message_loop_) { message_loop_->PostTask( @@ -82,11 +100,6 @@ void EventExecutorWin::HandleKey(const KeyEvent* event) { SendInput(1, &input, sizeof(INPUT)); } -protocol::InputStub* CreateEventExecutor(MessageLoopForUI* message_loop, - Capturer* capturer) { - return new EventExecutorWin(message_loop, capturer); -} - void EventExecutorWin::HandleMouse(const MouseEvent* event) { // TODO(garykac) Collapse mouse (x,y) and button events into a single // input event when possible. @@ -153,4 +166,14 @@ void EventExecutorWin::HandleMouse(const MouseEvent* event) { } } +} // namespace + +EventExecutor* EventExecutor::Create(MessageLoopForUI* message_loop, + Capturer* capturer) { + return new EventExecutorWin(message_loop, capturer); +} + } // namespace remoting + +DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::EventExecutorWin); + diff --git a/remoting/host/event_executor_win.h b/remoting/host/event_executor_win.h deleted file mode 100644 index 9498319..0000000 --- a/remoting/host/event_executor_win.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2011 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_EVENT_EXECUTOR_WIN_H_ -#define REMOTING_HOST_EVENT_EXECUTOR_WIN_H_ - -#include <vector> - -#include "base/task.h" -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" -#include "remoting/host/event_executor.h" -#include "remoting/protocol/input_stub.h" - -namespace remoting { - -class EventExecutorWinPimpl; - -// A class to generate events on Windows. -class EventExecutorWin : public protocol::InputStub { - public: - EventExecutorWin(MessageLoopForUI* message_loop, Capturer* capturer); - virtual ~EventExecutorWin(); - - virtual void InjectKeyEvent(const protocol::KeyEvent* event, Task* done); - virtual void InjectMouseEvent(const protocol::MouseEvent* event, Task* done); - - private: - void HandleKey(const protocol::KeyEvent* event); - void HandleMouse(const protocol::MouseEvent* event); - - MessageLoopForUI* message_loop_; - Capturer* capturer_; - - DISALLOW_COPY_AND_ASSIGN(EventExecutorWin); -}; - -} // namespace remoting - -DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::EventExecutorWin); - -#endif // REMOTING_HOST_EVENT_EXECUTOR_WIN_H_ diff --git a/remoting/host/host_mock_objects.cc b/remoting/host/host_mock_objects.cc index 14dd4db..f47a284 100644 --- a/remoting/host/host_mock_objects.cc +++ b/remoting/host/host_mock_objects.cc @@ -10,9 +10,13 @@ MockCapturer::MockCapturer() {} MockCapturer::~MockCapturer() {} -MockCurtain::MockCurtain() { } +MockCurtain::MockCurtain() {} -MockCurtain::~MockCurtain() { } +MockCurtain::~MockCurtain() {} + +MockEventExecutor::MockEventExecutor() {} + +MockEventExecutor::~MockEventExecutor() {} Curtain* Curtain::Create() { return new MockCurtain(); @@ -27,4 +31,8 @@ MockClientSessionEventHandler::MockClientSessionEventHandler() {} MockClientSessionEventHandler::~MockClientSessionEventHandler() {} +MockUserAuthenticator::MockUserAuthenticator() {} + +MockUserAuthenticator::~MockUserAuthenticator() {} + } // namespace remoting diff --git a/remoting/host/host_mock_objects.h b/remoting/host/host_mock_objects.h index 31d0ba4..58d6381 100644 --- a/remoting/host/host_mock_objects.h +++ b/remoting/host/host_mock_objects.h @@ -9,6 +9,8 @@ #include "remoting/host/curtain.h" #include "remoting/host/chromoting_host_context.h" #include "remoting/host/client_session.h" +#include "remoting/host/event_executor.h" +#include "remoting/host/user_authenticator.h" #include "testing/gmock/include/gmock/gmock.h" namespace remoting { @@ -69,6 +71,32 @@ class MockClientSessionEventHandler : public ClientSession::EventHandler { DISALLOW_COPY_AND_ASSIGN(MockClientSessionEventHandler); }; +class MockEventExecutor : public EventExecutor { + public: + MockEventExecutor(); + virtual ~MockEventExecutor(); + + MOCK_METHOD2(InjectKeyEvent, void(const protocol::KeyEvent* event, + Task* done)); + MOCK_METHOD2(InjectMouseEvent, void(const protocol::MouseEvent* event, + Task* done)); + + private: + DISALLOW_COPY_AND_ASSIGN(MockEventExecutor); +}; + +class MockUserAuthenticator : public UserAuthenticator { + public: + MockUserAuthenticator(); + virtual ~MockUserAuthenticator(); + + MOCK_METHOD2(Authenticate, bool(const std::string& username, + const std::string& password)); + + private: + DISALLOW_COPY_AND_ASSIGN(MockUserAuthenticator); +}; + } // namespace remoting #endif // REMOTING_HOST_HOST_MOCK_OBJECTS_H_ diff --git a/remoting/host/screen_recorder_unittest.cc b/remoting/host/screen_recorder_unittest.cc index b5e8f8a..69650ee 100644 --- a/remoting/host/screen_recorder_unittest.cc +++ b/remoting/host/screen_recorder_unittest.cc @@ -15,7 +15,6 @@ using ::remoting::protocol::MockConnectionToClient; using ::remoting::protocol::MockConnectionToClientEventHandler; using ::remoting::protocol::MockHostStub; -using ::remoting::protocol::MockInputStub; using ::remoting::protocol::MockVideoStub; using ::testing::_; @@ -82,7 +81,7 @@ class ScreenRecorderTest : public testing::Test { encoder_ = new MockEncoder(); connection_ = new MockConnectionToClient(&message_loop_, &handler_, - &host_stub_, &input_stub_); + &host_stub_, &event_executor_); record_ = new ScreenRecorder( &message_loop_, &message_loop_, &message_loop_, @@ -94,7 +93,7 @@ class ScreenRecorderTest : public testing::Test { MockConnectionToClientEventHandler handler_; MockHostStub host_stub_; - MockInputStub input_stub_; + MockEventExecutor event_executor_; scoped_refptr<MockConnectionToClient> connection_; // The following mock objects are owned by ScreenRecorder. diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc index a0cebf57..7c3a595 100644 --- a/remoting/host/simple_host_process.cc +++ b/remoting/host/simple_host_process.cc @@ -131,12 +131,12 @@ int main(int argc, char** argv) { if (fake) { remoting::Capturer* capturer = new remoting::CapturerFake(); - remoting::protocol::InputStub* input_stub = - CreateEventExecutor(context.ui_message_loop(), capturer); + remoting::EventExecutor* event_executor = + remoting::EventExecutor::Create(context.ui_message_loop(), capturer); remoting::Curtain* curtain = remoting::Curtain::Create(); host = ChromotingHost::Create( &context, config, - new DesktopEnvironment(capturer, input_stub, curtain)); + new DesktopEnvironment(capturer, event_executor, curtain)); } else { host = ChromotingHost::Create(&context, config); } diff --git a/remoting/host/user_authenticator.h b/remoting/host/user_authenticator.h index b6f6a7f..4ac71ad 100644 --- a/remoting/host/user_authenticator.h +++ b/remoting/host/user_authenticator.h @@ -11,8 +11,6 @@ namespace remoting { // Interface for authenticating users for access to remote desktop session. // Implementation is platform-specific. -// Implementations may assume each instance of this class handles only a -// single Authenticate request. // TODO(lambroslambrou): Decide whether this needs an asychronous interface // (for example AuthenticateStart()..AuthenticateEndCallback()), or whether the diff --git a/remoting/host/user_authenticator_fake.cc b/remoting/host/user_authenticator_fake.cc deleted file mode 100644 index 61b19f7..0000000 --- a/remoting/host/user_authenticator_fake.cc +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2011 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/user_authenticator_fake.h" - -#include <string> - -namespace remoting { - -UserAuthenticatorFake::UserAuthenticatorFake() {} -UserAuthenticatorFake::~UserAuthenticatorFake() {} - -bool UserAuthenticatorFake::Authenticate(const std::string& username, - const std::string& password) { - return (username.compare(fail_username()) || - password.compare(fail_password())); -} - -const char* UserAuthenticatorFake::fail_username() { - return "userfail"; -} - -const char* UserAuthenticatorFake::fail_password() { - return "passwordfail"; -} - -} // namespace remoting diff --git a/remoting/host/user_authenticator_fake.h b/remoting/host/user_authenticator_fake.h deleted file mode 100644 index faf1171..0000000 --- a/remoting/host/user_authenticator_fake.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2011 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_USER_AUTHENTICATOR_FAKE_H_ -#define REMOTING_HOST_USER_AUTHENTICATOR_FAKE_H_ - -#include <string> - -#include "base/basictypes.h" -#include "remoting/host/user_authenticator.h" - -namespace remoting { - -// A fake UserAuthenticator, which accepts all but one user/password pair. -class UserAuthenticatorFake : public UserAuthenticator { - public: - UserAuthenticatorFake(); - virtual ~UserAuthenticatorFake(); - - virtual bool Authenticate(const std::string& username, - const std::string& password); - - // Get the user/password pair that a UserAuthenticatorFake rejects. - static const char* fail_username(); - static const char* fail_password(); - - private: - DISALLOW_COPY_AND_ASSIGN(UserAuthenticatorFake); -}; - -} // namespace remoting - -#endif // REMOTING_HOST_USER_AUTHENTICATOR_FAKE_H_ diff --git a/remoting/host/user_authenticator_linux.cc b/remoting/host/user_authenticator_linux.cc index d3b837c..b1a70cd 100644 --- a/remoting/host/user_authenticator_linux.cc +++ b/remoting/host/user_authenticator_linux.cc @@ -2,10 +2,132 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "remoting/host/user_authenticator_pam.h" +#include "remoting/host/user_authenticator.h" + +#include <security/pam_appl.h> +#include <stdlib.h> + +#include <string> + +#include "base/basictypes.h" namespace remoting { +namespace { + +// Class to perform a single PAM user authentication. +// +// TODO(lambroslambrou): As pam_authenticate() can be blocking, this needs to +// expose an asynchronous API, with pam_authenticate() called in a background +// thread. +class UserAuthenticatorPam : public UserAuthenticator { + public: + UserAuthenticatorPam() {} + virtual ~UserAuthenticatorPam() {} + virtual bool Authenticate(const std::string& username, + const std::string& password); + + private: + // Conversation function passed to PAM as a callback. + static int ConvFunction(int num_msg, + const pam_message** msg, + pam_response** resp, + void* appdata_ptr); + + // Store these for the PAM conversation function. + std::string username_; + std::string password_; + + DISALLOW_COPY_AND_ASSIGN(UserAuthenticatorPam); +}; + +const char kPamServiceName[] = "chromoting"; + +bool UserAuthenticatorPam::Authenticate(const std::string& username, + const std::string& password) { + username_ = username; + password_ = password; + pam_conv conversation; + conversation.conv = ConvFunction; + conversation.appdata_ptr = static_cast<void*>(this); + // TODO(lambroslambrou): Allow PAM service name to be configurable. + pam_handle_t* pam_handle; + if (pam_start(kPamServiceName, username_.c_str(), + &conversation, &pam_handle) != PAM_SUCCESS) { + return false; + } + + // TODO(lambroslambrou): Move to separate thread. + int pam_status = pam_authenticate(pam_handle, 0); + pam_end(pam_handle, pam_status); + return pam_status == PAM_SUCCESS; +} + +// static +int UserAuthenticatorPam::ConvFunction(int num_msg, + const pam_message** msg, + pam_response** resp, + void* appdata_ptr) { + if (num_msg <= 0) + return PAM_CONV_ERR; + UserAuthenticatorPam* user_auth = + static_cast<UserAuthenticatorPam*>(appdata_ptr); + // Must allocate with malloc(), as the calling PAM module will + // release the memory with free(). + pam_response* resp_tmp = static_cast<pam_response*>( + malloc(num_msg * sizeof(pam_response))); + if (resp_tmp == NULL) + return PAM_CONV_ERR; + + bool raise_error = false; + // On exit from the loop, 'count' will hold the number of initialised items + // that the cleanup code needs to look at, in case of error. + int count; + for (count = 0; count < num_msg; count++) { + // Alias for readability. + pam_response* resp_item = &resp_tmp[count]; + resp_item->resp_retcode = 0; + resp_item->resp = NULL; + switch (msg[count]->msg_style) { + case PAM_PROMPT_ECHO_ON: + resp_item->resp = strdup(user_auth->username_.c_str()); + if (resp_item->resp == NULL) + raise_error = true; + break; + case PAM_PROMPT_ECHO_OFF: + resp_item->resp = strdup(user_auth->password_.c_str()); + if (resp_item->resp == NULL) + raise_error = true; + break; + case PAM_TEXT_INFO: + // No response needed, as this instructs the PAM client to display + // text to the user. Leave as NULL and continue with next prompt. + break; + default: + // Unexpected style code, so abort. + raise_error = true; + } + if (raise_error) + break; + } + + if (raise_error) { + // Not passing the response back, so free up any memory used. + for (int n = 0; n < count; n++) { + if (resp_tmp[n].resp) { + free(resp_tmp[n].resp); + } + } + free(resp_tmp); + return PAM_CONV_ERR; + } else { + *resp = resp_tmp; + return PAM_SUCCESS; + } +} + +} // namespace + // static UserAuthenticator* UserAuthenticator::Create() { return new UserAuthenticatorPam(); diff --git a/remoting/host/user_authenticator_mac.cc b/remoting/host/user_authenticator_mac.cc index dd44b06..88c0951 100644 --- a/remoting/host/user_authenticator_mac.cc +++ b/remoting/host/user_authenticator_mac.cc @@ -2,23 +2,31 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "remoting/host/user_authenticator_mac.h" +#include "remoting/host/user_authenticator.h" #include <Security/Security.h> #include <string> +#include "base/basictypes.h" #include "base/logging.h" namespace remoting { -static const char kAuthorizationRightName[] = "system.login.tty"; +namespace { -UserAuthenticatorMac::UserAuthenticatorMac() { -} +class UserAuthenticatorMac : public UserAuthenticator { + public: + UserAuthenticatorMac() {} + virtual ~UserAuthenticatorMac() {} + virtual bool Authenticate(const std::string& username, + const std::string& password); -UserAuthenticatorMac::~UserAuthenticatorMac() { -} + private: + DISALLOW_COPY_AND_ASSIGN(UserAuthenticatorMac); +}; + +const char kAuthorizationRightName[] = "system.login.tty"; bool UserAuthenticatorMac::Authenticate(const std::string& username, const std::string& password) { @@ -33,6 +41,7 @@ bool UserAuthenticatorMac::Authenticate(const std::string& username, AuthorizationRights rights; rights.count = 1; rights.items = &right; + // Passing the username/password as an "environment" parameter causes these // to be submitted to the Security Framework, instead of the interactive // password prompt appearing on the host system. Valid on OS X 10.4 and @@ -66,6 +75,8 @@ bool UserAuthenticatorMac::Authenticate(const std::string& username, } } +} // namespace + // static UserAuthenticator* UserAuthenticator::Create() { return new UserAuthenticatorMac(); diff --git a/remoting/host/user_authenticator_mac.h b/remoting/host/user_authenticator_mac.h deleted file mode 100644 index bb99ce7..0000000 --- a/remoting/host/user_authenticator_mac.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2011 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_USER_AUTHENTICATOR_MAC_H_ -#define REMOTING_HOST_USER_AUTHENTICATOR_MAC_H_ - -#include <string> - -#include "base/basictypes.h" -#include "remoting/host/user_authenticator.h" - -namespace remoting { - -class UserAuthenticatorMac : public UserAuthenticator { - public: - UserAuthenticatorMac(); - virtual ~UserAuthenticatorMac(); - virtual bool Authenticate(const std::string& username, - const std::string& password); - - private: - DISALLOW_COPY_AND_ASSIGN(UserAuthenticatorMac); -}; - -} // namespace remoting - -#endif // REMOTING_HOST_USER_AUTHENTICATOR_MAC_H_ diff --git a/remoting/host/user_authenticator_pam.cc b/remoting/host/user_authenticator_pam.cc deleted file mode 100644 index 5a45f4c..0000000 --- a/remoting/host/user_authenticator_pam.cc +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) 2011 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/user_authenticator_pam.h" - -#include <stdlib.h> - -#include <string> - -#include <security/pam_appl.h> - -namespace remoting { - -static const char kPamServiceName[] = "chromoting"; - -UserAuthenticatorPam::UserAuthenticatorPam() { -} - -UserAuthenticatorPam::~UserAuthenticatorPam() { -} - -bool UserAuthenticatorPam::Authenticate(const std::string& username, - const std::string& password) { - username_ = username; - password_ = password; - pam_conv conversation; - conversation.conv = ConvFunction; - conversation.appdata_ptr = static_cast<void*>(this); - // TODO(lambroslambrou): Allow PAM service name to be configurable. - pam_handle_t* pam_handle; - if (pam_start(kPamServiceName, username_.c_str(), - &conversation, &pam_handle) != PAM_SUCCESS) { - return false; - } - - // TODO(lambroslambrou): Move to separate thread. - int pam_status = pam_authenticate(pam_handle, 0); - pam_end(pam_handle, pam_status); - return pam_status == PAM_SUCCESS; -} - -// static -int UserAuthenticatorPam::ConvFunction(int num_msg, - const pam_message** msg, - pam_response** resp, - void* appdata_ptr) { - if (num_msg <= 0) - return PAM_CONV_ERR; - UserAuthenticatorPam* user_auth = - static_cast<UserAuthenticatorPam*>(appdata_ptr); - // Must allocate with malloc(), as the calling PAM module will - // release the memory with free(). - pam_response* resp_tmp = static_cast<pam_response*>( - malloc(num_msg * sizeof(pam_response))); - if (resp_tmp == NULL) - return PAM_CONV_ERR; - - bool raise_error = false; - // On exit from the loop, 'count' will hold the number of initialised items - // that the cleanup code needs to look at, in case of error. - int count; - for (count = 0; count < num_msg; count++) { - // Alias for readability. - pam_response* resp_item = &resp_tmp[count]; - resp_item->resp_retcode = 0; - resp_item->resp = NULL; - switch (msg[count]->msg_style) { - case PAM_PROMPT_ECHO_ON: - resp_item->resp = strdup(user_auth->username_.c_str()); - if (resp_item->resp == NULL) - raise_error = true; - break; - case PAM_PROMPT_ECHO_OFF: - resp_item->resp = strdup(user_auth->password_.c_str()); - if (resp_item->resp == NULL) - raise_error = true; - break; - case PAM_TEXT_INFO: - // No response needed, as this instructs the PAM client to display - // text to the user. Leave as NULL and continue with next prompt. - break; - default: - // Unexpected style code, so abort. - raise_error = true; - } - if (raise_error) - break; - } - - if (raise_error) { - // Not passing the response back, so free up any memory used. - for (int n = 0; n < count; n++) { - if (resp_tmp[n].resp) { - free(resp_tmp[n].resp); - } - } - free(resp_tmp); - return PAM_CONV_ERR; - } else { - *resp = resp_tmp; - return PAM_SUCCESS; - } -} - -} // namespace remoting diff --git a/remoting/host/user_authenticator_pam.h b/remoting/host/user_authenticator_pam.h deleted file mode 100644 index f854731..0000000 --- a/remoting/host/user_authenticator_pam.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2011 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_USER_AUTHENTICATOR_PAM_H_ -#define REMOTING_HOST_USER_AUTHENTICATOR_PAM_H_ - -#include <string> - -#include "base/basictypes.h" -#include "remoting/host/user_authenticator.h" - -struct pam_message; -struct pam_response; - -namespace remoting { - -// Class to perform a single PAM user authentication. -// -// TODO(lambroslambrou): As pam_authenticate() can be blocking, this needs to -// expose an asynchronous API, with pam_authenticate() called in a background -// thread. -class UserAuthenticatorPam : public UserAuthenticator { - public: - UserAuthenticatorPam(); - virtual ~UserAuthenticatorPam(); - virtual bool Authenticate(const std::string& username, - const std::string& password); - - private: - // Conversation function passed to PAM as a callback. - static int ConvFunction(int num_msg, - const pam_message** msg, - pam_response** resp, - void* appdata_ptr); - - // Store these for the PAM conversation function. - std::string username_; - std::string password_; - - DISALLOW_COPY_AND_ASSIGN(UserAuthenticatorPam); -}; - -} // namespace remoting - -#endif // REMOTING_HOST_USER_AUTHENTICATOR_PAM_H_ diff --git a/remoting/host/user_authenticator_win.cc b/remoting/host/user_authenticator_win.cc index 956484a..3efb357 100644 --- a/remoting/host/user_authenticator_win.cc +++ b/remoting/host/user_authenticator_win.cc @@ -2,13 +2,40 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "remoting/host/user_authenticator_fake.h" +#include "remoting/host/user_authenticator.h" + +#include <string> + +#include "base/basictypes.h" +#include "base/logging.h" namespace remoting { +namespace { + +class UserAuthenticatorWin : public UserAuthenticator { + public: + UserAuthenticatorWin() {} + virtual ~UserAuthenticatorWin() {} + + virtual bool Authenticate(const std::string& username, + const std::string& password); + + private: + DISALLOW_COPY_AND_ASSIGN(UserAuthenticatorWin); +}; + +bool UserAuthenticatorWin::Authenticate(const std::string& username, + const std::string& password) { + NOTIMPLEMENTED(); + return true; +} + +} // namespace + // static UserAuthenticator* UserAuthenticator::Create() { - return new UserAuthenticatorFake(); + return new UserAuthenticatorWin(); } } // namespace remoting diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index 9c6f056..f2080f1 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -105,19 +105,9 @@ '../media/base/yuv_convert.h', '../media/base/yuv_row.h', '../media/base/yuv_row_table.cc', + '../media/base/yuv_row_win.cc', + '../media/base/yuv_row_posix.cc', ], - 'conditions': [ - ['OS=="win"', { - 'sources': [ - '../media/base/yuv_row_win.cc', - ], - }], - ['OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="mac"', { - 'sources': [ - '../media/base/yuv_row_posix.cc', - ], - }], - ], # end of 'conditions' }, # end of target 'chromoting_plugin' { @@ -204,6 +194,9 @@ 'host/capturer_helper.h', 'host/capturer_fake.cc', 'host/capturer_fake.h', + 'host/capturer_linux.cc', + 'host/capturer_mac.cc', + 'host/capturer_win.cc', 'host/chromoting_host.cc', 'host/chromoting_host.h', 'host/chromoting_host_context.cc', @@ -211,52 +204,40 @@ 'host/client_session.cc', 'host/client_session.h', 'host/curtain.h', + 'host/curtain_linux.cc', + 'host/curtain_mac.cc', + 'host/curtain_win.cc', 'host/desktop_environment.cc', 'host/desktop_environment.h', 'host/differ.h', 'host/differ.cc', - 'host/screen_recorder.cc', - 'host/screen_recorder.h', + 'host/event_executor.h', + 'host/event_executor_linux.cc', + 'host/event_executor_mac.cc', + 'host/event_executor_win.cc', 'host/heartbeat_sender.cc', 'host/heartbeat_sender.h', 'host/host_config.cc', 'host/host_config.h', 'host/host_key_pair.cc', 'host/host_key_pair.h', - 'host/json_host_config.cc', - 'host/json_host_config.h', 'host/in_memory_host_config.cc', 'host/in_memory_host_config.h', + 'host/json_host_config.cc', + 'host/json_host_config.h', + 'host/screen_recorder.cc', + 'host/screen_recorder.h', 'host/user_authenticator.h', + 'host/user_authenticator_linux.cc', + 'host/user_authenticator_mac.cc', + 'host/user_authenticator_win.cc', ], 'conditions': [ - ['OS=="win"', { - 'sources': [ - 'host/capturer_gdi.cc', - 'host/capturer_gdi.h', - 'host/curtain_win.cc', - 'host/curtain_win.h', - 'host/event_executor_win.cc', - 'host/event_executor_win.h', - 'host/user_authenticator_fake.cc', - 'host/user_authenticator_fake.h', - 'host/user_authenticator_win.cc', - ], - }], ['OS=="linux"', { 'dependencies': [ '../build/linux/system.gyp:gtk', ], 'sources': [ - 'host/capturer_linux.cc', - 'host/capturer_linux.h', - 'host/curtain_linux.cc', - 'host/curtain_linux.h', - 'host/event_executor_linux.cc', - 'host/event_executor_linux.h', - 'host/user_authenticator_linux.cc', - 'host/user_authenticator_pam.cc', - 'host/user_authenticator_pam.h', 'host/x_server_pixel_buffer.cc', 'host/x_server_pixel_buffer.h', ], @@ -271,16 +252,6 @@ }, }], ['OS=="mac"', { - 'sources': [ - 'host/capturer_mac.cc', - 'host/capturer_mac.h', - 'host/curtain_mac.cc', - 'host/curtain_mac.h', - 'host/event_executor_mac.cc', - 'host/event_executor_mac.h', - 'host/user_authenticator_mac.cc', - 'host/user_authenticator_mac.h', - ], 'link_settings': { 'libraries': [ '$(SDKROOT)/System/Library/Frameworks/OpenGL.framework', @@ -541,6 +512,9 @@ 'base/base_mock_objects.h', # BUG57351 'client/chromoting_view_unittest.cc', 'host/access_verifier_unittest.cc', + 'host/capturer_linux_unittest.cc', + 'host/capturer_mac_unittest.cc', + 'host/capturer_win_unittest.cc', 'host/chromoting_host_context_unittest.cc', 'host/chromoting_host_unittest.cc', 'host/client_session_unittest.cc', @@ -553,8 +527,6 @@ 'host/json_host_config_unittest.cc', 'host/screen_recorder_unittest.cc', 'host/test_key_pair.h', - 'host/user_authenticator_fake.cc', - 'host/user_authenticator_fake.h', 'jingle_glue/iq_request_unittest.cc', 'jingle_glue/jingle_client_unittest.cc', 'jingle_glue/jingle_thread_unittest.cc', @@ -573,11 +545,6 @@ 'run_all_unittests.cc', ], 'conditions': [ - ['OS=="win"', { - 'sources': [ - 'host/capturer_gdi_unittest.cc', - ], - }], ['OS=="linux"', { 'dependencies': [ '../app/app.gyp:app_base', @@ -587,9 +554,6 @@ # gtk/gtk.h '../build/linux/system.gyp:gtk', ], - 'sources': [ - 'host/capturer_linux_unittest.cc', - ], 'conditions': [ [ 'linux_use_tcmalloc==1', { 'dependencies': [ @@ -599,11 +563,6 @@ ], ], }], - ['OS=="mac"', { - 'sources': [ - 'host/capturer_mac_unittest.cc', - ], - }], ['target_arch=="arm"', { 'sources!': [ 'base/decoder_vp8_unittest.cc', |