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

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

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 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_MAC_H_ 5 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_MAC_H_
6 #define CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_MAC_H_ 6 #define CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_MAC_H_
7 7
8 #include <DiskArbitration/DiskArbitration.h> 8 #include <DiskArbitration/DiskArbitration.h>
9 #include <map> 9 #include <map>
10 10
11 #include "base/mac/scoped_cftyperef.h" 11 #include "base/mac/scoped_cftyperef.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/system_monitor/system_monitor.h" 13 #include "base/system_monitor/system_monitor.h"
14 #include "chrome/browser/system_monitor/disk_info_mac.h" 14 #include "chrome/browser/system_monitor/disk_info_mac.h"
15 15
16 namespace chrome { 16 namespace chrome {
17 17
18 class RemovableDeviceNotificationsMac; 18 class RemovableDeviceNotificationsMac;
19 typedef RemovableDeviceNotificationsMac RemovableDeviceNotifications; 19 typedef RemovableDeviceNotificationsMac RemovableDeviceNotifications;
20 20
21 // This class posts notifications to base::SystemMonitor when a new disk 21 // This class posts notifications to base::SystemMonitor when a new disk
22 // is attached, removed, or changed. 22 // is attached, removed, or changed.
23 class RemovableDeviceNotificationsMac : 23 class RemovableDeviceNotificationsMac :
24 public base::SupportsWeakPtr<RemovableDeviceNotificationsMac> { 24 public base::RefCountedThreadSafe<RemovableDeviceNotificationsMac> {
25 public: 25 public:
26 enum UpdateType { 26 enum UpdateType {
27 UPDATE_DEVICE_ADDED, 27 UPDATE_DEVICE_ADDED,
28 UPDATE_DEVICE_CHANGED, 28 UPDATE_DEVICE_CHANGED,
29 UPDATE_DEVICE_REMOVED, 29 UPDATE_DEVICE_REMOVED,
30 }; 30 };
31 31
32 // Should only be called by browser start up code. Use GetInstance() instead. 32 // Should only be called by browser start up code. Use GetInstance() instead.
33 RemovableDeviceNotificationsMac(); 33 RemovableDeviceNotificationsMac();
34 virtual ~RemovableDeviceNotificationsMac();
35 34
36 static RemovableDeviceNotificationsMac* GetInstance(); 35 static RemovableDeviceNotificationsMac* GetInstance();
37 36
38 void UpdateDisk(const DiskInfoMac& info, UpdateType update_type); 37 void UpdateDisk(const DiskInfoMac& info, UpdateType update_type);
39 38
40 bool GetDeviceInfoForPath( 39 bool GetDeviceInfoForPath(
41 const FilePath& path, 40 const FilePath& path,
42 base::SystemMonitor::RemovableStorageInfo* device_info) const; 41 base::SystemMonitor::RemovableStorageInfo* device_info) const;
43 42
44 private: 43 private:
44 friend class base::RefCountedThreadSafe<RemovableDeviceNotificationsMac>;
45 virtual ~RemovableDeviceNotificationsMac();
46
45 static void DiskAppearedCallback(DADiskRef disk, void* context); 47 static void DiskAppearedCallback(DADiskRef disk, void* context);
46 static void DiskDisappearedCallback(DADiskRef disk, void* context); 48 static void DiskDisappearedCallback(DADiskRef disk, void* context);
47 static void DiskDescriptionChangedCallback(DADiskRef disk, 49 static void DiskDescriptionChangedCallback(DADiskRef disk,
48 CFArrayRef keys, 50 CFArrayRef keys,
49 void *context); 51 void *context);
50 52
51 bool ShouldPostNotificationForDisk(const DiskInfoMac& info) const; 53 bool ShouldPostNotificationForDisk(const DiskInfoMac& info) const;
52 bool FindDiskWithMountPoint(const FilePath& mount_point, 54 bool FindDiskWithMountPoint(const FilePath& mount_point,
53 DiskInfoMac* info) const; 55 DiskInfoMac* info) const;
54 56
55 base::mac::ScopedCFTypeRef<DASessionRef> session_; 57 base::mac::ScopedCFTypeRef<DASessionRef> session_;
56 // Maps disk bsd names to disk info objects. This map tracks all mountable 58 // Maps disk bsd names to disk info objects. This map tracks all mountable
57 // devices on the system though only notifications for removable devices are 59 // devices on the system though only notifications for removable devices are
58 // posted. 60 // posted.
59 std::map<std::string, DiskInfoMac> disk_info_map_; 61 std::map<std::string, DiskInfoMac> disk_info_map_;
60 62
61 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsMac); 63 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsMac);
62 }; 64 };
63 65
64 } // namespace chrome 66 } // namespace chrome
65 67
66 #endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_MAC_H_ 68 #endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698