diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-23 05:02:42 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-23 05:02:42 +0000 |
commit | 886ee30c5a5ee2a43d1532a1bf145d2c5814b0b6 (patch) | |
tree | 23418c0b0af2c65f9848d7a2fd874004ab7da2fa | |
parent | 5258563b754dc3eb017a37ce679a963aee9a0b12 (diff) | |
download | chromium_src-886ee30c5a5ee2a43d1532a1bf145d2c5814b0b6.zip chromium_src-886ee30c5a5ee2a43d1532a1bf145d2c5814b0b6.tar.gz chromium_src-886ee30c5a5ee2a43d1532a1bf145d2c5814b0b6.tar.bz2 |
Move SensorsSource to chrome/browser/chromeos/dbus.
In the new place, SensorsSource can use the D-Bus thread managed by
DBusThreadManager, rather than FILE thread.
BUG=None
TEST=run chrome with --enable-sensors --vmodule=sensors_source=1; dbus-send --system / org.chromium.Sensors.ScreenOrientationChanged int32:1; confirm that "Orientation changed to upward 1" is emitted from VLOG(1).
Review URL: http://codereview.chromium.org/7970016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102448 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/chrome_browser_main_chromeos.cc | 21 | ||||
-rw-r--r-- | chrome/browser/chromeos/chrome_browser_main_chromeos.h | 3 | ||||
-rw-r--r-- | chrome/browser/chromeos/dbus/dbus_thread_manager.cc | 10 | ||||
-rw-r--r-- | chrome/browser/chromeos/dbus/dbus_thread_manager.h | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/dbus/sensors_source.cc (renamed from chrome/browser/chromeos/sensors_source_chromeos.cc) | 49 | ||||
-rw-r--r-- | chrome/browser/chromeos/dbus/sensors_source.h (renamed from chrome/browser/chromeos/sensors_source_chromeos.h) | 33 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 4 |
7 files changed, 41 insertions, 81 deletions
diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc index 0f0a530..b0f82dd 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc @@ -13,7 +13,6 @@ #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/dbus/dbus_thread_manager.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" @@ -21,17 +20,6 @@ #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. @@ -112,15 +100,6 @@ void ChromeBrowserMainPartsChromeos::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_)); - } - // Initialize DBusThreadManager for the browser. This must be done after // the main message loop is started, as it uses the message loop. chromeos::DBusThreadManager::Initialize(); diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.h b/chrome/browser/chromeos/chrome_browser_main_chromeos.h index f5be25e9..57aa5f0 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.h +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.h @@ -22,9 +22,6 @@ class ChromeBrowserMainPartsChromeos : public ChromeBrowserMainPartsGtk { virtual void PreMainMessageLoopStart() OVERRIDE; virtual void PostMainMessageLoopStart() OVERRIDE; - private: - scoped_refptr<sensors::SensorsSourceChromeos> sensors_source_; - DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainPartsChromeos); }; diff --git a/chrome/browser/chromeos/dbus/dbus_thread_manager.cc b/chrome/browser/chromeos/dbus/dbus_thread_manager.cc index 5f4232c..34ac9c5 100644 --- a/chrome/browser/chromeos/dbus/dbus_thread_manager.cc +++ b/chrome/browser/chromeos/dbus/dbus_thread_manager.cc @@ -4,8 +4,11 @@ #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" +#include "base/command_line.h" #include "base/threading/thread.h" #include "chrome/browser/chromeos/dbus/cros_dbus_service.h" +#include "chrome/browser/chromeos/dbus/sensors_source.h" +#include "chrome/common/chrome_switches.h" #include "dbus/bus.h" namespace chromeos { @@ -30,6 +33,13 @@ DBusThreadManager::DBusThreadManager() { // Create and start the cros D-Bus service. cros_dbus_service_ = CrosDBusService::Get(system_bus_.get()); cros_dbus_service_->Start(); + + // Start monitoring sensors if needed. + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + if (command_line.HasSwitch(switches::kEnableSensors)) { + sensors_source_ = new SensorsSource; + sensors_source_->Init(system_bus_.get()); + } } DBusThreadManager::~DBusThreadManager() { diff --git a/chrome/browser/chromeos/dbus/dbus_thread_manager.h b/chrome/browser/chromeos/dbus/dbus_thread_manager.h index c4da3b6..65a7851 100644 --- a/chrome/browser/chromeos/dbus/dbus_thread_manager.h +++ b/chrome/browser/chromeos/dbus/dbus_thread_manager.h @@ -20,6 +20,7 @@ class Bus; namespace chromeos { class CrosDBusService; +class SensorsSource; // DBusThreadManager manages the D-Bus thread, the thread dedicated to // handling asynchronous D-Bus operations. @@ -62,6 +63,7 @@ class DBusThreadManager { scoped_ptr<base::Thread> dbus_thread_; scoped_refptr<dbus::Bus> system_bus_; CrosDBusService* cros_dbus_service_; + scoped_refptr<SensorsSource> sensors_source_; DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); }; diff --git a/chrome/browser/chromeos/sensors_source_chromeos.cc b/chrome/browser/chromeos/dbus/sensors_source.cc index 233511a..bd57821 100644 --- a/chrome/browser/chromeos/sensors_source_chromeos.cc +++ b/chrome/browser/chromeos/dbus/sensors_source.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 "chrome/browser/chromeos/sensors_source_chromeos.h" +#include "chrome/browser/chromeos/dbus/sensors_source.h" #include "base/bind.h" #include "base/callback.h" @@ -21,48 +21,28 @@ 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) { +SensorsSource::SensorsSource() : sensors_proxy_(NULL) { } -bool SensorsSourceChromeos::Init() { +void SensorsSource::Init(dbus::Bus* bus) { 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_ = 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(); + base::Bind(&SensorsSource::OrientationChangedReceived, this), + base::Bind(&SensorsSource::OrientationChangedConnected, this)); } -SensorsSourceChromeos::~SensorsSourceChromeos() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - Stop(); +SensorsSource::~SensorsSource() { } -void SensorsSourceChromeos::OrientationChangedReceived(dbus::Signal* signal) { +void SensorsSource::OrientationChangedReceived(dbus::Signal* signal) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - ScreenOrientation orientation; + sensors::ScreenOrientation orientation; dbus::MessageReader reader(signal); int32 upward = 0; @@ -71,12 +51,13 @@ void SensorsSourceChromeos::OrientationChangedReceived(dbus::Signal* signal) { << signal->ToString(); return; } - orientation.upward = static_cast<ScreenOrientation::Side>(upward); + VLOG(1) << "Orientation changed to upward " << upward; + orientation.upward = static_cast<sensors::ScreenOrientation::Side>(upward); - Provider::GetInstance()->ScreenOrientationChanged(orientation); + sensors::Provider::GetInstance()->ScreenOrientationChanged(orientation); } -void SensorsSourceChromeos::OrientationChangedConnected( +void SensorsSource::OrientationChangedConnected( const std::string& interface_name, const std::string& signal_name, bool success) { @@ -85,4 +66,4 @@ void SensorsSourceChromeos::OrientationChangedConnected( LOG(WARNING) << "Failed to connect to orientation changed signal."; } -} // namespace sensors +} // namespace chromeos diff --git a/chrome/browser/chromeos/sensors_source_chromeos.h b/chrome/browser/chromeos/dbus/sensors_source.h index fe8cc6f..e6deba2 100644 --- a/chrome/browser/chromeos/sensors_source_chromeos.h +++ b/chrome/browser/chromeos/dbus/sensors_source.h @@ -2,8 +2,8 @@ // 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_ +#ifndef CHROME_BROWSER_CHROMEOS_DBUS_SENSORS_SOURCE_H_ +#define CHROME_BROWSER_CHROMEOS_DBUS_SENSORS_SOURCE_H_ #include "base/memory/ref_counted.h" #include "content/browser/browser_thread.h" @@ -16,31 +16,23 @@ class ObjectProxy; class Signal; } // namespace -namespace sensors { +namespace chromeos { // 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> { +class SensorsSource + : public base::RefCountedThreadSafe<SensorsSource> { public: // Creates an inactive sensors source. - SensorsSourceChromeos(); + SensorsSource(); // 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(); + void Init(dbus::Bus* bus); private: - friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; - friend class DeleteTask<SensorsSourceChromeos>; - virtual ~SensorsSourceChromeos(); + friend class base::RefCountedThreadSafe<SensorsSource>; + virtual ~SensorsSource(); // Called by dbus:: in when an orientation change signal is received. void OrientationChangedReceived(dbus::Signal* signal); @@ -50,12 +42,11 @@ class SensorsSourceChromeos const std::string& signal_name, bool success); - scoped_refptr<dbus::Bus> bus_; dbus::ObjectProxy* sensors_proxy_; - DISALLOW_COPY_AND_ASSIGN(SensorsSourceChromeos); + DISALLOW_COPY_AND_ASSIGN(SensorsSource); }; -} // namespace sensors +} // namespace chromeos -#endif // CHROME_BROWSER_CHROMEOS_SENSORS_SOURCE_CHROMEOS_H_ +#endif // CHROME_BROWSER_CHROMEOS_DBUS_SENSORS_SOURCE_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index bf619d3..cdcce85 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -409,6 +409,8 @@ 'browser/chromeos/dbus/dbus_thread_manager.h', 'browser/chromeos/dbus/proxy_resolution_service_provider.cc', 'browser/chromeos/dbus/proxy_resolution_service_provider.h', + 'browser/chromeos/dbus/sensors_source.cc', + 'browser/chromeos/dbus/sensors_source.h', 'browser/chromeos/drop_shadow_label.cc', 'browser/chromeos/enterprise_extension_observer.cc', 'browser/chromeos/enterprise_extension_observer.h', @@ -714,8 +716,6 @@ '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', |