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

Side by Side Diff: chrome/browser/extensions/api/image_writer_private/removable_storage_provider.h

Issue 291333006: Adds removable-drive listing for OS X. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removes unnecessary changes. Created 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_REMOVABLE_STORAGE_PRO VIDER_H_ 4 #ifndef CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_REMOVABLE_STORAGE_PRO VIDER_H_
5 #define CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_REMOVABLE_STORAGE_PRO VIDER_H_ 5 #define CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_REMOVABLE_STORAGE_PRO VIDER_H_
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "chrome/common/extensions/api/image_writer_private.h" 8 #include "chrome/common/extensions/api/image_writer_private.h"
9 #include "chrome/common/ref_counted_util.h" 9 #include "chrome/common/ref_counted_util.h"
10 10
11 #if defined(OS_MACOSX)
12 #include <CoreFoundation/CoreFoundation.h>
13 #include <DiskArbitration/DiskArbitration.h>
14
15 #include "base/mac/foundation_util.h"
16 #include "base/memory/weak_ptr.h"
17 #endif
18
11 namespace extensions { 19 namespace extensions {
12 20
13 // TODO(haven): Clean up this class to remove refcounting. http://crbug/370590 21 // TODO(haven): Clean up this class to remove refcounting. http://crbug/370590
14 22
15 typedef RefCountedVector<linked_ptr 23 typedef RefCountedVector<linked_ptr<
16 <api::image_writer_private::RemovableStorageDevice> > StorageDeviceList; 24 api::image_writer_private::RemovableStorageDevice> > StorageDeviceList;
25 typedef base::Callback<void(scoped_refptr<StorageDeviceList>, bool)>
26 DeviceListReadyCallback;
17 27
18 // Abstraction for platform specific implementations of listing removable 28 // Abstraction for platform specific implementations of listing removable
19 // storage devices 29 // storage devices
20 class RemovableStorageProvider { 30 class RemovableStorageProvider {
21 public: 31 public:
22 typedef base::Callback<void(scoped_refptr<StorageDeviceList>, bool)>
23 DeviceListReadyCallback;
24 32
25 // Gets the list of all available devices and returns it via callback. 33 // Gets the list of all available devices and returns it via callback.
26 static void GetAllDevices(DeviceListReadyCallback callback); 34 static void GetAllDevices(const DeviceListReadyCallback& callback);
27 35
28 // Sets the list of devices that will be returned by GetAllDevices during 36 // Sets the list of devices that will be returned by GetAllDevices during
29 // testing. All calls to |GetAllDevices| will return this list until 37 // testing. All calls to |GetAllDevices| will return this list until
30 // |ClearDeviceListForTesting| is called. 38 // |ClearDeviceListForTesting| is called.
31 static void SetDeviceListForTesting( 39 static void SetDeviceListForTesting(
32 scoped_refptr<StorageDeviceList> device_list); 40 scoped_refptr<StorageDeviceList> device_list);
33 // Clears the list of devices that is used during testing. 41 // Clears the list of devices that is used during testing.
34 static void ClearDeviceListForTesting(); 42 static void ClearDeviceListForTesting();
35 43
36 private: 44 private:
37 // Fills the provided empty device list with the available devices. 45 // This is the actual implementation of the logic, which will be skipped if a
38 static bool PopulateDeviceList(scoped_refptr<StorageDeviceList> device_list); 46 // testing value is set.
47 static void GetAllDevicesImpl(const DeviceListReadyCallback& callback);
39 }; 48 };
40 49
50 #if defined(OS_MACOSX)
51 // A wrapper around the DiskArbitration state.
52 //
53 // Listing devices on OS X involves asynchronous callbacks through the Disk
54 // Arbitration framework. This class serves to wrap up that state and maintain
55 // it while we still have outstanding calls expected.
56 class DAWrapper : public base::SupportsWeakPtr<DAWrapper> {
Robert Sesek 2014/06/02 19:56:05 A better name for this would be RemovableStoragePr
Drew Haven 2014/06/03 02:03:23 I think I originally put this here just to make it
57 public:
58 DAWrapper();
59 virtual ~DAWrapper();
60
61 // Gets the list of all available devices and returns it via callback.
62 void GetDeviceList(const DeviceListReadyCallback& callback);
63
64 // A wrapper for DeviceListReadyCallbacks which will delete the wrapper when
65 // it is fired.
66 static void WrapperDeleter(DAWrapper* wrapper,
67 const DeviceListReadyCallback& callback,
68 scoped_refptr<StorageDeviceList> device_list,
69 bool success);
70
71 private:
72 // A testing spouse.
73 friend class DAWrapperSpouse;
74
75 // Processes a disk-appeared event. This increments |updates_pending_| and
76 // then posts a task to AddDisk. This is so we can collect all the immediate
77 // disk-appeared events and know how many we need to process and thus when to
78 // call the callback. Operates on the disk-description dictionary.
79 void ProcessDisk(base::ScopedCFTypeRef<CFDictionaryRef> dict);
80 // Adds a disk to the disk_list. Decrements |updates_pending_| and triggers
81 // the callback when it reaches zero. Operates on the disk-description
82 // dictionary.
83 void AddDisk(base::ScopedCFTypeRef<CFDictionaryRef> dict);
84 // Responds to a disk-appeared event.
85 static void DiskAppearedCallback(DADiskRef disk, void* context);
86 // Responds to a disk-disappeared event.
87 static void DiskDisappearedCallback(DADiskRef disk, void* context);
88 // Checks whether the disk description in |dict| is a valid removable device.
89 static bool DiskIsValidTarget(CFDictionaryRef dict);
90
91 int updates_pending_;
92 scoped_refptr<StorageDeviceList> device_list_;
93 DeviceListReadyCallback callback_;
94 base::ScopedCFTypeRef<DASessionRef> session_;
95
96 DISALLOW_COPY_AND_ASSIGN(DAWrapper);
97 };
98
99 // A testing spouse for |DAWrapper|.
100 class DAWrapperSpouse {
Robert Sesek 2014/06/02 19:56:05 This does not belong in a public .h file.
Drew Haven 2014/06/03 02:03:23 Moved to test_utils.h
101 public:
102 explicit DAWrapperSpouse(DAWrapper* spouse);
103 virtual ~DAWrapperSpouse();
104
105 // Sets the |callback_| of the |DAWrapper|.
106 void SetCallback(const DeviceListReadyCallback& callback);
107 // Sets the current |device_list_| of the |DAWrapper|.
108 void SetDeviceList(scoped_refptr<StorageDeviceList> device_list);
109 // Triggers |ProcessDisk| on the |DAWrapper|.
110 void ProcessDisk(base::ScopedCFTypeRef<CFDictionaryRef> dict);
111 // runs |DiskIsValidTarget| on the |DAWrapper|.
112 static bool DiskIsValidTarget(CFDictionaryRef dict);
113
114 private:
115 DAWrapper* spouse_;
116 };
117 #endif
118
41 } // namespace extensions 119 } // namespace extensions
42 120
43 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_REMOVABLE_STORAGE_ PROVIDER_H_ 121 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_REMOVABLE_STORAGE_ PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698