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

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

Issue 10948019: Remove use of weakptr for RemovableDeviceNotificationsMac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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* 13 static RemovableDeviceNotificationsMac*
14 g_removable_device_notifications_mac = NULL; 14 g_removable_device_notifications_mac = NULL;
15 15
16 void GetDiskInfoAndUpdateOnFileThread( 16 void GetDiskInfoAndUpdateOnFileThread(
17 const base::WeakPtr<RemovableDeviceNotificationsMac>& notifications, 17 const scoped_refptr<RemovableDeviceNotificationsMac>& notifications,
18 base::mac::ScopedCFTypeRef<CFDictionaryRef> dict, 18 base::mac::ScopedCFTypeRef<CFDictionaryRef> dict,
19 RemovableDeviceNotificationsMac::UpdateType update_type) { 19 RemovableDeviceNotificationsMac::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(&RemovableDeviceNotificationsMac::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 base::WeakPtr<RemovableDeviceNotificationsMac>& notifications, 34 const scoped_refptr<RemovableDeviceNotificationsMac>& notifications,
35 DADiskRef disk, 35 DADiskRef disk,
36 RemovableDeviceNotificationsMac::UpdateType update_type) { 36 RemovableDeviceNotificationsMac::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));
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 return false; 141 return false;
142 } 142 }
143 143
144 // static 144 // static
145 void RemovableDeviceNotificationsMac::DiskAppearedCallback( 145 void RemovableDeviceNotificationsMac::DiskAppearedCallback(
146 DADiskRef disk, 146 DADiskRef disk,
147 void* context) { 147 void* context) {
148 RemovableDeviceNotificationsMac* notifications = 148 RemovableDeviceNotificationsMac* notifications =
149 static_cast<RemovableDeviceNotificationsMac*>(context); 149 static_cast<RemovableDeviceNotificationsMac*>(context);
150 GetDiskInfoAndUpdate(notifications->AsWeakPtr(), 150 GetDiskInfoAndUpdate(notifications,
vandebo (ex-Chrome) 2012/09/18 22:41:56 Does this work? raw pointer passed to function tha
sail 2012/09/18 22:52:49 Yep! When the raw pointer is passed to GetDiskInfo
vandebo (ex-Chrome) 2012/09/18 23:03:47 What I meant is that maybe GetDiskInfoAndUpdate co
sail 2012/09/18 23:28:51 Ahh, I see what you mean. I tried simply removing
151 disk, 151 disk,
152 UPDATE_DEVICE_ADDED); 152 UPDATE_DEVICE_ADDED);
153 } 153 }
154 154
155 // static 155 // static
156 void RemovableDeviceNotificationsMac::DiskDisappearedCallback( 156 void RemovableDeviceNotificationsMac::DiskDisappearedCallback(
157 DADiskRef disk, 157 DADiskRef disk,
158 void* context) { 158 void* context) {
159 RemovableDeviceNotificationsMac* notifications = 159 RemovableDeviceNotificationsMac* notifications =
160 static_cast<RemovableDeviceNotificationsMac*>(context); 160 static_cast<RemovableDeviceNotificationsMac*>(context);
161 GetDiskInfoAndUpdate(notifications->AsWeakPtr(), 161 GetDiskInfoAndUpdate(notifications,
162 disk, 162 disk,
163 UPDATE_DEVICE_REMOVED); 163 UPDATE_DEVICE_REMOVED);
164 } 164 }
165 165
166 // static 166 // static
167 void RemovableDeviceNotificationsMac::DiskDescriptionChangedCallback( 167 void RemovableDeviceNotificationsMac::DiskDescriptionChangedCallback(
168 DADiskRef disk, 168 DADiskRef disk,
169 CFArrayRef keys, 169 CFArrayRef keys,
170 void *context) { 170 void *context) {
171 RemovableDeviceNotificationsMac* notifications = 171 RemovableDeviceNotificationsMac* notifications =
172 static_cast<RemovableDeviceNotificationsMac*>(context); 172 static_cast<RemovableDeviceNotificationsMac*>(context);
173 GetDiskInfoAndUpdate(notifications->AsWeakPtr(), 173 GetDiskInfoAndUpdate(notifications,
174 disk, 174 disk,
175 UPDATE_DEVICE_CHANGED); 175 UPDATE_DEVICE_CHANGED);
176 } 176 }
177 177
178 bool RemovableDeviceNotificationsMac::ShouldPostNotificationForDisk( 178 bool RemovableDeviceNotificationsMac::ShouldPostNotificationForDisk(
179 const DiskInfoMac& info) const { 179 const DiskInfoMac& info) const {
180 // Only post notifications about disks that have no empty fields and 180 // Only post notifications about disks that have no empty fields and
181 // are removable. 181 // are removable.
182 return !info.bsd_name().empty() && 182 return !info.bsd_name().empty() &&
183 !info.device_id().empty() && 183 !info.device_id().empty() &&
(...skipping 10 matching lines...) Expand all
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