diff options
author | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-01 02:20:13 +0000 |
---|---|---|
committer | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-01 02:20:13 +0000 |
commit | 4b59a4240d02d872cb94b529cc38cee34360a5dd (patch) | |
tree | 45cea3ce45d3571c60d5b6e87f8214e105664ae0 /base/system_monitor | |
parent | f160e2fef08c9e12336efb14834ec36ce7d2a685 (diff) | |
download | chromium_src-4b59a4240d02d872cb94b529cc38cee34360a5dd.zip chromium_src-4b59a4240d02d872cb94b529cc38cee34360a5dd.tar.gz chromium_src-4b59a4240d02d872cb94b529cc38cee34360a5dd.tar.bz2 |
Revert 124288 (made mac browser and ui_tests flaky) - Add Media device notification to SystemMonitor and Mac impl
BUG=110400
TEST=run chrome with -v=1, attach and a mass storage media device and observe the log entries for the attach and detach events.
Review URL: https://chromiumcodereview.appspot.com/9363008
TBR=vandebo@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9555014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124335 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/system_monitor')
-rw-r--r-- | base/system_monitor/system_monitor.cc | 27 | ||||
-rw-r--r-- | base/system_monitor/system_monitor.h | 27 | ||||
-rw-r--r-- | base/system_monitor/system_monitor_unittest.cc | 54 |
3 files changed, 28 insertions, 80 deletions
diff --git a/base/system_monitor/system_monitor.cc b/base/system_monitor/system_monitor.cc index afca3fc..28fc70b 100644 --- a/base/system_monitor/system_monitor.cc +++ b/base/system_monitor/system_monitor.cc @@ -1,10 +1,9 @@ -// Copyright (c) 2012 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 "base/system_monitor/system_monitor.h" -#include "base/file_path.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/time.h" @@ -84,16 +83,6 @@ void SystemMonitor::ProcessDevicesChanged() { NotifyDevicesChanged(); } -void SystemMonitor::ProcessMediaDeviceAttached(const DeviceIdType& id, - const std::string& name, - const FilePath& path) { - NotifyMediaDeviceAttached(id, name, path); -} - -void SystemMonitor::ProcessMediaDeviceDetached(const DeviceIdType& id) { - NotifyMediaDeviceDetached(id); -} - void SystemMonitor::AddPowerObserver(PowerObserver* obs) { power_observer_list_->AddObserver(obs); } @@ -116,20 +105,6 @@ void SystemMonitor::NotifyDevicesChanged() { &DevicesChangedObserver::OnDevicesChanged); } -void SystemMonitor::NotifyMediaDeviceAttached(const DeviceIdType& id, - const std::string& name, - const FilePath& path) { - DVLOG(1) << "MediaDeviceAttached with name " << name << " and id " << id; - devices_changed_observer_list_->Notify( - &DevicesChangedObserver::OnMediaDeviceAttached, id, name, path); -} - -void SystemMonitor::NotifyMediaDeviceDetached(const DeviceIdType& id) { - DVLOG(1) << "MediaDeviceDetached for id " << id; - devices_changed_observer_list_->Notify( - &DevicesChangedObserver::OnMediaDeviceDetached, id); -} - void SystemMonitor::NotifyPowerStateChange() { DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off") << " battery"; diff --git a/base/system_monitor/system_monitor.h b/base/system_monitor/system_monitor.h index 3f73b15..7684523 100644 --- a/base/system_monitor/system_monitor.h +++ b/base/system_monitor/system_monitor.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 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. @@ -6,8 +6,6 @@ #define BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ #pragma once -#include <string> - #include "base/base_export.h" #include "base/basictypes.h" #include "build/build_config.h" @@ -30,8 +28,6 @@ #include <IOKit/IOMessage.h> #endif // OS_MACOSX -class FilePath; - namespace base { // Class for monitoring various system-related subsystems @@ -46,8 +42,6 @@ class BASE_EXPORT SystemMonitor { RESUME_EVENT // The system is being resumed. }; - typedef unsigned int DeviceIdType; - // Create SystemMonitor. Only one SystemMonitor instance per application // is allowed. SystemMonitor(); @@ -99,19 +93,8 @@ class BASE_EXPORT SystemMonitor { class BASE_EXPORT DevicesChangedObserver { public: // Notification that the devices connected to the system have changed. - // This is only implemented on Windows currently. virtual void OnDevicesChanged() {} - // When a media device is attached or detached, one of these two events - // is triggered. - // TODO(vandebo) Pass an appropriate device identifier or way to interact - // with the devices instead of FilePath. - virtual void OnMediaDeviceAttached(const DeviceIdType& id, - const std::string& name, - const FilePath& path) {} - - virtual void OnMediaDeviceDetached(const DeviceIdType& id) {} - protected: virtual ~DevicesChangedObserver() {} }; @@ -140,10 +123,6 @@ class BASE_EXPORT SystemMonitor { // Cross-platform handling of a device change event. void ProcessDevicesChanged(); - void ProcessMediaDeviceAttached(const DeviceIdType& id, - const std::string& name, - const FilePath& path); - void ProcessMediaDeviceDetached(const DeviceIdType& id); private: #if defined(OS_MACOSX) @@ -162,10 +141,6 @@ class BASE_EXPORT SystemMonitor { // Functions to trigger notifications. void NotifyDevicesChanged(); - void NotifyMediaDeviceAttached(const DeviceIdType& id, - const std::string& name, - const FilePath& path); - void NotifyMediaDeviceDetached(const DeviceIdType& id); void NotifyPowerStateChange(); void NotifySuspend(); void NotifyResume(); diff --git a/base/system_monitor/system_monitor_unittest.cc b/base/system_monitor/system_monitor_unittest.cc index eaed974..1d5d6af 100644 --- a/base/system_monitor/system_monitor_unittest.cc +++ b/base/system_monitor/system_monitor_unittest.cc @@ -1,11 +1,8 @@ -// Copyright (c) 2012 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 "base/file_path.h" -#include "base/test/mock_devices_changed_observer.h" #include "base/system_monitor/system_monitor.h" -#include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" namespace base { @@ -93,6 +90,26 @@ TEST(SystemMonitor, PowerNotifications) { EXPECT_EQ(test[0].resumes(), 1); } +class DevicesChangedTest : public SystemMonitor::DevicesChangedObserver { + public: + DevicesChangedTest() + : changes_(0) { + } + + // DevicesChangedObserver callbacks. + virtual void OnDevicesChanged() OVERRIDE { + changes_++; + } + + // Test status counts. + int changes() const { return changes_; } + + private: + int changes_; // Count of OnDevicesChanged notifications. + + DISALLOW_COPY_AND_ASSIGN(DevicesChangedTest); +}; + TEST(SystemMonitor, DeviceChangeNotifications) { const int kObservers = 5; @@ -103,38 +120,19 @@ TEST(SystemMonitor, DeviceChangeNotifications) { SystemMonitor::AllocateSystemIOPorts(); #endif - testing::Sequence mock_sequencer[kObservers]; SystemMonitor system_monitor; - MockDevicesChangedObserver observers[kObservers]; - for (int index = 0; index < kObservers; ++index) { - system_monitor.AddDevicesChangedObserver(&observers[index]); - - EXPECT_CALL(observers[index], OnDevicesChanged()) - .Times(3) - .InSequence(mock_sequencer[index]); - EXPECT_CALL(observers[index], OnMediaDeviceAttached(1, "media device", - testing::_)) - .InSequence(mock_sequencer[index]); - EXPECT_CALL(observers[index], OnMediaDeviceDetached(1)) - .InSequence(mock_sequencer[index]); - EXPECT_CALL(observers[index], OnMediaDeviceDetached(2)) - .InSequence(mock_sequencer[index]); - } + DevicesChangedTest test[kObservers]; + for (int index = 0; index < kObservers; ++index) + system_monitor.AddDevicesChangedObserver(&test[index]); system_monitor.ProcessDevicesChanged(); loop.RunAllPending(); + EXPECT_EQ(1, test[0].changes()); system_monitor.ProcessDevicesChanged(); system_monitor.ProcessDevicesChanged(); loop.RunAllPending(); - - system_monitor.ProcessMediaDeviceAttached( - 1, "media device", FilePath(FILE_PATH_LITERAL("path"))); - loop.RunAllPending(); - - system_monitor.ProcessMediaDeviceDetached(1); - system_monitor.ProcessMediaDeviceDetached(2); - loop.RunAllPending(); + EXPECT_EQ(3, test[0].changes()); } } // namespace base |