private_api_drive.h revision 58537e28ecd584eab876aee8be7156509866d23a
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 {
22
23// Retrieves property information for an entry and returns it as a dictionary.
24// On error, returns a dictionary with the key "error" set to the error number
25// (drive::FileError).
26class FileBrowserPrivateGetDriveEntryPropertiesFunction
27    : public LoggedAsyncExtensionFunction {
28 public:
29  DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getDriveEntryProperties",
30                             FILEBROWSERPRIVATE_GETDRIVEFILEPROPERTIES)
31
32  FileBrowserPrivateGetDriveEntryPropertiesFunction();
33
34 protected:
35  virtual ~FileBrowserPrivateGetDriveEntryPropertiesFunction();
36
37  // AsyncExtensionFunction overrides.
38  virtual bool RunImpl() OVERRIDE;
39
40 private:
41  void OnGetFileInfo(drive::FileError error,
42                     scoped_ptr<drive::ResourceEntry> entry);
43
44  void CacheStateReceived(bool success,
45                          const drive::FileCacheEntry& cache_entry);
46
47  void CompleteGetFileProperties(drive::FileError error);
48
49  base::FilePath file_path_;
50  scoped_ptr<base::DictionaryValue> properties_;
51};
52
53// Implements the chrome.fileBrowserPrivate.pinDriveFile method.
54class FileBrowserPrivatePinDriveFileFunction
55    : public LoggedAsyncExtensionFunction {
56 public:
57  DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.pinDriveFile",
58                             FILEBROWSERPRIVATE_PINDRIVEFILE)
59
60  FileBrowserPrivatePinDriveFileFunction();
61
62 protected:
63  virtual ~FileBrowserPrivatePinDriveFileFunction();
64
65  // AsyncExtensionFunction overrides.
66  virtual bool RunImpl() OVERRIDE;
67
68 private:
69  // Callback for RunImpl().
70  void OnPinStateSet(drive::FileError error);
71};
72
73// Get drive files for the given list of file URLs. Initiate downloading of
74// drive files if these are not cached. Return a list of local file names.
75// This function puts empty strings instead of local paths for files could
76// not be obtained. For instance, this can happen if the user specifies a new
77// file name to save a file on drive. There may be other reasons to fail. The
78// file manager should check if the local paths returned from getDriveFiles()
79// contain empty paths.
80// TODO(satorux): Should we propagate error types to the JavaScript layer?
81class FileBrowserPrivateGetDriveFilesFunction
82    : public LoggedAsyncExtensionFunction {
83 public:
84  DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getDriveFiles",
85                             FILEBROWSERPRIVATE_GETDRIVEFILES)
86
87  FileBrowserPrivateGetDriveFilesFunction();
88
89 protected:
90  virtual ~FileBrowserPrivateGetDriveFilesFunction();
91
92  // AsyncExtensionFunction overrides.
93  virtual bool RunImpl() OVERRIDE;
94
95 private:
96  // Gets the file on the top of the |remaining_drive_paths_| or sends the
97  // response if the queue is empty.
98  void GetFileOrSendResponse();
99
100  // Called by FileSystem::GetFile(). Pops the file from
101  // |remaining_drive_paths_|, and calls GetFileOrSendResponse().
102  void OnFileReady(drive::FileError error,
103                   const base::FilePath& local_path,
104                   scoped_ptr<drive::ResourceEntry> entry);
105
106  std::queue<base::FilePath> remaining_drive_paths_;
107  ListValue* local_paths_;
108};
109
110// Implements the chrome.fileBrowserPrivate.cancelFileTransfers method.
111class FileBrowserPrivateCancelFileTransfersFunction
112    : public LoggedAsyncExtensionFunction {
113 public:
114  DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.cancelFileTransfers",
115                             FILEBROWSERPRIVATE_CANCELFILETRANSFERS)
116
117  FileBrowserPrivateCancelFileTransfersFunction();
118
119 protected:
120  virtual ~FileBrowserPrivateCancelFileTransfersFunction();
121
122  // AsyncExtensionFunction overrides.
123  virtual bool RunImpl() OVERRIDE;
124};
125
126class FileBrowserPrivateSearchDriveFunction
127    : public LoggedAsyncExtensionFunction {
128 public:
129  DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.searchDrive",
130                             FILEBROWSERPRIVATE_SEARCHDRIVE)
131
132  FileBrowserPrivateSearchDriveFunction();
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  FileBrowserPrivateSearchDriveMetadataFunction();
155
156 protected:
157  virtual ~FileBrowserPrivateSearchDriveMetadataFunction();
158
159  virtual bool RunImpl() OVERRIDE;
160
161 private:
162  // Callback for SearchMetadata();
163  void OnSearchMetadata(drive::FileError error,
164                        scoped_ptr<drive::MetadataSearchResultVector> results);
165};
166
167class FileBrowserPrivateClearDriveCacheFunction
168    : public LoggedAsyncExtensionFunction {
169 public:
170  DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.clearDriveCache",
171                             FILEBROWSERPRIVATE_CLEARDRIVECACHE)
172
173  FileBrowserPrivateClearDriveCacheFunction();
174
175 protected:
176  virtual ~FileBrowserPrivateClearDriveCacheFunction();
177
178  virtual bool RunImpl() OVERRIDE;
179};
180
181// Implements the chrome.fileBrowserPrivate.getDriveConnectionState method.
182class FileBrowserPrivateGetDriveConnectionStateFunction
183    : public SyncExtensionFunction {
184 public:
185  DECLARE_EXTENSION_FUNCTION(
186      "fileBrowserPrivate.getDriveConnectionState",
187      FILEBROWSERPRIVATE_GETDRIVECONNECTIONSTATE);
188
189  FileBrowserPrivateGetDriveConnectionStateFunction();
190
191 protected:
192  virtual ~FileBrowserPrivateGetDriveConnectionStateFunction();
193
194  virtual bool RunImpl() OVERRIDE;
195};
196
197// Implements the chrome.fileBrowserPrivate.requestAccessToken method.
198class FileBrowserPrivateRequestAccessTokenFunction
199    : public LoggedAsyncExtensionFunction {
200 public:
201  DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestAccessToken",
202                             FILEBROWSERPRIVATE_REQUESTACCESSTOKEN)
203
204  FileBrowserPrivateRequestAccessTokenFunction();
205
206 protected:
207  virtual ~FileBrowserPrivateRequestAccessTokenFunction();
208
209  // AsyncExtensionFunction overrides.
210  virtual bool RunImpl() OVERRIDE;
211
212  // Callback with a cached auth token (if available) or a fetched one.
213  void OnAccessTokenFetched(google_apis::GDataErrorCode code,
214                            const std::string& access_token);
215};
216
217// Implements the chrome.fileBrowserPrivate.getShareUrl method.
218class FileBrowserPrivateGetShareUrlFunction
219    : public LoggedAsyncExtensionFunction {
220 public:
221  DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getShareUrl",
222                             FILEBROWSERPRIVATE_GETSHAREURL)
223
224  FileBrowserPrivateGetShareUrlFunction();
225
226 protected:
227  virtual ~FileBrowserPrivateGetShareUrlFunction();
228
229  // AsyncExtensionFunction overrides.
230  virtual bool RunImpl() OVERRIDE;
231
232  // Callback with an url to the sharing dialog as |share_url|, called by
233  // FileSystem::GetShareUrl.
234  void OnGetShareUrl(drive::FileError error, const GURL& share_url);
235};
236
237}  // namespace extensions
238
239#endif  // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_
240