summaryrefslogtreecommitdiffstats
path: root/base/system_monitor
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-26 23:00:31 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-26 23:00:31 +0000
commit90d367425787ef9f9bf369b569737ab5a4044436 (patch)
tree5b2779ffcb6affc492744b0151069ab5d528c7f3 /base/system_monitor
parentb2ddc392e1b55908713501bd17c9261089bb62c5 (diff)
downloadchromium_src-90d367425787ef9f9bf369b569737ab5a4044436.zip
chromium_src-90d367425787ef9f9bf369b569737ab5a4044436.tar.gz
chromium_src-90d367425787ef9f9bf369b569737ab5a4044436.tar.bz2
Rename SystemMonitor's MediaDevice calls to RemovableStorage. Functional changes to follow in future CLs.
Review URL: https://chromiumcodereview.appspot.com/10873072 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153428 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/system_monitor')
-rw-r--r--base/system_monitor/system_monitor.cc46
-rw-r--r--base/system_monitor/system_monitor.h56
-rw-r--r--base/system_monitor/system_monitor_unittest.cc72
3 files changed, 86 insertions, 88 deletions
diff --git a/base/system_monitor/system_monitor.cc b/base/system_monitor/system_monitor.cc
index 8cff63b..3a3aded 100644
--- a/base/system_monitor/system_monitor.cc
+++ b/base/system_monitor/system_monitor.cc
@@ -22,11 +22,11 @@ static SystemMonitor* g_system_monitor = NULL;
static int kDelayedBatteryCheckMs = 10 * 1000;
#endif // defined(ENABLE_BATTERY_MONITORING)
-SystemMonitor::MediaDeviceInfo::MediaDeviceInfo(
+SystemMonitor::RemovableStorageInfo::RemovableStorageInfo(
const std::string& id,
const string16& device_name,
const FilePath::StringType& device_location)
- : unique_id(id),
+ : device_id(id),
name(device_name),
location(device_location) {
}
@@ -96,33 +96,33 @@ void SystemMonitor::ProcessDevicesChanged(DeviceType device_type) {
NotifyDevicesChanged(device_type);
}
-void SystemMonitor::ProcessMediaDeviceAttached(
+void SystemMonitor::ProcessRemovableStorageAttached(
const std::string& id,
const string16& name,
const FilePath::StringType& location) {
- MediaDeviceInfo info(id, name, location);
- if (ContainsKey(media_device_map_, id)) {
+ if (ContainsKey(removable_storage_map_, id)) {
// This can happen if our unique id scheme fails. Ignore the incoming
// non-unique attachment.
return;
}
- media_device_map_.insert(std::make_pair(id, info));
- NotifyMediaDeviceAttached(id, name, location);
+ RemovableStorageInfo info(id, name, location);
+ removable_storage_map_.insert(std::make_pair(id, info));
+ NotifyRemovableStorageAttached(id, name, location);
}
-void SystemMonitor::ProcessMediaDeviceDetached(const std::string& id) {
- MediaDeviceMap::iterator it = media_device_map_.find(id);
- if (it == media_device_map_.end())
+void SystemMonitor::ProcessRemovableStorageDetached(const std::string& id) {
+ RemovableStorageMap::iterator it = removable_storage_map_.find(id);
+ if (it == removable_storage_map_.end())
return;
- media_device_map_.erase(it);
- NotifyMediaDeviceDetached(id);
+ removable_storage_map_.erase(it);
+ NotifyRemovableStorageDetached(id);
}
-std::vector<SystemMonitor::MediaDeviceInfo>
-SystemMonitor::GetAttachedMediaDevices() const {
- std::vector<MediaDeviceInfo> results;
- for (MediaDeviceMap::const_iterator it = media_device_map_.begin();
- it != media_device_map_.end();
+std::vector<SystemMonitor::RemovableStorageInfo>
+SystemMonitor::GetAttachedRemovableStorage() const {
+ std::vector<RemovableStorageInfo> results;
+ for (RemovableStorageMap::const_iterator it = removable_storage_map_.begin();
+ it != removable_storage_map_.end();
++it) {
results.push_back(it->second);
}
@@ -151,20 +151,20 @@ void SystemMonitor::NotifyDevicesChanged(DeviceType device_type) {
&DevicesChangedObserver::OnDevicesChanged, device_type);
}
-void SystemMonitor::NotifyMediaDeviceAttached(
+void SystemMonitor::NotifyRemovableStorageAttached(
const std::string& id,
const string16& name,
const FilePath::StringType& location) {
- DVLOG(1) << "MediaDeviceAttached with name " << UTF16ToUTF8(name)
+ DVLOG(1) << "RemovableStorageAttached with name " << UTF16ToUTF8(name)
<< " and id " << id;
devices_changed_observer_list_->Notify(
- &DevicesChangedObserver::OnMediaDeviceAttached, id, name, location);
+ &DevicesChangedObserver::OnRemovableStorageAttached, id, name, location);
}
-void SystemMonitor::NotifyMediaDeviceDetached(const std::string& id) {
- DVLOG(1) << "MediaDeviceDetached for id " << id;
+void SystemMonitor::NotifyRemovableStorageDetached(const std::string& id) {
+ DVLOG(1) << "RemovableStorageDetached for id " << id;
devices_changed_observer_list_->Notify(
- &DevicesChangedObserver::OnMediaDeviceDetached, id);
+ &DevicesChangedObserver::OnRemovableStorageDetached, id);
}
void SystemMonitor::NotifyPowerStateChange() {
diff --git a/base/system_monitor/system_monitor.h b/base/system_monitor/system_monitor.h
index 7461b7a..3a48e3a 100644
--- a/base/system_monitor/system_monitor.h
+++ b/base/system_monitor/system_monitor.h
@@ -58,18 +58,18 @@ class BASE_EXPORT SystemMonitor {
DEVTYPE_UNKNOWN, // Other devices.
};
- struct BASE_EXPORT MediaDeviceInfo {
- MediaDeviceInfo(const std::string& id,
- const string16& device_name,
- const FilePath::StringType& device_location);
+ struct BASE_EXPORT RemovableStorageInfo {
+ RemovableStorageInfo(const std::string& id,
+ const string16& device_name,
+ const FilePath::StringType& device_location);
- // Unique media device id - persists between device attachments.
- std::string unique_id;
+ // Unique device id - persists between device attachments.
+ std::string device_id;
- // Human readable media device name.
+ // Human readable removable storage device name.
string16 name;
- // Current attached media device location.
+ // Current attached removable storage device location.
FilePath::StringType location;
};
@@ -93,8 +93,8 @@ class BASE_EXPORT SystemMonitor {
#endif // OS_IOS
#endif // OS_MACOSX
- // Returns information for attached media devices.
- std::vector<MediaDeviceInfo> GetAttachedMediaDevices() const;
+ // Returns information for attached removable storage.
+ std::vector<RemovableStorageInfo> GetAttachedRemovableStorage() const;
//
// Power-related APIs
@@ -134,13 +134,13 @@ class BASE_EXPORT SystemMonitor {
// This is only implemented on Windows currently.
virtual void OnDevicesChanged(DeviceType device_type) {}
- // When a media device is attached or detached, one of these two events
- // is triggered.
- virtual void OnMediaDeviceAttached(const std::string& id,
- const string16& name,
- const FilePath::StringType& location) {}
-
- virtual void OnMediaDeviceDetached(const std::string& id) {}
+ // 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() {}
@@ -170,14 +170,14 @@ class BASE_EXPORT SystemMonitor {
// Cross-platform handling of a device change event.
void ProcessDevicesChanged(DeviceType device_type);
- void ProcessMediaDeviceAttached(const std::string& id,
- const string16& name,
- const FilePath::StringType& location);
- void ProcessMediaDeviceDetached(const std::string& id);
+ 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, MediaDeviceInfo> MediaDeviceMap;
+ typedef std::map<std::string, RemovableStorageInfo> RemovableStorageMap;
#if defined(OS_MACOSX)
void PlatformInit();
@@ -195,10 +195,10 @@ class BASE_EXPORT SystemMonitor {
// Functions to trigger notifications.
void NotifyDevicesChanged(DeviceType device_type);
- void NotifyMediaDeviceAttached(const std::string& id,
- const string16& name,
- const FilePath::StringType& data);
- void NotifyMediaDeviceDetached(const std::string& id);
+ 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();
@@ -218,8 +218,8 @@ class BASE_EXPORT SystemMonitor {
std::vector<id> notification_observers_;
#endif
- // Map of all the attached media devices.
- MediaDeviceMap media_device_map_;
+ // 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 ee21cc8..feff974079 100644
--- a/base/system_monitor/system_monitor_unittest.cc
+++ b/base/system_monitor/system_monitor_unittest.cc
@@ -116,86 +116,84 @@ TEST_F(SystemMonitorTest, DeviceChangeNotifications) {
system_monitor_->AddDevicesChangedObserver(&observers[index]);
EXPECT_CALL(observers[index],
- OnDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN))
+ OnDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN))
.Times(3)
.InSequence(mock_sequencer[index]);
- EXPECT_CALL(observers[index],
- OnMediaDeviceAttached(kDeviceId1,
- kDeviceName,
- testing::_))
+ EXPECT_CALL(observers[index], OnRemovableStorageAttached(kDeviceId1,
+ kDeviceName,
+ testing::_))
.InSequence(mock_sequencer[index]);
- EXPECT_CALL(observers[index], OnMediaDeviceDetached(kDeviceId1))
+ EXPECT_CALL(observers[index], OnRemovableStorageDetached(kDeviceId1))
.InSequence(mock_sequencer[index]);
- EXPECT_CALL(observers[index], OnMediaDeviceDetached(kDeviceId2))
+ EXPECT_CALL(observers[index], OnRemovableStorageDetached(kDeviceId2))
.Times(0).InSequence(mock_sequencer[index]);
}
- system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN);
+ system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN);
message_loop_.RunAllPending();
- system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN);
- system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN);
+ system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN);
+ system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN);
message_loop_.RunAllPending();
- system_monitor_->ProcessMediaDeviceAttached(
- kDeviceId1,
- kDeviceName,
- FILE_PATH_LITERAL("path"));
+ system_monitor_->ProcessRemovableStorageAttached(kDeviceId1,
+ kDeviceName,
+ FILE_PATH_LITERAL("path"));
message_loop_.RunAllPending();
- system_monitor_->ProcessMediaDeviceDetached(kDeviceId1);
- system_monitor_->ProcessMediaDeviceDetached(kDeviceId2);
+ system_monitor_->ProcessRemovableStorageDetached(kDeviceId1);
+ system_monitor_->ProcessRemovableStorageDetached(kDeviceId2);
message_loop_.RunAllPending();
}
-TEST_F(SystemMonitorTest, GetAttachedMediaDevicesEmpty) {
- std::vector<SystemMonitor::MediaDeviceInfo> devices =
- system_monitor_->GetAttachedMediaDevices();
+TEST_F(SystemMonitorTest, GetAttachedRemovableStorageEmpty) {
+ std::vector<SystemMonitor::RemovableStorageInfo> devices =
+ system_monitor_->GetAttachedRemovableStorage();
EXPECT_EQ(0U, devices.size());
}
-TEST_F(SystemMonitorTest, GetAttachedMediaDevicesAttachDetach) {
+TEST_F(SystemMonitorTest, GetAttachedRemovableStorageAttachDetach) {
const std::string kDeviceId1 = "42";
const string16 kDeviceName1 = ASCIIToUTF16("test");
const FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo"));
- system_monitor_->ProcessMediaDeviceAttached(kDeviceId1,
- kDeviceName1,
- kDevicePath1.value());
+ system_monitor_->ProcessRemovableStorageAttached(kDeviceId1,
+ kDeviceName1,
+ kDevicePath1.value());
message_loop_.RunAllPending();
- std::vector<SystemMonitor::MediaDeviceInfo> devices =
- system_monitor_->GetAttachedMediaDevices();
+ std::vector<SystemMonitor::RemovableStorageInfo> devices =
+ system_monitor_->GetAttachedRemovableStorage();
ASSERT_EQ(1U, devices.size());
- EXPECT_EQ(kDeviceId1, devices[0].unique_id);
+ 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_->ProcessMediaDeviceAttached(kDeviceId2,
- kDeviceName2,
- kDevicePath2.value());
+ system_monitor_->ProcessRemovableStorageAttached(kDeviceId2,
+ kDeviceName2,
+ kDevicePath2.value());
message_loop_.RunAllPending();
- devices = system_monitor_->GetAttachedMediaDevices();
+ devices = system_monitor_->GetAttachedRemovableStorage();
ASSERT_EQ(2U, devices.size());
- EXPECT_EQ(kDeviceId1, devices[0].unique_id);
+ 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].unique_id);
+ EXPECT_EQ(kDeviceId2, devices[1].device_id);
EXPECT_EQ(kDeviceName2, devices[1].name);
EXPECT_EQ(kDevicePath2.value(), devices[1].location);
- system_monitor_->ProcessMediaDeviceDetached(kDeviceId1);
+ system_monitor_->ProcessRemovableStorageDetached(kDeviceId1);
message_loop_.RunAllPending();
- devices = system_monitor_->GetAttachedMediaDevices();
+ devices = system_monitor_->GetAttachedRemovableStorage();
ASSERT_EQ(1U, devices.size());
- EXPECT_EQ(kDeviceId2, devices[0].unique_id);
+ EXPECT_EQ(kDeviceId2, devices[0].device_id);
EXPECT_EQ(kDeviceName2, devices[0].name);
EXPECT_EQ(kDevicePath2.value(), devices[0].location);
- system_monitor_->ProcessMediaDeviceDetached(kDeviceId2);
+ system_monitor_->ProcessRemovableStorageDetached(kDeviceId2);
message_loop_.RunAllPending();
- devices = system_monitor_->GetAttachedMediaDevices();
+ devices = system_monitor_->GetAttachedRemovableStorage();
EXPECT_EQ(0U, devices.size());
}