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

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

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address jyasskin's comments\ Created 7 years, 7 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/storage_monitor/volume_mount_watcher_win.h" 5 #include "chrome/browser/storage_monitor/volume_mount_watcher_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include <dbt.h> 9 #include <dbt.h>
10 #include <fileapi.h> 10 #include <fileapi.h>
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 VolumeMountWatcherWin::GetDeviceDetailsCallbackType 429 VolumeMountWatcherWin::GetDeviceDetailsCallbackType
430 VolumeMountWatcherWin::GetDeviceDetailsCallback() const { 430 VolumeMountWatcherWin::GetDeviceDetailsCallback() const {
431 return base::Bind(&GetDeviceDetails); 431 return base::Bind(&GetDeviceDetails);
432 } 432 }
433 433
434 bool VolumeMountWatcherWin::GetDeviceInfo(const base::FilePath& device_path, 434 bool VolumeMountWatcherWin::GetDeviceInfo(const base::FilePath& device_path,
435 StorageInfo* info) const { 435 StorageInfo* info) const {
436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
437 base::FilePath path(device_path); 437 base::FilePath path(device_path);
438 MountPointDeviceMetadataMap::const_iterator iter = 438 MountPointDeviceMetadataMap::const_iterator iter =
439 device_metadata_.find(path.value()); 439 device_metadata_.find(path);
440 while (iter == device_metadata_.end() && path.DirName() != path) { 440 while (iter == device_metadata_.end() && path.DirName() != path) {
441 path = path.DirName(); 441 path = path.DirName();
442 iter = device_metadata_.find(path.value()); 442 iter = device_metadata_.find(path);
443 } 443 }
444 444
445 if (iter == device_metadata_.end()) 445 if (iter == device_metadata_.end())
446 return false; 446 return false;
447 447
448 if (info) 448 if (info)
449 *info = iter->second; 449 *info = iter->second;
450 450
451 return true; 451 return true;
452 } 452 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 VolumeMountWatcherWin::~VolumeMountWatcherWin() { 489 VolumeMountWatcherWin::~VolumeMountWatcherWin() {
490 weak_factory_.InvalidateWeakPtrs(); 490 weak_factory_.InvalidateWeakPtrs();
491 device_info_worker_pool_->Shutdown(); 491 device_info_worker_pool_->Shutdown();
492 } 492 }
493 493
494 void VolumeMountWatcherWin::HandleDeviceAttachEventOnUIThread( 494 void VolumeMountWatcherWin::HandleDeviceAttachEventOnUIThread(
495 const base::FilePath& device_path, 495 const base::FilePath& device_path,
496 const StorageInfo& info) { 496 const StorageInfo& info) {
497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
498 498
499 device_metadata_[device_path.value()] = info; 499 device_metadata_[device_path] = info;
500 500
501 DeviceCheckComplete(device_path); 501 DeviceCheckComplete(device_path);
502 502
503 // Don't call removable storage observers for fixed volumes. 503 // Don't call removable storage observers for fixed volumes.
504 if (!StorageInfo::IsRemovableDevice(info.device_id)) 504 if (!StorageInfo::IsRemovableDevice(info.device_id))
505 return; 505 return;
506 506
507 if (notifications_) 507 if (notifications_)
508 notifications_->ProcessAttach(info); 508 notifications_->ProcessAttach(info);
509 } 509 }
510 510
511 void VolumeMountWatcherWin::HandleDeviceDetachEventOnUIThread( 511 void VolumeMountWatcherWin::HandleDeviceDetachEventOnUIThread(
512 const string16& device_location) { 512 const string16& device_location) {
513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
514 514
515 MountPointDeviceMetadataMap::const_iterator device_info = 515 MountPointDeviceMetadataMap::const_iterator device_info =
516 device_metadata_.find(device_location); 516 device_metadata_.find(base::FilePath(device_location));
517 // If the device isn't type removable (like a CD), it won't be there. 517 // If the device isn't type removable (like a CD), it won't be there.
518 if (device_info == device_metadata_.end()) 518 if (device_info == device_metadata_.end())
519 return; 519 return;
520 520
521 if (notifications_) 521 if (notifications_)
522 notifications_->ProcessDetach(device_info->second.device_id); 522 notifications_->ProcessDetach(device_info->second.device_id);
523 device_metadata_.erase(device_info); 523 device_metadata_.erase(device_info);
524 } 524 }
525 525
526 void VolumeMountWatcherWin::EjectDevice( 526 void VolumeMountWatcherWin::EjectDevice(
527 const std::string& device_id, 527 const std::string& device_id,
528 base::Callback<void(StorageMonitor::EjectStatus)> callback) { 528 base::Callback<void(StorageMonitor::EjectStatus)> callback) {
529 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 529 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
530 base::FilePath device = 530 base::FilePath device =
531 chrome::MediaStorageUtil::FindDevicePathById(device_id); 531 chrome::MediaStorageUtil::FindDevicePathById(device_id);
532 if (device.empty()) { 532 if (device.empty()) {
533 callback.Run(StorageMonitor::EJECT_FAILURE); 533 callback.Run(StorageMonitor::EJECT_FAILURE);
534 return; 534 return;
535 } 535 }
536 if (device_metadata_.erase(device.value()) == 0) { 536 if (device_metadata_.erase(device) == 0) {
537 callback.Run(StorageMonitor::EJECT_FAILURE); 537 callback.Run(StorageMonitor::EJECT_FAILURE);
538 return; 538 return;
539 } 539 }
540 540
541 task_runner_->PostTask(FROM_HERE, 541 task_runner_->PostTask(FROM_HERE,
542 base::Bind(&EjectDeviceInThreadPool, device, callback, task_runner_, 0)); 542 base::Bind(&EjectDeviceInThreadPool, device, callback, task_runner_, 0));
543 } 543 }
544 544
545 } // namespace chrome 545 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698