app_shell: Add version number in user agent
[chromium-blink-merge.git] / chrome / browser / media_galleries / mac / mtp_device_delegate_impl_mac.h
blob13e25c2c19c45b100a98958e776e5687362be539
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 virtual void GetFileInfo(
36 const base::FilePath& file_path,
37 const GetFileInfoSuccessCallback& success_callback,
38 const ErrorCallback& error_callback) OVERRIDE;
40 // Note: passed absolute paths, but expects relative paths in reply.
41 virtual void ReadDirectory(
42 const base::FilePath& root,
43 const ReadDirectorySuccessCallback& success_callback,
44 const ErrorCallback& error_callback) OVERRIDE;
46 // Note: passed absolute paths.
47 virtual void CreateSnapshotFile(
48 const base::FilePath& device_file_path,
49 const base::FilePath& local_path,
50 const CreateSnapshotFileSuccessCallback& success_callback,
51 const ErrorCallback& error_callback) OVERRIDE;
52 virtual bool IsStreaming() OVERRIDE;
53 virtual void ReadBytes(
54 const base::FilePath& device_file_path,
55 net::IOBuffer* buf, int64 offset, int buf_len,
56 const ReadBytesSuccessCallback& success_callback,
57 const ErrorCallback& error_callback) OVERRIDE;
58 virtual void CancelPendingTasksAndDeleteDelegate() OVERRIDE;
60 // Forward delegates for ImageCaptureDeviceListener. These are
61 // invoked in callbacks of the ImageCapture library on the UI thread.
62 virtual void ItemAdded(const std::string& name,
63 const base::File::Info& info);
64 virtual void NoMoreItems();
65 virtual void DownloadedFile(const std::string& name,
66 base::File::Error error);
68 // Scheduled when early directory reads are requested. The
69 // timeout will signal an ABORT error to the caller if the
70 // device metadata cannot be read.
71 void ReadDirectoryTimeout(const base::FilePath& root);
73 private:
74 class DeviceListener;
76 virtual ~MTPDeviceDelegateImplMac();
78 // Delegate for GetFileInfo, called on the UI thread.
79 void GetFileInfoImpl(const base::FilePath& file_path,
80 base::File::Info* file_info,
81 base::File::Error* error);
83 // Delegate for ReadDirectory, called on the UI thread.
84 void ReadDirectoryImpl(
85 const base::FilePath& root,
86 const ReadDirectorySuccessCallback& success_callback,
87 const ErrorCallback& error_callback);
89 // Delegate for CreateSnapshotFile, called on the UI thread.
90 void DownloadFile(
91 const base::FilePath& device_file_path,
92 const base::FilePath& local_path,
93 const CreateSnapshotFileSuccessCallback& success_callback,
94 const ErrorCallback& error_callback);
96 // Public for closures; should not be called except by
97 // CancelTasksAndDeleteDelegate.
98 void CancelAndDelete();
100 // Cancels any outstanding downloads.
101 void CancelDownloads();
103 // If necessary, notifies the ReadDirectory callback that all data
104 // has been read.
105 void NotifyReadDir();
107 std::string device_id_;
108 base::FilePath root_path_;
110 // Interface object for the camera underlying this MTP session.
111 scoped_ptr<DeviceListener> camera_interface_;
113 // Stores a map from filename to file metadata received from the camera.
114 base::hash_map<base::FilePath::StringType,
115 base::File::Info> file_info_;
117 // List of filenames received from the camera.
118 std::vector<base::FilePath> file_paths_;
120 // Set to true when all file metadata has been received from the camera.
121 bool received_all_files_;
123 struct ReadFileRequest {
124 ReadFileRequest();
125 ReadFileRequest(const std::string& request_file,
126 const base::FilePath& snapshot_filename,
127 CreateSnapshotFileSuccessCallback success_cb,
128 ErrorCallback error_cb);
129 ~ReadFileRequest();
131 std::string request_file;
132 base::FilePath snapshot_file;
133 CreateSnapshotFileSuccessCallback success_callback;
134 ErrorCallback error_callback;
137 typedef std::list<ReadFileRequest> ReadFileTransactionList;
139 struct ReadDirectoryRequest {
140 ReadDirectoryRequest(const base::FilePath& dir,
141 ReadDirectorySuccessCallback success_cb,
142 ErrorCallback error_cb);
143 ~ReadDirectoryRequest();
145 base::FilePath directory;
146 ReadDirectorySuccessCallback success_callback;
147 ErrorCallback error_callback;
150 typedef std::list<ReadDirectoryRequest> ReadDirTransactionList;
152 ReadFileTransactionList read_file_transactions_;
153 ReadDirTransactionList read_dir_transactions_;
155 base::WeakPtrFactory<MTPDeviceDelegateImplMac> weak_factory_;
157 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplMac);
160 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MAC_MTP_DEVICE_DELEGATE_IMPL_MAC_H_