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

Side by Side Diff: chrome/browser/storage_monitor/storage_monitor_linux.cc

Issue 14016002: Storage Monitor: Make StorageMonitorLinux own the MediaTransferProtocolManager. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Rebase to ToT, still need to fix CrOS Created 7 years, 8 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 // StorageMonitorLinux implementation. 5 // StorageMonitorLinux implementation.
6 6
7 #include "chrome/browser/storage_monitor/storage_monitor_linux.h" 7 #include "chrome/browser/storage_monitor/storage_monitor_linux.h"
8 8
9 #include <mntent.h> 9 #include <mntent.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
224 // Owned by caller. 224 // Owned by caller.
225 return new MtabWatcherLinux(mtab_path, delegate); 225 return new MtabWatcherLinux(mtab_path, delegate);
226 } 226 }
227 227
228 } // namespace 228 } // namespace
229 229
230 StorageMonitorLinux::StorageMonitorLinux(const base::FilePath& path) 230 StorageMonitorLinux::StorageMonitorLinux(const base::FilePath& path)
231 : mtab_path_(path), 231 : mtab_path_(path),
232 get_device_info_callback_(base::Bind(&GetDeviceInfo)), 232 get_device_info_callback_(base::Bind(&GetDeviceInfo)),
233 use_dummy_media_transfer_protocol_manager_(false),
233 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 234 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
236
237 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
238 UseDummyMediaTransferProtocolManagerForTest();
239 }
235 } 240 }
236 241
237 StorageMonitorLinux::~StorageMonitorLinux() { 242 StorageMonitorLinux::~StorageMonitorLinux() {
238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
239 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType))
240 device::MediaTransferProtocolManager::Shutdown();
Greg Billock 2013/04/10 18:27:25 Still need to call this, right? Or does the destru
Lei Zhang 2013/04/11 06:54:04 The dtor does it now.
241 } 244 }
242 245
243 void StorageMonitorLinux::Init() { 246 void StorageMonitorLinux::Init() {
244 DCHECK(!mtab_path_.empty()); 247 DCHECK(!mtab_path_.empty());
245 248
246 BrowserThread::PostTaskAndReplyWithResult( 249 BrowserThread::PostTaskAndReplyWithResult(
247 BrowserThread::FILE, FROM_HERE, 250 BrowserThread::FILE, FROM_HERE,
248 base::Bind(&CreateMtabWatcherLinuxOnFileThread, 251 base::Bind(&CreateMtabWatcherLinuxOnFileThread,
249 mtab_path_, 252 mtab_path_,
250 weak_ptr_factory_.GetWeakPtr()), 253 weak_ptr_factory_.GetWeakPtr()),
251 base::Bind(&StorageMonitorLinux::OnMtabWatcherCreated, 254 base::Bind(&StorageMonitorLinux::OnMtabWatcherCreated,
252 weak_ptr_factory_.GetWeakPtr())); 255 weak_ptr_factory_.GetWeakPtr()));
253 256
254 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { 257 scoped_refptr<base::MessageLoopProxy> loop_proxy =
255 scoped_refptr<base::MessageLoopProxy> loop_proxy; 258 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE);
256 loop_proxy = content::BrowserThread::GetMessageLoopProxyForThread( 259 media_transfer_protocol_manager_.reset(
257 content::BrowserThread::FILE); 260 device::MediaTransferProtocolManager::Initialize(
258 device::MediaTransferProtocolManager::Initialize(loop_proxy); 261 loop_proxy, use_dummy_media_transfer_protocol_manager_));
259 262
260 media_transfer_protocol_device_observer_.reset( 263 media_transfer_protocol_device_observer_.reset(
261 new MediaTransferProtocolDeviceObserverLinux(receiver())); 264 new MediaTransferProtocolDeviceObserverLinux(receiver()));
262 }
263 } 265 }
264 266
265 bool StorageMonitorLinux::GetStorageInfoForPath( 267 bool StorageMonitorLinux::GetStorageInfoForPath(
266 const base::FilePath& path, 268 const base::FilePath& path,
267 StorageInfo* device_info) const { 269 StorageInfo* device_info) const {
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
269 271
270 // TODO(thestig) |media_transfer_protocol_device_observer_| should always be 272 // TODO(thestig) |media_transfer_protocol_device_observer_| should always be
271 // valid. 273 // valid.
272 if (media_transfer_protocol_device_observer_ && 274 if (media_transfer_protocol_device_observer_ &&
(...skipping 10 matching lines...) Expand all
283 current = current.DirName(); 285 current = current.DirName();
284 286
285 MountMap::const_iterator mount_info = mount_info_map_.find(current); 287 MountMap::const_iterator mount_info = mount_info_map_.find(current);
286 if (mount_info == mount_info_map_.end()) 288 if (mount_info == mount_info_map_.end())
287 return false; 289 return false;
288 if (device_info) 290 if (device_info)
289 *device_info = mount_info->second.storage_info; 291 *device_info = mount_info->second.storage_info;
290 return true; 292 return true;
291 } 293 }
292 294
295 device::MediaTransferProtocolManager*
296 StorageMonitorLinux::media_transfer_protocol_manager() {
297 return media_transfer_protocol_manager_.get();
298 }
299
293 void StorageMonitorLinux::SetGetDeviceInfoCallbackForTest( 300 void StorageMonitorLinux::SetGetDeviceInfoCallbackForTest(
294 const GetDeviceInfoCallback& get_device_info_callback) { 301 const GetDeviceInfoCallback& get_device_info_callback) {
295 get_device_info_callback_ = get_device_info_callback; 302 get_device_info_callback_ = get_device_info_callback;
296 } 303 }
297 304
305 void StorageMonitorLinux::UseDummyMediaTransferProtocolManagerForTest() {
306 use_dummy_media_transfer_protocol_manager_ = true;
307 }
308
298 void StorageMonitorLinux::OnMtabWatcherCreated(MtabWatcherLinux* watcher) { 309 void StorageMonitorLinux::OnMtabWatcherCreated(MtabWatcherLinux* watcher) {
299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
300 mtab_watcher_.reset(watcher); 311 mtab_watcher_.reset(watcher);
301 } 312 }
302 313
303 void StorageMonitorLinux::UpdateMtab(const MountPointDeviceMap& new_mtab) { 314 void StorageMonitorLinux::UpdateMtab(const MountPointDeviceMap& new_mtab) {
304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
305 316
306 // Check existing mtab entries for unaccounted mount points. 317 // Check existing mtab entries for unaccounted mount points.
307 // These mount points must have been removed in the new mtab. 318 // These mount points must have been removed in the new mtab.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 439
429 if (removable) { 440 if (removable) {
430 // TODO(gbillock) Do this in a higher level instead of here. 441 // TODO(gbillock) Do this in a higher level instead of here.
431 storage_info->name = MediaStorageUtil::GetDisplayNameForDevice( 442 storage_info->name = MediaStorageUtil::GetDisplayNameForDevice(
432 storage_info->total_size_in_bytes, storage_info->name); 443 storage_info->total_size_in_bytes, storage_info->name);
433 receiver()->ProcessAttach(*storage_info); 444 receiver()->ProcessAttach(*storage_info);
434 } 445 }
435 } 446 }
436 447
437 } // namespace chrome 448 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698