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_
10 #include "base/files/file.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/chromeos/drive/file_errors.h"
13 #include "chrome/browser/chromeos/drive/file_system_interface.h"
14 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
15 #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
20 struct SearchResultInfo;
23 namespace google_apis {
27 namespace extensions {
30 namespace file_manager_private {
31 struct EntryProperties;
32 } // namespace file_manager_private
35 // Retrieves property information for an entry and returns it as a dictionary.
36 // On error, returns a dictionary with the key "error" set to the error number
37 // (base::File::Error).
38 class FileManagerPrivateGetEntryPropertiesFunction
39 : public LoggedAsyncExtensionFunction {
41 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getEntryProperties",
42 FILEMANAGERPRIVATE_GETENTRYPROPERTIES)
44 FileManagerPrivateGetEntryPropertiesFunction();
47 virtual ~FileManagerPrivateGetEntryPropertiesFunction();
49 // AsyncExtensionFunction overrides.
50 virtual bool RunAsync() OVERRIDE;
53 void CompleteGetEntryProperties(
55 scoped_ptr<api::file_manager_private::EntryProperties> properties,
56 base::File::Error error);
58 size_t processed_count_;
59 std::vector<linked_ptr<api::file_manager_private::EntryProperties> >
63 // Implements the chrome.fileManagerPrivate.pinDriveFile method.
64 class FileManagerPrivatePinDriveFileFunction
65 : public LoggedAsyncExtensionFunction {
67 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.pinDriveFile",
68 FILEMANAGERPRIVATE_PINDRIVEFILE)
71 virtual ~FileManagerPrivatePinDriveFileFunction() {}
73 // AsyncExtensionFunction overrides.
74 virtual bool RunAsync() OVERRIDE;
77 // Callback for RunAsync().
78 void OnPinStateSet(drive::FileError error);
81 // Implements the chrome.fileManagerPrivate.cancelFileTransfers method.
82 class FileManagerPrivateCancelFileTransfersFunction
83 : public LoggedAsyncExtensionFunction {
85 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelFileTransfers",
86 FILEMANAGERPRIVATE_CANCELFILETRANSFERS)
89 virtual ~FileManagerPrivateCancelFileTransfersFunction() {}
91 // AsyncExtensionFunction overrides.
92 virtual bool RunAsync() OVERRIDE;
95 class FileManagerPrivateSearchDriveFunction
96 : public LoggedAsyncExtensionFunction {
98 typedef std::vector<drive::SearchResultInfo> SearchResultInfoList;
100 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchDrive",
101 FILEMANAGERPRIVATE_SEARCHDRIVE)
104 virtual ~FileManagerPrivateSearchDriveFunction() {}
106 virtual bool RunAsync() OVERRIDE;
109 // Callback for Search().
110 void OnSearch(drive::FileError error,
111 const GURL& next_link,
112 scoped_ptr<std::vector<drive::SearchResultInfo> > result_paths);
114 // Called when |result_paths| in OnSearch() are converted to a list of
115 // entry definitions.
116 void OnEntryDefinitionList(
117 const GURL& next_link,
118 scoped_ptr<SearchResultInfoList> search_result_info_list,
119 scoped_ptr<file_manager::util::EntryDefinitionList>
120 entry_definition_list);
123 // Similar to FileManagerPrivateSearchDriveFunction but this one is used for
124 // searching drive metadata which is stored locally.
125 class FileManagerPrivateSearchDriveMetadataFunction
126 : public LoggedAsyncExtensionFunction {
128 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchDriveMetadata",
129 FILEMANAGERPRIVATE_SEARCHDRIVEMETADATA)
132 virtual ~FileManagerPrivateSearchDriveMetadataFunction() {}
134 virtual bool RunAsync() OVERRIDE;
137 // Callback for SearchMetadata();
138 void OnSearchMetadata(drive::FileError error,
139 scoped_ptr<drive::MetadataSearchResultVector> results);
141 // Called when |results| in OnSearchMetadata() are converted to a list of
142 // entry definitions.
143 void OnEntryDefinitionList(
144 scoped_ptr<drive::MetadataSearchResultVector> search_result_info_list,
145 scoped_ptr<file_manager::util::EntryDefinitionList>
146 entry_definition_list);
149 // Implements the chrome.fileManagerPrivate.getDriveConnectionState method.
150 class FileManagerPrivateGetDriveConnectionStateFunction
151 : public ChromeSyncExtensionFunction {
153 DECLARE_EXTENSION_FUNCTION(
154 "fileManagerPrivate.getDriveConnectionState",
155 FILEMANAGERPRIVATE_GETDRIVECONNECTIONSTATE);
158 virtual ~FileManagerPrivateGetDriveConnectionStateFunction() {}
160 virtual bool RunSync() OVERRIDE;
163 // Implements the chrome.fileManagerPrivate.requestAccessToken method.
164 class FileManagerPrivateRequestAccessTokenFunction
165 : public LoggedAsyncExtensionFunction {
167 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestAccessToken",
168 FILEMANAGERPRIVATE_REQUESTACCESSTOKEN)
171 virtual ~FileManagerPrivateRequestAccessTokenFunction() {}
173 // AsyncExtensionFunction overrides.
174 virtual bool RunAsync() OVERRIDE;
176 // Callback with a cached auth token (if available) or a fetched one.
177 void OnAccessTokenFetched(google_apis::GDataErrorCode code,
178 const std::string& access_token);
181 // Implements the chrome.fileManagerPrivate.getShareUrl method.
182 class FileManagerPrivateGetShareUrlFunction
183 : public LoggedAsyncExtensionFunction {
185 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getShareUrl",
186 FILEMANAGERPRIVATE_GETSHAREURL)
189 virtual ~FileManagerPrivateGetShareUrlFunction() {}
191 // AsyncExtensionFunction overrides.
192 virtual bool RunAsync() OVERRIDE;
194 // Callback with an url to the sharing dialog as |share_url|, called by
195 // FileSystem::GetShareUrl.
196 void OnGetShareUrl(drive::FileError error, const GURL& share_url);
199 // Implements the chrome.fileManagerPrivate.requestDriveShare method.
200 class FileManagerPrivateRequestDriveShareFunction
201 : public LoggedAsyncExtensionFunction {
203 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestDriveShare",
204 FILEMANAGERPRIVATE_REQUESTDRIVESHARE);
207 virtual ~FileManagerPrivateRequestDriveShareFunction() {}
208 virtual bool RunAsync() OVERRIDE;
211 // Called back after the drive file system operation is finished.
212 void OnAddPermission(drive::FileError error);
215 // Implements the chrome.fileManagerPrivate.getDownloadUrl method.
216 class FileManagerPrivateGetDownloadUrlFunction
217 : public LoggedAsyncExtensionFunction {
219 FileManagerPrivateGetDownloadUrlFunction();
221 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getDownloadUrl",
222 FILEMANAGERPRIVATE_GETDOWNLOADURL)
225 virtual ~FileManagerPrivateGetDownloadUrlFunction();
227 // AsyncExtensionFunction overrides.
228 virtual bool RunAsync() OVERRIDE;
230 void OnGetResourceEntry(drive::FileError error,
231 scoped_ptr<drive::ResourceEntry> entry);
233 // Callback with an |access_token|, called by
234 // drive::DriveReadonlyTokenFetcher.
235 void OnTokenFetched(google_apis::GDataErrorCode code,
236 const std::string& access_token);
239 std::string download_url_;
240 scoped_ptr<google_apis::AuthService> auth_service_;
243 } // namespace extensions
245 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_