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.
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_
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"
23 struct SearchResultInfo
;
26 namespace google_apis
{
30 namespace extensions
{
33 namespace file_manager_private
{
34 struct EntryProperties
;
35 } // namespace file_manager_private
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
{
44 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getEntryProperties",
45 FILEMANAGERPRIVATEINTERNAL_GETENTRYPROPERTIES
)
47 FileManagerPrivateInternalGetEntryPropertiesFunction();
50 ~FileManagerPrivateInternalGetEntryPropertiesFunction() override
;
52 // AsyncExtensionFunction overrides.
53 bool RunAsync() override
;
56 void CompleteGetEntryProperties(
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
> >
67 // Implements the chrome.fileManagerPrivate.pinDriveFile method.
68 class FileManagerPrivateInternalPinDriveFileFunction
69 : public LoggedAsyncExtensionFunction
{
71 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.pinDriveFile",
72 FILEMANAGERPRIVATEINTERNAL_PINDRIVEFILE
)
75 ~FileManagerPrivateInternalPinDriveFileFunction() override
{}
77 // AsyncExtensionFunction overrides.
78 bool RunAsync() override
;
81 // Callback for RunAsync().
82 void OnPinStateSet(drive::FileError error
);
85 // Implements the chrome.fileManagerPrivate.cancelFileTransfers method.
86 class FileManagerPrivateInternalCancelFileTransfersFunction
87 : public LoggedAsyncExtensionFunction
{
89 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.cancelFileTransfers",
90 FILEMANAGERPRIVATEINTERNAL_CANCELFILETRANSFERS
)
93 ~FileManagerPrivateInternalCancelFileTransfersFunction() override
{}
95 // AsyncExtensionFunction overrides.
96 bool RunAsync() override
;
99 // Implements the chrome.fileManagerPrivate.cancelAllFileTransfers method.
100 class FileManagerPrivateCancelAllFileTransfersFunction
101 : public LoggedAsyncExtensionFunction
{
103 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelAllFileTransfers",
104 FILEMANAGERPRIVATE_CANCELALLFILETRANSFERS
)
107 ~FileManagerPrivateCancelAllFileTransfersFunction() override
{}
109 // AsyncExtensionFunction overrides.
110 bool RunAsync() override
;
113 class FileManagerPrivateSearchDriveFunction
114 : public LoggedAsyncExtensionFunction
{
116 typedef std::vector
<drive::SearchResultInfo
> SearchResultInfoList
;
118 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchDrive",
119 FILEMANAGERPRIVATE_SEARCHDRIVE
)
122 ~FileManagerPrivateSearchDriveFunction() override
{}
124 bool RunAsync() override
;
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
{
146 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchDriveMetadata",
147 FILEMANAGERPRIVATE_SEARCHDRIVEMETADATA
)
150 ~FileManagerPrivateSearchDriveMetadataFunction() override
{}
152 bool RunAsync() override
;
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
{
171 DECLARE_EXTENSION_FUNCTION(
172 "fileManagerPrivate.getDriveConnectionState",
173 FILEMANAGERPRIVATE_GETDRIVECONNECTIONSTATE
);
176 ~FileManagerPrivateGetDriveConnectionStateFunction() override
{}
178 bool RunSync() override
;
181 // Implements the chrome.fileManagerPrivate.requestAccessToken method.
182 class FileManagerPrivateRequestAccessTokenFunction
183 : public LoggedAsyncExtensionFunction
{
185 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestAccessToken",
186 FILEMANAGERPRIVATE_REQUESTACCESSTOKEN
)
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
{
203 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getShareUrl",
204 FILEMANAGERPRIVATEINTERNAL_GETSHAREURL
)
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
{
221 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.requestDriveShare",
222 FILEMANAGERPRIVATEINTERNAL_REQUESTDRIVESHARE
);
225 ~FileManagerPrivateInternalRequestDriveShareFunction() override
{}
226 bool RunAsync() override
;
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
{
237 FileManagerPrivateInternalGetDownloadUrlFunction();
239 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getDownloadUrl",
240 FILEMANAGERPRIVATEINTERNAL_GETDOWNLOADURL
)
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
);
258 scoped_ptr
<google_apis::AuthService
> auth_service_
;
261 } // namespace extensions
263 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_