| Index: chrome/browser/system_monitor/removable_storage_notifications.cc
|
| diff --git a/chrome/browser/system_monitor/removable_storage_notifications.cc b/chrome/browser/system_monitor/removable_storage_notifications.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e71ee1d193e8fc726fc510109a2c2f00614e7b82
|
| --- /dev/null
|
| +++ b/chrome/browser/system_monitor/removable_storage_notifications.cc
|
| @@ -0,0 +1,100 @@
|
| +// 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.
|
| +
|
| +#include "base/stl_util.h"
|
| +#include "base/utf_string_conversions.h"
|
| +#include "chrome/browser/system_monitor/removable_storage_notifications.h"
|
| +
|
| +namespace chrome {
|
| +
|
| +RemovableStorageNotifications::RemovableStorageInfo::RemovableStorageInfo() {
|
| +}
|
| +
|
| +RemovableStorageNotifications::RemovableStorageInfo::RemovableStorageInfo(
|
| + const std::string& id,
|
| + const string16& device_name,
|
| + const FilePath::StringType& device_location)
|
| + : device_id(id),
|
| + name(device_name),
|
| + location(device_location) {
|
| +}
|
| +
|
| +RemovableStorageNotifications::RemovableStorageNotifications()
|
| + : observer_list_(
|
| + new ObserverListThreadSafe<RemovableStorageObserver>()) {
|
| +}
|
| +
|
| +void RemovableStorageNotifications::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 RemovableStorageNotifications::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<RemovableStorageNotifications::RemovableStorageInfo>
|
| +RemovableStorageNotifications::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 RemovableStorageNotifications::AddRemovableStorageObserver(
|
| + RemovableStorageObserver* obs) {
|
| + observer_list_->AddObserver(obs);
|
| +}
|
| +
|
| +void RemovableStorageNotifications::RemoveRemovableStorageObserver(
|
| + RemovableStorageObserver* obs) {
|
| + observer_list_->RemoveObserver(obs);
|
| +}
|
| +
|
| +void RemovableStorageNotifications::NotifyRemovableStorageAttached(
|
| + const std::string& id,
|
| + const string16& name,
|
| + const FilePath::StringType& location) {
|
| + DVLOG(1) << "RemovableStorageAttached with name " << UTF16ToUTF8(name)
|
| + << " and id " << id;
|
| + observer_list_->Notify(
|
| + &RemovableStorageObserver::OnRemovableStorageAttached, id, name, location);
|
| +}
|
| +
|
| +void RemovableStorageNotifications::NotifyRemovableStorageDetached(
|
| + const std::string& id) {
|
| + DVLOG(1) << "RemovableStorageDetached for id " << id;
|
| + observer_list_->Notify(
|
| + &RemovableStorageObserver::OnRemovableStorageDetached, id);
|
| +}
|
| +
|
| +
|
| +
|
| +
|
| +} // namespace chrome
|
|
|