private_api_drive.h revision f2477e01787aa58f445919b809d89e252beef54f
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. 6 7#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_ 8#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_ 9 10#include "chrome/browser/chromeos/drive/file_errors.h" 11#include "chrome/browser/chromeos/drive/file_system_interface.h" 12#include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h" 13 14namespace drive { 15class FileCacheEntry; 16class ResourceEntry; 17struct DriveAppInfo; 18struct SearchResultInfo; 19} 20 21namespace extensions { 22namespace api { 23namespace file_browser_private{ 24struct DriveEntryProperties; 25} 26} 27 28// Retrieves property information for an entry and returns it as a dictionary. 29// On error, returns a dictionary with the key "error" set to the error number 30// (drive::FileError). 31class FileBrowserPrivateGetDriveEntryPropertiesFunction 32 : public LoggedAsyncExtensionFunction { 33 public: 34 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getDriveEntryProperties", 35 FILEBROWSERPRIVATE_GETDRIVEFILEPROPERTIES) 36 37 FileBrowserPrivateGetDriveEntryPropertiesFunction(); 38 39 protected: 40 virtual ~FileBrowserPrivateGetDriveEntryPropertiesFunction(); 41 42 // AsyncExtensionFunction overrides. 43 virtual bool RunImpl() OVERRIDE; 44 45 private: 46 void OnGetFileInfo(drive::FileError error, 47 scoped_ptr<drive::ResourceEntry> entry); 48 49 void CacheStateReceived(bool success, 50 const drive::FileCacheEntry& cache_entry); 51 52 void CompleteGetFileProperties(drive::FileError error); 53 54 base::FilePath file_path_; 55 scoped_ptr<extensions::api::file_browser_private:: 56 DriveEntryProperties> properties_; 57}; 58 59// Implements the chrome.fileBrowserPrivate.pinDriveFile method. 60class FileBrowserPrivatePinDriveFileFunction 61 : public LoggedAsyncExtensionFunction { 62 public: 63 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.pinDriveFile", 64 FILEBROWSERPRIVATE_PINDRIVEFILE) 65 66 protected: 67 virtual ~FileBrowserPrivatePinDriveFileFunction() {} 68 69 // AsyncExtensionFunction overrides. 70 virtual bool RunImpl() OVERRIDE; 71 72 private: 73 // Callback for RunImpl(). 74 void OnPinStateSet(drive::FileError error); 75}; 76 77// Get drive files for the given list of file URLs. Initiate downloading of 78// drive files if these are not cached. Return a list of local file names. 79// This function puts empty strings instead of local paths for files could 80// not be obtained. For instance, this can happen if the user specifies a new 81// file name to save a file on drive. There may be other reasons to fail. The 82// file manager should check if the local paths returned from getDriveFiles() 83// contain empty paths. 84// TODO(satorux): Should we propagate error types to the JavaScript layer? 85class FileBrowserPrivateGetDriveFilesFunction 86 : public LoggedAsyncExtensionFunction { 87 public: 88 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getDriveFiles", 89 FILEBROWSERPRIVATE_GETDRIVEFILES) 90 91 FileBrowserPrivateGetDriveFilesFunction(); 92 93 protected: 94 virtual ~FileBrowserPrivateGetDriveFilesFunction(); 95 96 // AsyncExtensionFunction overrides. 97 virtual bool RunImpl() OVERRIDE; 98 99 private: 100 // Gets the file on the top of the |remaining_drive_paths_| or sends the 101 // response if the queue is empty. 102 void GetFileOrSendResponse(); 103 104 // Called by FileSystem::GetFile(). Pops the file from 105 // |remaining_drive_paths_|, and calls GetFileOrSendResponse(). 106 void OnFileReady(drive::FileError error, 107 const base::FilePath& local_path, 108 scoped_ptr<drive::ResourceEntry> entry); 109 110 std::queue<base::FilePath> remaining_drive_paths_; 111 std::vector<std::string> local_paths_; 112}; 113 114// Implements the chrome.fileBrowserPrivate.cancelFileTransfers method. 115class FileBrowserPrivateCancelFileTransfersFunction 116 : public LoggedAsyncExtensionFunction { 117 public: 118 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.cancelFileTransfers", 119 FILEBROWSERPRIVATE_CANCELFILETRANSFERS) 120 121 protected: 122 virtual ~FileBrowserPrivateCancelFileTransfersFunction() {} 123 124 // AsyncExtensionFunction overrides. 125 virtual bool RunImpl() OVERRIDE; 126}; 127 128class FileBrowserPrivateSearchDriveFunction 129 : public LoggedAsyncExtensionFunction { 130 public: 131 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.searchDrive", 132 FILEBROWSERPRIVATE_SEARCHDRIVE) 133 134 protected: 135 virtual ~FileBrowserPrivateSearchDriveFunction() {} 136 137 virtual bool RunImpl() OVERRIDE; 138 139 private: 140 // Callback for Search(). 141 void OnSearch(drive::FileError error, 142 const GURL& next_link, 143 scoped_ptr<std::vector<drive::SearchResultInfo> > result_paths); 144}; 145 146// Similar to FileBrowserPrivateSearchDriveFunction but this one is used for 147// searching drive metadata which is stored locally. 148class FileBrowserPrivateSearchDriveMetadataFunction 149 : public LoggedAsyncExtensionFunction { 150 public: 151 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.searchDriveMetadata", 152 FILEBROWSERPRIVATE_SEARCHDRIVEMETADATA) 153 154 protected: 155 virtual ~FileBrowserPrivateSearchDriveMetadataFunction() {} 156 157 virtual bool RunImpl() OVERRIDE; 158 159 private: 160 // Callback for SearchMetadata(); 161 void OnSearchMetadata(drive::FileError error, 162 scoped_ptr<drive::MetadataSearchResultVector> results); 163}; 164 165// Implements the chrome.fileBrowserPrivate.getDriveConnectionState method. 166class FileBrowserPrivateGetDriveConnectionStateFunction 167 : public ChromeSyncExtensionFunction { 168 public: 169 DECLARE_EXTENSION_FUNCTION( 170 "fileBrowserPrivate.getDriveConnectionState", 171 FILEBROWSERPRIVATE_GETDRIVECONNECTIONSTATE); 172 173 protected: 174 virtual ~FileBrowserPrivateGetDriveConnectionStateFunction() {} 175 176 virtual bool RunImpl() OVERRIDE; 177}; 178 179// Implements the chrome.fileBrowserPrivate.requestAccessToken method. 180class FileBrowserPrivateRequestAccessTokenFunction 181 : public LoggedAsyncExtensionFunction { 182 public: 183 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestAccessToken", 184 FILEBROWSERPRIVATE_REQUESTACCESSTOKEN) 185 186 protected: 187 virtual ~FileBrowserPrivateRequestAccessTokenFunction() {} 188 189 // AsyncExtensionFunction overrides. 190 virtual bool RunImpl() OVERRIDE; 191 192 // Callback with a cached auth token (if available) or a fetched one. 193 void OnAccessTokenFetched(google_apis::GDataErrorCode code, 194 const std::string& access_token); 195}; 196 197// Implements the chrome.fileBrowserPrivate.getShareUrl method. 198class FileBrowserPrivateGetShareUrlFunction 199 : public LoggedAsyncExtensionFunction { 200 public: 201 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getShareUrl", 202 FILEBROWSERPRIVATE_GETSHAREURL) 203 204 protected: 205 virtual ~FileBrowserPrivateGetShareUrlFunction() {} 206 207 // AsyncExtensionFunction overrides. 208 virtual bool RunImpl() OVERRIDE; 209 210 // Callback with an url to the sharing dialog as |share_url|, called by 211 // FileSystem::GetShareUrl. 212 void OnGetShareUrl(drive::FileError error, const GURL& share_url); 213}; 214 215} // namespace extensions 216 217#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_ 218