// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // // This file provides Drive specific API functions. #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_ #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_ #include #include #include #include "base/files/file.h" #include "base/memory/scoped_ptr.h" #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h" #include "chrome/browser/chromeos/file_manager/fileapi_util.h" #include "components/drive/file_errors.h" #include "components/drive/file_system_interface.h" namespace drive { class FileCacheEntry; class ResourceEntry; struct SearchResultInfo; } namespace google_apis { class AuthService; } namespace extensions { namespace api { namespace file_manager_private { struct EntryProperties; } // namespace file_manager_private } // namespace api // Retrieves property information for an entry and returns it as a dictionary. // On error, returns a dictionary with the key "error" set to the error number // (base::File::Error). class FileManagerPrivateInternalGetEntryPropertiesFunction : public LoggedAsyncExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getEntryProperties", FILEMANAGERPRIVATEINTERNAL_GETENTRYPROPERTIES) FileManagerPrivateInternalGetEntryPropertiesFunction(); protected: ~FileManagerPrivateInternalGetEntryPropertiesFunction() override; // AsyncExtensionFunction overrides. bool RunAsync() override; private: void CompleteGetEntryProperties( size_t index, const storage::FileSystemURL& url, scoped_ptr properties, base::File::Error error); size_t processed_count_; std::vector > properties_list_; }; // Implements the chrome.fileManagerPrivate.pinDriveFile method. class FileManagerPrivateInternalPinDriveFileFunction : public LoggedAsyncExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.pinDriveFile", FILEMANAGERPRIVATEINTERNAL_PINDRIVEFILE) protected: ~FileManagerPrivateInternalPinDriveFileFunction() override {} // AsyncExtensionFunction overrides. bool RunAsync() override; private: // Callback for RunAsync(). void OnPinStateSet(drive::FileError error); }; // Implements the chrome.fileManagerPrivate.cancelFileTransfers method. class FileManagerPrivateInternalCancelFileTransfersFunction : public LoggedAsyncExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.cancelFileTransfers", FILEMANAGERPRIVATEINTERNAL_CANCELFILETRANSFERS) protected: ~FileManagerPrivateInternalCancelFileTransfersFunction() override {} // AsyncExtensionFunction overrides. bool RunAsync() override; }; // Implements the chrome.fileManagerPrivate.cancelAllFileTransfers method. class FileManagerPrivateCancelAllFileTransfersFunction : public LoggedAsyncExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelAllFileTransfers", FILEMANAGERPRIVATE_CANCELALLFILETRANSFERS) protected: ~FileManagerPrivateCancelAllFileTransfersFunction() override {} // AsyncExtensionFunction overrides. bool RunAsync() override; }; class FileManagerPrivateSearchDriveFunction : public LoggedAsyncExtensionFunction { public: typedef std::vector SearchResultInfoList; DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchDrive", FILEMANAGERPRIVATE_SEARCHDRIVE) protected: ~FileManagerPrivateSearchDriveFunction() override {} bool RunAsync() override; private: // Callback for Search(). void OnSearch(drive::FileError error, const GURL& next_link, scoped_ptr > result_paths); // Called when |result_paths| in OnSearch() are converted to a list of // entry definitions. void OnEntryDefinitionList( const GURL& next_link, scoped_ptr search_result_info_list, scoped_ptr entry_definition_list); }; // Similar to FileManagerPrivateSearchDriveFunction but this one is used for // searching drive metadata which is stored locally. class FileManagerPrivateSearchDriveMetadataFunction : public LoggedAsyncExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchDriveMetadata", FILEMANAGERPRIVATE_SEARCHDRIVEMETADATA) protected: ~FileManagerPrivateSearchDriveMetadataFunction() override {} bool RunAsync() override; private: // Callback for SearchMetadata(); void OnSearchMetadata(drive::FileError error, scoped_ptr results); // Called when |results| in OnSearchMetadata() are converted to a list of // entry definitions. void OnEntryDefinitionList( scoped_ptr search_result_info_list, scoped_ptr entry_definition_list); }; // Implements the chrome.fileManagerPrivate.getDriveConnectionState method. class FileManagerPrivateGetDriveConnectionStateFunction : public ChromeSyncExtensionFunction { public: DECLARE_EXTENSION_FUNCTION( "fileManagerPrivate.getDriveConnectionState", FILEMANAGERPRIVATE_GETDRIVECONNECTIONSTATE); protected: ~FileManagerPrivateGetDriveConnectionStateFunction() override {} bool RunSync() override; }; // Implements the chrome.fileManagerPrivate.requestAccessToken method. class FileManagerPrivateRequestAccessTokenFunction : public LoggedAsyncExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestAccessToken", FILEMANAGERPRIVATE_REQUESTACCESSTOKEN) protected: ~FileManagerPrivateRequestAccessTokenFunction() override {} // AsyncExtensionFunction overrides. bool RunAsync() override; // Callback with a cached auth token (if available) or a fetched one. void OnAccessTokenFetched(google_apis::DriveApiErrorCode code, const std::string& access_token); }; // Implements the chrome.fileManagerPrivate.getShareUrl method. class FileManagerPrivateInternalGetShareUrlFunction : public LoggedAsyncExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getShareUrl", FILEMANAGERPRIVATEINTERNAL_GETSHAREURL) protected: ~FileManagerPrivateInternalGetShareUrlFunction() override {} // AsyncExtensionFunction overrides. bool RunAsync() override; // Callback with an url to the sharing dialog as |share_url|, called by // FileSystem::GetShareUrl. void OnGetShareUrl(drive::FileError error, const GURL& share_url); }; // Implements the chrome.fileManagerPrivate.requestDriveShare method. class FileManagerPrivateInternalRequestDriveShareFunction : public LoggedAsyncExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.requestDriveShare", FILEMANAGERPRIVATEINTERNAL_REQUESTDRIVESHARE); protected: ~FileManagerPrivateInternalRequestDriveShareFunction() override {} bool RunAsync() override; private: // Called back after the drive file system operation is finished. void OnAddPermission(drive::FileError error); }; // Implements the chrome.fileManagerPrivate.getDownloadUrl method. class FileManagerPrivateInternalGetDownloadUrlFunction : public LoggedAsyncExtensionFunction { public: FileManagerPrivateInternalGetDownloadUrlFunction(); DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getDownloadUrl", FILEMANAGERPRIVATEINTERNAL_GETDOWNLOADURL) protected: ~FileManagerPrivateInternalGetDownloadUrlFunction() override; // AsyncExtensionFunction overrides. bool RunAsync() override; void OnGetResourceEntry(drive::FileError error, scoped_ptr entry); // Callback with an |access_token|, called by // drive::DriveReadonlyTokenFetcher. void OnTokenFetched(google_apis::DriveApiErrorCode code, const std::string& access_token); private: GURL download_url_; scoped_ptr auth_service_; }; } // namespace extensions #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_