summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-02 19:43:42 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-02 19:43:42 +0000
commit8b6b5a9fbf4ec07104e8f463515d810b17b6138a (patch)
tree4cd11a1b867359a73d0d436a95f43739b7f569ee
parentc86fd471f8e8a75b747a0e14cfc7a45efe2ae1e6 (diff)
downloadchromium_src-8b6b5a9fbf4ec07104e8f463515d810b17b6138a.zip
chromium_src-8b6b5a9fbf4ec07104e8f463515d810b17b6138a.tar.gz
chromium_src-8b6b5a9fbf4ec07104e8f463515d810b17b6138a.tar.bz2
Revert 191782 "Use StorageInfo in Mac"
Hitting a NOTREACHED on startup. BUG=225813 > Use StorageInfo in Mac > > BUG= > > > Review URL: https://chromiumcodereview.appspot.com/12643002 TBR=gbillock@chromium.org Review URL: https://codereview.chromium.org/13461014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191877 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chrome_browser_main_mac.h4
-rw-r--r--chrome/browser/chrome_browser_main_mac.mm2
-rw-r--r--chrome/browser/storage_monitor/disk_info_mac.h45
-rw-r--r--chrome/browser/storage_monitor/disk_info_mac.mm118
-rw-r--r--chrome/browser/storage_monitor/storage_monitor_mac.h25
-rw-r--r--chrome/browser/storage_monitor/storage_monitor_mac.mm192
-rw-r--r--chrome/browser/storage_monitor/storage_monitor_mac_unittest.mm102
-rw-r--r--chrome/chrome_browser.gypi2
8 files changed, 280 insertions, 210 deletions
diff --git a/chrome/browser/chrome_browser_main_mac.h b/chrome/browser/chrome_browser_main_mac.h
index 52f6cf1..d3cb484 100644
--- a/chrome/browser/chrome_browser_main_mac.h
+++ b/chrome/browser/chrome_browser_main_mac.h
@@ -5,8 +5,8 @@
#ifndef CHROME_BROWSER_CHROME_BROWSER_MAIN_MAC_H_
#define CHROME_BROWSER_CHROME_BROWSER_MAIN_MAC_H_
-#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chrome_browser_main_posix.h"
+#include "base/memory/ref_counted.h"
namespace chrome {
class StorageMonitorMac;
@@ -29,7 +29,7 @@ class ChromeBrowserMainPartsMac : public ChromeBrowserMainPartsPosix {
static void DidEndMainMessageLoop();
private:
- scoped_ptr<chrome::StorageMonitorMac> storage_monitor_;
+ scoped_refptr<chrome::StorageMonitorMac> storage_monitor_;
DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainPartsMac);
};
diff --git a/chrome/browser/chrome_browser_main_mac.mm b/chrome/browser/chrome_browser_main_mac.mm
index a8fe28f..cd32ec4 100644
--- a/chrome/browser/chrome_browser_main_mac.mm
+++ b/chrome/browser/chrome_browser_main_mac.mm
@@ -281,7 +281,7 @@ void ChromeBrowserMainPartsMac::PreMainMessageLoopStart() {
}
void ChromeBrowserMainPartsMac::PreProfileInit() {
- storage_monitor_.reset(new chrome::StorageMonitorMac());
+ storage_monitor_ = new chrome::StorageMonitorMac();
ChromeBrowserMainPartsPosix::PreProfileInit();
}
diff --git a/chrome/browser/storage_monitor/disk_info_mac.h b/chrome/browser/storage_monitor/disk_info_mac.h
new file mode 100644
index 0000000..332d087
--- /dev/null
+++ b/chrome/browser/storage_monitor/disk_info_mac.h
@@ -0,0 +1,45 @@
+// 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.
+
+#ifndef CHROME_BROWSER_STORAGE_MONITOR_DISK_INFO_MAC_H_
+#define CHROME_BROWSER_STORAGE_MONITOR_DISK_INFO_MAC_H_
+
+#include <CoreFoundation/CoreFoundation.h>
+
+#include "base/files/file_path.h"
+#include "chrome/browser/storage_monitor/media_storage_util.h"
+
+namespace chrome {
+
+// This class stores information about a particular disk.
+class DiskInfoMac {
+ public:
+ DiskInfoMac();
+ ~DiskInfoMac();
+
+ // Creates a disk info object based on information from the given
+ // dictionary. This function must be called on the file thread.
+ static DiskInfoMac BuildDiskInfoOnFileThread(CFDictionaryRef dict);
+
+ const std::string& bsd_name() const { return bsd_name_; }
+ const std::string& device_id() const { return device_id_; }
+ const std::string& model_name() const { return model_name_; }
+ const string16& device_name() const { return device_name_; }
+ const base::FilePath& mount_point() const { return mount_point_; }
+ MediaStorageUtil::Type type() const { return type_; }
+ uint64 total_size_in_bytes() const { return total_size_in_bytes_; }
+
+ private:
+ std::string bsd_name_;
+ std::string device_id_;
+ std::string model_name_;
+ string16 device_name_;
+ base::FilePath mount_point_;
+ MediaStorageUtil::Type type_;
+ uint64 total_size_in_bytes_;
+};
+
+} // namespace chrome
+
+#endif // CHROME_BROWSER_STORAGE_MONITOR_DISK_INFO_MAC_H_
diff --git a/chrome/browser/storage_monitor/disk_info_mac.mm b/chrome/browser/storage_monitor/disk_info_mac.mm
new file mode 100644
index 0000000..6e90aee
--- /dev/null
+++ b/chrome/browser/storage_monitor/disk_info_mac.mm
@@ -0,0 +1,118 @@
+// 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 "chrome/browser/storage_monitor/disk_info_mac.h"
+
+#include "base/mac/foundation_util.h"
+#include "base/strings/sys_string_conversions.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/storage_monitor/media_storage_util.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace chrome {
+namespace {
+
+string16 GetUTF16FromDictionary(CFDictionaryRef dictionary, CFStringRef key) {
+ CFStringRef value =
+ base::mac::GetValueFromDictionary<CFStringRef>(dictionary, key);
+ if (!value)
+ return string16();
+ return base::SysCFStringRefToUTF16(value);
+}
+
+string16 JoinName(const string16& name, const string16& addition) {
+ if (addition.empty())
+ return name;
+ if (name.empty())
+ return addition;
+ return name + static_cast<char16>(' ') + addition;
+}
+
+MediaStorageUtil::Type GetDeviceType(bool is_removable, bool has_dcim) {
+ if (!is_removable)
+ return MediaStorageUtil::FIXED_MASS_STORAGE;
+ if (has_dcim)
+ return MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM;
+ return MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM;
+}
+
+} // namespace
+
+DiskInfoMac::DiskInfoMac() : total_size_in_bytes_(0) {
+}
+
+DiskInfoMac::~DiskInfoMac() {
+}
+
+// static
+DiskInfoMac DiskInfoMac::BuildDiskInfoOnFileThread(CFDictionaryRef dict) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
+ DiskInfoMac info;
+
+ CFStringRef bsd_name = base::mac::GetValueFromDictionary<CFStringRef>(
+ dict, kDADiskDescriptionMediaBSDNameKey);
+ if (bsd_name)
+ info.bsd_name_ = base::SysCFStringRefToUTF8(bsd_name);
+
+ CFURLRef url = base::mac::GetValueFromDictionary<CFURLRef>(
+ dict, kDADiskDescriptionVolumePathKey);
+ NSURL* nsurl = base::mac::CFToNSCast(url);
+ info.mount_point_ = base::mac::NSStringToFilePath([nsurl path]);
+ CFNumberRef size_number =
+ base::mac::GetValueFromDictionary<CFNumberRef>(
+ dict, kDADiskDescriptionMediaSizeKey);
+ if (size_number) {
+ CFNumberGetValue(size_number, kCFNumberLongLongType,
+ &(info.total_size_in_bytes_));
+ }
+
+ string16 vendor_name = GetUTF16FromDictionary(
+ dict, kDADiskDescriptionDeviceVendorKey);
+ string16 model_name = GetUTF16FromDictionary(
+ dict, kDADiskDescriptionDeviceModelKey);
+ string16 volume_name = GetUTF16FromDictionary(
+ dict, kDADiskDescriptionVolumeNameKey);
+
+ if (!volume_name.empty()) {
+ info.device_name_ = volume_name;
+ } else {
+ info.device_name_ = MediaStorageUtil::GetFullProductName(
+ UTF16ToUTF8(vendor_name),
+ UTF16ToUTF8(model_name));
+ }
+ info.model_name_ = UTF16ToUTF8(model_name);
+
+ CFUUIDRef uuid = base::mac::GetValueFromDictionary<CFUUIDRef>(
+ dict, kDADiskDescriptionVolumeUUIDKey);
+ std::string unique_id;
+ if (uuid) {
+ base::mac::ScopedCFTypeRef<CFStringRef> uuid_string(
+ CFUUIDCreateString(NULL, uuid));
+ if (uuid_string.get())
+ unique_id = base::SysCFStringRefToUTF8(uuid_string);
+ }
+ if (unique_id.empty()) {
+ string16 revision = GetUTF16FromDictionary(
+ dict, kDADiskDescriptionDeviceRevisionKey);
+ string16 unique_id2 = vendor_name;
+ unique_id2 = JoinName(unique_id2, model_name);
+ unique_id2 = JoinName(unique_id2, revision);
+ unique_id = UTF16ToUTF8(unique_id2);
+ }
+
+ CFBooleanRef is_removable_ref =
+ base::mac::GetValueFromDictionary<CFBooleanRef>(
+ dict, kDADiskDescriptionMediaRemovableKey);
+ bool is_removable = is_removable_ref && CFBooleanGetValue(is_removable_ref);
+ // Checking for DCIM only matters on removable devices.
+ bool has_dcim =
+ is_removable && MediaStorageUtil::HasDcim(info.mount_point_.value());
+ info.type_ = GetDeviceType(is_removable, has_dcim);
+ if (!unique_id.empty())
+ info.device_id_ = MediaStorageUtil::MakeDeviceId(info.type_, unique_id);
+
+ return info;
+}
+
+} // namesapce chrome
diff --git a/chrome/browser/storage_monitor/storage_monitor_mac.h b/chrome/browser/storage_monitor/storage_monitor_mac.h
index 5b2e73f..e52efe1 100644
--- a/chrome/browser/storage_monitor/storage_monitor_mac.h
+++ b/chrome/browser/storage_monitor/storage_monitor_mac.h
@@ -9,7 +9,8 @@
#include <map>
#include "base/mac/scoped_cftyperef.h"
-#include "base/memory/weak_ptr.h"
+#include "base/memory/ref_counted.h"
+#include "chrome/browser/storage_monitor/disk_info_mac.h"
#include "chrome/browser/storage_monitor/storage_monitor.h"
namespace chrome {
@@ -18,8 +19,9 @@ class ImageCaptureDeviceManager;
// This class posts notifications to listeners when a new disk
// is attached, removed, or changed.
-class StorageMonitorMac : public StorageMonitor,
- public base::SupportsWeakPtr<StorageMonitorMac> {
+class StorageMonitorMac
+ : public StorageMonitor,
+ public base::RefCountedThreadSafe<StorageMonitorMac> {
public:
enum UpdateType {
UPDATE_DEVICE_ADDED,
@@ -30,13 +32,9 @@ class StorageMonitorMac : public StorageMonitor,
// Should only be called by browser start up code. Use GetInstance() instead.
StorageMonitorMac();
- virtual ~StorageMonitorMac();
-
void Init();
- void UpdateDisk(const std::string& bsd_name,
- const StorageInfo& info,
- UpdateType update_type);
+ void UpdateDisk(const DiskInfoMac& info, UpdateType update_type);
virtual bool GetStorageInfoForPath(
const base::FilePath& path,
@@ -52,21 +50,24 @@ class StorageMonitorMac : public StorageMonitor,
base::Callback<void(EjectStatus)> callback) OVERRIDE;
private:
+ friend class base::RefCountedThreadSafe<StorageMonitorMac>;
+ virtual ~StorageMonitorMac();
+
static void DiskAppearedCallback(DADiskRef disk, void* context);
static void DiskDisappearedCallback(DADiskRef disk, void* context);
static void DiskDescriptionChangedCallback(DADiskRef disk,
CFArrayRef keys,
void *context);
- bool ShouldPostNotificationForDisk(const StorageInfo& info) const;
+ bool ShouldPostNotificationForDisk(const DiskInfoMac& info) const;
bool FindDiskWithMountPoint(const base::FilePath& mount_point,
- StorageInfo* info) const;
+ DiskInfoMac* info) const;
base::mac::ScopedCFTypeRef<DASessionRef> session_;
// Maps disk bsd names to disk info objects. This map tracks all mountable
- // devices on the system, though only notifications for removable devices are
+ // devices on the system though only notifications for removable devices are
// posted.
- std::map<std::string, StorageInfo> disk_info_map_;
+ std::map<std::string, DiskInfoMac> disk_info_map_;
scoped_ptr<chrome::ImageCaptureDeviceManager> image_capture_device_manager_;
diff --git a/chrome/browser/storage_monitor/storage_monitor_mac.mm b/chrome/browser/storage_monitor/storage_monitor_mac.mm
index d124c12..f52ad79 100644
--- a/chrome/browser/storage_monitor/storage_monitor_mac.mm
+++ b/chrome/browser/storage_monitor/storage_monitor_mac.mm
@@ -4,10 +4,7 @@
#include "chrome/browser/storage_monitor/storage_monitor_mac.h"
-#include "base/mac/foundation_util.h"
#include "base/mac/mac_util.h"
-#include "base/strings/sys_string_conversions.h"
-#include "base/utf_string_conversions.h"
#include "chrome/browser/storage_monitor/image_capture_device_manager.h"
#include "chrome/browser/storage_monitor/media_storage_util.h"
#include "content/public/browser/browser_thread.h"
@@ -18,110 +15,15 @@ namespace {
const char kDiskImageModelName[] = "Disk Image";
-string16 GetUTF16FromDictionary(CFDictionaryRef dictionary, CFStringRef key) {
- CFStringRef value =
- base::mac::GetValueFromDictionary<CFStringRef>(dictionary, key);
- if (!value)
- return string16();
- return base::SysCFStringRefToUTF16(value);
-}
-
-string16 JoinName(const string16& name, const string16& addition) {
- if (addition.empty())
- return name;
- if (name.empty())
- return addition;
- return name + static_cast<char16>(' ') + addition;
-}
-
-MediaStorageUtil::Type GetDeviceType(bool is_removable, bool has_dcim) {
- if (!is_removable)
- return MediaStorageUtil::FIXED_MASS_STORAGE;
- if (has_dcim)
- return MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM;
- return MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM;
-}
-
-StorageInfo BuildStorageInfo(
- CFDictionaryRef dict, std::string* bsd_name) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
-
- StorageInfo info;
-
- CFStringRef device_bsd_name = base::mac::GetValueFromDictionary<CFStringRef>(
- dict, kDADiskDescriptionMediaBSDNameKey);
- if (device_bsd_name && bsd_name)
- *bsd_name = base::SysCFStringRefToUTF8(device_bsd_name);
-
- CFURLRef url = base::mac::GetValueFromDictionary<CFURLRef>(
- dict, kDADiskDescriptionVolumePathKey);
- NSURL* nsurl = base::mac::CFToNSCast(url);
- info.location = base::mac::NSStringToFilePath([nsurl path]).value();
- CFNumberRef size_number =
- base::mac::GetValueFromDictionary<CFNumberRef>(
- dict, kDADiskDescriptionMediaSizeKey);
- if (size_number) {
- CFNumberGetValue(size_number, kCFNumberLongLongType,
- &(info.total_size_in_bytes));
- }
-
- info.vendor_name = GetUTF16FromDictionary(
- dict, kDADiskDescriptionDeviceVendorKey);
- info.model_name = GetUTF16FromDictionary(
- dict, kDADiskDescriptionDeviceModelKey);
- info.storage_label = GetUTF16FromDictionary(
- dict, kDADiskDescriptionVolumeNameKey);
-
- if (!info.storage_label.empty()) {
- info.name = info.storage_label;
- } else {
- info.name = MediaStorageUtil::GetFullProductName(
- UTF16ToUTF8(info.vendor_name), UTF16ToUTF8(info.model_name));
- }
-
- CFUUIDRef uuid = base::mac::GetValueFromDictionary<CFUUIDRef>(
- dict, kDADiskDescriptionVolumeUUIDKey);
- std::string unique_id;
- if (uuid) {
- base::mac::ScopedCFTypeRef<CFStringRef> uuid_string(
- CFUUIDCreateString(NULL, uuid));
- if (uuid_string.get())
- unique_id = base::SysCFStringRefToUTF8(uuid_string);
- }
- if (unique_id.empty()) {
- string16 revision = GetUTF16FromDictionary(
- dict, kDADiskDescriptionDeviceRevisionKey);
- string16 unique_id2 = info.vendor_name;
- unique_id2 = JoinName(unique_id2, info.model_name);
- unique_id2 = JoinName(unique_id2, revision);
- unique_id = UTF16ToUTF8(unique_id2);
- }
-
- CFBooleanRef is_removable_ref =
- base::mac::GetValueFromDictionary<CFBooleanRef>(
- dict, kDADiskDescriptionMediaRemovableKey);
- bool is_removable = is_removable_ref && CFBooleanGetValue(is_removable_ref);
- // Checking for DCIM only matters on removable devices.
- bool has_dcim = is_removable &&
- MediaStorageUtil::IsMediaDevice(info.location);
- MediaStorageUtil::Type device_type = GetDeviceType(is_removable, has_dcim);
- if (!unique_id.empty())
- info.device_id = MediaStorageUtil::MakeDeviceId(device_type,
- unique_id);
-
- return info;
-}
+// TODO(gbillock): Make these take weak pointers and don't have
+// StorageMonitorMac be ref counted.
void GetDiskInfoAndUpdateOnFileThread(
- const base::WeakPtr<StorageMonitorMac>& monitor,
+ const scoped_refptr<StorageMonitorMac>& monitor,
base::mac::ScopedCFTypeRef<CFDictionaryRef> dict,
StorageMonitorMac::UpdateType update_type) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
-
- std::string bsd_name;
- StorageInfo info = BuildStorageInfo(dict, &bsd_name);
-
- if (info.device_id.empty())
+ DiskInfoMac info = DiskInfoMac::BuildDiskInfoOnFileThread(dict);
+ if (info.device_id().empty())
return;
content::BrowserThread::PostTask(
@@ -129,22 +31,19 @@ void GetDiskInfoAndUpdateOnFileThread(
FROM_HERE,
base::Bind(&StorageMonitorMac::UpdateDisk,
monitor,
- bsd_name,
info,
update_type));
}
-void GetDiskInfoAndUpdate(StorageMonitorMac* monitor,
+void GetDiskInfoAndUpdate(const scoped_refptr<StorageMonitorMac>& monitor,
DADiskRef disk,
StorageMonitorMac::UpdateType update_type) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
-
base::mac::ScopedCFTypeRef<CFDictionaryRef> dict(DADiskCopyDescription(disk));
content::BrowserThread::PostTask(
content::BrowserThread::FILE,
FROM_HERE,
base::Bind(GetDiskInfoAndUpdateOnFileThread,
- monitor->AsWeakPtr(),
+ monitor,
dict,
update_type));
}
@@ -230,41 +129,35 @@ void StorageMonitorMac::Init() {
}
}
-void StorageMonitorMac::UpdateDisk(
- const std::string& bsd_name,
- const StorageInfo& info,
- UpdateType update_type) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
-
- if (bsd_name.empty())
+void StorageMonitorMac::UpdateDisk(const DiskInfoMac& info,
+ UpdateType update_type) {
+ if (info.bsd_name().empty())
return;
- std::map<std::string, StorageInfo>::iterator it =
- disk_info_map_.find(bsd_name);
+ std::map<std::string, DiskInfoMac>::iterator it =
+ disk_info_map_.find(info.bsd_name());
if (it != disk_info_map_.end()) {
// If an attached notification was previously posted then post a detached
// notification now. This is used for devices that are being removed or
// devices that have changed.
if (ShouldPostNotificationForDisk(it->second)) {
- receiver()->ProcessDetach(it->second.device_id);
+ receiver()->ProcessDetach(it->second.device_id());
}
}
- StorageInfo storage_info(info);
- if (ShouldPostNotificationForDisk(storage_info)) {
- storage_info.name = MediaStorageUtil::GetDisplayNameForDevice(
- storage_info.total_size_in_bytes, storage_info.name);
- }
-
if (update_type == UPDATE_DEVICE_REMOVED) {
if (it != disk_info_map_.end())
disk_info_map_.erase(it);
} else {
- disk_info_map_[bsd_name] = storage_info;
- MediaStorageUtil::RecordDeviceInfoHistogram(true, storage_info.device_id,
- storage_info.name);
- if (ShouldPostNotificationForDisk(storage_info))
- receiver()->ProcessAttach(storage_info);
+ disk_info_map_[info.bsd_name()] = info;
+ MediaStorageUtil::RecordDeviceInfoHistogram(true, info.device_id(),
+ info.device_name());
+ if (ShouldPostNotificationForDisk(info)) {
+ string16 display_name = MediaStorageUtil::GetDisplayNameForDevice(
+ info.total_size_in_bytes(), info.device_name());
+ receiver()->ProcessAttach(StorageInfo(
+ info.device_id(), display_name, info.mount_point().value()));
+ }
}
}
@@ -276,9 +169,11 @@ bool StorageMonitorMac::GetStorageInfoForPath(const base::FilePath& path,
base::FilePath current = path;
const base::FilePath root(base::FilePath::kSeparators);
while (current != root) {
- StorageInfo info;
+ DiskInfoMac info;
if (FindDiskWithMountPoint(current, &info)) {
- *device_info = info;
+ device_info->device_id = info.device_id();
+ device_info->name = info.device_name();
+ device_info->location = info.mount_point().value();
return true;
}
current = current.DirName();
@@ -288,19 +183,19 @@ bool StorageMonitorMac::GetStorageInfoForPath(const base::FilePath& path,
}
uint64 StorageMonitorMac::GetStorageSize(const std::string& location) const {
- StorageInfo info;
+ DiskInfoMac info;
if (!FindDiskWithMountPoint(base::FilePath(location), &info))
return 0;
- return info.total_size_in_bytes;
+ return info.total_size_in_bytes();
}
void StorageMonitorMac::EjectDevice(
const std::string& device_id,
base::Callback<void(EjectStatus)> callback) {
std::string bsd_name;
- for (std::map<std::string, StorageInfo>::iterator
+ for (std::map<std::string, DiskInfoMac>::iterator
it = disk_info_map_.begin(); it != disk_info_map_.end(); ++it) {
- if (it->second.device_id == device_id) {
+ if (it->second.device_id() == device_id) {
bsd_name = it->first;
disk_info_map_.erase(it);
break;
@@ -338,13 +233,13 @@ void StorageMonitorMac::EjectDevice(
// static
void StorageMonitorMac::DiskAppearedCallback(DADiskRef disk, void* context) {
StorageMonitorMac* monitor = static_cast<StorageMonitorMac*>(context);
- GetDiskInfoAndUpdate(monitor->AsWeakPtr(), disk, UPDATE_DEVICE_ADDED);
+ GetDiskInfoAndUpdate(monitor, disk, UPDATE_DEVICE_ADDED);
}
// static
void StorageMonitorMac::DiskDisappearedCallback(DADiskRef disk, void* context) {
StorageMonitorMac* monitor = static_cast<StorageMonitorMac*>(context);
- GetDiskInfoAndUpdate(monitor->AsWeakPtr(), disk, UPDATE_DEVICE_REMOVED);
+ GetDiskInfoAndUpdate(monitor, disk, UPDATE_DEVICE_REMOVED);
}
// static
@@ -352,27 +247,28 @@ void StorageMonitorMac::DiskDescriptionChangedCallback(DADiskRef disk,
CFArrayRef keys,
void *context) {
StorageMonitorMac* monitor = static_cast<StorageMonitorMac*>(context);
- GetDiskInfoAndUpdate(monitor->AsWeakPtr(), disk, UPDATE_DEVICE_CHANGED);
+ GetDiskInfoAndUpdate(monitor, disk, UPDATE_DEVICE_CHANGED);
}
bool StorageMonitorMac::ShouldPostNotificationForDisk(
- const StorageInfo& info) const {
+ const DiskInfoMac& info) const {
// Only post notifications about disks that have no empty fields and
// are removable. Also exclude disk images (DMGs).
- return !info.device_id.empty() &&
- !info.name.empty() &&
- !info.location.empty() &&
- info.model_name != ASCIIToUTF16(kDiskImageModelName) &&
- MediaStorageUtil::IsRemovableDevice(info.device_id) &&
- MediaStorageUtil::IsMassStorageDevice(info.device_id);
+ return !info.bsd_name().empty() &&
+ !info.device_id().empty() &&
+ !info.device_name().empty() &&
+ !info.mount_point().empty() &&
+ info.model_name() != kDiskImageModelName &&
+ (info.type() == MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM ||
+ info.type() == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM);
}
bool StorageMonitorMac::FindDiskWithMountPoint(
const base::FilePath& mount_point,
- StorageInfo* info) const {
- for (std::map<std::string, StorageInfo>::const_iterator
+ DiskInfoMac* info) const {
+ for (std::map<std::string, DiskInfoMac>::const_iterator
it = disk_info_map_.begin(); it != disk_info_map_.end(); ++it) {
- if (it->second.location == mount_point.value()) {
+ if (it->second.mount_point() == mount_point) {
*info = it->second;
return true;
}
diff --git a/chrome/browser/storage_monitor/storage_monitor_mac_unittest.mm b/chrome/browser/storage_monitor/storage_monitor_mac_unittest.mm
index 300acad..2a750e1 100644
--- a/chrome/browser/storage_monitor/storage_monitor_mac_unittest.mm
+++ b/chrome/browser/storage_monitor/storage_monitor_mac_unittest.mm
@@ -8,7 +8,6 @@
#include "base/files/scoped_temp_dir.h"
#include "base/mac/foundation_util.h"
#include "base/message_loop.h"
-#include "base/run_loop.h"
#include "base/strings/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/storage_monitor/media_storage_util.h"
@@ -23,16 +22,30 @@ uint64 kTestSize = 1000000ULL;
namespace {
-StorageInfo CreateStorageInfo(
- const std::string& device_id,
- const std::string& model_name,
- const string16& display_name,
- const base::FilePath& mount_point,
- uint64 size_bytes) {
- return StorageInfo(
- device_id, display_name, mount_point.value(),
- string16(), string16(), UTF8ToUTF16(model_name),
- size_bytes);
+DiskInfoMac CreateDiskInfoMac(const std::string& unique_id,
+ const std::string& model_name,
+ const string16& display_name,
+ const base::FilePath& mount_point,
+ uint64 size_bytes) {
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
+ [dict setObject:@"dummy_bsd_name"
+ forKey:base::mac::CFToNSCast(kDADiskDescriptionMediaBSDNameKey)];
+ [dict setObject:base::SysUTF8ToNSString(unique_id)
+ forKey:base::mac::CFToNSCast(kDADiskDescriptionDeviceRevisionKey)];
+ if (!model_name.empty()) {
+ [dict setObject:base::SysUTF8ToNSString(model_name)
+ forKey:base::mac::CFToNSCast(kDADiskDescriptionDeviceModelKey)];
+ }
+ NSString* path = base::mac::FilePathToNSString(mount_point);
+ [dict setObject:[NSURL fileURLWithPath:path]
+ forKey:base::mac::CFToNSCast(kDADiskDescriptionVolumePathKey)];
+ [dict setObject:base::SysUTF16ToNSString(display_name)
+ forKey:base::mac::CFToNSCast(kDADiskDescriptionVolumeNameKey)];
+ [dict setObject:[NSNumber numberWithBool:YES]
+ forKey:base::mac::CFToNSCast(kDADiskDescriptionMediaRemovableKey)];
+ [dict setObject:[NSNumber numberWithInt:size_bytes]
+ forKey:base::mac::CFToNSCast(kDADiskDescriptionMediaSizeKey)];
+ return DiskInfoMac::BuildDiskInfoOnFileThread(base::mac::NSToCFCast(dict));
}
} // namespace
@@ -40,12 +53,12 @@ StorageInfo CreateStorageInfo(
class StorageMonitorMacTest : public testing::Test {
public:
StorageMonitorMacTest()
- : ui_thread_(content::BrowserThread::UI, &message_loop_),
+ : message_loop_(MessageLoop::TYPE_IO),
file_thread_(content::BrowserThread::FILE, &message_loop_) {
}
virtual void SetUp() OVERRIDE {
- monitor_.reset(new StorageMonitorMac);
+ monitor_ = new StorageMonitorMac;
mock_storage_observer_.reset(new MockRemovableStorageObserver);
monitor_->AddObserver(mock_storage_observer_.get());
@@ -55,23 +68,14 @@ class StorageMonitorMacTest : public testing::Test {
mount_point_ = base::FilePath("/unused_test_directory");
device_id_ = MediaStorageUtil::MakeDeviceId(
MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, unique_id_);
- disk_info_ = CreateStorageInfo(device_id_, "",
+ disk_info_ = CreateDiskInfoMac(unique_id_, "",
ASCIIToUTF16("Test Display Name"),
mount_point_, kTestSize);
}
- void UpdateDisk(StorageInfo info, StorageMonitorMac::UpdateType update_type) {
- content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
- base::Bind(&StorageMonitorMac::UpdateDisk,
- base::Unretained(monitor_.get()),
- "dummy_bsd_name", info, update_type));
- base::RunLoop().RunUntilIdle();
- }
-
protected:
// The message loop and file thread to run tests on.
- MessageLoopForUI message_loop_;
- content::TestBrowserThread ui_thread_;
+ MessageLoop message_loop_;
content::TestBrowserThread file_thread_;
scoped_ptr<MockRemovableStorageObserver> mock_storage_observer_;
@@ -81,14 +85,14 @@ class StorageMonitorMacTest : public testing::Test {
string16 display_name_;
base::FilePath mount_point_;
std::string device_id_;
- StorageInfo disk_info_;
+ DiskInfoMac disk_info_;
- scoped_ptr<StorageMonitorMac> monitor_;
+ scoped_refptr<StorageMonitorMac> monitor_;
};
TEST_F(StorageMonitorMacTest, AddRemove) {
- UpdateDisk(disk_info_, StorageMonitorMac::UPDATE_DEVICE_ADDED);
-
+ monitor_->UpdateDisk(disk_info_, StorageMonitorMac::UPDATE_DEVICE_ADDED);
+ message_loop_.RunUntilIdle();
EXPECT_EQ(1, mock_storage_observer_->attach_calls());
EXPECT_EQ(0, mock_storage_observer_->detach_calls());
EXPECT_EQ(device_id_, mock_storage_observer_->last_attached().device_id);
@@ -96,15 +100,16 @@ TEST_F(StorageMonitorMacTest, AddRemove) {
EXPECT_EQ(mount_point_.value(),
mock_storage_observer_->last_attached().location);
- UpdateDisk(disk_info_, StorageMonitorMac::UPDATE_DEVICE_REMOVED);
-
+ monitor_->UpdateDisk(disk_info_, StorageMonitorMac::UPDATE_DEVICE_REMOVED);
+ message_loop_.RunUntilIdle();
EXPECT_EQ(1, mock_storage_observer_->attach_calls());
EXPECT_EQ(1, mock_storage_observer_->detach_calls());
EXPECT_EQ(device_id_, mock_storage_observer_->last_detached().device_id);
}
TEST_F(StorageMonitorMacTest, UpdateVolumeName) {
- UpdateDisk(disk_info_, StorageMonitorMac::UPDATE_DEVICE_ADDED);
+ monitor_->UpdateDisk(disk_info_, StorageMonitorMac::UPDATE_DEVICE_ADDED);
+ message_loop_.RunUntilIdle();
EXPECT_EQ(1, mock_storage_observer_->attach_calls());
EXPECT_EQ(0, mock_storage_observer_->detach_calls());
@@ -114,10 +119,10 @@ TEST_F(StorageMonitorMacTest, UpdateVolumeName) {
mock_storage_observer_->last_attached().location);
string16 new_display_name(ASCIIToUTF16("977 KB Test Display Name"));
- StorageInfo info2 = CreateStorageInfo(
- device_id_, "", ASCIIToUTF16("Test Display Name"), mount_point_,
+ DiskInfoMac info2 = CreateDiskInfoMac(
+ unique_id_, "", ASCIIToUTF16("Test Display Name"), mount_point_,
kTestSize);
- UpdateDisk(info2, StorageMonitorMac::UPDATE_DEVICE_CHANGED);
+ monitor_->UpdateDisk(info2, StorageMonitorMac::UPDATE_DEVICE_CHANGED);
message_loop_.RunUntilIdle();
EXPECT_EQ(1, mock_storage_observer_->detach_calls());
@@ -136,13 +141,14 @@ TEST_F(StorageMonitorMacTest, DCIM) {
temp_dir.path().Append(kDCIMDirectoryName)));
base::FilePath mount_point = temp_dir.path();
+ DiskInfoMac info = CreateDiskInfoMac(
+ unique_id_, "", ASCIIToUTF16("Test Display Name"), mount_point,
+ kTestSize);
std::string device_id = MediaStorageUtil::MakeDeviceId(
MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, unique_id_);
- StorageInfo info = CreateStorageInfo(
- device_id, "", ASCIIToUTF16("Test Display Name"), mount_point,
- kTestSize);
- UpdateDisk(info, StorageMonitorMac::UPDATE_DEVICE_ADDED);
+ monitor_->UpdateDisk(info, StorageMonitorMac::UPDATE_DEVICE_ADDED);
+ message_loop_.RunUntilIdle();
EXPECT_EQ(1, mock_storage_observer_->attach_calls());
EXPECT_EQ(0, mock_storage_observer_->detach_calls());
@@ -153,7 +159,8 @@ TEST_F(StorageMonitorMacTest, DCIM) {
}
TEST_F(StorageMonitorMacTest, GetStorageInfo) {
- UpdateDisk(disk_info_, StorageMonitorMac::UPDATE_DEVICE_ADDED);
+ monitor_->UpdateDisk(disk_info_, StorageMonitorMac::UPDATE_DEVICE_ADDED);
+ message_loop_.RunUntilIdle();
EXPECT_EQ(1, mock_storage_observer_->attach_calls());
EXPECT_EQ(0, mock_storage_observer_->detach_calls());
@@ -165,17 +172,17 @@ TEST_F(StorageMonitorMacTest, GetStorageInfo) {
StorageInfo info;
EXPECT_TRUE(monitor_->GetStorageInfoForPath(mount_point_.AppendASCII("foo"),
&info));
- EXPECT_EQ(device_id_, info.device_id);
- EXPECT_EQ(ASCIIToUTF16("977 KB Test Display Name"), info.name);
- EXPECT_EQ(mount_point_.value(), info.location);
- EXPECT_EQ(1000000ULL, info.total_size_in_bytes);
+ EXPECT_EQ(info.device_id, device_id_);
+ EXPECT_EQ(info.name, ASCIIToUTF16("Test Display Name"));
+ EXPECT_EQ(info.location, mount_point_.value());
EXPECT_FALSE(monitor_->GetStorageInfoForPath(
base::FilePath("/non/matching/path"), &info));
}
TEST_F(StorageMonitorMacTest, GetStorageSize) {
- UpdateDisk(disk_info_, StorageMonitorMac::UPDATE_DEVICE_ADDED);
+ monitor_->UpdateDisk(disk_info_, StorageMonitorMac::UPDATE_DEVICE_ADDED);
+ message_loop_.RunUntilIdle();
EXPECT_EQ(1, mock_storage_observer_->attach_calls());
EXPECT_EQ(kTestSize,
@@ -184,9 +191,10 @@ TEST_F(StorageMonitorMacTest, GetStorageSize) {
// Test that mounting a DMG doesn't send a notification.
TEST_F(StorageMonitorMacTest, DMG) {
- StorageInfo info = CreateStorageInfo(
- device_id_, "Disk Image", display_name_, mount_point_, kTestSize);
- UpdateDisk(info, StorageMonitorMac::UPDATE_DEVICE_ADDED);
+ DiskInfoMac info = CreateDiskInfoMac(
+ unique_id_, "Disk Image", display_name_, mount_point_, kTestSize);
+ monitor_->UpdateDisk(info, StorageMonitorMac::UPDATE_DEVICE_ADDED);
+ message_loop_.RunUntilIdle();
EXPECT_EQ(0, mock_storage_observer_->attach_calls());
}
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 62f3b29..bda8b2d 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1782,6 +1782,8 @@
'browser/status_icons/status_icon_observer.h',
'browser/status_icons/status_tray.cc',
'browser/status_icons/status_tray.h',
+ 'browser/storage_monitor/disk_info_mac.h',
+ 'browser/storage_monitor/disk_info_mac.mm',
'browser/storage_monitor/image_capture_device.h',
'browser/storage_monitor/image_capture_device.mm',
'browser/storage_monitor/image_capture_device_manager.h',