| 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 <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 19 #include "base/platform_file.h" | 19 #include "base/platform_file.h" |
| 20 #include "base/scoped_temp_dir.h" |
| 20 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
| 21 #include "chrome/browser/chromeos/gdata/gdata_files.h" | 22 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
| 22 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" | 23 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" |
| 23 #include "chrome/browser/chromeos/gdata/gdata_params.h" | 24 #include "chrome/browser/chromeos/gdata/gdata_params.h" |
| 24 #include "chrome/browser/chromeos/gdata/gdata_parser.h" | 25 #include "chrome/browser/chromeos/gdata/gdata_parser.h" |
| 25 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" | 26 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" |
| 26 #include "chrome/browser/profiles/profile_keyed_service.h" | 27 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 27 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 28 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
| 28 | 29 |
| 29 namespace base { | 30 namespace base { |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 virtual FilePath GetGDataTempDownloadFolderPath() const = 0; | 343 virtual FilePath GetGDataTempDownloadFolderPath() const = 0; |
| 343 | 344 |
| 344 // Returns the pinned sub-directory under gdata cache directory, i.e. | 345 // Returns the pinned sub-directory under gdata cache directory, i.e. |
| 345 // <user_profile_dir>/GCache/v1/pinned | 346 // <user_profile_dir>/GCache/v1/pinned |
| 346 virtual FilePath GetGDataCachePinnedDirectory() const = 0; | 347 virtual FilePath GetGDataCachePinnedDirectory() const = 0; |
| 347 | 348 |
| 348 // Returns the pinned sub-directory under gdata cache directory, i.e. | 349 // Returns the pinned sub-directory under gdata cache directory, i.e. |
| 349 // <user_profile_dir>/GCache/v1/pinned | 350 // <user_profile_dir>/GCache/v1/pinned |
| 350 virtual FilePath GetGDataCachePersistentDirectory() const = 0; | 351 virtual FilePath GetGDataCachePersistentDirectory() const = 0; |
| 351 | 352 |
| 353 // Returns the directory for hosting temporary document JSON files, i.e. |
| 354 // <system_temp_dir>/<unique_temp_dir> |
| 355 virtual FilePath GetGDataTempDocumentDirectory() const = 0; |
| 356 |
| 352 // Returns absolute path of the file if it were cached or to be cached. | 357 // Returns absolute path of the file if it were cached or to be cached. |
| 353 virtual FilePath GetCacheFilePath( | 358 virtual FilePath GetCacheFilePath( |
| 354 const std::string& resource_id, | 359 const std::string& resource_id, |
| 355 const std::string& md5, | 360 const std::string& md5, |
| 356 GDataRootDirectory::CacheSubDirectoryType sub_dir_type, | 361 GDataRootDirectory::CacheSubDirectoryType sub_dir_type, |
| 357 CachedFileOrigin file_orign) const = 0; | 362 CachedFileOrigin file_orign) const = 0; |
| 358 | 363 |
| 359 // Fetches the user's Account Metadata to find out current quota information | 364 // Fetches the user's Account Metadata to find out current quota information |
| 360 // and returns it to the callback. | 365 // and returns it to the callback. |
| 361 virtual void GetAvailableSpace(const GetAvailableSpaceCallback& callback) = 0; | 366 virtual void GetAvailableSpace(const GetAvailableSpaceCallback& callback) = 0; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 GDataOperationRegistry::Observer* observer) OVERRIDE; | 424 GDataOperationRegistry::Observer* observer) OVERRIDE; |
| 420 virtual void GetCacheState(const std::string& resource_id, | 425 virtual void GetCacheState(const std::string& resource_id, |
| 421 const std::string& md5, | 426 const std::string& md5, |
| 422 const GetCacheStateCallback& callback) OVERRIDE; | 427 const GetCacheStateCallback& callback) OVERRIDE; |
| 423 virtual bool GetFileInfoFromPath(const FilePath& gdata_file_path, | 428 virtual bool GetFileInfoFromPath(const FilePath& gdata_file_path, |
| 424 GDataFileProperties* properties) OVERRIDE; | 429 GDataFileProperties* properties) OVERRIDE; |
| 425 virtual FilePath GetGDataCacheTmpDirectory() const OVERRIDE; | 430 virtual FilePath GetGDataCacheTmpDirectory() const OVERRIDE; |
| 426 virtual FilePath GetGDataTempDownloadFolderPath() const OVERRIDE; | 431 virtual FilePath GetGDataTempDownloadFolderPath() const OVERRIDE; |
| 427 virtual FilePath GetGDataCachePinnedDirectory() const OVERRIDE; | 432 virtual FilePath GetGDataCachePinnedDirectory() const OVERRIDE; |
| 428 virtual FilePath GetGDataCachePersistentDirectory() const OVERRIDE; | 433 virtual FilePath GetGDataCachePersistentDirectory() const OVERRIDE; |
| 434 virtual FilePath GetGDataTempDocumentDirectory() const OVERRIDE; |
| 429 virtual FilePath GetCacheFilePath( | 435 virtual FilePath GetCacheFilePath( |
| 430 const std::string& resource_id, | 436 const std::string& resource_id, |
| 431 const std::string& md5, | 437 const std::string& md5, |
| 432 GDataRootDirectory::CacheSubDirectoryType sub_dir_type, | 438 GDataRootDirectory::CacheSubDirectoryType sub_dir_type, |
| 433 CachedFileOrigin file_orign) const OVERRIDE; | 439 CachedFileOrigin file_orign) const OVERRIDE; |
| 434 virtual void GetAvailableSpace( | 440 virtual void GetAvailableSpace( |
| 435 const GetAvailableSpaceCallback& callback) OVERRIDE; | 441 const GetAvailableSpaceCallback& callback) OVERRIDE; |
| 436 virtual void AddUploadedFile(const FilePath& virtual_dir_path, | 442 virtual void AddUploadedFile(const FilePath& virtual_dir_path, |
| 437 DocumentEntry* entry, | 443 DocumentEntry* entry, |
| 438 const FilePath& file_content_path, | 444 const FilePath& file_content_path, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 void UnsafeFindFileByPath(const FilePath& file_path, | 584 void UnsafeFindFileByPath(const FilePath& file_path, |
| 579 FindFileDelegate* delegate); | 585 FindFileDelegate* delegate); |
| 580 | 586 |
| 581 // Converts document feed from gdata service into DirectoryInfo. On failure, | 587 // Converts document feed from gdata service into DirectoryInfo. On failure, |
| 582 // returns NULL and fills in |error| with an appropriate value. | 588 // returns NULL and fills in |error| with an appropriate value. |
| 583 GDataDirectory* ParseGDataFeed(GDataErrorCode status, | 589 GDataDirectory* ParseGDataFeed(GDataErrorCode status, |
| 584 base::Value* data, | 590 base::Value* data, |
| 585 base::PlatformFileError *error); | 591 base::PlatformFileError *error); |
| 586 | 592 |
| 587 // Creates a temporary JSON file representing a document with |edit_url| | 593 // Creates a temporary JSON file representing a document with |edit_url| |
| 588 // and |resource_id| on IO thread pool. Upon completion it will invoke | 594 // and |resource_id| under |document_dir| on IO thread pool. Upon completion |
| 589 // |callback| with the path of the created temporary file on thread | 595 // it will invoke |callback| with the path of the created temporary file on |
| 590 // represented by |relay_proxy|. | 596 // thread represented by |relay_proxy|. |
| 591 static void CreateDocumentJsonFileOnIOThreadPool( | 597 static void CreateDocumentJsonFileOnIOThreadPool( |
| 598 const FilePath& document_dir, |
| 592 const GURL& edit_url, | 599 const GURL& edit_url, |
| 593 const std::string& resource_id, | 600 const std::string& resource_id, |
| 594 const GetFileCallback& callback, | 601 const GetFileCallback& callback, |
| 595 scoped_refptr<base::MessageLoopProxy> relay_proxy); | 602 scoped_refptr<base::MessageLoopProxy> relay_proxy); |
| 596 | 603 |
| 597 // Renames a file or directory at |file_path| to |new_name|. | 604 // Renames a file or directory at |file_path| to |new_name|. |
| 598 void Rename(const FilePath& file_path, | 605 void Rename(const FilePath& file_path, |
| 599 const FilePath::StringType& new_name, | 606 const FilePath::StringType& new_name, |
| 600 const FilePathUpdateCallback& callback); | 607 const FilePathUpdateCallback& callback); |
| 601 | 608 |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 // The document service for the GDataFileSystem. | 1155 // The document service for the GDataFileSystem. |
| 1149 scoped_ptr<DocumentsServiceInterface> documents_service_; | 1156 scoped_ptr<DocumentsServiceInterface> documents_service_; |
| 1150 | 1157 |
| 1151 // Base path for GData cache, e.g. <user_profile_dir>/user/GCache/v1. | 1158 // Base path for GData cache, e.g. <user_profile_dir>/user/GCache/v1. |
| 1152 FilePath gdata_cache_path_; | 1159 FilePath gdata_cache_path_; |
| 1153 | 1160 |
| 1154 // Paths for all subdirectories of GCache, one for each | 1161 // Paths for all subdirectories of GCache, one for each |
| 1155 // GDataRootDirectory::CacheSubDirectoryType enum. | 1162 // GDataRootDirectory::CacheSubDirectoryType enum. |
| 1156 std::vector<FilePath> cache_paths_; | 1163 std::vector<FilePath> cache_paths_; |
| 1157 | 1164 |
| 1165 // Directory for hosting temporary document JSON files. |
| 1166 ScopedTempDir temp_document_dir_; |
| 1167 |
| 1158 scoped_ptr<base::WaitableEvent> on_io_completed_; | 1168 scoped_ptr<base::WaitableEvent> on_io_completed_; |
| 1159 | 1169 |
| 1160 // True if cache initialization has started, is in progress or has completed, | 1170 // True if cache initialization has started, is in progress or has completed, |
| 1161 // we only want to initialize cache once. | 1171 // we only want to initialize cache once. |
| 1162 bool cache_initialization_started_; | 1172 bool cache_initialization_started_; |
| 1163 | 1173 |
| 1164 // Number of pending tasks on the worker thread pool. | 1174 // Number of pending tasks on the worker thread pool. |
| 1165 int num_pending_tasks_; | 1175 int num_pending_tasks_; |
| 1166 base::Lock num_pending_tasks_lock_; | 1176 base::Lock num_pending_tasks_lock_; |
| 1167 | 1177 |
| 1168 // WeakPtrFactory and WeakPtr bound to the UI thread. | 1178 // WeakPtrFactory and WeakPtr bound to the UI thread. |
| 1169 scoped_ptr<base::WeakPtrFactory<GDataFileSystem> > ui_weak_ptr_factory_; | 1179 scoped_ptr<base::WeakPtrFactory<GDataFileSystem> > ui_weak_ptr_factory_; |
| 1170 base::WeakPtr<GDataFileSystem> ui_weak_ptr_; | 1180 base::WeakPtr<GDataFileSystem> ui_weak_ptr_; |
| 1171 | 1181 |
| 1172 // WeakPtrFactory bound to the IO thread. Created when needed. | 1182 // WeakPtrFactory bound to the IO thread. Created when needed. |
| 1173 scoped_ptr<base::WeakPtrFactory<GDataFileSystem> > io_weak_ptr_factory_; | 1183 scoped_ptr<base::WeakPtrFactory<GDataFileSystem> > io_weak_ptr_factory_; |
| 1174 | 1184 |
| 1175 ObserverList<Observer> observers_; | 1185 ObserverList<Observer> observers_; |
| 1176 }; | 1186 }; |
| 1177 | 1187 |
| 1178 } // namespace gdata | 1188 } // namespace gdata |
| 1179 | 1189 |
| 1180 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 1190 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
| OLD | NEW |