Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(924)

Side by Side Diff: chrome/browser/storage_monitor/storage_monitor_mac.mm

Issue 12382005: Rename RemovableDeviceNotifications=>StorageMonitor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix some includes from recent merge. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/storage_monitor/removable_device_notifications_mac.h" 5 #include "chrome/browser/storage_monitor/storage_monitor_mac.h"
6 6
7 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" 7 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 9
10 namespace chrome { 10 namespace chrome {
11 11
12 namespace { 12 namespace {
13 13
14 const char kDiskImageModelName[] = "Disk Image"; 14 const char kDiskImageModelName[] = "Disk Image";
15 15
16 void GetDiskInfoAndUpdateOnFileThread( 16 void GetDiskInfoAndUpdateOnFileThread(
17 const scoped_refptr<RemovableDeviceNotificationsMac>& notifications, 17 const scoped_refptr<StorageMonitorMac>& notifications,
18 base::mac::ScopedCFTypeRef<CFDictionaryRef> dict, 18 base::mac::ScopedCFTypeRef<CFDictionaryRef> dict,
19 RemovableDeviceNotificationsMac::UpdateType update_type) { 19 StorageMonitorMac::UpdateType update_type) {
20 DiskInfoMac info = DiskInfoMac::BuildDiskInfoOnFileThread(dict); 20 DiskInfoMac info = DiskInfoMac::BuildDiskInfoOnFileThread(dict);
21 if (info.device_id().empty()) 21 if (info.device_id().empty())
22 return; 22 return;
23 23
24 content::BrowserThread::PostTask( 24 content::BrowserThread::PostTask(
25 content::BrowserThread::UI, 25 content::BrowserThread::UI,
26 FROM_HERE, 26 FROM_HERE,
27 base::Bind(&RemovableDeviceNotificationsMac::UpdateDisk, 27 base::Bind(&StorageMonitorMac::UpdateDisk,
28 notifications, 28 notifications,
29 info, 29 info,
30 update_type)); 30 update_type));
31 } 31 }
32 32
33 void GetDiskInfoAndUpdate( 33 void GetDiskInfoAndUpdate(
34 const scoped_refptr<RemovableDeviceNotificationsMac>& notifications, 34 const scoped_refptr<StorageMonitorMac>& notifications,
35 DADiskRef disk, 35 DADiskRef disk,
36 RemovableDeviceNotificationsMac::UpdateType update_type) { 36 StorageMonitorMac::UpdateType update_type) {
37 base::mac::ScopedCFTypeRef<CFDictionaryRef> dict(DADiskCopyDescription(disk)); 37 base::mac::ScopedCFTypeRef<CFDictionaryRef> dict(DADiskCopyDescription(disk));
38 content::BrowserThread::PostTask( 38 content::BrowserThread::PostTask(
39 content::BrowserThread::FILE, 39 content::BrowserThread::FILE,
40 FROM_HERE, 40 FROM_HERE,
41 base::Bind(GetDiskInfoAndUpdateOnFileThread, 41 base::Bind(GetDiskInfoAndUpdateOnFileThread,
42 notifications, 42 notifications,
43 dict, 43 dict,
44 update_type)); 44 update_type));
45 } 45 }
46 46
47 } // namespace 47 } // namespace
48 48
49 RemovableDeviceNotificationsMac::RemovableDeviceNotificationsMac() { 49 StorageMonitorMac::StorageMonitorMac() {
50 session_.reset(DASessionCreate(NULL)); 50 session_.reset(DASessionCreate(NULL));
51 51
52 DASessionScheduleWithRunLoop( 52 DASessionScheduleWithRunLoop(
53 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); 53 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
54 54
55 // Register for callbacks for attached, changed, and removed devices. 55 // Register for callbacks for attached, changed, and removed devices.
56 // This will send notifications for existing devices too. 56 // This will send notifications for existing devices too.
57 DARegisterDiskAppearedCallback( 57 DARegisterDiskAppearedCallback(
58 session_, 58 session_,
59 kDADiskDescriptionMatchVolumeMountable, 59 kDADiskDescriptionMatchVolumeMountable,
60 DiskAppearedCallback, 60 DiskAppearedCallback,
61 this); 61 this);
62 DARegisterDiskDisappearedCallback( 62 DARegisterDiskDisappearedCallback(
63 session_, 63 session_,
64 kDADiskDescriptionMatchVolumeMountable, 64 kDADiskDescriptionMatchVolumeMountable,
65 DiskDisappearedCallback, 65 DiskDisappearedCallback,
66 this); 66 this);
67 DARegisterDiskDescriptionChangedCallback( 67 DARegisterDiskDescriptionChangedCallback(
68 session_, 68 session_,
69 kDADiskDescriptionMatchVolumeMountable, 69 kDADiskDescriptionMatchVolumeMountable,
70 kDADiskDescriptionWatchVolumePath, 70 kDADiskDescriptionWatchVolumePath,
71 DiskDescriptionChangedCallback, 71 DiskDescriptionChangedCallback,
72 this); 72 this);
73 } 73 }
74 74
75 RemovableDeviceNotificationsMac::~RemovableDeviceNotificationsMac() { 75 StorageMonitorMac::~StorageMonitorMac() {
76 DASessionUnscheduleFromRunLoop( 76 DASessionUnscheduleFromRunLoop(
77 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); 77 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
78 } 78 }
79 79
80 void RemovableDeviceNotificationsMac::UpdateDisk( 80 void StorageMonitorMac::UpdateDisk(
81 const DiskInfoMac& info, 81 const DiskInfoMac& info,
82 UpdateType update_type) { 82 UpdateType update_type) {
83 if (info.bsd_name().empty()) 83 if (info.bsd_name().empty())
84 return; 84 return;
85 85
86 std::map<std::string, DiskInfoMac>::iterator it = 86 std::map<std::string, DiskInfoMac>::iterator it =
87 disk_info_map_.find(info.bsd_name()); 87 disk_info_map_.find(info.bsd_name());
88 if (it != disk_info_map_.end()) { 88 if (it != disk_info_map_.end()) {
89 // If an attached notification was previously posted then post a detached 89 // If an attached notification was previously posted then post a detached
90 // notification now. This is used for devices that are being removed or 90 // notification now. This is used for devices that are being removed or
(...skipping 12 matching lines...) Expand all
103 info.device_name()); 103 info.device_name());
104 if (ShouldPostNotificationForDisk(info)) { 104 if (ShouldPostNotificationForDisk(info)) {
105 string16 display_name = GetDisplayNameForDevice( 105 string16 display_name = GetDisplayNameForDevice(
106 info.total_size_in_bytes(), info.device_name()); 106 info.total_size_in_bytes(), info.device_name());
107 receiver()->ProcessAttach(StorageInfo( 107 receiver()->ProcessAttach(StorageInfo(
108 info.device_id(), display_name, info.mount_point().value())); 108 info.device_id(), display_name, info.mount_point().value()));
109 } 109 }
110 } 110 }
111 } 111 }
112 112
113 bool RemovableDeviceNotificationsMac::GetStorageInfoForPath( 113 bool StorageMonitorMac::GetStorageInfoForPath(
114 const base::FilePath& path, 114 const base::FilePath& path,
115 StorageInfo* device_info) const { 115 StorageInfo* device_info) const {
116 if (!path.IsAbsolute()) 116 if (!path.IsAbsolute())
117 return false; 117 return false;
118 118
119 base::FilePath current = path; 119 base::FilePath current = path;
120 const base::FilePath root(base::FilePath::kSeparators); 120 const base::FilePath root(base::FilePath::kSeparators);
121 while (current != root) { 121 while (current != root) {
122 DiskInfoMac info; 122 DiskInfoMac info;
123 if (FindDiskWithMountPoint(current, &info)) { 123 if (FindDiskWithMountPoint(current, &info)) {
124 device_info->device_id = info.device_id(); 124 device_info->device_id = info.device_id();
125 device_info->name = info.device_name(); 125 device_info->name = info.device_name();
126 device_info->location = info.mount_point().value(); 126 device_info->location = info.mount_point().value();
127 return true; 127 return true;
128 } 128 }
129 current = current.DirName(); 129 current = current.DirName();
130 } 130 }
131 131
132 return false; 132 return false;
133 } 133 }
134 134
135 uint64 RemovableDeviceNotificationsMac::GetStorageSize( 135 uint64 StorageMonitorMac::GetStorageSize(
136 const std::string& location) const { 136 const std::string& location) const {
137 DiskInfoMac info; 137 DiskInfoMac info;
138 if (!FindDiskWithMountPoint(base::FilePath(location), &info)) 138 if (!FindDiskWithMountPoint(base::FilePath(location), &info))
139 return 0; 139 return 0;
140 return info.total_size_in_bytes(); 140 return info.total_size_in_bytes();
141 } 141 }
142 142
143 // static 143 // static
144 void RemovableDeviceNotificationsMac::DiskAppearedCallback( 144 void StorageMonitorMac::DiskAppearedCallback(
145 DADiskRef disk, 145 DADiskRef disk,
146 void* context) { 146 void* context) {
147 RemovableDeviceNotificationsMac* notifications = 147 StorageMonitorMac* notifications =
148 static_cast<RemovableDeviceNotificationsMac*>(context); 148 static_cast<StorageMonitorMac*>(context);
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap
149 GetDiskInfoAndUpdate(notifications, 149 GetDiskInfoAndUpdate(notifications,
150 disk, 150 disk,
151 UPDATE_DEVICE_ADDED); 151 UPDATE_DEVICE_ADDED);
152 } 152 }
153 153
154 // static 154 // static
155 void RemovableDeviceNotificationsMac::DiskDisappearedCallback( 155 void StorageMonitorMac::DiskDisappearedCallback(
156 DADiskRef disk, 156 DADiskRef disk,
157 void* context) { 157 void* context) {
158 RemovableDeviceNotificationsMac* notifications = 158 StorageMonitorMac* notifications =
159 static_cast<RemovableDeviceNotificationsMac*>(context); 159 static_cast<StorageMonitorMac*>(context);
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap
160 GetDiskInfoAndUpdate(notifications, 160 GetDiskInfoAndUpdate(notifications,
161 disk, 161 disk,
162 UPDATE_DEVICE_REMOVED); 162 UPDATE_DEVICE_REMOVED);
163 } 163 }
164 164
165 // static 165 // static
166 void RemovableDeviceNotificationsMac::DiskDescriptionChangedCallback( 166 void StorageMonitorMac::DiskDescriptionChangedCallback(
167 DADiskRef disk, 167 DADiskRef disk,
168 CFArrayRef keys, 168 CFArrayRef keys,
169 void *context) { 169 void *context) {
170 RemovableDeviceNotificationsMac* notifications = 170 StorageMonitorMac* notifications =
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap
171 static_cast<RemovableDeviceNotificationsMac*>(context); 171 static_cast<StorageMonitorMac*>(context);
172 GetDiskInfoAndUpdate(notifications, 172 GetDiskInfoAndUpdate(notifications,
173 disk, 173 disk,
174 UPDATE_DEVICE_CHANGED); 174 UPDATE_DEVICE_CHANGED);
175 } 175 }
176 176
177 bool RemovableDeviceNotificationsMac::ShouldPostNotificationForDisk( 177 bool StorageMonitorMac::ShouldPostNotificationForDisk(
178 const DiskInfoMac& info) const { 178 const DiskInfoMac& info) const {
179 // Only post notifications about disks that have no empty fields and 179 // Only post notifications about disks that have no empty fields and
180 // are removable. Also exclude disk images (DMGs). 180 // are removable. Also exclude disk images (DMGs).
181 return !info.bsd_name().empty() && 181 return !info.bsd_name().empty() &&
182 !info.device_id().empty() && 182 !info.device_id().empty() &&
183 !info.device_name().empty() && 183 !info.device_name().empty() &&
184 !info.mount_point().empty() && 184 !info.mount_point().empty() &&
185 info.model_name() != kDiskImageModelName && 185 info.model_name() != kDiskImageModelName &&
186 (info.type() == MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM || 186 (info.type() == MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM ||
187 info.type() == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM); 187 info.type() == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM);
188 } 188 }
189 189
190 bool RemovableDeviceNotificationsMac::FindDiskWithMountPoint( 190 bool StorageMonitorMac::FindDiskWithMountPoint(
191 const base::FilePath& mount_point, 191 const base::FilePath& mount_point,
192 DiskInfoMac* info) const { 192 DiskInfoMac* info) const {
193 for (std::map<std::string, DiskInfoMac>::const_iterator 193 for (std::map<std::string, DiskInfoMac>::const_iterator
194 it = disk_info_map_.begin(); it != disk_info_map_.end(); ++it) { 194 it = disk_info_map_.begin(); it != disk_info_map_.end(); ++it) {
195 if (it->second.mount_point() == mount_point) { 195 if (it->second.mount_point() == mount_point) {
196 *info = it->second; 196 *info = it->second;
197 return true; 197 return true;
198 } 198 }
199 } 199 }
200 return false; 200 return false;
201 } 201 }
202 202
203 } // namespace chrome 203 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698