Chromium Code Reviews| Index: chrome/browser/media_gallery/media_device_manager.cc | 
| =================================================================== | 
| --- chrome/browser/media_gallery/media_device_manager.cc (revision 0) | 
| +++ chrome/browser/media_gallery/media_device_manager.cc (revision 0) | 
| @@ -0,0 +1,138 @@ | 
| +// Copyright (c) 2012 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. | 
| + | 
| +// MediaDeviceManager implementation. | 
| + | 
| +#include "chrome/browser/media_gallery/media_device_manager.h" | 
| + | 
| +#include <map> | 
| + | 
| +#include "base/compiler_specific.h" | 
| +#include "base/file_path.h" | 
| +#include "base/system_monitor/system_monitor.h" | 
| + | 
| +#if defined(OS_WIN) | 
| +#include "chrome/browser/media_gallery/media_device_notifications_window_win.h" | 
| +#elif defined(OS_LINUX) | 
| +#include "chrome/browser/media_gallery/media_device_notifications_linux.h" | 
| +#endif | 
| + | 
| +namespace chrome { | 
| + | 
| +/* | 
| + * MediaDeviceManagerImpl | 
| + */ | 
| +class MediaDeviceManager::MediaDeviceManagerImpl | 
| + : public base::SystemMonitor::DevicesChangedObserver { | 
| + public: | 
| + MediaDeviceManagerImpl(); | 
| + virtual ~MediaDeviceManagerImpl(); | 
| + | 
| + void GetDevices(std::vector<MediaDeviceManager::MediaDeviceInfo>* results); | 
| + | 
| + // DevicesChangedObserver implementation. | 
| + virtual void OnMediaDeviceAttached( | 
| + const base::SystemMonitor::DeviceIdType& id, | 
| + const std::string& name, | 
| + const FilePath& path) OVERRIDE; | 
| + virtual void OnMediaDeviceDetached( | 
| + const base::SystemMonitor::DeviceIdType& id) OVERRIDE; | 
| + | 
| + private: | 
| + typedef std::map<base::SystemMonitor::DeviceIdType, | 
| + MediaDeviceManager::MediaDeviceInfo> DeviceMap; | 
| + | 
| +#if defined(OS_WIN) | 
| 
 
vandebo (ex-Chrome)
2012/05/17 21:17:08
Can we have a single Init method that is defined d
 
 | 
| + void InitWin(); | 
| +#elif defined(OS_LINUX) | 
| + void InitLinux(); | 
| +#endif | 
| + | 
| +#if defined(OS_WIN) | 
| + scoped_ptr<MediaDeviceNotificationsWindowWin> | 
| + media_device_notifications_window_; | 
| 
 
vandebo (ex-Chrome)
2012/05/17 21:17:08
If we keep this, lets use the same name across pla
 
 | 
| +#elif defined(OS_LINUX) | 
| + scoped_refptr<MediaDeviceNotificationsLinux> | 
| + media_device_notifications_linux_; | 
| +#endif | 
| + | 
| + DeviceMap device_map_; | 
| + | 
| + DISALLOW_COPY_AND_ASSIGN(MediaDeviceManagerImpl); | 
| +}; | 
| + | 
| +MediaDeviceManager::MediaDeviceManagerImpl::MediaDeviceManagerImpl() { | 
| +#if defined(OS_WIN) | 
| + InitWin(); | 
| +#elif defined(OS_LINUX) | 
| + InitLinux(); | 
| +#endif | 
| + base::SystemMonitor::Get()->AddDevicesChangedObserver(this); | 
| +} | 
| + | 
| +MediaDeviceManager::MediaDeviceManagerImpl::~MediaDeviceManagerImpl() { | 
| + base::SystemMonitor::Get()->RemoveDevicesChangedObserver(this); | 
| +} | 
| + | 
| +void MediaDeviceManager::MediaDeviceManagerImpl::GetDevices( | 
| + std::vector<MediaDeviceManager::MediaDeviceInfo>* results) { | 
| + for (DeviceMap::const_iterator it = device_map_.begin(); | 
| + it != device_map_.end(); | 
| + ++it) { | 
| + results->push_back(it->second); | 
| + } | 
| +} | 
| + | 
| +void MediaDeviceManager::MediaDeviceManagerImpl::OnMediaDeviceAttached( | 
| + const base::SystemMonitor::DeviceIdType& id, | 
| + const std::string& name, | 
| + const FilePath& path) { | 
| + if (device_map_.find(id) != device_map_.end()) { | 
| + NOTREACHED(); | 
| + return; | 
| + } | 
| + | 
| + device_map_.insert(std::make_pair(id, std::make_pair(name, path))); | 
| +} | 
| + | 
| +void MediaDeviceManager::MediaDeviceManagerImpl::OnMediaDeviceDetached( | 
| + const base::SystemMonitor::DeviceIdType& id) { | 
| + DeviceMap::iterator it = device_map_.find(id); | 
| + if (it == device_map_.end()) { | 
| + NOTREACHED(); | 
| + return; | 
| + } | 
| + device_map_.erase(it); | 
| +} | 
| + | 
| +#if defined(OS_WIN) | 
| +void MediaDeviceManager::MediaDeviceManagerImpl::InitWin() { | 
| + media_device_notifications_window_.reset( | 
| + new chrome::MediaDeviceNotificationsWindowWin()); | 
| +} | 
| +#elif defined(OS_LINUX) | 
| +void MediaDeviceManager::MediaDeviceManagerImpl::InitLinux() { | 
| + const FilePath kDefaultMtabPath("/etc/mtab"); | 
| + media_device_notifications_linux_ = | 
| + new chrome::MediaDeviceNotificationsLinux(kDefaultMtabPath); | 
| + media_device_notifications_linux_->Init(); | 
| +} | 
| +#endif | 
| + | 
| +/* | 
| + * MediaDeviceManager | 
| + */ | 
| + | 
| +MediaDeviceManager::MediaDeviceManager() { | 
| 
 
vandebo (ex-Chrome)
2012/05/17 21:17:08
Use initialization list?
 
 | 
| + impl_.reset(new MediaDeviceManagerImpl()); | 
| +} | 
| + | 
| +MediaDeviceManager::~MediaDeviceManager() { | 
| +} | 
| + | 
| +void MediaDeviceManager::GetDevices(std::vector<MediaDeviceInfo>* results) { | 
| + return impl_->GetDevices(results); | 
| +} | 
| + | 
| +} // namespace chrome | 
| Property changes on: chrome/browser/media_gallery/media_device_manager.cc | 
| ___________________________________________________________________ | 
| Added: svn:eol-style | 
| + LF |