Chromium Code Reviews| 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_set_observer.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; | |
|
achuithb
2012/04/04 19:14:11
Shouldn't this be HideHostedDocuments?
zel
2012/04/04 20:16:57
it's a simple getter, unlike its setter method tha
achuithb
2012/04/04 20:46:19
I'm not sure what the rule is with getters when th
| |
| 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 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1199 // Helper function used to perform file search on the calling thread of | 1211 // Helper function used to perform file search on the calling thread of |
| 1200 // FindFileByPath() request. | 1212 // FindFileByPath() request. |
| 1201 void FindFileByPathOnCallingThread(const FilePath& search_file_path, | 1213 void FindFileByPathOnCallingThread(const FilePath& search_file_path, |
| 1202 const FindFileCallback& callback); | 1214 const FindFileCallback& callback); |
| 1203 | 1215 |
| 1204 void OnSetPinStateCompleted(const FileOperationCallback& callback, | 1216 void OnSetPinStateCompleted(const FileOperationCallback& callback, |
| 1205 base::PlatformFileError error, | 1217 base::PlatformFileError error, |
| 1206 const std::string& resource_id, | 1218 const std::string& resource_id, |
| 1207 const std::string& md5); | 1219 const std::string& md5); |
| 1208 | 1220 |
| 1221 // Changes state of hosted documents visibility, triggers directory refresh. | |
| 1222 void SetHideHostedDocuments(bool hide); | |
| 1223 | |
| 1224 // Initializes preference change observer. | |
| 1225 void InitializePreferenceObserver(); | |
| 1226 | |
| 1209 scoped_ptr<GDataRootDirectory> root_; | 1227 scoped_ptr<GDataRootDirectory> root_; |
| 1210 | 1228 |
| 1211 // This guards regular states. | 1229 // This guards regular states. |
| 1212 base::Lock lock_; | 1230 base::Lock lock_; |
| 1213 | 1231 |
| 1214 // The profile hosts the GDataFileSystem via GDataSystemService. | 1232 // The profile hosts the GDataFileSystem via GDataSystemService. |
| 1215 Profile* profile_; | 1233 Profile* profile_; |
| 1216 | 1234 |
| 1217 // The document service for the GDataFileSystem. | 1235 // The document service for the GDataFileSystem. |
| 1218 scoped_ptr<DocumentsServiceInterface> documents_service_; | 1236 scoped_ptr<DocumentsServiceInterface> documents_service_; |
| 1219 | 1237 |
| 1220 // Base path for GData cache, e.g. <user_profile_dir>/user/GCache/v1. | 1238 // Base path for GData cache, e.g. <user_profile_dir>/user/GCache/v1. |
| 1221 FilePath gdata_cache_path_; | 1239 FilePath gdata_cache_path_; |
| 1222 | 1240 |
| 1223 // Paths for all subdirectories of GCache, one for each | 1241 // Paths for all subdirectories of GCache, one for each |
| 1224 // GDataRootDirectory::CacheSubDirectoryType enum. | 1242 // GDataRootDirectory::CacheSubDirectoryType enum. |
| 1225 std::vector<FilePath> cache_paths_; | 1243 std::vector<FilePath> cache_paths_; |
| 1226 | 1244 |
| 1227 scoped_ptr<base::WaitableEvent> on_io_completed_; | 1245 scoped_ptr<base::WaitableEvent> on_io_completed_; |
| 1228 | 1246 |
| 1229 // True if cache initialization has started, is in progress or has completed, | 1247 // True if cache initialization has started, is in progress or has completed, |
| 1230 // we only want to initialize cache once. | 1248 // we only want to initialize cache once. |
| 1231 bool cache_initialization_started_; | 1249 bool cache_initialization_started_; |
| 1232 | 1250 |
| 1233 // Number of pending tasks on the blocking thread pool. | 1251 // Number of pending tasks on the blocking thread pool. |
| 1234 int num_pending_tasks_; | 1252 int num_pending_tasks_; |
| 1235 base::Lock num_pending_tasks_lock_; | 1253 base::Lock num_pending_tasks_lock_; |
| 1236 | 1254 |
| 1255 // True if hosted documents should be hidden. | |
| 1256 bool hide_hosted_docs_; | |
| 1257 | |
| 1258 scoped_ptr<PrefSetObserver> pref_observer_; | |
| 1259 | |
| 1237 // WeakPtrFactory and WeakPtr bound to the UI thread. | 1260 // WeakPtrFactory and WeakPtr bound to the UI thread. |
| 1238 scoped_ptr<base::WeakPtrFactory<GDataFileSystem> > ui_weak_ptr_factory_; | 1261 scoped_ptr<base::WeakPtrFactory<GDataFileSystem> > ui_weak_ptr_factory_; |
| 1239 base::WeakPtr<GDataFileSystem> ui_weak_ptr_; | 1262 base::WeakPtr<GDataFileSystem> ui_weak_ptr_; |
| 1240 | 1263 |
| 1241 // WeakPtrFactory bound to the IO thread. Created when needed. | 1264 // WeakPtrFactory bound to the IO thread. Created when needed. |
| 1242 scoped_ptr<base::WeakPtrFactory<GDataFileSystem> > io_weak_ptr_factory_; | 1265 scoped_ptr<base::WeakPtrFactory<GDataFileSystem> > io_weak_ptr_factory_; |
| 1243 | 1266 |
| 1244 ObserverList<Observer> observers_; | 1267 ObserverList<Observer> observers_; |
| 1245 }; | 1268 }; |
| 1246 | 1269 |
| 1247 } // namespace gdata | 1270 } // namespace gdata |
| 1248 | 1271 |
| 1249 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 1272 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
| OLD | NEW |