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
4 // found in the LICENSE file.
6 #include "base/lazy_instance.h"
7 #include "chrome/browser/extensions/api/image_writer_private/removable_storage_provider.h"
8 #include "content/public/browser/browser_thread.h"
10 namespace extensions
{
12 // A device list to be returned when testing.
13 static base::LazyInstance
<scoped_refptr
<StorageDeviceList
> > g_test_device_list
;
15 // TODO(haven): Udev code may be duplicated in the Chrome codebase.
16 // https://code.google.com/p/chromium/issues/detail?id=284898
18 void RemovableStorageProvider::GetAllDevices(DeviceListReadyCallback callback
) {
19 if (g_test_device_list
.Get().get() != NULL
) {
20 content::BrowserThread::PostTask(
21 content::BrowserThread::FILE,
23 base::Bind(callback
, g_test_device_list
.Get(), true));
27 scoped_refptr
<StorageDeviceList
> device_list(new StorageDeviceList
);
29 // We need to do some file i/o to get the device block size
30 content::BrowserThread::PostTaskAndReplyWithResult(
31 content::BrowserThread::FILE,
33 base::Bind(PopulateDeviceList
, device_list
),
34 base::Bind(callback
, device_list
));
37 void RemovableStorageProvider::SetDeviceListForTesting(
38 scoped_refptr
<StorageDeviceList
> device_list
) {
39 g_test_device_list
.Get() = device_list
;
42 void RemovableStorageProvider::ClearDeviceListForTesting() {
43 g_test_device_list
.Get() = NULL
;
46 } // namespace extensions