ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / media_galleries / mac / mtp_device_delegate_impl_mac.h
blob0440fbd6815c187f22d81afb9e20f51b600bf91e
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_MAC_MTP_DEVICE_DELEGATE_IMPL_MAC_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_MAC_MTP_DEVICE_DELEGATE_IMPL_MAC_H_
8 #include <list>
9 #include <map>
10 #include <vector>
12 #include "base/containers/hash_tables.h"
13 #include "base/files/file.h"
14 #include "base/files/file_path.h"
15 #include "base/memory/weak_ptr.h"
16 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h"
18 // Delegate for presenting an Image Capture device through the filesystem
19 // API. The synthetic filesystem will be rooted at the constructed location,
20 // and names of all files notified through the ItemAdded call will be
21 // all appear as children of that directory. (ItemAdded calls with directories
22 // will be ignored.)
23 // Note on thread management: This class is thread-compatible: it can be created
24 // on any thread, but then mutates all state on the UI thread. The async
25 // delegate interface can be invoked on any thread, as it simply forwards calls
26 // to the UI thread.
27 class MTPDeviceDelegateImplMac : public MTPDeviceAsyncDelegate {
28 public:
29 MTPDeviceDelegateImplMac(const std::string& device_id,
30 const base::FilePath::StringType& synthetic_path);
32 // MTPDeviceAsyncDelegate implementation. These functions are called on the
33 // IO thread by the async filesystem file util. They forward to
34 // similarly-named methods on the UI thread.
35 void GetFileInfo(const base::FilePath& file_path,
36 const GetFileInfoSuccessCallback& success_callback,
37 const ErrorCallback& error_callback) override;
39 // Note: passed absolute paths, but expects relative paths in reply.
40 void ReadDirectory(const base::FilePath& root,
41 const ReadDirectorySuccessCallback& success_callback,
42 const ErrorCallback& error_callback) override;
44 // Note: passed absolute paths.
45 void CreateSnapshotFile(
46 const base::FilePath& device_file_path,
47 const base::FilePath& local_path,
48 const CreateSnapshotFileSuccessCallback& success_callback,
49 const ErrorCallback& error_callback) override;
50 bool IsStreaming() override;
51 void ReadBytes(const base::FilePath& device_file_path,
52 const scoped_refptr<net::IOBuffer>& buf,
53 int64 offset,
54 int buf_len,
55 const ReadBytesSuccessCallback& success_callback,
56 const ErrorCallback& error_callback) override;
57 void CancelPendingTasksAndDeleteDelegate() override;
59 // Forward delegates for ImageCaptureDeviceListener. These are
60 // invoked in callbacks of the ImageCapture library on the UI thread.
61 virtual void ItemAdded(const std::string& name,
62 const base::File::Info& info);
63 virtual void NoMoreItems();
64 virtual void DownloadedFile(const std::string& name,
65 base::File::Error error);
67 // Scheduled when early directory reads are requested. The
68 // timeout will signal an ABORT error to the caller if the
69 // device metadata cannot be read.
70 void ReadDirectoryTimeout(const base::FilePath& root);
72 private:
73 class DeviceListener;
75 ~MTPDeviceDelegateImplMac() override;
77 // Delegate for GetFileInfo, called on the UI thread.
78 void GetFileInfoImpl(const base::FilePath& file_path,
79 base::File::Info* file_info,
80 base::File::Error* error);
82 // Delegate for ReadDirectory, called on the UI thread.
83 void ReadDirectoryImpl(
84 const base::FilePath& root,
85 const ReadDirectorySuccessCallback& success_callback,
86 const ErrorCallback& error_callback);
88 // Delegate for CreateSnapshotFile, called on the UI thread.
89 void DownloadFile(
90 const base::FilePath& device_file_path,
91 const base::FilePath& local_path,
92 const CreateSnapshotFileSuccessCallback& success_callback,
93 const ErrorCallback& error_callback);
95 // Public for closures; should not be called except by
96 // CancelTasksAndDeleteDelegate.
97 void CancelAndDelete();
99 // Cancels any outstanding downloads.
100 void CancelDownloads();
102 // If necessary, notifies the ReadDirectory callback that all data
103 // has been read.
104 void NotifyReadDir();
106 std::string device_id_;
107 base::FilePath root_path_;
109 // Interface object for the camera underlying this MTP session.
110 scoped_ptr<DeviceListener> camera_interface_;
112 // Stores a map from filename to file metadata received from the camera.
113 base::hash_map<base::FilePath::StringType,
114 base::File::Info> file_info_;
116 // List of filenames received from the camera.
117 std::vector<base::FilePath> file_paths_;
119 // Set to true when all file metadata has been received from the camera.
120 bool received_all_files_;
122 struct ReadFileRequest {
123 ReadFileRequest();
124 ReadFileRequest(const std::string& request_file,
125 const base::FilePath& snapshot_filename,
126 CreateSnapshotFileSuccessCallback success_cb,
127 ErrorCallback error_cb);
128 ~ReadFileRequest();
130 std::string request_file;
131 base::FilePath snapshot_file;
132 CreateSnapshotFileSuccessCallback success_callback;
133 ErrorCallback error_callback;
136 typedef std::list<ReadFileRequest> ReadFileTransactionList;
138 struct ReadDirectoryRequest {
139 ReadDirectoryRequest(const base::FilePath& dir,
140 ReadDirectorySuccessCallback success_cb,
141 ErrorCallback error_cb);
142 ~ReadDirectoryRequest();
144 base::FilePath directory;
145 ReadDirectorySuccessCallback success_callback;
146 ErrorCallback error_callback;
149 typedef std::list<ReadDirectoryRequest> ReadDirTransactionList;
151 ReadFileTransactionList read_file_transactions_;
152 ReadDirTransactionList read_dir_transactions_;
154 base::WeakPtrFactory<MTPDeviceDelegateImplMac> weak_factory_;
156 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplMac);
159 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MAC_MTP_DEVICE_DELEGATE_IMPL_MAC_H_