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

Side by Side Diff: chrome/browser/storage_monitor/storage_monitor_mac.mm

Issue 12334096: Regularize ownerships and lifecycle for storage monitor platform classes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix comment name Created 7 years, 9 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
« no previous file with comments | « chrome/browser/storage_monitor/storage_monitor_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/storage_monitor/storage_monitor_mac.h" 5 #include "chrome/browser/storage_monitor/storage_monitor_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_storage_util.h" 9 #include "chrome/browser/storage_monitor/media_storage_util.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 // StorageMonitorMac be ref counted.
20
16 void GetDiskInfoAndUpdateOnFileThread( 21 void GetDiskInfoAndUpdateOnFileThread(
17 const scoped_refptr<StorageMonitorMac>& monitor, 22 const scoped_refptr<StorageMonitorMac>& monitor,
18 base::mac::ScopedCFTypeRef<CFDictionaryRef> dict, 23 base::mac::ScopedCFTypeRef<CFDictionaryRef> dict,
19 StorageMonitorMac::UpdateType update_type) { 24 StorageMonitorMac::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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 82 }
78 83
79 void EjectDisk(EjectDiskOptions* options) { 84 void EjectDisk(EjectDiskOptions* options) {
80 DADiskUnmount(options->disk.get(), kDADiskUnmountOptionWhole, 85 DADiskUnmount(options->disk.get(), kDADiskUnmountOptionWhole,
81 PostUnmountCallback, options); 86 PostUnmountCallback, options);
82 } 87 }
83 88
84 } // namespace 89 } // namespace
85 90
86 StorageMonitorMac::StorageMonitorMac() { 91 StorageMonitorMac::StorageMonitorMac() {
92 }
93
94 StorageMonitorMac::~StorageMonitorMac() {
95 if (session_.get()) {
96 DASessionUnscheduleFromRunLoop(
97 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
98 }
99 }
100
101 void StorageMonitorMac::Init() {
87 session_.reset(DASessionCreate(NULL)); 102 session_.reset(DASessionCreate(NULL));
88 103
89 DASessionScheduleWithRunLoop(
90 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
91
92 // Register for callbacks for attached, changed, and removed devices. 104 // Register for callbacks for attached, changed, and removed devices.
93 // This will send notifications for existing devices too. 105 // This will send notifications for existing devices too.
94 DARegisterDiskAppearedCallback( 106 DARegisterDiskAppearedCallback(
95 session_, 107 session_,
96 kDADiskDescriptionMatchVolumeMountable, 108 kDADiskDescriptionMatchVolumeMountable,
97 DiskAppearedCallback, 109 DiskAppearedCallback,
98 this); 110 this);
99 DARegisterDiskDisappearedCallback( 111 DARegisterDiskDisappearedCallback(
100 session_, 112 session_,
101 kDADiskDescriptionMatchVolumeMountable, 113 kDADiskDescriptionMatchVolumeMountable,
102 DiskDisappearedCallback, 114 DiskDisappearedCallback,
103 this); 115 this);
104 DARegisterDiskDescriptionChangedCallback( 116 DARegisterDiskDescriptionChangedCallback(
105 session_, 117 session_,
106 kDADiskDescriptionMatchVolumeMountable, 118 kDADiskDescriptionMatchVolumeMountable,
107 kDADiskDescriptionWatchVolumePath, 119 kDADiskDescriptionWatchVolumePath,
108 DiskDescriptionChangedCallback, 120 DiskDescriptionChangedCallback,
109 this); 121 this);
110 }
111 122
112 StorageMonitorMac::~StorageMonitorMac() { 123 DASessionScheduleWithRunLoop(
113 DASessionUnscheduleFromRunLoop(
114 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); 124 session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
125
126 if (base::mac::IsOSLionOrLater()) {
127 image_capture_device_manager_.reset(new chrome::ImageCaptureDeviceManager);
128 image_capture_device_manager_->SetNotifications(receiver());
129 }
115 } 130 }
116 131
117 void StorageMonitorMac::UpdateDisk(const DiskInfoMac& info, 132 void StorageMonitorMac::UpdateDisk(const DiskInfoMac& info,
118 UpdateType update_type) { 133 UpdateType update_type) {
119 if (info.bsd_name().empty()) 134 if (info.bsd_name().empty())
120 return; 135 return;
121 136
122 std::map<std::string, DiskInfoMac>::iterator it = 137 std::map<std::string, DiskInfoMac>::iterator it =
123 disk_info_map_.find(info.bsd_name()); 138 disk_info_map_.find(info.bsd_name());
124 if (it != disk_info_map_.end()) { 139 if (it != disk_info_map_.end()) {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 it = disk_info_map_.begin(); it != disk_info_map_.end(); ++it) { 270 it = disk_info_map_.begin(); it != disk_info_map_.end(); ++it) {
256 if (it->second.mount_point() == mount_point) { 271 if (it->second.mount_point() == mount_point) {
257 *info = it->second; 272 *info = it->second;
258 return true; 273 return true;
259 } 274 }
260 } 275 }
261 return false; 276 return false;
262 } 277 }
263 278
264 } // namespace chrome 279 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/storage_monitor/storage_monitor_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698