Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / file_manager / private_api_drive.h
blob143f45b75ff3eb966330984641bc4b230498a78c
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
3 // found in the LICENSE file.
4 //
5 // This file provides Drive specific API functions.
7 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_
8 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_
10 #include <string>
11 #include <vector>
13 #include "base/files/file.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
16 #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
17 #include "components/drive/file_errors.h"
18 #include "components/drive/file_system_interface.h"
20 namespace drive {
21 class FileCacheEntry;
22 class ResourceEntry;
23 struct SearchResultInfo;
26 namespace google_apis {
27 class AuthService;
30 namespace extensions {
32 namespace api {
33 namespace file_manager_private {
34 struct EntryProperties;
35 } // namespace file_manager_private
36 } // namespace api
38 // Retrieves property information for an entry and returns it as a dictionary.
39 // On error, returns a dictionary with the key "error" set to the error number
40 // (base::File::Error).
41 class FileManagerPrivateInternalGetEntryPropertiesFunction
42 : public LoggedAsyncExtensionFunction {
43 public:
44 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getEntryProperties",
45 FILEMANAGERPRIVATEINTERNAL_GETENTRYPROPERTIES)
47 FileManagerPrivateInternalGetEntryPropertiesFunction();
49 protected:
50 ~FileManagerPrivateInternalGetEntryPropertiesFunction() override;
52 // AsyncExtensionFunction overrides.
53 bool RunAsync() override;
55 private:
56 void CompleteGetEntryProperties(
57 size_t index,
58 const storage::FileSystemURL& url,
59 scoped_ptr<api::file_manager_private::EntryProperties> properties,
60 base::File::Error error);
62 size_t processed_count_;
63 std::vector<linked_ptr<api::file_manager_private::EntryProperties> >
64 properties_list_;
67 // Implements the chrome.fileManagerPrivate.pinDriveFile method.
68 class FileManagerPrivateInternalPinDriveFileFunction
69 : public LoggedAsyncExtensionFunction {
70 public:
71 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.pinDriveFile",
72 FILEMANAGERPRIVATEINTERNAL_PINDRIVEFILE)
74 protected:
75 ~FileManagerPrivateInternalPinDriveFileFunction() override {}
77 // AsyncExtensionFunction overrides.
78 bool RunAsync() override;
80 private:
81 // Callback for RunAsync().
82 void OnPinStateSet(drive::FileError error);
85 // Implements the chrome.fileManagerPrivate.cancelFileTransfers method.
86 class FileManagerPrivateInternalCancelFileTransfersFunction
87 : public LoggedAsyncExtensionFunction {
88 public:
89 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.cancelFileTransfers",
90 FILEMANAGERPRIVATEINTERNAL_CANCELFILETRANSFERS)
92 protected:
93 ~FileManagerPrivateInternalCancelFileTransfersFunction() override {}
95 // AsyncExtensionFunction overrides.
96 bool RunAsync() override;
99 // Implements the chrome.fileManagerPrivate.cancelAllFileTransfers method.
100 class FileManagerPrivateCancelAllFileTransfersFunction
101 : public LoggedAsyncExtensionFunction {
102 public:
103 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelAllFileTransfers",
104 FILEMANAGERPRIVATE_CANCELALLFILETRANSFERS)
106 protected:
107 ~FileManagerPrivateCancelAllFileTransfersFunction() override {}
109 // AsyncExtensionFunction overrides.
110 bool RunAsync() override;
113 class FileManagerPrivateSearchDriveFunction
114 : public LoggedAsyncExtensionFunction {
115 public:
116 typedef std::vector<drive::SearchResultInfo> SearchResultInfoList;
118 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchDrive",
119 FILEMANAGERPRIVATE_SEARCHDRIVE)
121 protected:
122 ~FileManagerPrivateSearchDriveFunction() override {}
124 bool RunAsync() override;
126 private:
127 // Callback for Search().
128 void OnSearch(drive::FileError error,
129 const GURL& next_link,
130 scoped_ptr<std::vector<drive::SearchResultInfo> > result_paths);
132 // Called when |result_paths| in OnSearch() are converted to a list of
133 // entry definitions.
134 void OnEntryDefinitionList(
135 const GURL& next_link,
136 scoped_ptr<SearchResultInfoList> search_result_info_list,
137 scoped_ptr<file_manager::util::EntryDefinitionList>
138 entry_definition_list);
141 // Similar to FileManagerPrivateSearchDriveFunction but this one is used for
142 // searching drive metadata which is stored locally.
143 class FileManagerPrivateSearchDriveMetadataFunction
144 : public LoggedAsyncExtensionFunction {
145 public:
146 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchDriveMetadata",
147 FILEMANAGERPRIVATE_SEARCHDRIVEMETADATA)
149 protected:
150 ~FileManagerPrivateSearchDriveMetadataFunction() override {}
152 bool RunAsync() override;
154 private:
155 // Callback for SearchMetadata();
156 void OnSearchMetadata(drive::FileError error,
157 scoped_ptr<drive::MetadataSearchResultVector> results);
159 // Called when |results| in OnSearchMetadata() are converted to a list of
160 // entry definitions.
161 void OnEntryDefinitionList(
162 scoped_ptr<drive::MetadataSearchResultVector> search_result_info_list,
163 scoped_ptr<file_manager::util::EntryDefinitionList>
164 entry_definition_list);
167 // Implements the chrome.fileManagerPrivate.getDriveConnectionState method.
168 class FileManagerPrivateGetDriveConnectionStateFunction
169 : public ChromeSyncExtensionFunction {
170 public:
171 DECLARE_EXTENSION_FUNCTION(
172 "fileManagerPrivate.getDriveConnectionState",
173 FILEMANAGERPRIVATE_GETDRIVECONNECTIONSTATE);
175 protected:
176 ~FileManagerPrivateGetDriveConnectionStateFunction() override {}
178 bool RunSync() override;
181 // Implements the chrome.fileManagerPrivate.requestAccessToken method.
182 class FileManagerPrivateRequestAccessTokenFunction
183 : public LoggedAsyncExtensionFunction {
184 public:
185 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestAccessToken",
186 FILEMANAGERPRIVATE_REQUESTACCESSTOKEN)
188 protected:
189 ~FileManagerPrivateRequestAccessTokenFunction() override {}
191 // AsyncExtensionFunction overrides.
192 bool RunAsync() override;
194 // Callback with a cached auth token (if available) or a fetched one.
195 void OnAccessTokenFetched(google_apis::DriveApiErrorCode code,
196 const std::string& access_token);
199 // Implements the chrome.fileManagerPrivate.getShareUrl method.
200 class FileManagerPrivateInternalGetShareUrlFunction
201 : public LoggedAsyncExtensionFunction {
202 public:
203 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getShareUrl",
204 FILEMANAGERPRIVATEINTERNAL_GETSHAREURL)
206 protected:
207 ~FileManagerPrivateInternalGetShareUrlFunction() override {}
209 // AsyncExtensionFunction overrides.
210 bool RunAsync() override;
212 // Callback with an url to the sharing dialog as |share_url|, called by
213 // FileSystem::GetShareUrl.
214 void OnGetShareUrl(drive::FileError error, const GURL& share_url);
217 // Implements the chrome.fileManagerPrivate.requestDriveShare method.
218 class FileManagerPrivateInternalRequestDriveShareFunction
219 : public LoggedAsyncExtensionFunction {
220 public:
221 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.requestDriveShare",
222 FILEMANAGERPRIVATEINTERNAL_REQUESTDRIVESHARE);
224 protected:
225 ~FileManagerPrivateInternalRequestDriveShareFunction() override {}
226 bool RunAsync() override;
228 private:
229 // Called back after the drive file system operation is finished.
230 void OnAddPermission(drive::FileError error);
233 // Implements the chrome.fileManagerPrivate.getDownloadUrl method.
234 class FileManagerPrivateInternalGetDownloadUrlFunction
235 : public LoggedAsyncExtensionFunction {
236 public:
237 FileManagerPrivateInternalGetDownloadUrlFunction();
239 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getDownloadUrl",
240 FILEMANAGERPRIVATEINTERNAL_GETDOWNLOADURL)
242 protected:
243 ~FileManagerPrivateInternalGetDownloadUrlFunction() override;
245 // AsyncExtensionFunction overrides.
246 bool RunAsync() override;
248 void OnGetResourceEntry(drive::FileError error,
249 scoped_ptr<drive::ResourceEntry> entry);
251 // Callback with an |access_token|, called by
252 // drive::DriveReadonlyTokenFetcher.
253 void OnTokenFetched(google_apis::DriveApiErrorCode code,
254 const std::string& access_token);
256 private:
257 GURL download_url_;
258 scoped_ptr<google_apis::AuthService> auth_service_;
261 } // namespace extensions
263 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_