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/drive/file_errors.h"
16 #include "chrome/browser/chromeos/drive/file_system_interface.h"
17 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
18 #include "chrome/browser/chromeos/file_manager/fileapi_util.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 FileManagerPrivateGetEntryPropertiesFunction
42 : public LoggedAsyncExtensionFunction
{
44 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getEntryProperties",
45 FILEMANAGERPRIVATE_GETENTRYPROPERTIES
)
47 FileManagerPrivateGetEntryPropertiesFunction();
50 ~FileManagerPrivateGetEntryPropertiesFunction() 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 FileManagerPrivatePinDriveFileFunction
69 : public LoggedAsyncExtensionFunction
{
71 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.pinDriveFile",
72 FILEMANAGERPRIVATE_PINDRIVEFILE
)
75 ~FileManagerPrivatePinDriveFileFunction() 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 FileManagerPrivateCancelFileTransfersFunction
87 : public LoggedAsyncExtensionFunction
{
89 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelFileTransfers",
90 FILEMANAGERPRIVATE_CANCELFILETRANSFERS
)
93 ~FileManagerPrivateCancelFileTransfersFunction() override
{}
95 // AsyncExtensionFunction overrides.
96 bool RunAsync() override
;
99 class FileManagerPrivateSearchDriveFunction
100 : public LoggedAsyncExtensionFunction
{
102 typedef std::vector
<drive::SearchResultInfo
> SearchResultInfoList
;
104 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchDrive",
105 FILEMANAGERPRIVATE_SEARCHDRIVE
)
108 ~FileManagerPrivateSearchDriveFunction() override
{}
110 bool RunAsync() override
;
113 // Callback for Search().
114 void OnSearch(drive::FileError error
,
115 const GURL
& next_link
,
116 scoped_ptr
<std::vector
<drive::SearchResultInfo
> > result_paths
);
118 // Called when |result_paths| in OnSearch() are converted to a list of
119 // entry definitions.
120 void OnEntryDefinitionList(
121 const GURL
& next_link
,
122 scoped_ptr
<SearchResultInfoList
> search_result_info_list
,
123 scoped_ptr
<file_manager::util::EntryDefinitionList
>
124 entry_definition_list
);
127 // Similar to FileManagerPrivateSearchDriveFunction but this one is used for
128 // searching drive metadata which is stored locally.
129 class FileManagerPrivateSearchDriveMetadataFunction
130 : public LoggedAsyncExtensionFunction
{
132 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchDriveMetadata",
133 FILEMANAGERPRIVATE_SEARCHDRIVEMETADATA
)
136 ~FileManagerPrivateSearchDriveMetadataFunction() override
{}
138 bool RunAsync() override
;
141 // Callback for SearchMetadata();
142 void OnSearchMetadata(drive::FileError error
,
143 scoped_ptr
<drive::MetadataSearchResultVector
> results
);
145 // Called when |results| in OnSearchMetadata() are converted to a list of
146 // entry definitions.
147 void OnEntryDefinitionList(
148 scoped_ptr
<drive::MetadataSearchResultVector
> search_result_info_list
,
149 scoped_ptr
<file_manager::util::EntryDefinitionList
>
150 entry_definition_list
);
153 // Implements the chrome.fileManagerPrivate.getDriveConnectionState method.
154 class FileManagerPrivateGetDriveConnectionStateFunction
155 : public ChromeSyncExtensionFunction
{
157 DECLARE_EXTENSION_FUNCTION(
158 "fileManagerPrivate.getDriveConnectionState",
159 FILEMANAGERPRIVATE_GETDRIVECONNECTIONSTATE
);
162 ~FileManagerPrivateGetDriveConnectionStateFunction() override
{}
164 bool RunSync() override
;
167 // Implements the chrome.fileManagerPrivate.requestAccessToken method.
168 class FileManagerPrivateRequestAccessTokenFunction
169 : public LoggedAsyncExtensionFunction
{
171 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestAccessToken",
172 FILEMANAGERPRIVATE_REQUESTACCESSTOKEN
)
175 ~FileManagerPrivateRequestAccessTokenFunction() override
{}
177 // AsyncExtensionFunction overrides.
178 bool RunAsync() override
;
180 // Callback with a cached auth token (if available) or a fetched one.
181 void OnAccessTokenFetched(google_apis::DriveApiErrorCode code
,
182 const std::string
& access_token
);
185 // Implements the chrome.fileManagerPrivate.getShareUrl method.
186 class FileManagerPrivateGetShareUrlFunction
187 : public LoggedAsyncExtensionFunction
{
189 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getShareUrl",
190 FILEMANAGERPRIVATE_GETSHAREURL
)
193 ~FileManagerPrivateGetShareUrlFunction() override
{}
195 // AsyncExtensionFunction overrides.
196 bool RunAsync() override
;
198 // Callback with an url to the sharing dialog as |share_url|, called by
199 // FileSystem::GetShareUrl.
200 void OnGetShareUrl(drive::FileError error
, const GURL
& share_url
);
203 // Implements the chrome.fileManagerPrivate.requestDriveShare method.
204 class FileManagerPrivateRequestDriveShareFunction
205 : public LoggedAsyncExtensionFunction
{
207 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestDriveShare",
208 FILEMANAGERPRIVATE_REQUESTDRIVESHARE
);
211 ~FileManagerPrivateRequestDriveShareFunction() override
{}
212 bool RunAsync() override
;
215 // Called back after the drive file system operation is finished.
216 void OnAddPermission(drive::FileError error
);
219 // Implements the chrome.fileManagerPrivate.getDownloadUrl method.
220 class FileManagerPrivateGetDownloadUrlFunction
221 : public LoggedAsyncExtensionFunction
{
223 FileManagerPrivateGetDownloadUrlFunction();
225 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getDownloadUrl",
226 FILEMANAGERPRIVATE_GETDOWNLOADURL
)
229 ~FileManagerPrivateGetDownloadUrlFunction() override
;
231 // AsyncExtensionFunction overrides.
232 bool RunAsync() override
;
234 void OnGetResourceEntry(drive::FileError error
,
235 scoped_ptr
<drive::ResourceEntry
> entry
);
237 // Callback with an |access_token|, called by
238 // drive::DriveReadonlyTokenFetcher.
239 void OnTokenFetched(google_apis::DriveApiErrorCode code
,
240 const std::string
& access_token
);
243 std::string download_url_
;
244 scoped_ptr
<google_apis::AuthService
> auth_service_
;
247 } // namespace extensions
249 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_