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

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

Issue 15988011: Refine StorageMonitor storage device getter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix SystemInfoStorageApiTest failures in browser_tests Created 7 years, 6 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
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_win.h" 5 #include "chrome/browser/storage_monitor/storage_monitor_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <dbt.h> 8 #include <dbt.h>
9 #include <fileapi.h> 9 #include <fileapi.h>
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 portable_device_watcher_->Init(window_); 67 portable_device_watcher_->Init(window_);
68 } 68 }
69 69
70 bool StorageMonitorWin::GetStorageInfoForPath(const base::FilePath& path, 70 bool StorageMonitorWin::GetStorageInfoForPath(const base::FilePath& path,
71 StorageInfo* device_info) const { 71 StorageInfo* device_info) const {
72 DCHECK(device_info); 72 DCHECK(device_info);
73 73
74 // TODO(gbillock): Move this logic up to StorageMonitor. 74 // TODO(gbillock): Move this logic up to StorageMonitor.
75 // If we already know the StorageInfo for the path, just return it. 75 // If we already know the StorageInfo for the path, just return it.
76 // This will account for portable devices as well. 76 // This will account for portable devices as well.
77 std::vector<StorageInfo> attached_devices = GetAttachedStorage(); 77 std::vector<StorageInfo> attached_devices = GetAllAvailableStorages();
78 size_t best_parent = attached_devices.size(); 78 size_t best_parent = attached_devices.size();
79 size_t best_length = 0; 79 size_t best_length = 0;
80 for (size_t i = 0; i < attached_devices.size(); i++) { 80 for (size_t i = 0; i < attached_devices.size(); i++) {
81 if (!StorageInfo::IsRemovableDevice(attached_devices[i].device_id()))
82 continue;
81 base::FilePath relative; 83 base::FilePath relative;
82 if (base::FilePath(attached_devices[i].location()).AppendRelativePath( 84 if (base::FilePath(attached_devices[i].location()).AppendRelativePath(
83 path, &relative)) { 85 path, &relative)) {
84 // Note: the relative path is longer for shorter shared path between 86 // Note: the relative path is longer for shorter shared path between
85 // the path and the device mount point, so we want the shortest 87 // the path and the device mount point, so we want the shortest
86 // relative path. 88 // relative path.
87 if (relative.value().size() < best_length) { 89 if (relative.value().size() < best_length) {
88 best_parent = i; 90 best_parent = i;
89 best_length = relative.value().size(); 91 best_length = relative.value().size();
90 } 92 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // portable device as a media gallery. 161 // portable device as a media gallery.
160 return volume_mount_watcher_->GetDeviceInfo(device_path, info); 162 return volume_mount_watcher_->GetDeviceInfo(device_path, info);
161 } 163 }
162 164
163 void StorageMonitorWin::OnDeviceChange(UINT event_type, LPARAM data) { 165 void StorageMonitorWin::OnDeviceChange(UINT event_type, LPARAM data) {
164 volume_mount_watcher_->OnWindowMessage(event_type, data); 166 volume_mount_watcher_->OnWindowMessage(event_type, data);
165 portable_device_watcher_->OnWindowMessage(event_type, data); 167 portable_device_watcher_->OnWindowMessage(event_type, data);
166 } 168 }
167 169
168 } // namespace chrome 170 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698