diff options
author | cwolfe@chromium.org <cwolfe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-15 21:54:13 +0000 |
---|---|---|
committer | cwolfe@chromium.org <cwolfe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-15 21:54:13 +0000 |
commit | 5a8b12dc6eba4c0697a557eeec61eae805f8ee7d (patch) | |
tree | ca4dad402909fef457b06589809e419412be8ac5 /chrome | |
parent | c579e424e985efb95eb719848fd1498045ac04d1 (diff) | |
download | chromium_src-5a8b12dc6eba4c0697a557eeec61eae805f8ee7d.zip chromium_src-5a8b12dc6eba4c0697a557eeec61eae805f8ee7d.tar.gz chromium_src-5a8b12dc6eba4c0697a557eeec61eae805f8ee7d.tar.bz2 |
chromeos: Add operations to monitor the screen orientation.
This is intended to help test <http://codereview.chromium.org/7273073/>.
These orientation-only functions will later be replaced with a
generalized sensors API (after appropriate design review). Getting
this pipeline working helps root out bugs and issues in the interim.
BUG=None
TEST=Inject orientation changes via dbus API.
With <http://codereview.chromium.org/7845029/>, inject changes using dbus-send:
dbus-send --system / org.chromium.Sensors.ScreenOrientationChanged int32:1
Review URL: http://codereview.chromium.org/7862020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101387 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chromeos/DEPS | 1 | ||||
-rw-r--r-- | chrome/browser/chromeos/chrome_browser_main_chromeos.cc | 25 | ||||
-rw-r--r-- | chrome/browser/chromeos/chrome_browser_main_chromeos.h | 9 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/login_utils.cc | 1 | ||||
-rw-r--r-- | chrome/browser/chromeos/sensors_source_chromeos.cc | 88 | ||||
-rw-r--r-- | chrome/browser/chromeos/sensors_source_chromeos.h | 61 | ||||
-rw-r--r-- | chrome/browser/ui/touch/frame/touch_browser_frame_view.cc | 12 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 4 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 |
10 files changed, 196 insertions, 8 deletions
diff --git a/chrome/browser/chromeos/DEPS b/chrome/browser/chromeos/DEPS index 53f46fd..27f2ce6 100644 --- a/chrome/browser/chromeos/DEPS +++ b/chrome/browser/chromeos/DEPS @@ -1,3 +1,4 @@ include_rules = [ "+cros", + "+dbus", ] diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc index 2fa1a04..dfabefc 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc @@ -1,15 +1,18 @@ -// 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 "chrome/browser/chromeos/chrome_browser_main_chromeos.h" +#include "base/bind.h" +#include "base/callback.h" #include "base/command_line.h" #include "base/lazy_instance.h" #include "base/message_loop.h" #include "chrome/browser/chromeos/boot_times_loader.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/net/cros_network_change_notifier_factory.h" +#include "chrome/browser/chromeos/sensors_source_chromeos.h" #include "chrome/browser/defaults.h" #include "chrome/common/chrome_switches.h" #include "content/common/main_function_params.h" @@ -17,6 +20,17 @@ #include <gtk/gtk.h> +namespace { + +// Queued in PostMainMessageLoopStart. Needs to run after the IO thread is +// available via BrowserThread, as this is used by SensorsSourceChromeos. +void DoDeferredSensorsInit(sensors::SensorsSourceChromeos* source) { + if (!source->Init()) + LOG(WARNING) << "Failed to initialize sensors source."; +} + +} // namespace + class MessageLoopObserver : public MessageLoopForUI::Observer { virtual void WillProcessEvent(GdkEvent* event) { // On chromeos we want to map Alt-left click to right click. @@ -93,4 +107,13 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopStart() { ChromeBrowserMainPartsPosix::PostMainMessageLoopStart(); MessageLoopForUI* message_loop = MessageLoopForUI::current(); message_loop->AddObserver(g_message_loop_observer.Pointer()); + + if (parameters().command_line_.HasSwitch(switches::kEnableSensors)) { + sensors_source_ = new sensors::SensorsSourceChromeos(); + // This initialization needs to be performed after BrowserThread::FILE is + // started. Post it into the current (UI) message loop, so that will be + // deferred until after browser main. + message_loop->PostTask(FROM_HERE, + base::Bind(&DoDeferredSensorsInit, sensors_source_)); + } } diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.h b/chrome/browser/chromeos/chrome_browser_main_chromeos.h index cd4ef5c..f5be25e9 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.h +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.h @@ -1,12 +1,17 @@ -// 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 CHROME_BROWSER_CHROMEOS_CHROME_BROWSER_MAIN_CHROMEOS_H_ #define CHROME_BROWSER_CHROMEOS_CHROME_BROWSER_MAIN_CHROMEOS_H_ +#include "base/memory/ref_counted.h" #include "chrome/browser/chrome_browser_main_gtk.h" +namespace sensors { +class SensorsSourceChromeos; +} // namespace sensors + class ChromeBrowserMainPartsChromeos : public ChromeBrowserMainPartsGtk { public: explicit ChromeBrowserMainPartsChromeos(const MainFunctionParams& parameters); @@ -18,6 +23,8 @@ class ChromeBrowserMainPartsChromeos : public ChromeBrowserMainPartsGtk { virtual void PostMainMessageLoopStart() OVERRIDE; private: + scoped_refptr<sensors::SensorsSourceChromeos> sensors_source_; + DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainPartsChromeos); }; diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc index 3b5630d..f7406a9 100644 --- a/chrome/browser/chromeos/login/login_utils.cc +++ b/chrome/browser/chromeos/login/login_utils.cc @@ -796,6 +796,7 @@ std::string LoginUtilsImpl::GetOffTheRecordCommandLine( switches::kUserDataDir, switches::kScrollPixels, switches::kEnableGView, + switches::kEnableSensors, switches::kNoFirstRun, switches::kLoginProfile, switches::kCompressSystemFeedback, diff --git a/chrome/browser/chromeos/sensors_source_chromeos.cc b/chrome/browser/chromeos/sensors_source_chromeos.cc new file mode 100644 index 0000000..233511a --- /dev/null +++ b/chrome/browser/chromeos/sensors_source_chromeos.cc @@ -0,0 +1,88 @@ +// 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 "chrome/browser/chromeos/sensors_source_chromeos.h" + +#include "base/bind.h" +#include "base/callback.h" +#include "content/browser/browser_thread.h" +#include "content/browser/sensors/sensors_provider.h" +#include "dbus/bus.h" +#include "dbus/message.h" +#include "dbus/object_proxy.h" + +// TODO(cwolfe): Fix the DEPs so that these can be pulled in from +// "chromeos/dbus/service_constants.h". +namespace chromeos { +// Sensors service identifiers. +const char kSensorsServiceName[] = "org.chromium.Sensors"; +const char kSensorsServicePath[] = "/org/chromium/Sensors"; +const char kSensorsServiceInterface[] = "org.chromium.Sensors"; +// Sensors signal names. +const char kScreenOrientationChanged[] = "ScreenOrientationChanged"; +} // namespace chromeos + +namespace sensors { + +SensorsSourceChromeos::SensorsSourceChromeos() : sensors_proxy_(NULL) { +} + +bool SensorsSourceChromeos::Init() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::FILE)); + + dbus::Bus::Options options; + options.bus_type = dbus::Bus::SYSTEM; + options.connection_type = dbus::Bus::PRIVATE; + options.dbus_thread_message_loop_proxy = + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); + bus_ = new dbus::Bus(options); + + sensors_proxy_ = bus_->GetObjectProxy(chromeos::kSensorsServiceName, + chromeos::kSensorsServicePath); + sensors_proxy_->ConnectToSignal(chromeos::kSensorsServiceInterface, + chromeos::kScreenOrientationChanged, + base::Bind(&SensorsSourceChromeos::OrientationChangedReceived, this), + base::Bind(&SensorsSourceChromeos::OrientationChangedConnected, this)); + return true; +} + +void SensorsSourceChromeos::Stop() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + if (bus_) + bus_->ShutdownOnDBusThreadAndBlock(); +} + +SensorsSourceChromeos::~SensorsSourceChromeos() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + Stop(); +} + +void SensorsSourceChromeos::OrientationChangedReceived(dbus::Signal* signal) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + ScreenOrientation orientation; + + dbus::MessageReader reader(signal); + int32 upward = 0; + if (!reader.PopInt32(&upward)) { + LOG(WARNING) << "Orientation changed signal had incorrect parameters: " + << signal->ToString(); + return; + } + orientation.upward = static_cast<ScreenOrientation::Side>(upward); + + Provider::GetInstance()->ScreenOrientationChanged(orientation); +} + +void SensorsSourceChromeos::OrientationChangedConnected( + const std::string& interface_name, + const std::string& signal_name, + bool success) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + if (!success) + LOG(WARNING) << "Failed to connect to orientation changed signal."; +} + +} // namespace sensors diff --git a/chrome/browser/chromeos/sensors_source_chromeos.h b/chrome/browser/chromeos/sensors_source_chromeos.h new file mode 100644 index 0000000..fe8cc6f --- /dev/null +++ b/chrome/browser/chromeos/sensors_source_chromeos.h @@ -0,0 +1,61 @@ +// 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 CHROME_BROWSER_CHROMEOS_SENSORS_SOURCE_CHROMEOS_H_ +#define CHROME_BROWSER_CHROMEOS_SENSORS_SOURCE_CHROMEOS_H_ + +#include "base/memory/ref_counted.h" +#include "content/browser/browser_thread.h" + +#include <string> + +namespace dbus { +class Bus; +class ObjectProxy; +class Signal; +} // namespace + +namespace sensors { + +// Creates and manages a dbus signal receiver for device orientation changes, +// and eventually receives data for other motion-related sensors. +class SensorsSourceChromeos + : public base::RefCountedThreadSafe<SensorsSourceChromeos, + BrowserThread::DeleteOnUIThread> { + public: + // Creates an inactive sensors source. + SensorsSourceChromeos(); + + // Initializes this sensor source and begins listening for signals. + // Returns true on success. + // + // The sensor source performs DBus operations using BrowserThread::FILE, + // which must have been started before calling this method. + bool Init(); + + // Shuts down this sensors source and the underlying DBus connection. + void Stop(); + + private: + friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; + friend class DeleteTask<SensorsSourceChromeos>; + virtual ~SensorsSourceChromeos(); + + // Called by dbus:: in when an orientation change signal is received. + void OrientationChangedReceived(dbus::Signal* signal); + + // Called by dbus:: when the orientation change signal is initially connected. + void OrientationChangedConnected(const std::string& interface_name, + const std::string& signal_name, + bool success); + + scoped_refptr<dbus::Bus> bus_; + dbus::ObjectProxy* sensors_proxy_; + + DISALLOW_COPY_AND_ASSIGN(SensorsSourceChromeos); +}; + +} // namespace sensors + +#endif // CHROME_BROWSER_CHROMEOS_SENSORS_SOURCE_CHROMEOS_H_ diff --git a/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc b/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc index c81d51b..6dda0f7 100644 --- a/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc +++ b/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc @@ -109,10 +109,10 @@ void TouchBrowserFrameView::OnScreenOrientationChanged( initialized_screen_rotation_ = true; } - ui::Transform xform = SideToTransform(change.upward, - to_rotate->GetTransform(), - to_rotate->size()); - - to_rotate->SetTransform(xform); + const ui::Transform& old_xform = to_rotate->GetTransform(); + const ui::Transform& new_xform = SideToTransform(change.upward, + old_xform, + to_rotate->size()); + if (old_xform != new_xform) + to_rotate->SetTransform(new_xform); } - diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 4b3183c..0db412c 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -720,6 +720,8 @@ 'browser/chromeos/proxy_config_service_impl.h', 'browser/chromeos/proxy_cros_settings_provider.cc', 'browser/chromeos/proxy_cros_settings_provider.h', + 'browser/chromeos/sensors_source_chromeos.cc', + 'browser/chromeos/sensors_source_chromeos.h', 'browser/chromeos/setting_level_bubble.cc', 'browser/chromeos/setting_level_bubble.h', 'browser/chromeos/setting_level_bubble_view.cc', diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index a9fa984..c14dbb5 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -1045,6 +1045,10 @@ const char kEnableGView[] = "enable-gview"; // Should we show the image based login? const char kEnableLoginImages[] = "enable-login-images"; +// Rotate the screen in response to orientation changed events from dbus. +// Will be reused for more generic sensors. +const char kEnableSensors[] = "enable-sensors"; + // Enables static ip configuration. // This flag should be removed when it's on by default. const char kEnableStaticIPConfig[] = "enable-static-ip-config"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 85521283..27cabc8 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -283,6 +283,7 @@ extern const char kSkipOAuthLogin[]; extern const char kEnableDevicePolicy[]; extern const char kEnableGView[]; extern const char kEnableLoginImages[]; +extern const char kEnableSensors[]; extern const char kEnableStaticIPConfig[]; extern const char kLoginManager[]; // TODO(avayvod): Remove this flag when it's unnecessary for testing |