OLD | NEW |
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/removable_device_notifications_mac.h" |
6 | 6 |
| 7 #include "base/mac/mac_util.h" |
| 8 #include "chrome/browser/storage_monitor/image_capture_device_manager.h" |
7 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" | 9 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" |
8 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
9 | 11 |
10 namespace chrome { | 12 namespace chrome { |
11 | 13 |
12 namespace { | 14 namespace { |
13 | 15 |
14 const char kDiskImageModelName[] = "Disk Image"; | 16 const char kDiskImageModelName[] = "Disk Image"; |
15 | 17 |
| 18 // TODO(gbillock): Make these take weak pointers and don't have |
| 19 // RemovableDeviceNotificationsMac be ref counted. |
| 20 |
16 void GetDiskInfoAndUpdateOnFileThread( | 21 void GetDiskInfoAndUpdateOnFileThread( |
17 const scoped_refptr<RemovableDeviceNotificationsMac>& notifications, | 22 const scoped_refptr<RemovableDeviceNotificationsMac>& notifications, |
18 base::mac::ScopedCFTypeRef<CFDictionaryRef> dict, | 23 base::mac::ScopedCFTypeRef<CFDictionaryRef> dict, |
19 RemovableDeviceNotificationsMac::UpdateType update_type) { | 24 RemovableDeviceNotificationsMac::UpdateType update_type) { |
20 DiskInfoMac info = DiskInfoMac::BuildDiskInfoOnFileThread(dict); | 25 DiskInfoMac info = DiskInfoMac::BuildDiskInfoOnFileThread(dict); |
21 if (info.device_id().empty()) | 26 if (info.device_id().empty()) |
22 return; | 27 return; |
23 | 28 |
24 content::BrowserThread::PostTask( | 29 content::BrowserThread::PostTask( |
25 content::BrowserThread::UI, | 30 content::BrowserThread::UI, |
(...skipping 14 matching lines...) Expand all Loading... |
40 FROM_HERE, | 45 FROM_HERE, |
41 base::Bind(GetDiskInfoAndUpdateOnFileThread, | 46 base::Bind(GetDiskInfoAndUpdateOnFileThread, |
42 notifications, | 47 notifications, |
43 dict, | 48 dict, |
44 update_type)); | 49 update_type)); |
45 } | 50 } |
46 | 51 |
47 } // namespace | 52 } // namespace |
48 | 53 |
49 RemovableDeviceNotificationsMac::RemovableDeviceNotificationsMac() { | 54 RemovableDeviceNotificationsMac::RemovableDeviceNotificationsMac() { |
| 55 } |
| 56 |
| 57 RemovableDeviceNotificationsMac::~RemovableDeviceNotificationsMac() { |
| 58 if (session_.get()) { |
| 59 DASessionUnscheduleFromRunLoop( |
| 60 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); |
| 61 } |
| 62 } |
| 63 |
| 64 void RemovableDeviceNotificationsMac::Init() { |
50 session_.reset(DASessionCreate(NULL)); | 65 session_.reset(DASessionCreate(NULL)); |
51 | 66 |
52 DASessionScheduleWithRunLoop( | |
53 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); | |
54 | |
55 // Register for callbacks for attached, changed, and removed devices. | 67 // Register for callbacks for attached, changed, and removed devices. |
56 // This will send notifications for existing devices too. | 68 // This will send notifications for existing devices too. |
57 DARegisterDiskAppearedCallback( | 69 DARegisterDiskAppearedCallback( |
58 session_, | 70 session_, |
59 kDADiskDescriptionMatchVolumeMountable, | 71 kDADiskDescriptionMatchVolumeMountable, |
60 DiskAppearedCallback, | 72 DiskAppearedCallback, |
61 this); | 73 this); |
62 DARegisterDiskDisappearedCallback( | 74 DARegisterDiskDisappearedCallback( |
63 session_, | 75 session_, |
64 kDADiskDescriptionMatchVolumeMountable, | 76 kDADiskDescriptionMatchVolumeMountable, |
65 DiskDisappearedCallback, | 77 DiskDisappearedCallback, |
66 this); | 78 this); |
67 DARegisterDiskDescriptionChangedCallback( | 79 DARegisterDiskDescriptionChangedCallback( |
68 session_, | 80 session_, |
69 kDADiskDescriptionMatchVolumeMountable, | 81 kDADiskDescriptionMatchVolumeMountable, |
70 kDADiskDescriptionWatchVolumePath, | 82 kDADiskDescriptionWatchVolumePath, |
71 DiskDescriptionChangedCallback, | 83 DiskDescriptionChangedCallback, |
72 this); | 84 this); |
73 } | |
74 | 85 |
75 RemovableDeviceNotificationsMac::~RemovableDeviceNotificationsMac() { | 86 DASessionScheduleWithRunLoop( |
76 DASessionUnscheduleFromRunLoop( | |
77 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); | 87 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); |
| 88 |
| 89 if (base::mac::IsOSLionOrLater()) { |
| 90 image_capture_device_manager_.reset(new chrome::ImageCaptureDeviceManager); |
| 91 image_capture_device_manager_->SetNotifications(receiver()); |
| 92 } |
78 } | 93 } |
79 | 94 |
80 void RemovableDeviceNotificationsMac::UpdateDisk( | 95 void RemovableDeviceNotificationsMac::UpdateDisk( |
81 const DiskInfoMac& info, | 96 const DiskInfoMac& info, |
82 UpdateType update_type) { | 97 UpdateType update_type) { |
83 if (info.bsd_name().empty()) | 98 if (info.bsd_name().empty()) |
84 return; | 99 return; |
85 | 100 |
86 std::map<std::string, DiskInfoMac>::iterator it = | 101 std::map<std::string, DiskInfoMac>::iterator it = |
87 disk_info_map_.find(info.bsd_name()); | 102 disk_info_map_.find(info.bsd_name()); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 it = disk_info_map_.begin(); it != disk_info_map_.end(); ++it) { | 209 it = disk_info_map_.begin(); it != disk_info_map_.end(); ++it) { |
195 if (it->second.mount_point() == mount_point) { | 210 if (it->second.mount_point() == mount_point) { |
196 *info = it->second; | 211 *info = it->second; |
197 return true; | 212 return true; |
198 } | 213 } |
199 } | 214 } |
200 return false; | 215 return false; |
201 } | 216 } |
202 | 217 |
203 } // namespace chrome | 218 } // namespace chrome |
OLD | NEW |