- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / extensions / file_manager / private_api_drive.h
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
14 namespace drive {
15 class FileCacheEntry;
16 class ResourceEntry;
17 struct DriveAppInfo;
18 struct SearchResultInfo;
19 }
20
21 namespace extensions {
22 namespace api {
23 namespace file_browser_private{
24 struct 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).
31 class 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.
60 class 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?
85 class 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.
115 class 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
128 class 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.
148 class 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 class FileBrowserPrivateClearDriveCacheFunction
166     : public LoggedAsyncExtensionFunction {
167  public:
168   DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.clearDriveCache",
169                              FILEBROWSERPRIVATE_CLEARDRIVECACHE)
170
171  protected:
172   virtual ~FileBrowserPrivateClearDriveCacheFunction() {}
173
174   virtual bool RunImpl() OVERRIDE;
175 };
176
177 // Implements the chrome.fileBrowserPrivate.getDriveConnectionState method.
178 class FileBrowserPrivateGetDriveConnectionStateFunction
179     : public ChromeSyncExtensionFunction {
180  public:
181   DECLARE_EXTENSION_FUNCTION(
182       "fileBrowserPrivate.getDriveConnectionState",
183       FILEBROWSERPRIVATE_GETDRIVECONNECTIONSTATE);
184
185  protected:
186   virtual ~FileBrowserPrivateGetDriveConnectionStateFunction() {}
187
188   virtual bool RunImpl() OVERRIDE;
189 };
190
191 // Implements the chrome.fileBrowserPrivate.requestAccessToken method.
192 class FileBrowserPrivateRequestAccessTokenFunction
193     : public LoggedAsyncExtensionFunction {
194  public:
195   DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestAccessToken",
196                              FILEBROWSERPRIVATE_REQUESTACCESSTOKEN)
197
198  protected:
199   virtual ~FileBrowserPrivateRequestAccessTokenFunction() {}
200
201   // AsyncExtensionFunction overrides.
202   virtual bool RunImpl() OVERRIDE;
203
204   // Callback with a cached auth token (if available) or a fetched one.
205   void OnAccessTokenFetched(google_apis::GDataErrorCode code,
206                             const std::string& access_token);
207 };
208
209 // Implements the chrome.fileBrowserPrivate.getShareUrl method.
210 class FileBrowserPrivateGetShareUrlFunction
211     : public LoggedAsyncExtensionFunction {
212  public:
213   DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getShareUrl",
214                              FILEBROWSERPRIVATE_GETSHAREURL)
215
216  protected:
217   virtual ~FileBrowserPrivateGetShareUrlFunction() {}
218
219   // AsyncExtensionFunction overrides.
220   virtual bool RunImpl() OVERRIDE;
221
222   // Callback with an url to the sharing dialog as |share_url|, called by
223   // FileSystem::GetShareUrl.
224   void OnGetShareUrl(drive::FileError error, const GURL& share_url);
225 };
226
227 }  // namespace extensions
228
229 #endif  // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_