OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 class GDataFileBase { | 30 class GDataFileBase { |
31 public: | 31 public: |
32 explicit GDataFileBase(GDataDirectory* parent); | 32 explicit GDataFileBase(GDataDirectory* parent); |
33 virtual ~GDataFileBase(); | 33 virtual ~GDataFileBase(); |
34 // Converts DocumentEntry into GDataFileBase. | 34 // Converts DocumentEntry into GDataFileBase. |
35 static GDataFileBase* FromDocumentEntry(GDataDirectory* parent, | 35 static GDataFileBase* FromDocumentEntry(GDataDirectory* parent, |
36 DocumentEntry* doc); | 36 DocumentEntry* doc); |
37 virtual GDataFile* AsGDataFile(); | 37 virtual GDataFile* AsGDataFile(); |
38 virtual GDataDirectory* AsGDataDirectory(); | 38 virtual GDataDirectory* AsGDataDirectory(); |
39 GDataDirectory* parent() { return parent_; } | 39 GDataDirectory* parent() { return parent_; } |
40 const GURL& content_url() const { return content_url_; } | |
41 const base::PlatformFileInfo& file_info() const { return file_info_; } | 40 const base::PlatformFileInfo& file_info() const { return file_info_; } |
42 const FilePath::StringType& file_name() const { return file_name_; } | 41 const FilePath::StringType& file_name() const { return file_name_; } |
43 const FilePath::StringType& original_file_name() const { | 42 const FilePath::StringType& original_file_name() const { |
44 return original_file_name_; | 43 return original_file_name_; |
45 } | 44 } |
46 void set_file_name(const FilePath::StringType& name) { file_name_ = name; } | 45 void set_file_name(const FilePath::StringType& name) { file_name_ = name; } |
| 46 |
| 47 // The content URL is used for downloading regular files as is. |
| 48 const GURL& content_url() const { return content_url_; } |
| 49 |
| 50 // The self URL is used for removing files and hosted documents. |
47 const GURL& self_url() const { return self_url_; } | 51 const GURL& self_url() const { return self_url_; } |
| 52 |
48 // Returns virtual file path representing this file system entry. This path | 53 // Returns virtual file path representing this file system entry. This path |
49 // corresponds to file path expected by public methods of GDataFileSyste | 54 // corresponds to file path expected by public methods of GDataFileSyste |
50 // class. | 55 // class. |
51 FilePath GetFilePath(); | 56 FilePath GetFilePath(); |
52 | 57 |
53 protected: | 58 protected: |
54 base::PlatformFileInfo file_info_; | 59 base::PlatformFileInfo file_info_; |
55 FilePath::StringType file_name_; | 60 FilePath::StringType file_name_; |
56 FilePath::StringType original_file_name_; | 61 FilePath::StringType original_file_name_; |
57 // Files with the same original name will be uniquely identified with this | 62 // Files with the same original name will be uniquely identified with this |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 ~FindFileParams(); | 235 ~FindFileParams(); |
231 | 236 |
232 const FilePath file_path; | 237 const FilePath file_path; |
233 const bool require_content; | 238 const bool require_content; |
234 const FilePath directory_path; | 239 const FilePath directory_path; |
235 const GURL feed_url; | 240 const GURL feed_url; |
236 const bool initial_feed; | 241 const bool initial_feed; |
237 const scoped_refptr<FindFileDelegate> delegate; | 242 const scoped_refptr<FindFileDelegate> delegate; |
238 }; | 243 }; |
239 | 244 |
| 245 // Used for file operations like removing files. |
240 typedef base::Callback<void(base::PlatformFileError error)> | 246 typedef base::Callback<void(base::PlatformFileError error)> |
241 FileOperationCallback; | 247 FileOperationCallback; |
242 | 248 |
| 249 // Used to get files from the file system. |
| 250 typedef base::Callback<void(base::PlatformFileError error, |
| 251 const FilePath& file_path)> |
| 252 GetFileCallback; |
| 253 |
243 // ProfileKeyedService override: | 254 // ProfileKeyedService override: |
244 virtual void Shutdown() OVERRIDE; | 255 virtual void Shutdown() OVERRIDE; |
245 | 256 |
246 // Authenticates the user by fetching the auth token as | 257 // Authenticates the user by fetching the auth token as |
247 // needed. |callback| will be run with the error code and the auth | 258 // needed. |callback| will be run with the error code and the auth |
248 // token, on the thread this function is run. | 259 // token, on the thread this function is run. |
249 // | 260 // |
250 // Must be called on UI thread. | 261 // Must be called on UI thread. |
251 void Authenticate(const AuthStatusCallback& callback); | 262 void Authenticate(const AuthStatusCallback& callback); |
252 | 263 |
(...skipping 24 matching lines...) Expand all Loading... |
277 // an error is raised in case a directory is already present at the | 288 // an error is raised in case a directory is already present at the |
278 // |directory_path|. If |is_recursive| is true, the call creates parent | 289 // |directory_path|. If |is_recursive| is true, the call creates parent |
279 // directories as needed just like mkdir -p does. | 290 // directories as needed just like mkdir -p does. |
280 // | 291 // |
281 // Can be called from any thread. |callback| is run on the calling thread. | 292 // Can be called from any thread. |callback| is run on the calling thread. |
282 void CreateDirectory(const FilePath& directory_path, | 293 void CreateDirectory(const FilePath& directory_path, |
283 bool is_exclusive, | 294 bool is_exclusive, |
284 bool is_recursive, | 295 bool is_recursive, |
285 const FileOperationCallback& callback); | 296 const FileOperationCallback& callback); |
286 | 297 |
287 // Initiates directory feed fetching operation and continues previously | 298 // Gets |file_path| from the file system. The file entry represented by |
| 299 // |file_path| needs to be present in in-memory representation of the file |
| 300 // system in order to be retrieved. If the file is not cached, the file |
| 301 // will be downloaded through gdata api. |
| 302 // |
| 303 // Can be called from any thread. |callback| is run on the calling thread. |
| 304 void GetFile(const FilePath& file_path, const GetFileCallback& callback); |
| 305 |
288 // initiated FindFileByPath() attempt upon its completion. Safe to be called | 306 // initiated FindFileByPath() attempt upon its completion. Safe to be called |
289 // from any thread. Internally, it will route content refresh request to | 307 // from any thread. Internally, it will route content refresh request to |
290 // DocumentsService::GetDocuments() which will initiated content | 308 // DocumentsService::GetDocuments() which will initiated content |
291 // fetching from UI thread as required by gdata library (UrlFetcher). | 309 // fetching from UI thread as required by gdata library (UrlFetcher). |
292 // | 310 // |
293 // Can be called from any thread. | 311 // Can be called from any thread. |
294 void StartDirectoryRefresh(const FindFileParams& params); | 312 void StartDirectoryRefresh(const FindFileParams& params); |
295 | 313 |
| 314 // Finds file object by |file_path| and returns the file info. |
| 315 // Returns NULL if it does not find the file. |
| 316 GDataFileBase* GetGDataFileInfoFromPath(const FilePath& file_path); |
| 317 |
296 private: | 318 private: |
297 friend class GDataFileSystemFactory; | 319 friend class GDataFileSystemFactory; |
298 friend class GDataFileSystemTest; | 320 friend class GDataFileSystemTest; |
299 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, | 321 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, |
300 FindFirstMissingParentDirectory); | 322 FindFirstMissingParentDirectory); |
301 | 323 |
302 // Defines possible search results of FindFirstMissingParentDirectory(). | 324 // Defines possible search results of FindFirstMissingParentDirectory(). |
303 enum FindMissingDirectoryResult { | 325 enum FindMissingDirectoryResult { |
304 // Target directory found, it's not a directory. | 326 // Target directory found, it's not a directory. |
305 FOUND_INVALID, | 327 FOUND_INVALID, |
(...skipping 22 matching lines...) Expand all Loading... |
328 scoped_refptr<base::MessageLoopProxy> proxy; | 350 scoped_refptr<base::MessageLoopProxy> proxy; |
329 }; | 351 }; |
330 | 352 |
331 explicit GDataFileSystem(Profile* profile); | 353 explicit GDataFileSystem(Profile* profile); |
332 virtual ~GDataFileSystem(); | 354 virtual ~GDataFileSystem(); |
333 | 355 |
334 // Unsafe (unlocked) version of the function above. | 356 // Unsafe (unlocked) version of the function above. |
335 void UnsafeFindFileByPath(const FilePath& file_path, | 357 void UnsafeFindFileByPath(const FilePath& file_path, |
336 scoped_refptr<FindFileDelegate> delegate); | 358 scoped_refptr<FindFileDelegate> delegate); |
337 | 359 |
338 // Finds file object by |file_path| and returns its gdata self-url. | |
339 // Returns empty GURL if it does not find the file. | |
340 GURL GetDocumentUrlFromPath(const FilePath& file_path); | |
341 | |
342 // Converts document feed from gdata service into DirectoryInfo. On failure, | 360 // Converts document feed from gdata service into DirectoryInfo. On failure, |
343 // returns NULL and fills in |error| with an appropriate value. | 361 // returns NULL and fills in |error| with an appropriate value. |
344 GDataDirectory* ParseGDataFeed(GDataErrorCode status, | 362 GDataDirectory* ParseGDataFeed(GDataErrorCode status, |
345 base::Value* data, | 363 base::Value* data, |
346 base::PlatformFileError *error); | 364 base::PlatformFileError *error); |
347 | 365 |
348 // Callback for handling feed content fetching while searching for file info. | 366 // Callback for handling feed content fetching while searching for file info. |
349 // This callback is invoked after async feed fetch operation that was | 367 // This callback is invoked after async feed fetch operation that was |
350 // invoked by StartDirectoryRefresh() completes. This callback will update | 368 // invoked by StartDirectoryRefresh() completes. This callback will update |
351 // the content of the refreshed directory object and continue initially | 369 // the content of the refreshed directory object and continue initially |
(...skipping 10 matching lines...) Expand all Loading... |
362 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 380 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
363 GDataErrorCode status, | 381 GDataErrorCode status, |
364 const GURL& document_url); | 382 const GURL& document_url); |
365 | 383 |
366 // Callback for handling directory create requests. | 384 // Callback for handling directory create requests. |
367 void OnCreateDirectoryCompleted( | 385 void OnCreateDirectoryCompleted( |
368 const CreateDirectoryParams& params, | 386 const CreateDirectoryParams& params, |
369 GDataErrorCode status, | 387 GDataErrorCode status, |
370 base::Value* created_entry); | 388 base::Value* created_entry); |
371 | 389 |
| 390 // Callback for handling file downloading requests. |
| 391 void OnFileDownloaded( |
| 392 const GetFileCallback& callback, |
| 393 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 394 GDataErrorCode status, |
| 395 const GURL& content_url, |
| 396 const FilePath& temp_file); |
| 397 |
372 // Removes file under |file_path| from in-memory snapshot of the file system. | 398 // Removes file under |file_path| from in-memory snapshot of the file system. |
373 // Return PLATFORM_FILE_OK if successful. | 399 // Return PLATFORM_FILE_OK if successful. |
374 base::PlatformFileError RemoveFileFromFileSystem(const FilePath& file_path); | 400 base::PlatformFileError RemoveFileFromFileSystem(const FilePath& file_path); |
375 | 401 |
376 // Updates content of the directory identified with |directory_path|. If the | 402 // Updates content of the directory identified with |directory_path|. If the |
377 // feed was not complete, it will return URL for the remaining portion in | 403 // feed was not complete, it will return URL for the remaining portion in |
378 // |next_feed|. On success, returns PLATFORM_FILE_OK. | 404 // |next_feed|. On success, returns PLATFORM_FILE_OK. |
379 base::PlatformFileError UpdateDirectoryWithDocumentFeed( | 405 base::PlatformFileError UpdateDirectoryWithDocumentFeed( |
380 const FilePath& directory_path, | 406 const FilePath& directory_path, |
381 const GURL& feed_url, | 407 const GURL& feed_url, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 virtual ~GDataFileSystemFactory(); | 462 virtual ~GDataFileSystemFactory(); |
437 | 463 |
438 // ProfileKeyedServiceFactory: | 464 // ProfileKeyedServiceFactory: |
439 virtual ProfileKeyedService* BuildServiceInstanceFor( | 465 virtual ProfileKeyedService* BuildServiceInstanceFor( |
440 Profile* profile) const OVERRIDE; | 466 Profile* profile) const OVERRIDE; |
441 }; | 467 }; |
442 | 468 |
443 } // namespace gdata | 469 } // namespace gdata |
444 | 470 |
445 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 471 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
OLD | NEW |