| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
| 20 #include "base/platform_file.h" | 20 #include "base/platform_file.h" |
| 21 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
| 22 #include "chrome/browser/chromeos/gdata/find_entry_delegate.h" |
| 22 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" | 23 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" |
| 23 #include "chrome/browser/chromeos/gdata/gdata_files.h" | 24 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
| 24 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" | 25 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" |
| 25 #include "chrome/browser/chromeos/gdata/gdata_params.h" | 26 #include "chrome/browser/chromeos/gdata/gdata_params.h" |
| 26 #include "chrome/browser/chromeos/gdata/gdata_parser.h" | 27 #include "chrome/browser/chromeos/gdata/gdata_parser.h" |
| 27 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" | 28 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" |
| 28 #include "chrome/browser/prefs/pref_change_registrar.h" | 29 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 29 #include "chrome/browser/profiles/profile_keyed_service.h" | 30 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 30 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 31 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
| 31 #include "content/public/browser/notification_observer.h" | 32 #include "content/public/browser/notification_observer.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 52 const std::string& resource_id, | 53 const std::string& resource_id, |
| 53 const std::string& md5)> CacheOperationCallback; | 54 const std::string& md5)> CacheOperationCallback; |
| 54 | 55 |
| 55 // Callback for GetFileFromCache. | 56 // Callback for GetFileFromCache. |
| 56 typedef base::Callback<void(base::PlatformFileError error, | 57 typedef base::Callback<void(base::PlatformFileError error, |
| 57 const std::string& resource_id, | 58 const std::string& resource_id, |
| 58 const std::string& md5, | 59 const std::string& md5, |
| 59 const FilePath& cache_file_path)> | 60 const FilePath& cache_file_path)> |
| 60 GetFileFromCacheCallback; | 61 GetFileFromCacheCallback; |
| 61 | 62 |
| 62 // Used to get result of file search. Please note that |file| is a live | |
| 63 // object provided to this callback under lock. It must not be used outside | |
| 64 // of the callback method. This callback can be invoked on different thread | |
| 65 // than one that started FileFileByPath() request. | |
| 66 typedef base::Callback<void(base::PlatformFileError error, | |
| 67 const FilePath& directory_path, | |
| 68 GDataEntry* entry)> | |
| 69 FindEntryCallback; | |
| 70 | |
| 71 // Used to get files from the file system. | 63 // Used to get files from the file system. |
| 72 typedef base::Callback<void(base::PlatformFileError error, | 64 typedef base::Callback<void(base::PlatformFileError error, |
| 73 const FilePath& file_path, | 65 const FilePath& file_path, |
| 74 const std::string& mime_type, | 66 const std::string& mime_type, |
| 75 GDataFileType file_type)> | 67 GDataFileType file_type)> |
| 76 GetFileCallback; | 68 GetFileCallback; |
| 77 | 69 |
| 78 // Callback for SetMountedState. | 70 // Callback for SetMountedState. |
| 79 typedef base::Callback<void(base::PlatformFileError error, | 71 typedef base::Callback<void(base::PlatformFileError error, |
| 80 const FilePath& file_path)> | 72 const FilePath& file_path)> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 98 | 90 |
| 99 // Used by GDataFileSystem::GetDocumentResourceIdOnIOThreadPool to return | 91 // Used by GDataFileSystem::GetDocumentResourceIdOnIOThreadPool to return |
| 100 // the resource ID read from a document JSON file on the local file system. | 92 // the resource ID read from a document JSON file on the local file system. |
| 101 typedef base::Callback<void(const std::string& resource_id)> | 93 typedef base::Callback<void(const std::string& resource_id)> |
| 102 GetDocumentResourceIdCallback; | 94 GetDocumentResourceIdCallback; |
| 103 | 95 |
| 104 // Callback for GetCacheState operation. | 96 // Callback for GetCacheState operation. |
| 105 typedef base::Callback<void(base::PlatformFileError error, | 97 typedef base::Callback<void(base::PlatformFileError error, |
| 106 int cache_state)> GetCacheStateCallback; | 98 int cache_state)> GetCacheStateCallback; |
| 107 | 99 |
| 108 // Delegate class used to deal with results synchronous read-only search | |
| 109 // over virtual file system. | |
| 110 class FindEntryDelegate { | |
| 111 public: | |
| 112 virtual ~FindEntryDelegate(); | |
| 113 | |
| 114 // Called when FindEntryByPathSync() completes search. | |
| 115 virtual void OnDone(base::PlatformFileError error, | |
| 116 const FilePath& directory_path, | |
| 117 GDataEntry* entry) = 0; | |
| 118 }; | |
| 119 | |
| 120 // Delegate used to find a directory element for file system updates. | |
| 121 class ReadOnlyFindEntryDelegate : public FindEntryDelegate { | |
| 122 public: | |
| 123 ReadOnlyFindEntryDelegate(); | |
| 124 | |
| 125 // Returns found entry. | |
| 126 GDataEntry* entry() { return entry_; } | |
| 127 | |
| 128 private: | |
| 129 // FindEntryDelegate overrides. | |
| 130 virtual void OnDone(base::PlatformFileError error, | |
| 131 const FilePath& directory_path, | |
| 132 GDataEntry* entry) OVERRIDE; | |
| 133 | |
| 134 // Entry that was found. | |
| 135 GDataEntry* entry_; | |
| 136 }; | |
| 137 | |
| 138 // Helper structure used for extracting key properties from GDataFile object. | 100 // Helper structure used for extracting key properties from GDataFile object. |
| 139 struct GDataFileProperties { | 101 struct GDataFileProperties { |
| 140 GDataFileProperties(); | 102 GDataFileProperties(); |
| 141 ~GDataFileProperties(); | 103 ~GDataFileProperties(); |
| 142 | 104 |
| 143 base::PlatformFileInfo file_info; | 105 base::PlatformFileInfo file_info; |
| 144 std::string resource_id; | 106 std::string resource_id; |
| 145 std::string file_md5; | 107 std::string file_md5; |
| 146 std::string mime_type; | 108 std::string mime_type; |
| 147 GURL content_url; | 109 GURL content_url; |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 const FilePath& destination_directory, | 555 const FilePath& destination_directory, |
| 594 const FilePath& virtual_path, | 556 const FilePath& virtual_path, |
| 595 const InitiateUploadCallback& callback); | 557 const InitiateUploadCallback& callback); |
| 596 | 558 |
| 597 // Resumes upload operation for chunk of file defined in |params.. | 559 // Resumes upload operation for chunk of file defined in |params.. |
| 598 // | 560 // |
| 599 // Can be called from UI/IO thread. |callback| is run on the calling thread. | 561 // Can be called from UI/IO thread. |callback| is run on the calling thread. |
| 600 void ResumeUpload(const ResumeUploadParams& params, | 562 void ResumeUpload(const ResumeUploadParams& params, |
| 601 const ResumeFileUploadCallback& callback); | 563 const ResumeFileUploadCallback& callback); |
| 602 | 564 |
| 603 // Unsafe (unlocked) version of FindEntryByPathSync method. | |
| 604 void UnsafeFindEntryByPath(const FilePath& file_path, | |
| 605 FindEntryDelegate* delegate); | |
| 606 | |
| 607 // Converts document feed from gdata service into DirectoryInfo. On failure, | 565 // Converts document feed from gdata service into DirectoryInfo. On failure, |
| 608 // returns NULL and fills in |error| with an appropriate value. | 566 // returns NULL and fills in |error| with an appropriate value. |
| 609 GDataDirectory* ParseGDataFeed(GDataErrorCode status, | 567 GDataDirectory* ParseGDataFeed(GDataErrorCode status, |
| 610 base::Value* data, | 568 base::Value* data, |
| 611 base::PlatformFileError *error); | 569 base::PlatformFileError *error); |
| 612 | 570 |
| 613 // Checks if a local file at |local_file_path| is a JSON file referencing a | 571 // Checks if a local file at |local_file_path| is a JSON file referencing a |
| 614 // hosted document on IO thread poll, and if so, gets the resource ID of the | 572 // hosted document on IO thread poll, and if so, gets the resource ID of the |
| 615 // document. | 573 // document. |
| 616 static void GetDocumentResourceIdOnIOThreadPool( | 574 static void GetDocumentResourceIdOnIOThreadPool( |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 }; | 1302 }; |
| 1345 | 1303 |
| 1346 // Sets the free disk space getter for testing. | 1304 // Sets the free disk space getter for testing. |
| 1347 // The existing getter is deleted. | 1305 // The existing getter is deleted. |
| 1348 void SetFreeDiskSpaceGetterForTesting( | 1306 void SetFreeDiskSpaceGetterForTesting( |
| 1349 FreeDiskSpaceGetterInterface* getter); | 1307 FreeDiskSpaceGetterInterface* getter); |
| 1350 | 1308 |
| 1351 } // namespace gdata | 1309 } // namespace gdata |
| 1352 | 1310 |
| 1353 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 1311 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
| OLD | NEW |