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

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

Issue 16186002: Refine StorageMonitor storage device getter (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 portable_device_watcher_->Init(window_); 74 portable_device_watcher_->Init(window_);
75 } 75 }
76 76
77 bool StorageMonitorWin::GetStorageInfoForPath(const base::FilePath& path, 77 bool StorageMonitorWin::GetStorageInfoForPath(const base::FilePath& path,
78 StorageInfo* device_info) const { 78 StorageInfo* device_info) const {
79 DCHECK(device_info); 79 DCHECK(device_info);
80 80
81 // TODO(gbillock): Move this logic up to StorageMonitor. 81 // TODO(gbillock): Move this logic up to StorageMonitor.
82 // If we already know the StorageInfo for the path, just return it. 82 // If we already know the StorageInfo for the path, just return it.
83 // This will account for portable devices as well. 83 // This will account for portable devices as well.
84 std::vector<StorageInfo> attached_devices = GetAttachedStorage(); 84 std::vector<StorageInfo> attached_devices = GetAttachedRemovableStorages();
85 size_t best_parent = attached_devices.size(); 85 size_t best_parent = attached_devices.size();
86 size_t best_length = 0; 86 size_t best_length = 0;
87 for (size_t i = 0; i < attached_devices.size(); i++) { 87 for (size_t i = 0; i < attached_devices.size(); i++) {
88 base::FilePath relative; 88 base::FilePath relative;
89 if (base::FilePath(attached_devices[i].location()).AppendRelativePath( 89 if (base::FilePath(attached_devices[i].location()).AppendRelativePath(
90 path, &relative)) { 90 path, &relative)) {
91 // Note: the relative path is longer for shorter shared path between 91 // Note: the relative path is longer for shorter shared path between
92 // the path and the device mount point, so we want the shortest 92 // the path and the device mount point, so we want the shortest
93 // relative path. 93 // relative path.
94 if (relative.value().size() < best_length) { 94 if (relative.value().size() < best_length) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 const std::string& storage_device_id, 127 const std::string& storage_device_id,
128 string16* device_location, 128 string16* device_location,
129 string16* storage_object_id) const { 129 string16* storage_object_id) const {
130 StorageInfo::Type type; 130 StorageInfo::Type type;
131 StorageInfo::CrackDeviceId(storage_device_id, &type, NULL); 131 StorageInfo::CrackDeviceId(storage_device_id, &type, NULL);
132 return ((type == StorageInfo::MTP_OR_PTP) && 132 return ((type == StorageInfo::MTP_OR_PTP) &&
133 portable_device_watcher_->GetMTPStorageInfoFromDeviceId( 133 portable_device_watcher_->GetMTPStorageInfoFromDeviceId(
134 storage_device_id, device_location, storage_object_id)); 134 storage_device_id, device_location, storage_object_id));
135 } 135 }
136 136
137 std::vector<StorageInfo> StorageMonitorWin::GetAllAvailableStorages() const {
138 std::vector<StorageInfo> results;
139 if (volume_mount_watcher_.get())
140 results = volume_mount_watcher_->GetAllVolumeStorages();
141 return results;
142 }
143
137 // static 144 // static
138 LRESULT CALLBACK StorageMonitorWin::WndProcThunk(HWND hwnd, UINT message, 145 LRESULT CALLBACK StorageMonitorWin::WndProcThunk(HWND hwnd, UINT message,
139 WPARAM wparam, LPARAM lparam) { 146 WPARAM wparam, LPARAM lparam) {
140 StorageMonitorWin* msg_wnd = reinterpret_cast<StorageMonitorWin*>( 147 StorageMonitorWin* msg_wnd = reinterpret_cast<StorageMonitorWin*>(
141 GetWindowLongPtr(hwnd, GWLP_USERDATA)); 148 GetWindowLongPtr(hwnd, GWLP_USERDATA));
142 if (msg_wnd) 149 if (msg_wnd)
143 return msg_wnd->WndProc(hwnd, message, wparam, lparam); 150 return msg_wnd->WndProc(hwnd, message, wparam, lparam);
144 return ::DefWindowProc(hwnd, message, wparam, lparam); 151 return ::DefWindowProc(hwnd, message, wparam, lparam);
145 } 152 }
146 153
(...skipping 17 matching lines...) Expand all
164 // portable device as a media gallery. 171 // portable device as a media gallery.
165 return volume_mount_watcher_->GetDeviceInfo(device_path, info); 172 return volume_mount_watcher_->GetDeviceInfo(device_path, info);
166 } 173 }
167 174
168 void StorageMonitorWin::OnDeviceChange(UINT event_type, LPARAM data) { 175 void StorageMonitorWin::OnDeviceChange(UINT event_type, LPARAM data) {
169 volume_mount_watcher_->OnWindowMessage(event_type, data); 176 volume_mount_watcher_->OnWindowMessage(event_type, data);
170 portable_device_watcher_->OnWindowMessage(event_type, data); 177 portable_device_watcher_->OnWindowMessage(event_type, data);
171 } 178 }
172 179
173 } // namespace chrome 180 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698