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

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

Issue 12912013: Storage Monitor Linux: Do not try to initialize MediaTransferProtocolManager during unit tests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: 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 | 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 StorageMonitorLinux::StorageMonitorLinux(const base::FilePath& path, 268 StorageMonitorLinux::StorageMonitorLinux(const base::FilePath& path,
269 GetDeviceInfoFunc get_device_info_func) 269 GetDeviceInfoFunc get_device_info_func)
270 : initialized_(false), 270 : initialized_(false),
271 mtab_path_(path), 271 mtab_path_(path),
272 get_device_info_func_(get_device_info_func) { 272 get_device_info_func_(get_device_info_func) {
273 } 273 }
274 274
275 StorageMonitorLinux::~StorageMonitorLinux() { 275 StorageMonitorLinux::~StorageMonitorLinux() {
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
277 277
278 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { 278 if (!IsRunningTest()) {
279 BrowserThread::PostTask( 279 BrowserThread::PostTask(
280 BrowserThread::UI, FROM_HERE, 280 BrowserThread::UI, FROM_HERE,
281 base::Bind(&device::MediaTransferProtocolManager::Shutdown)); 281 base::Bind(&device::MediaTransferProtocolManager::Shutdown));
282 } 282 }
283 } 283 }
284 284
285 void StorageMonitorLinux::Init() { 285 void StorageMonitorLinux::Init() {
286 DCHECK(!mtab_path_.empty()); 286 DCHECK(!mtab_path_.empty());
287 287
288 // Put |kKnownFileSystems| in std::set to get O(log N) access time. 288 // Put |kKnownFileSystems| in std::set to get O(log N) access time.
289 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i) 289 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i)
290 known_file_systems_.insert(kKnownFileSystems[i]); 290 known_file_systems_.insert(kKnownFileSystems[i]);
291 291
292 BrowserThread::PostTask( 292 BrowserThread::PostTask(
293 BrowserThread::FILE, FROM_HERE, 293 BrowserThread::FILE, FROM_HERE,
294 base::Bind(&StorageMonitorLinux::InitOnFileThread, this)); 294 base::Bind(&StorageMonitorLinux::InitOnFileThread, this));
295 295
296 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { 296 if (!IsRunningTest()) {
297 scoped_refptr<base::MessageLoopProxy> loop_proxy; 297 scoped_refptr<base::MessageLoopProxy> loop_proxy;
298 loop_proxy = content::BrowserThread::GetMessageLoopProxyForThread( 298 loop_proxy = content::BrowserThread::GetMessageLoopProxyForThread(
299 content::BrowserThread::FILE); 299 content::BrowserThread::FILE);
300 device::MediaTransferProtocolManager::Initialize(loop_proxy); 300 device::MediaTransferProtocolManager::Initialize(loop_proxy);
301 301
302 media_transfer_protocol_device_observer_.reset( 302 media_transfer_protocol_device_observer_.reset(
303 new MediaTransferProtocolDeviceObserverLinux()); 303 new MediaTransferProtocolDeviceObserverLinux());
304 media_transfer_protocol_device_observer_->SetNotifications(receiver()); 304 media_transfer_protocol_device_observer_->SetNotifications(receiver());
305 } 305 }
306 } 306 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 return; 339 return;
340 } 340 }
341 if (error) { 341 if (error) {
342 LOG(ERROR) << "Error watching " << mtab_path_.value(); 342 LOG(ERROR) << "Error watching " << mtab_path_.value();
343 return; 343 return;
344 } 344 }
345 345
346 UpdateMtab(); 346 UpdateMtab();
347 } 347 }
348 348
349 bool StorageMonitorLinux::IsRunningTest() const {
350 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType);
351 }
352
349 void StorageMonitorLinux::InitOnFileThread() { 353 void StorageMonitorLinux::InitOnFileThread() {
350 DCHECK(!initialized_); 354 DCHECK(!initialized_);
351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
352 initialized_ = true; 356 initialized_ = true;
353 357
354 // The callback passed to Watch() has to be unretained. Otherwise 358 // The callback passed to Watch() has to be unretained. Otherwise
355 // StorageMonitorLinux will live longer than expected, and FilePathWatcher 359 // StorageMonitorLinux will live longer than expected, and FilePathWatcher
356 // will get in trouble at shutdown time. 360 // will get in trouble at shutdown time.
357 bool ret = file_watcher_.Watch( 361 bool ret = file_watcher_.Watch(
358 mtab_path_, false, 362 mtab_path_, false,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 if (removable) { 490 if (removable) {
487 string16 display_name = MediaStorageUtil::GetDisplayNameForDevice( 491 string16 display_name = MediaStorageUtil::GetDisplayNameForDevice(
488 partition_size_in_bytes, name); 492 partition_size_in_bytes, name);
489 493
490 receiver()->ProcessAttach(StorageInfo(device_id, display_name, 494 receiver()->ProcessAttach(StorageInfo(device_id, display_name,
491 mount_point.value())); 495 mount_point.value()));
492 } 496 }
493 } 497 }
494 498
495 } // namespace chrome 499 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698