| 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/gdata_files.h" | 22 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
| 23 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" | 23 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" |
| 24 #include "chrome/browser/chromeos/gdata/gdata_params.h" | 24 #include "chrome/browser/chromeos/gdata/gdata_params.h" |
| 25 #include "chrome/browser/chromeos/gdata/gdata_parser.h" | 25 #include "chrome/browser/chromeos/gdata/gdata_parser.h" |
| 26 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" | 26 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" |
| 27 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 27 #include "chrome/browser/profiles/profile_keyed_service.h" | 28 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 28 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 29 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
| 30 #include "content/public/browser/notification_observer.h" |
| 29 | 31 |
| 30 namespace base { | 32 namespace base { |
| 31 class WaitableEvent; | 33 class WaitableEvent; |
| 32 } | 34 } |
| 33 | 35 |
| 34 namespace gdata { | 36 namespace gdata { |
| 35 | 37 |
| 36 class DocumentsServiceInterface; | 38 class DocumentsServiceInterface; |
| 37 struct UploadFileInfo; | 39 struct UploadFileInfo; |
| 38 | 40 |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 // Pin or unpin file. | 390 // Pin or unpin file. |
| 389 virtual void SetPinState(const FilePath& file_path, bool to_pin, | 391 virtual void SetPinState(const FilePath& file_path, bool to_pin, |
| 390 const FileOperationCallback& callback) = 0; | 392 const FileOperationCallback& callback) = 0; |
| 391 | 393 |
| 392 // Creates a new file from |entry| under |virtual_dir_path|. Stored its | 394 // Creates a new file from |entry| under |virtual_dir_path|. Stored its |
| 393 // content from |file_content_path| into the cache. | 395 // content from |file_content_path| into the cache. |
| 394 virtual void AddUploadedFile(const FilePath& virtual_dir_path, | 396 virtual void AddUploadedFile(const FilePath& virtual_dir_path, |
| 395 DocumentEntry* entry, | 397 DocumentEntry* entry, |
| 396 const FilePath& file_content_path, | 398 const FilePath& file_content_path, |
| 397 FileOperationType cache_operation) = 0; | 399 FileOperationType cache_operation) = 0; |
| 400 |
| 401 // Returns true if hosted documents should be hidden. |
| 402 virtual bool hide_hosted_documents() = 0; |
| 398 }; | 403 }; |
| 399 | 404 |
| 400 // The production implementation of GDataFileSystemInterface. | 405 // The production implementation of GDataFileSystemInterface. |
| 401 class GDataFileSystem : public GDataFileSystemInterface { | 406 class GDataFileSystem : public GDataFileSystemInterface, |
| 407 public content::NotificationObserver { |
| 402 public: | 408 public: |
| 403 GDataFileSystem(Profile* profile, | 409 GDataFileSystem(Profile* profile, |
| 404 DocumentsServiceInterface* documents_service); | 410 DocumentsServiceInterface* documents_service); |
| 405 virtual ~GDataFileSystem(); | 411 virtual ~GDataFileSystem(); |
| 406 | 412 |
| 407 // Shuts down the file system on UI thread. All pending operations are | 413 // Shuts down the file system on UI thread. All pending operations are |
| 408 // canceled. Most parts of shutdown happens here. The destructor is only | 414 // canceled. Most parts of shutdown happens here. The destructor is only |
| 409 // used to release objects on the IO thread. | 415 // used to release objects on the IO thread. |
| 410 void ShutdownOnUIThread(); | 416 void ShutdownOnUIThread(); |
| 411 | 417 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 CachedFileOrigin file_orign) const OVERRIDE; | 474 CachedFileOrigin file_orign) const OVERRIDE; |
| 469 virtual void GetAvailableSpace( | 475 virtual void GetAvailableSpace( |
| 470 const GetAvailableSpaceCallback& callback) OVERRIDE; | 476 const GetAvailableSpaceCallback& callback) OVERRIDE; |
| 471 // Calls private Pin or Unpin methods with |callback|. | 477 // Calls private Pin or Unpin methods with |callback|. |
| 472 virtual void SetPinState(const FilePath& file_path, bool pin, | 478 virtual void SetPinState(const FilePath& file_path, bool pin, |
| 473 const FileOperationCallback& callback) OVERRIDE; | 479 const FileOperationCallback& callback) OVERRIDE; |
| 474 virtual void AddUploadedFile(const FilePath& virtual_dir_path, | 480 virtual void AddUploadedFile(const FilePath& virtual_dir_path, |
| 475 DocumentEntry* entry, | 481 DocumentEntry* entry, |
| 476 const FilePath& file_content_path, | 482 const FilePath& file_content_path, |
| 477 FileOperationType cache_operation) OVERRIDE; | 483 FileOperationType cache_operation) OVERRIDE; |
| 484 virtual bool hide_hosted_documents() OVERRIDE; |
| 485 |
| 486 // content::NotificationObserver implementation. |
| 487 virtual void Observe(int type, |
| 488 const content::NotificationSource& source, |
| 489 const content::NotificationDetails& details) OVERRIDE; |
| 478 | 490 |
| 479 private: | 491 private: |
| 480 friend class GDataUploader; | 492 friend class GDataUploader; |
| 481 friend class GDataFileSystemTest; | 493 friend class GDataFileSystemTest; |
| 482 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, | 494 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, |
| 483 FindFirstMissingParentDirectory); | 495 FindFirstMissingParentDirectory); |
| 484 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, | 496 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, |
| 485 GetGDataFileInfoFromPath); | 497 GetGDataFileInfoFromPath); |
| 486 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, | 498 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, |
| 487 GetFromCacheForPath); | 499 GetFromCacheForPath); |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 // Helper function used to perform file search on the calling thread of | 1263 // Helper function used to perform file search on the calling thread of |
| 1252 // FindFileByPath() request. | 1264 // FindFileByPath() request. |
| 1253 void FindFileByPathOnCallingThread(const FilePath& search_file_path, | 1265 void FindFileByPathOnCallingThread(const FilePath& search_file_path, |
| 1254 const FindFileCallback& callback); | 1266 const FindFileCallback& callback); |
| 1255 | 1267 |
| 1256 void OnSetPinStateCompleted(const FileOperationCallback& callback, | 1268 void OnSetPinStateCompleted(const FileOperationCallback& callback, |
| 1257 base::PlatformFileError error, | 1269 base::PlatformFileError error, |
| 1258 const std::string& resource_id, | 1270 const std::string& resource_id, |
| 1259 const std::string& md5); | 1271 const std::string& md5); |
| 1260 | 1272 |
| 1273 // Changes state of hosted documents visibility, triggers directory refresh. |
| 1274 void SetHideHostedDocuments(bool hide); |
| 1275 |
| 1276 // Initializes preference change observer. |
| 1277 void InitializePreferenceObserver(); |
| 1278 |
| 1261 scoped_ptr<GDataRootDirectory> root_; | 1279 scoped_ptr<GDataRootDirectory> root_; |
| 1262 | 1280 |
| 1263 // This guards regular states. | 1281 // This guards regular states. |
| 1264 base::Lock lock_; | 1282 base::Lock lock_; |
| 1265 | 1283 |
| 1266 // The profile hosts the GDataFileSystem via GDataSystemService. | 1284 // The profile hosts the GDataFileSystem via GDataSystemService. |
| 1267 Profile* profile_; | 1285 Profile* profile_; |
| 1268 | 1286 |
| 1269 // The document service for the GDataFileSystem. | 1287 // The document service for the GDataFileSystem. |
| 1270 scoped_ptr<DocumentsServiceInterface> documents_service_; | 1288 scoped_ptr<DocumentsServiceInterface> documents_service_; |
| 1271 | 1289 |
| 1272 // Base path for GData cache, e.g. <user_profile_dir>/user/GCache/v1. | 1290 // Base path for GData cache, e.g. <user_profile_dir>/user/GCache/v1. |
| 1273 FilePath gdata_cache_path_; | 1291 FilePath gdata_cache_path_; |
| 1274 | 1292 |
| 1275 // Paths for all subdirectories of GCache, one for each | 1293 // Paths for all subdirectories of GCache, one for each |
| 1276 // GDataRootDirectory::CacheSubDirectoryType enum. | 1294 // GDataRootDirectory::CacheSubDirectoryType enum. |
| 1277 std::vector<FilePath> cache_paths_; | 1295 std::vector<FilePath> cache_paths_; |
| 1278 | 1296 |
| 1279 scoped_ptr<base::WaitableEvent> on_io_completed_; | 1297 scoped_ptr<base::WaitableEvent> on_io_completed_; |
| 1280 | 1298 |
| 1281 // True if cache initialization has started, is in progress or has completed, | 1299 // True if cache initialization has started, is in progress or has completed, |
| 1282 // we only want to initialize cache once. | 1300 // we only want to initialize cache once. |
| 1283 bool cache_initialization_started_; | 1301 bool cache_initialization_started_; |
| 1284 | 1302 |
| 1285 // Number of pending tasks on the blocking thread pool. | 1303 // Number of pending tasks on the blocking thread pool. |
| 1286 int num_pending_tasks_; | 1304 int num_pending_tasks_; |
| 1287 base::Lock num_pending_tasks_lock_; | 1305 base::Lock num_pending_tasks_lock_; |
| 1288 | 1306 |
| 1307 // True if hosted documents should be hidden. |
| 1308 bool hide_hosted_docs_; |
| 1309 |
| 1310 PrefChangeRegistrar pref_registrar_; |
| 1311 |
| 1289 // WeakPtrFactory and WeakPtr bound to the UI thread. | 1312 // WeakPtrFactory and WeakPtr bound to the UI thread. |
| 1290 scoped_ptr<base::WeakPtrFactory<GDataFileSystem> > ui_weak_ptr_factory_; | 1313 scoped_ptr<base::WeakPtrFactory<GDataFileSystem> > ui_weak_ptr_factory_; |
| 1291 base::WeakPtr<GDataFileSystem> ui_weak_ptr_; | 1314 base::WeakPtr<GDataFileSystem> ui_weak_ptr_; |
| 1292 | 1315 |
| 1293 // WeakPtrFactory bound to the IO thread. Created when needed. | 1316 // WeakPtrFactory bound to the IO thread. Created when needed. |
| 1294 scoped_ptr<base::WeakPtrFactory<GDataFileSystem> > io_weak_ptr_factory_; | 1317 scoped_ptr<base::WeakPtrFactory<GDataFileSystem> > io_weak_ptr_factory_; |
| 1295 | 1318 |
| 1296 ObserverList<Observer> observers_; | 1319 ObserverList<Observer> observers_; |
| 1297 }; | 1320 }; |
| 1298 | 1321 |
| 1299 } // namespace gdata | 1322 } // namespace gdata |
| 1300 | 1323 |
| 1301 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 1324 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
| OLD | NEW |