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

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

Issue 10909259: Share MediaStorageUtil common code among platforms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Try a different way Created 8 years, 3 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 "content/public/browser/browser_thread.h" 7 #include "content/public/browser/browser_thread.h"
8 8
9 namespace chrome { 9 namespace chrome {
10 10
11 namespace { 11 namespace {
12 12
13 static RemovableDeviceNotificationsMac*
14 g_removable_device_notifications_mac = NULL;
15
13 void GetDiskInfoAndUpdateOnFileThread( 16 void GetDiskInfoAndUpdateOnFileThread(
14 const base::WeakPtr<RemovableDeviceNotificationsMac>& notifications, 17 const base::WeakPtr<RemovableDeviceNotificationsMac>& notifications,
15 base::mac::ScopedCFTypeRef<CFDictionaryRef> dict, 18 base::mac::ScopedCFTypeRef<CFDictionaryRef> dict,
16 RemovableDeviceNotificationsMac::UpdateType update_type) { 19 RemovableDeviceNotificationsMac::UpdateType update_type) {
17 DiskInfoMac info = DiskInfoMac::BuildDiskInfoOnFileThread(dict); 20 DiskInfoMac info = DiskInfoMac::BuildDiskInfoOnFileThread(dict);
18 if (info.device_id().empty()) 21 if (info.device_id().empty())
19 return; 22 return;
20 23
21 content::BrowserThread::PostTask( 24 content::BrowserThread::PostTask(
22 content::BrowserThread::UI, 25 content::BrowserThread::UI,
(...skipping 15 matching lines...) Expand all
38 base::Bind(GetDiskInfoAndUpdateOnFileThread, 41 base::Bind(GetDiskInfoAndUpdateOnFileThread,
39 notifications, 42 notifications,
40 dict, 43 dict,
41 update_type)); 44 update_type));
42 } 45 }
43 46
44 } // namespace 47 } // namespace
45 48
46 RemovableDeviceNotificationsMac::RemovableDeviceNotificationsMac() { 49 RemovableDeviceNotificationsMac::RemovableDeviceNotificationsMac() {
47 session_.reset(DASessionCreate(NULL)); 50 session_.reset(DASessionCreate(NULL));
51 DCHECK(!g_removable_device_notifications_mac);
52 g_removable_device_notifications_mac = this;
53
48 DASessionScheduleWithRunLoop( 54 DASessionScheduleWithRunLoop(
49 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); 55 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
50 56
51 // Register for callbacks for attached, changed, and removed devices. 57 // Register for callbacks for attached, changed, and removed devices.
52 // This will send notifications for existing devices too. 58 // This will send notifications for existing devices too.
53 DARegisterDiskAppearedCallback( 59 DARegisterDiskAppearedCallback(
54 session_, 60 session_,
55 kDADiskDescriptionMatchVolumeMountable, 61 kDADiskDescriptionMatchVolumeMountable,
56 DiskAppearedCallback, 62 DiskAppearedCallback,
57 this); 63 this);
58 DARegisterDiskDisappearedCallback( 64 DARegisterDiskDisappearedCallback(
59 session_, 65 session_,
60 kDADiskDescriptionMatchVolumeMountable, 66 kDADiskDescriptionMatchVolumeMountable,
61 DiskDisappearedCallback, 67 DiskDisappearedCallback,
62 this); 68 this);
63 DARegisterDiskDescriptionChangedCallback( 69 DARegisterDiskDescriptionChangedCallback(
64 session_, 70 session_,
65 kDADiskDescriptionMatchVolumeMountable, 71 kDADiskDescriptionMatchVolumeMountable,
66 kDADiskDescriptionWatchVolumePath, 72 kDADiskDescriptionWatchVolumePath,
67 DiskDescriptionChangedCallback, 73 DiskDescriptionChangedCallback,
68 this); 74 this);
69 } 75 }
70 76
71 RemovableDeviceNotificationsMac::~RemovableDeviceNotificationsMac() { 77 RemovableDeviceNotificationsMac::~RemovableDeviceNotificationsMac() {
78 DCHECK_EQ(this, g_removable_device_notifications_mac);
79 g_removable_device_notifications_mac = NULL;
80
72 DASessionUnscheduleFromRunLoop( 81 DASessionUnscheduleFromRunLoop(
73 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); 82 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
74 } 83 }
75 84
85 // static
86 RemovableDeviceNotificationsMac*
87 RemovableDeviceNotificationsMac::GetInstance() {
88 DCHECK(g_removable_device_notifications_mac != NULL);
89 return g_removable_device_notifications_mac;
90 }
91
76 void RemovableDeviceNotificationsMac::UpdateDisk( 92 void RemovableDeviceNotificationsMac::UpdateDisk(
77 const DiskInfoMac& info, 93 const DiskInfoMac& info,
78 UpdateType update_type) { 94 UpdateType update_type) {
79 if (info.bsd_name().empty()) 95 if (info.bsd_name().empty())
80 return; 96 return;
81 97
82 std::map<std::string, DiskInfoMac>::iterator it = 98 std::map<std::string, DiskInfoMac>::iterator it =
83 disk_info_map_.find(info.bsd_name()); 99 disk_info_map_.find(info.bsd_name());
84 if (it != disk_info_map_.end()) { 100 if (it != disk_info_map_.end()) {
85 // If an attached notification was previously posted then post a detached 101 // If an attached notification was previously posted then post a detached
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 it = disk_info_map_.begin(); it != disk_info_map_.end(); ++it) { 194 it = disk_info_map_.begin(); it != disk_info_map_.end(); ++it) {
179 if (it->second.mount_point() == mount_point) { 195 if (it->second.mount_point() == mount_point) {
180 *info = it->second; 196 *info = it->second;
181 return true; 197 return true;
182 } 198 }
183 } 199 }
184 return false; 200 return false;
185 } 201 }
186 202
187 } // namespace chrome 203 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698