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

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

Issue 12476026: Disable drive scan on startup to avoid spinning floppy drives (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add DoNothing closure to spawn a thread early 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
« no previous file with comments | « chrome/browser/storage_monitor/volume_mount_watcher_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <dbt.h> 8 #include <dbt.h>
9 #include <fileapi.h> 9 #include <fileapi.h>
10 10
11 #include "base/bind_helpers.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "base/string_util.h" 13 #include "base/string_util.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" 16 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h"
16 #include "chrome/browser/storage_monitor/media_storage_util.h" 17 #include "chrome/browser/storage_monitor/media_storage_util.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 19
19 using content::BrowserThread; 20 using content::BrowserThread;
20 21
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 168 }
168 169
169 } // namespace 170 } // namespace
170 171
171 namespace chrome { 172 namespace chrome {
172 173
173 const int kWorkerPoolNumThreads = 3; 174 const int kWorkerPoolNumThreads = 3;
174 const char* kWorkerPoolNamePrefix = "DeviceInfoPool"; 175 const char* kWorkerPoolNamePrefix = "DeviceInfoPool";
175 176
176 VolumeMountWatcherWin::VolumeMountWatcherWin() 177 VolumeMountWatcherWin::VolumeMountWatcherWin()
177 : device_info_worker_pool_(new base::SequencedWorkerPool( 178 : weak_factory_(this),
178 kWorkerPoolNumThreads, kWorkerPoolNamePrefix)),
179 weak_factory_(this),
180 notifications_(NULL) { 179 notifications_(NULL) {
181 get_attached_devices_callback_ = base::Bind(&GetAttachedDevices); 180 get_attached_devices_callback_ = base::Bind(&GetAttachedDevices);
182 get_device_details_callback_ = base::Bind(&GetDeviceDetails); 181 get_device_details_callback_ = base::Bind(&GetDeviceDetails);
182
183 device_info_worker_pool_ = new base::SequencedWorkerPool(
184 kWorkerPoolNumThreads, kWorkerPoolNamePrefix);
185 task_runner_ =
186 device_info_worker_pool_->GetSequencedTaskRunnerWithShutdownBehavior(
187 device_info_worker_pool_->GetSequenceToken(),
188 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
183 } 189 }
184 190
185 // static 191 // static
186 base::FilePath VolumeMountWatcherWin::DriveNumberToFilePath(int drive_number) { 192 base::FilePath VolumeMountWatcherWin::DriveNumberToFilePath(int drive_number) {
187 if (drive_number < 0 || drive_number > 25) 193 if (drive_number < 0 || drive_number > 25)
188 return base::FilePath(); 194 return base::FilePath();
189 string16 path(L"_:\\"); 195 string16 path(L"_:\\");
190 path[0] = L'A' + drive_number; 196 path[0] = L'A' + drive_number;
191 return base::FilePath(path); 197 return base::FilePath(path);
192 } 198 }
193 199
194 // In order to get all the weak pointers created on the UI thread, and doing 200 // In order to get all the weak pointers created on the UI thread, and doing
195 // synchronous Windows calls in the worker pool, this kicks off a chain of 201 // synchronous Windows calls in the worker pool, this kicks off a chain of
196 // events which will 202 // events which will
197 // a) Enumerate attached devices 203 // a) Enumerate attached devices
198 // b) Create weak pointers for which to send completion signals from 204 // b) Create weak pointers for which to send completion signals from
199 // c) Retrieve metadata on the volumes and then 205 // c) Retrieve metadata on the volumes and then
200 // d) Notify that metadata to listeners. 206 // d) Notify that metadata to listeners.
201 void VolumeMountWatcherWin::Init() { 207 void VolumeMountWatcherWin::Init() {
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
203 209
204 // When VolumeMountWatcherWin is created, the message pumps are not running 210 // When VolumeMountWatcherWin is created, the message pumps are not running
205 // so a posted task from the constructor would never run. Therefore, do all 211 // so a posted task from the constructor would never run. Therefore, do all
206 // the initializations here. 212 // the initializations here.
207 device_info_worker_pool_->PostTask(FROM_HERE, base::Bind( 213 // Disabled pending resolution of http://crbug.com/173953
208 &FindExistingDevicesAndAdd, get_attached_devices_callback_, 214 // task_runner_->PostTask(FROM_HERE, base::Bind(
209 weak_factory_.GetWeakPtr())); 215 // &FindExistingDevicesAndAdd, get_attached_devices_callback_,
216 // weak_factory_.GetWeakPtr()));
217
218 // This task is a mystery. Without it, the ToastCrasher test fails, but
219 // it isn't clear why. Need to move pool creation later?
220 task_runner_->PostTask(FROM_HERE, base::Bind(&base::DoNothing));
210 } 221 }
211 222
212 // static 223 // static
213 void VolumeMountWatcherWin::FindExistingDevicesAndAdd( 224 void VolumeMountWatcherWin::FindExistingDevicesAndAdd(
214 base::Callback<std::vector<base::FilePath>(void)> 225 base::Callback<std::vector<base::FilePath>(void)>
215 get_attached_devices_callback, 226 get_attached_devices_callback,
216 base::WeakPtr<chrome::VolumeMountWatcherWin> volume_watcher) { 227 base::WeakPtr<chrome::VolumeMountWatcherWin> volume_watcher) {
217 std::vector<base::FilePath> removable_devices = 228 std::vector<base::FilePath> removable_devices =
218 get_attached_devices_callback.Run(); 229 get_attached_devices_callback.Run();
219 230
220 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( 231 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
221 &chrome::VolumeMountWatcherWin::AddDevicesOnUIThread, 232 &chrome::VolumeMountWatcherWin::AddDevicesOnUIThread,
222 volume_watcher, removable_devices)); 233 volume_watcher, removable_devices));
223 } 234 }
224 235
225 void VolumeMountWatcherWin::AddDevicesOnUIThread( 236 void VolumeMountWatcherWin::AddDevicesOnUIThread(
226 std::vector<base::FilePath> removable_devices) { 237 std::vector<base::FilePath> removable_devices) {
227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
228 239
229 scoped_refptr<base::TaskRunner> runner =
230 device_info_worker_pool_->GetTaskRunnerWithShutdownBehavior(
231 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
232 for (size_t i = 0; i < removable_devices.size(); i++) { 240 for (size_t i = 0; i < removable_devices.size(); i++) {
233 if (ContainsKey(pending_device_checks_, removable_devices[i])) 241 if (ContainsKey(pending_device_checks_, removable_devices[i]))
234 continue; 242 continue;
235 pending_device_checks_.insert(removable_devices[i]); 243 pending_device_checks_.insert(removable_devices[i]);
236 runner->PostTask(FROM_HERE, 244 task_runner_->PostTask(FROM_HERE,
237 base::Bind(&RetrieveInfoForDeviceAndAdd, 245 base::Bind(&RetrieveInfoForDeviceAndAdd,
238 removable_devices[i], 246 removable_devices[i],
239 get_device_details_callback_, 247 get_device_details_callback_,
240 weak_factory_.GetWeakPtr())); 248 weak_factory_.GetWeakPtr()));
241 } 249 }
242 } 250 }
243 251
244 // static 252 // static
245 void VolumeMountWatcherWin::RetrieveInfoForDeviceAndAdd( 253 void VolumeMountWatcherWin::RetrieveInfoForDeviceAndAdd(
246 const base::FilePath& device_path, 254 const base::FilePath& device_path,
247 base::Callback<bool(const base::FilePath&, string16*, std::string*, 255 base::Callback<bool(const base::FilePath&, string16*, std::string*,
248 string16*, bool*, uint64*)> get_device_details_callback, 256 string16*, bool*, uint64*)> get_device_details_callback,
249 base::WeakPtr<chrome::VolumeMountWatcherWin> volume_watcher) { 257 base::WeakPtr<chrome::VolumeMountWatcherWin> volume_watcher) {
250 string16 device_location; 258 string16 device_location;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 // If the device isn't type removable (like a CD), it won't be there. 406 // If the device isn't type removable (like a CD), it won't be there.
399 if (device_info == device_metadata_.end()) 407 if (device_info == device_metadata_.end())
400 return; 408 return;
401 409
402 if (notifications_) 410 if (notifications_)
403 notifications_->ProcessDetach(device_info->second.device_id); 411 notifications_->ProcessDetach(device_info->second.device_id);
404 device_metadata_.erase(device_info); 412 device_metadata_.erase(device_info);
405 } 413 }
406 414
407 } // namespace chrome 415 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/storage_monitor/volume_mount_watcher_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698