diff options
author | gbillock@chromium.org <gbillock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-06 20:53:58 +0000 |
---|---|---|
committer | gbillock@chromium.org <gbillock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-06 20:53:58 +0000 |
commit | ca553c1164356a2bf9b98866ff3d0767d4b34723 (patch) | |
tree | 7fdbbde2c30b6af56769dba016ac19ffef6a6bca | |
parent | 6596cf7da0733edb63ab1cc217d039329cc8a7b6 (diff) | |
download | chromium_src-ca553c1164356a2bf9b98866ff3d0767d4b34723.zip chromium_src-ca553c1164356a2bf9b98866ff3d0767d4b34723.tar.gz chromium_src-ca553c1164356a2bf9b98866ff3d0767d4b34723.tar.bz2 |
Remove removable storage notifications from base System Monitor. (part 3)
Previous changes have placed these notifications in chrome/browser/system_monitor.
The storage and device interfaces have been decoupled in all consumers.
R=vandebo@chromium.org
BUG=149059
Review URL: https://chromiumcodereview.appspot.com/11852029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181047 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/system_monitor/system_monitor.cc | 71 | ||||
-rw-r--r-- | base/system_monitor/system_monitor.h | 46 | ||||
-rw-r--r-- | base/system_monitor/system_monitor_unittest.cc | 73 | ||||
-rw-r--r-- | base/test/mock_devices_changed_observer.h | 5 |
4 files changed, 0 insertions, 195 deletions
diff --git a/base/system_monitor/system_monitor.cc b/base/system_monitor/system_monitor.cc index 2616275..7c960cc 100644 --- a/base/system_monitor/system_monitor.cc +++ b/base/system_monitor/system_monitor.cc @@ -8,9 +8,7 @@ #include "base/logging.h" #include "base/message_loop.h" -#include "base/stl_util.h" #include "base/time.h" -#include "base/utf_string_conversions.h" namespace base { @@ -22,18 +20,6 @@ static SystemMonitor* g_system_monitor = NULL; static int kDelayedBatteryCheckMs = 10 * 1000; #endif // defined(ENABLE_BATTERY_MONITORING) -SystemMonitor::RemovableStorageInfo::RemovableStorageInfo() { -} - -SystemMonitor::RemovableStorageInfo::RemovableStorageInfo( - const std::string& id, - const string16& device_name, - const FilePath::StringType& device_location) - : device_id(id), - name(device_name), - location(device_location) { -} - SystemMonitor::SystemMonitor() : power_observer_list_(new ObserverListThreadSafe<PowerObserver>()), devices_changed_observer_list_( @@ -99,47 +85,6 @@ void SystemMonitor::ProcessDevicesChanged(DeviceType device_type) { NotifyDevicesChanged(device_type); } -void SystemMonitor::ProcessRemovableStorageAttached( - const std::string& id, - const string16& name, - const FilePath::StringType& location) { - { - base::AutoLock lock(removable_storage_lock_); - if (ContainsKey(removable_storage_map_, id)) { - // This can happen if our unique id scheme fails. Ignore the incoming - // non-unique attachment. - return; - } - RemovableStorageInfo info(id, name, location); - removable_storage_map_.insert(std::make_pair(id, info)); - } - NotifyRemovableStorageAttached(id, name, location); -} - -void SystemMonitor::ProcessRemovableStorageDetached(const std::string& id) { - { - base::AutoLock lock(removable_storage_lock_); - RemovableStorageMap::iterator it = removable_storage_map_.find(id); - if (it == removable_storage_map_.end()) - return; - removable_storage_map_.erase(it); - } - NotifyRemovableStorageDetached(id); -} - -std::vector<SystemMonitor::RemovableStorageInfo> -SystemMonitor::GetAttachedRemovableStorage() const { - std::vector<RemovableStorageInfo> results; - - base::AutoLock lock(removable_storage_lock_); - for (RemovableStorageMap::const_iterator it = removable_storage_map_.begin(); - it != removable_storage_map_.end(); - ++it) { - results.push_back(it->second); - } - return results; -} - void SystemMonitor::AddPowerObserver(PowerObserver* obs) { power_observer_list_->AddObserver(obs); } @@ -162,22 +107,6 @@ void SystemMonitor::NotifyDevicesChanged(DeviceType device_type) { &DevicesChangedObserver::OnDevicesChanged, device_type); } -void SystemMonitor::NotifyRemovableStorageAttached( - const std::string& id, - const string16& name, - const FilePath::StringType& location) { - DVLOG(1) << "RemovableStorageAttached with name " << UTF16ToUTF8(name) - << " and id " << id; - devices_changed_observer_list_->Notify( - &DevicesChangedObserver::OnRemovableStorageAttached, id, name, location); -} - -void SystemMonitor::NotifyRemovableStorageDetached(const std::string& id) { - DVLOG(1) << "RemovableStorageDetached for id " << id; - devices_changed_observer_list_->Notify( - &DevicesChangedObserver::OnRemovableStorageDetached, 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 ea95da8..6620d27 100644 --- a/base/system_monitor/system_monitor.h +++ b/base/system_monitor/system_monitor.h @@ -11,9 +11,6 @@ #include "base/base_export.h" #include "base/basictypes.h" -#include "base/file_path.h" -#include "base/string16.h" -#include "base/synchronization/lock.h" #include "build/build_config.h" // Windows HiRes timers drain the battery faster so we need to know the battery @@ -59,22 +56,6 @@ class BASE_EXPORT SystemMonitor { DEVTYPE_UNKNOWN, // Other devices. }; - struct BASE_EXPORT RemovableStorageInfo { - RemovableStorageInfo(); - RemovableStorageInfo(const std::string& id, - const string16& device_name, - const FilePath::StringType& device_location); - - // Unique device id - persists between device attachments. - std::string device_id; - - // Human readable removable storage device name. - string16 name; - - // Current attached removable storage device location. - FilePath::StringType location; - }; - // Create SystemMonitor. Only one SystemMonitor instance per application // is allowed. SystemMonitor(); @@ -95,9 +76,6 @@ class BASE_EXPORT SystemMonitor { #endif // OS_IOS #endif // OS_MACOSX - // Returns information for attached removable storage. - std::vector<RemovableStorageInfo> GetAttachedRemovableStorage() const; - // // Power-related APIs // @@ -136,14 +114,6 @@ class BASE_EXPORT SystemMonitor { // This is only implemented on Windows currently. virtual void OnDevicesChanged(DeviceType device_type) {} - // When a removable storage device is attached or detached, one of these - // two events is triggered. - virtual void OnRemovableStorageAttached( - const std::string& id, - const string16& name, - const FilePath::StringType& location) {} - virtual void OnRemovableStorageDetached(const std::string& id) {} - protected: virtual ~DevicesChangedObserver() {} }; @@ -176,15 +146,8 @@ class BASE_EXPORT SystemMonitor { // Cross-platform handling of a device change event. void ProcessDevicesChanged(DeviceType device_type); - void ProcessRemovableStorageAttached(const std::string& id, - const string16& name, - const FilePath::StringType& location); - void ProcessRemovableStorageDetached(const std::string& id); private: - // Mapping of unique device id to device info tuple. - typedef std::map<std::string, RemovableStorageInfo> RemovableStorageMap; - #if defined(OS_MACOSX) void PlatformInit(); void PlatformDestroy(); @@ -201,10 +164,6 @@ class BASE_EXPORT SystemMonitor { // Functions to trigger notifications. void NotifyDevicesChanged(DeviceType device_type); - void NotifyRemovableStorageAttached(const std::string& id, - const string16& name, - const FilePath::StringType& location); - void NotifyRemovableStorageDetached(const std::string& id); void NotifyPowerStateChange(); void NotifySuspend(); void NotifyResume(); @@ -224,11 +183,6 @@ class BASE_EXPORT SystemMonitor { std::vector<id> notification_observers_; #endif - // For manipulating removable_storage_map_ structure. - mutable base::Lock removable_storage_lock_; - // Map of all the attached removable storage devices. - RemovableStorageMap removable_storage_map_; - DISALLOW_COPY_AND_ASSIGN(SystemMonitor); }; diff --git a/base/system_monitor/system_monitor_unittest.cc b/base/system_monitor/system_monitor_unittest.cc index 56f48ef..43f1dd6 100644 --- a/base/system_monitor/system_monitor_unittest.cc +++ b/base/system_monitor/system_monitor_unittest.cc @@ -4,11 +4,9 @@ #include "base/system_monitor/system_monitor.h" -#include "base/file_path.h" #include "base/message_loop.h" #include "base/run_loop.h" #include "base/test/mock_devices_changed_observer.h" -#include "base/utf_string_conversions.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -107,9 +105,6 @@ TEST_F(SystemMonitorTest, PowerNotifications) { TEST_F(SystemMonitorTest, DeviceChangeNotifications) { const int kObservers = 5; - const string16 kDeviceName = ASCIIToUTF16("media device"); - const std::string kDeviceId1 = "1"; - const std::string kDeviceId2 = "2"; testing::Sequence mock_sequencer[kObservers]; MockDevicesChangedObserver observers[kObservers]; @@ -120,14 +115,6 @@ TEST_F(SystemMonitorTest, DeviceChangeNotifications) { OnDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN)) .Times(3) .InSequence(mock_sequencer[index]); - EXPECT_CALL(observers[index], OnRemovableStorageAttached(kDeviceId1, - kDeviceName, - testing::_)) - .InSequence(mock_sequencer[index]); - EXPECT_CALL(observers[index], OnRemovableStorageDetached(kDeviceId1)) - .InSequence(mock_sequencer[index]); - EXPECT_CALL(observers[index], OnRemovableStorageDetached(kDeviceId2)) - .Times(0).InSequence(mock_sequencer[index]); } system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN); @@ -136,66 +123,6 @@ TEST_F(SystemMonitorTest, DeviceChangeNotifications) { system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN); system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN); RunLoop().RunUntilIdle(); - - system_monitor_->ProcessRemovableStorageAttached(kDeviceId1, - kDeviceName, - FILE_PATH_LITERAL("path")); - RunLoop().RunUntilIdle(); - - system_monitor_->ProcessRemovableStorageDetached(kDeviceId1); - system_monitor_->ProcessRemovableStorageDetached(kDeviceId2); - RunLoop().RunUntilIdle(); -} - -TEST_F(SystemMonitorTest, GetAttachedRemovableStorageEmpty) { - std::vector<SystemMonitor::RemovableStorageInfo> devices = - system_monitor_->GetAttachedRemovableStorage(); - EXPECT_EQ(0U, devices.size()); -} - -TEST_F(SystemMonitorTest, GetAttachedRemovableStorageAttachDetach) { - const std::string kDeviceId1 = "42"; - const string16 kDeviceName1 = ASCIIToUTF16("test"); - const FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo")); - system_monitor_->ProcessRemovableStorageAttached(kDeviceId1, - kDeviceName1, - kDevicePath1.value()); - RunLoop().RunUntilIdle(); - std::vector<SystemMonitor::RemovableStorageInfo> devices = - system_monitor_->GetAttachedRemovableStorage(); - ASSERT_EQ(1U, devices.size()); - EXPECT_EQ(kDeviceId1, devices[0].device_id); - EXPECT_EQ(kDeviceName1, devices[0].name); - EXPECT_EQ(kDevicePath1.value(), devices[0].location); - - const std::string kDeviceId2 = "44"; - const string16 kDeviceName2 = ASCIIToUTF16("test2"); - const FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar")); - system_monitor_->ProcessRemovableStorageAttached(kDeviceId2, - kDeviceName2, - kDevicePath2.value()); - RunLoop().RunUntilIdle(); - devices = system_monitor_->GetAttachedRemovableStorage(); - ASSERT_EQ(2U, devices.size()); - EXPECT_EQ(kDeviceId1, devices[0].device_id); - EXPECT_EQ(kDeviceName1, devices[0].name); - EXPECT_EQ(kDevicePath1.value(), devices[0].location); - EXPECT_EQ(kDeviceId2, devices[1].device_id); - EXPECT_EQ(kDeviceName2, devices[1].name); - EXPECT_EQ(kDevicePath2.value(), devices[1].location); - - system_monitor_->ProcessRemovableStorageDetached(kDeviceId1); - RunLoop().RunUntilIdle(); - devices = system_monitor_->GetAttachedRemovableStorage(); - ASSERT_EQ(1U, devices.size()); - EXPECT_EQ(kDeviceId2, devices[0].device_id); - EXPECT_EQ(kDeviceName2, devices[0].name); - EXPECT_EQ(kDevicePath2.value(), devices[0].location); - - system_monitor_->ProcessRemovableStorageDetached(kDeviceId2); - RunLoop().RunUntilIdle(); - devices = system_monitor_->GetAttachedRemovableStorage(); - EXPECT_EQ(0U, devices.size()); } } // namespace diff --git a/base/test/mock_devices_changed_observer.h b/base/test/mock_devices_changed_observer.h index 1d0f3dd..3ada16b 100644 --- a/base/test/mock_devices_changed_observer.h +++ b/base/test/mock_devices_changed_observer.h @@ -20,11 +20,6 @@ class MockDevicesChangedObserver MOCK_METHOD1(OnDevicesChanged, void(base::SystemMonitor::DeviceType device_type)); - MOCK_METHOD3(OnRemovableStorageAttached, - void(const std::string& id, - const string16& name, - const FilePath::StringType& location)); - MOCK_METHOD1(OnRemovableStorageDetached, void(const std::string& id)); DISALLOW_COPY_AND_ASSIGN(MockDevicesChangedObserver); }; |