NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / media_galleries / fileapi / mtp_device_async_delegate.h
blob9ac5f7bb7740b1e6f37b74588a77bd7b1b97797c
1 // Copyright (c) 2013 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_FILEAPI_MTP_DEVICE_ASYNC_DELEGATE_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MTP_DEVICE_ASYNC_DELEGATE_H_
8 #include "base/callback.h"
9 #include "base/files/file.h"
10 #include "base/memory/ref_counted.h"
11 #include "webkit/browser/fileapi/async_file_util.h"
13 namespace base {
14 class FilePath;
17 namespace net {
18 class IOBuffer;
21 // Asynchronous delegate for media transfer protocol (MTP) device to perform
22 // media device isolated file system operations. Class that implements this
23 // delegate does the actual communication with the MTP device.
24 // The lifetime of the delegate is managed by the MTPDeviceMapService class.
25 // Member functions and callbacks run on the IO thread.
26 class MTPDeviceAsyncDelegate {
27 public:
28 // A callback to be called when GetFileInfo method call succeeds.
29 typedef base::Callback<
30 void(const base::File::Info& file_info)> GetFileInfoSuccessCallback;
32 // A callback to be called when ReadDirectory method call succeeds.
33 typedef base::Callback<
34 void(const fileapi::AsyncFileUtil::EntryList& file_list,
35 bool has_more)> ReadDirectorySuccessCallback;
37 // A callback to be called when GetFileInfo/ReadDirectory/CreateSnapshot
38 // method call fails.
39 typedef base::Callback<void(base::File::Error error)> ErrorCallback;
41 // A callback to be called when CreateSnapshotFile method call succeeds.
42 typedef base::Callback<
43 void(const base::File::Info& file_info,
44 const base::FilePath& local_path)> CreateSnapshotFileSuccessCallback;
46 // A callback to be called when ReadBytes method call succeeds.
47 typedef base::Callback<void(int)> ReadBytesSuccessCallback;
49 struct ReadBytesRequest {
50 ReadBytesRequest(const std::string& device_file_relative_path,
51 net::IOBuffer* buf, int64 offset, int buf_len,
52 const ReadBytesSuccessCallback& success_callback,
53 const ErrorCallback& error_callback);
54 ~ReadBytesRequest();
56 std::string device_file_relative_path;
57 scoped_refptr<net::IOBuffer> buf;
58 int64 offset;
59 int buf_len;
60 ReadBytesSuccessCallback success_callback;
61 ErrorCallback error_callback;
64 // Gets information about the given |file_path| and invokes the appropriate
65 // callback asynchronously when complete.
66 virtual void GetFileInfo(
67 const base::FilePath& file_path,
68 const GetFileInfoSuccessCallback& success_callback,
69 const ErrorCallback& error_callback) = 0;
71 // Enumerates the |root| directory contents and invokes the appropriate
72 // callback asynchronously when complete.
73 virtual void ReadDirectory(
74 const base::FilePath& root,
75 const ReadDirectorySuccessCallback& success_callback,
76 const ErrorCallback& error_callback) = 0;
78 // Copy the contents of |device_file_path| to |local_path|. Invokes the
79 // appropriate callback asynchronously when complete.
80 virtual void CreateSnapshotFile(
81 const base::FilePath& device_file_path,
82 const base::FilePath& local_path,
83 const CreateSnapshotFileSuccessCallback& success_callback,
84 const ErrorCallback& error_callback) = 0;
86 // Platform-specific implementations that are streaming don't create a local
87 // snapshot file. Blobs are instead FileSystemURL backed and read in a stream.
88 virtual bool IsStreaming() = 0;
90 // Reads up to |buf_len| bytes from |device_file_path| into |buf|. Invokes the
91 // appropriate callback asynchronously when complete. Only valid when
92 // IsStreaming() is true.
93 virtual void ReadBytes(
94 const base::FilePath& device_file_path,
95 net::IOBuffer* buf, int64 offset, int buf_len,
96 const ReadBytesSuccessCallback& success_callback,
97 const ErrorCallback& error_callback) = 0;
99 // Called when the
100 // (1) Browser application is in shutdown mode (or)
101 // (2) Last extension using this MTP device is destroyed (or)
102 // (3) Attached MTP device is removed (or)
103 // (4) User revoked the MTP device gallery permission.
104 // Ownership of |MTPDeviceAsyncDelegate| is handed off to the delegate
105 // implementation class by this call. This function should take care of
106 // cancelling all the pending tasks before deleting itself.
107 virtual void CancelPendingTasksAndDeleteDelegate() = 0;
109 protected:
110 // Always destruct this object via CancelPendingTasksAndDeleteDelegate().
111 virtual ~MTPDeviceAsyncDelegate() {}
114 typedef base::Callback<void(MTPDeviceAsyncDelegate*)>
115 CreateMTPDeviceAsyncDelegateCallback;
117 void CreateMTPDeviceAsyncDelegate(
118 const base::FilePath::StringType& device_location,
119 const CreateMTPDeviceAsyncDelegateCallback& callback);
121 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MTP_DEVICE_ASYNC_DELEGATE_H_