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

Side by Side Diff: chrome/browser/system_monitor/removable_device_notifications_mac.mm

Issue 11573048: [Media Galleries] Move RemovableStorageInfo notifications to chrome namespace (part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make singleton pointer live in base class. Created 7 years, 11 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 | Annotate | Revision Log
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/system_monitor/removable_device_notifications_mac.h" 5 #include "chrome/browser/system_monitor/removable_device_notifications_mac.h"
6 6
7 #include "chrome/browser/system_monitor/media_device_notifications_utils.h" 7 #include "chrome/browser/system_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 static RemovableDeviceNotificationsMac*
17 g_removable_device_notifications_mac = NULL;
18
19 void GetDiskInfoAndUpdateOnFileThread( 16 void GetDiskInfoAndUpdateOnFileThread(
20 const scoped_refptr<RemovableDeviceNotificationsMac>& notifications, 17 const scoped_refptr<RemovableDeviceNotificationsMac>& notifications,
21 base::mac::ScopedCFTypeRef<CFDictionaryRef> dict, 18 base::mac::ScopedCFTypeRef<CFDictionaryRef> dict,
22 RemovableDeviceNotificationsMac::UpdateType update_type) { 19 RemovableDeviceNotificationsMac::UpdateType update_type) {
23 DiskInfoMac info = DiskInfoMac::BuildDiskInfoOnFileThread(dict); 20 DiskInfoMac info = DiskInfoMac::BuildDiskInfoOnFileThread(dict);
24 if (info.device_id().empty()) 21 if (info.device_id().empty())
25 return; 22 return;
26 23
27 content::BrowserThread::PostTask( 24 content::BrowserThread::PostTask(
28 content::BrowserThread::UI, 25 content::BrowserThread::UI,
(...skipping 15 matching lines...) Expand all
44 base::Bind(GetDiskInfoAndUpdateOnFileThread, 41 base::Bind(GetDiskInfoAndUpdateOnFileThread,
45 notifications, 42 notifications,
46 dict, 43 dict,
47 update_type)); 44 update_type));
48 } 45 }
49 46
50 } // namespace 47 } // namespace
51 48
52 RemovableDeviceNotificationsMac::RemovableDeviceNotificationsMac() { 49 RemovableDeviceNotificationsMac::RemovableDeviceNotificationsMac() {
53 session_.reset(DASessionCreate(NULL)); 50 session_.reset(DASessionCreate(NULL));
54 DCHECK(!g_removable_device_notifications_mac);
55 g_removable_device_notifications_mac = this;
56 51
57 DASessionScheduleWithRunLoop( 52 DASessionScheduleWithRunLoop(
58 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); 53 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
59 54
60 // Register for callbacks for attached, changed, and removed devices. 55 // Register for callbacks for attached, changed, and removed devices.
61 // This will send notifications for existing devices too. 56 // This will send notifications for existing devices too.
62 DARegisterDiskAppearedCallback( 57 DARegisterDiskAppearedCallback(
63 session_, 58 session_,
64 kDADiskDescriptionMatchVolumeMountable, 59 kDADiskDescriptionMatchVolumeMountable,
65 DiskAppearedCallback, 60 DiskAppearedCallback,
66 this); 61 this);
67 DARegisterDiskDisappearedCallback( 62 DARegisterDiskDisappearedCallback(
68 session_, 63 session_,
69 kDADiskDescriptionMatchVolumeMountable, 64 kDADiskDescriptionMatchVolumeMountable,
70 DiskDisappearedCallback, 65 DiskDisappearedCallback,
71 this); 66 this);
72 DARegisterDiskDescriptionChangedCallback( 67 DARegisterDiskDescriptionChangedCallback(
73 session_, 68 session_,
74 kDADiskDescriptionMatchVolumeMountable, 69 kDADiskDescriptionMatchVolumeMountable,
75 kDADiskDescriptionWatchVolumePath, 70 kDADiskDescriptionWatchVolumePath,
76 DiskDescriptionChangedCallback, 71 DiskDescriptionChangedCallback,
77 this); 72 this);
78 } 73 }
79 74
80 RemovableDeviceNotificationsMac::~RemovableDeviceNotificationsMac() { 75 RemovableDeviceNotificationsMac::~RemovableDeviceNotificationsMac() {
81 DCHECK_EQ(this, g_removable_device_notifications_mac);
82 g_removable_device_notifications_mac = NULL;
83
84 DASessionUnscheduleFromRunLoop( 76 DASessionUnscheduleFromRunLoop(
85 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); 77 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
86 } 78 }
87 79
88 void RemovableDeviceNotificationsMac::UpdateDisk( 80 void RemovableDeviceNotificationsMac::UpdateDisk(
89 const DiskInfoMac& info, 81 const DiskInfoMac& info,
90 UpdateType update_type) { 82 UpdateType update_type) {
91 if (info.bsd_name().empty()) 83 if (info.bsd_name().empty())
92 return; 84 return;
93 85
94 std::map<std::string, DiskInfoMac>::iterator it = 86 std::map<std::string, DiskInfoMac>::iterator it =
95 disk_info_map_.find(info.bsd_name()); 87 disk_info_map_.find(info.bsd_name());
96 if (it != disk_info_map_.end()) { 88 if (it != disk_info_map_.end()) {
97 // If an attached notification was previously posted then post a detached 89 // If an attached notification was previously posted then post a detached
98 // 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
99 // devices that have changed. 91 // devices that have changed.
100 if (ShouldPostNotificationForDisk(it->second)) { 92 if (ShouldPostNotificationForDisk(it->second)) {
101 base::SystemMonitor::Get()->ProcessRemovableStorageDetached( 93 ProcessDetach(it->second.device_id());
102 it->second.device_id());
103 } 94 }
104 } 95 }
105 96
106 if (update_type == UPDATE_DEVICE_REMOVED) { 97 if (update_type == UPDATE_DEVICE_REMOVED) {
107 if (it != disk_info_map_.end()) 98 if (it != disk_info_map_.end())
108 disk_info_map_.erase(it); 99 disk_info_map_.erase(it);
109 } else { 100 } else {
110 disk_info_map_[info.bsd_name()] = info; 101 disk_info_map_[info.bsd_name()] = info;
111 MediaStorageUtil::RecordDeviceInfoHistogram(true, info.device_id(), 102 MediaStorageUtil::RecordDeviceInfoHistogram(true, info.device_id(),
112 info.device_name()); 103 info.device_name());
113 if (ShouldPostNotificationForDisk(info)) { 104 if (ShouldPostNotificationForDisk(info)) {
114 string16 display_name = GetDisplayNameForDevice( 105 string16 display_name = GetDisplayNameForDevice(
115 info.total_size_in_bytes(), info.device_name()); 106 info.total_size_in_bytes(), info.device_name());
116 base::SystemMonitor::Get()->ProcessRemovableStorageAttached( 107 ProcessAttach(info.device_id(), display_name, info.mount_point().value());
117 info.device_id(), display_name, info.mount_point().value());
118 } 108 }
119 } 109 }
120 } 110 }
121 111
122 bool RemovableDeviceNotificationsMac::GetDeviceInfoForPath( 112 bool RemovableDeviceNotificationsMac::GetDeviceInfoForPath(
123 const FilePath& path, 113 const FilePath& path,
124 base::SystemMonitor::RemovableStorageInfo* device_info) const { 114 StorageInfo* device_info) const {
125 if (!path.IsAbsolute()) 115 if (!path.IsAbsolute())
126 return false; 116 return false;
127 117
128 FilePath current = path; 118 FilePath current = path;
129 const FilePath root(FilePath::kSeparators); 119 const FilePath root(FilePath::kSeparators);
130 while (current != root) { 120 while (current != root) {
131 DiskInfoMac info; 121 DiskInfoMac info;
132 if (FindDiskWithMountPoint(current, &info)) { 122 if (FindDiskWithMountPoint(current, &info)) {
133 device_info->device_id = info.device_id(); 123 device_info->device_id = info.device_id();
134 device_info->name = info.device_name(); 124 device_info->name = info.device_name();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 for (std::map<std::string, DiskInfoMac>::const_iterator 192 for (std::map<std::string, DiskInfoMac>::const_iterator
203 it = disk_info_map_.begin(); it != disk_info_map_.end(); ++it) { 193 it = disk_info_map_.begin(); it != disk_info_map_.end(); ++it) {
204 if (it->second.mount_point() == mount_point) { 194 if (it->second.mount_point() == mount_point) {
205 *info = it->second; 195 *info = it->second;
206 return true; 196 return true;
207 } 197 }
208 } 198 }
209 return false; 199 return false;
210 } 200 }
211 201
212 // static
213 RemovableStorageNotifications* RemovableStorageNotifications::GetInstance() {
214 DCHECK(g_removable_device_notifications_mac != NULL);
215 return g_removable_device_notifications_mac;
216 }
217
218 } // namespace chrome 202 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698