OLD | NEW |
1 | 1 |
2 // Copyright 2014 The Chromium Authors. All rights reserved. | 2 // Copyright 2014 The Chromium Authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 | 5 |
6 #include "base/lazy_instance.h" | 6 #include "base/lazy_instance.h" |
7 #include "chrome/browser/extensions/api/image_writer_private/removable_storage_p
rovider.h" | 7 #include "chrome/browser/extensions/api/image_writer_private/removable_storage_p
rovider.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 | 9 |
10 namespace extensions { | 10 namespace extensions { |
11 | 11 |
12 // A device list to be returned when testing. | 12 // A device list to be returned when testing. |
13 static base::LazyInstance<scoped_refptr<StorageDeviceList>>::DestructorAtExit | 13 static base::LazyInstance<scoped_refptr<StorageDeviceList>>::DestructorAtExit |
14 g_test_device_list = LAZY_INSTANCE_INITIALIZER; | 14 g_test_device_list = LAZY_INSTANCE_INITIALIZER; |
15 | 15 |
16 // TODO(haven): Udev code may be duplicated in the Chrome codebase. | 16 // TODO(haven): Udev code may be duplicated in the Chrome codebase. |
17 // https://code.google.com/p/chromium/issues/detail?id=284898 | 17 // https://code.google.com/p/chromium/issues/detail?id=284898 |
18 | 18 |
19 void RemovableStorageProvider::GetAllDevices(DeviceListReadyCallback callback) { | 19 void RemovableStorageProvider::GetAllDevices(DeviceListReadyCallback callback) { |
20 if (g_test_device_list.Get().get() != NULL) { | 20 if (g_test_device_list.Get().get() != NULL) { |
21 content::BrowserThread::PostTask( | 21 content::BrowserThread::PostTask( |
22 content::BrowserThread::FILE, | 22 content::BrowserThread::FILE, FROM_HERE, |
23 FROM_HERE, | 23 base::BindOnce(callback, g_test_device_list.Get(), true)); |
24 base::Bind(callback, g_test_device_list.Get(), true)); | |
25 return; | 24 return; |
26 } | 25 } |
27 | 26 |
28 scoped_refptr<StorageDeviceList> device_list(new StorageDeviceList); | 27 scoped_refptr<StorageDeviceList> device_list(new StorageDeviceList); |
29 | 28 |
30 // We need to do some file i/o to get the device block size | 29 // We need to do some file i/o to get the device block size |
31 content::BrowserThread::PostTaskAndReplyWithResult( | 30 content::BrowserThread::PostTaskAndReplyWithResult( |
32 content::BrowserThread::FILE, | 31 content::BrowserThread::FILE, |
33 FROM_HERE, | 32 FROM_HERE, |
34 base::Bind(PopulateDeviceList, device_list), | 33 base::Bind(PopulateDeviceList, device_list), |
35 base::Bind(callback, device_list)); | 34 base::Bind(callback, device_list)); |
36 } | 35 } |
37 | 36 |
38 void RemovableStorageProvider::SetDeviceListForTesting( | 37 void RemovableStorageProvider::SetDeviceListForTesting( |
39 scoped_refptr<StorageDeviceList> device_list) { | 38 scoped_refptr<StorageDeviceList> device_list) { |
40 g_test_device_list.Get() = device_list; | 39 g_test_device_list.Get() = device_list; |
41 } | 40 } |
42 | 41 |
43 void RemovableStorageProvider::ClearDeviceListForTesting() { | 42 void RemovableStorageProvider::ClearDeviceListForTesting() { |
44 g_test_device_list.Get() = NULL; | 43 g_test_device_list.Get() = NULL; |
45 } | 44 } |
46 | 45 |
47 } // namespace extensions | 46 } // namespace extensions |
OLD | NEW |