| 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_FILES_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/platform_file.h" | 16 #include "base/platform_file.h" |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #include "chrome/browser/chromeos/gdata/gdata_params.h" | 18 #include "chrome/browser/chromeos/gdata/gdata_params.h" |
| 19 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" | 19 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" |
| 20 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" | 20 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" |
| 21 #include "chrome/browser/profiles/profile_keyed_service.h" | 21 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 22 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 22 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
| 23 | 23 |
| 24 namespace base { |
| 25 class SequencedTaskRunner; |
| 26 } |
| 27 |
| 24 namespace gdata { | 28 namespace gdata { |
| 25 | 29 |
| 30 struct CreateDBParams; |
| 26 class GDataFile; | 31 class GDataFile; |
| 27 class GDataDirectory; | 32 class GDataDirectory; |
| 28 class GDataDirectoryService; | 33 class GDataDirectoryService; |
| 34 class ResourceMetadataDB; |
| 29 | 35 |
| 30 class GDataEntryProto; | 36 class GDataEntryProto; |
| 31 class GDataDirectoryProto; | 37 class GDataDirectoryProto; |
| 32 class GDataRootDirectoryProto; | 38 class GDataRootDirectoryProto; |
| 33 class PlatformFileInfoProto; | 39 class PlatformFileInfoProto; |
| 34 | 40 |
| 35 // The root directory content origin. | 41 // The root directory content origin. |
| 36 enum ContentOrigin { | 42 enum ContentOrigin { |
| 37 UNINITIALIZED, | 43 UNINITIALIZED, |
| 38 // Content is currently loading from somewhere. Needs to wait. | 44 // Content is currently loading from somewhere. Needs to wait. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 static void ConvertProtoToPlatformFileInfo( | 101 static void ConvertProtoToPlatformFileInfo( |
| 96 const PlatformFileInfoProto& proto, | 102 const PlatformFileInfoProto& proto, |
| 97 base::PlatformFileInfo* file_info); | 103 base::PlatformFileInfo* file_info); |
| 98 | 104 |
| 99 // Converts the platform file info to the proto representation. | 105 // Converts the platform file info to the proto representation. |
| 100 static void ConvertPlatformFileInfoToProto( | 106 static void ConvertPlatformFileInfoToProto( |
| 101 const base::PlatformFileInfo& file_info, | 107 const base::PlatformFileInfo& file_info, |
| 102 PlatformFileInfoProto* proto); | 108 PlatformFileInfoProto* proto); |
| 103 | 109 |
| 104 // Converts to/from proto. Only handles the common part (i.e. does not | 110 // Converts to/from proto. Only handles the common part (i.e. does not |
| 105 // touch |file_specific_info| and |directory_specific_info|. | 111 // touch |file_specific_info|). |
| 106 bool FromProto(const GDataEntryProto& proto) WARN_UNUSED_RESULT; | 112 bool FromProto(const GDataEntryProto& proto) WARN_UNUSED_RESULT; |
| 107 void ToProto(GDataEntryProto* proto) const; | 113 void ToProto(GDataEntryProto* proto) const; |
| 108 | 114 |
| 109 // Similar to ToProto() but this fills in |file_specific_info| and | 115 // Similar to ToProto() but this fills in |file_specific_info| and |
| 110 // |directory_specific_info| based on the actual type of the entry. | 116 // |directory_specific_info| based on the actual type of the entry. |
| 111 // Used to obtain full metadata of a file or a directory as | 117 // Used to obtain full metadata of a file or a directory as |
| 112 // GDataEntryProto. | 118 // GDataEntryProto. |
| 113 void ToProtoFull(GDataEntryProto* proto) const; | 119 void ToProtoFull(GDataEntryProto* proto) const; |
| 114 | 120 |
| 115 // Escapes forward slashes from file names with magic unicode character | 121 // Escapes forward slashes from file names with magic unicode character |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 // entry instance. | 331 // entry instance. |
| 326 bool RemoveChild(GDataEntry* entry); | 332 bool RemoveChild(GDataEntry* entry); |
| 327 | 333 |
| 328 // Collection of children GDataEntry items. | 334 // Collection of children GDataEntry items. |
| 329 GDataFileCollection child_files_; | 335 GDataFileCollection child_files_; |
| 330 GDataDirectoryCollection child_directories_; | 336 GDataDirectoryCollection child_directories_; |
| 331 | 337 |
| 332 DISALLOW_COPY_AND_ASSIGN(GDataDirectory); | 338 DISALLOW_COPY_AND_ASSIGN(GDataDirectory); |
| 333 }; | 339 }; |
| 334 | 340 |
| 341 // TODO(achuith,hashimoto,satorux): Move this to a separate file. |
| 342 // crbug.com/140317. |
| 335 // Class to handle GDataEntry* lookups, add/remove GDataEntry*. | 343 // Class to handle GDataEntry* lookups, add/remove GDataEntry*. |
| 336 class GDataDirectoryService { | 344 class GDataDirectoryService { |
| 337 public: | 345 public: |
| 338 // Callback for GetEntryByResourceIdAsync. | 346 // Callback for GetEntryByResourceIdAsync. |
| 339 typedef base::Callback<void(GDataEntry* entry)> GetEntryByResourceIdCallback; | 347 typedef base::Callback<void(GDataEntry* entry)> GetEntryByResourceIdCallback; |
| 340 | 348 |
| 349 // Map of resource id and serialized GDataEntry. |
| 350 typedef std::map<std::string, std::string> SerializedMap; |
| 351 |
| 341 GDataDirectoryService(); | 352 GDataDirectoryService(); |
| 342 ~GDataDirectoryService(); | 353 ~GDataDirectoryService(); |
| 343 | 354 |
| 344 GDataDirectory* root() { return root_.get(); } | 355 GDataDirectory* root() { return root_.get(); } |
| 345 | 356 |
| 346 // Last time when we dumped serialized file system to disk. | 357 // Last time when we dumped serialized file system to disk. |
| 347 const base::Time& last_serialized() const { return last_serialized_; } | 358 const base::Time& last_serialized() const { return last_serialized_; } |
| 348 void set_last_serialized(const base::Time& time) { last_serialized_ = time; } | 359 void set_last_serialized(const base::Time& time) { last_serialized_ = time; } |
| 349 // Size of serialized file system on disk in bytes. | 360 // Size of serialized file system on disk in bytes. |
| 350 const size_t serialized_size() const { return serialized_size_; } | 361 const size_t serialized_size() const { return serialized_size_; } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 void RefreshFile(scoped_ptr<GDataFile> fresh_file); | 405 void RefreshFile(scoped_ptr<GDataFile> fresh_file); |
| 395 | 406 |
| 396 // Replaces file entry |old_entry| with its fresh value |fresh_file|. | 407 // Replaces file entry |old_entry| with its fresh value |fresh_file|. |
| 397 static void RefreshFileInternal(scoped_ptr<GDataFile> fresh_file, | 408 static void RefreshFileInternal(scoped_ptr<GDataFile> fresh_file, |
| 398 GDataEntry* old_entry); | 409 GDataEntry* old_entry); |
| 399 | 410 |
| 400 // Serializes/Parses to/from string via proto classes. | 411 // Serializes/Parses to/from string via proto classes. |
| 401 void SerializeToString(std::string* serialized_proto) const; | 412 void SerializeToString(std::string* serialized_proto) const; |
| 402 bool ParseFromString(const std::string& serialized_proto); | 413 bool ParseFromString(const std::string& serialized_proto); |
| 403 | 414 |
| 415 // Restores from and saves to database. |
| 416 void InitFromDB(const FilePath& db_path, |
| 417 base::SequencedTaskRunner* blocking_task_runner, |
| 418 const FileOperationCallback& callback); |
| 419 void SaveToDB(); |
| 420 |
| 404 private: | 421 private: |
| 405 // A map table of file's resource string to its GDataFile* entry. | 422 // A map table of file's resource string to its GDataFile* entry. |
| 406 typedef std::map<std::string, GDataEntry*> ResourceMap; | 423 typedef std::map<std::string, GDataEntry*> ResourceMap; |
| 407 | 424 |
| 425 // Initializes the resource map using serialized_resources fetched from the |
| 426 // database. |
| 427 void InitResourceMap(CreateDBParams* create_params, |
| 428 const FileOperationCallback& callback); |
| 429 |
| 430 // Clears root_ and the resource map. |
| 431 void ClearRoot(); |
| 432 |
| 433 // Creates GDataEntry from serialized string. |
| 434 scoped_ptr<GDataEntry> FromProtoString( |
| 435 const std::string& serialized_proto); |
| 436 |
| 437 // Private data members. |
| 438 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 439 scoped_ptr<ResourceMetadataDB> directory_service_db_; |
| 440 |
| 441 ResourceMap resource_map_; |
| 442 |
| 408 scoped_ptr<GDataDirectory> root_; // Stored in the serialized proto. | 443 scoped_ptr<GDataDirectory> root_; // Stored in the serialized proto. |
| 409 ResourceMap resource_map_; | |
| 410 | 444 |
| 411 base::Time last_serialized_; | 445 base::Time last_serialized_; |
| 412 size_t serialized_size_; | 446 size_t serialized_size_; |
| 413 int largest_changestamp_; // Stored in the serialized proto. | 447 int largest_changestamp_; // Stored in the serialized proto. |
| 414 ContentOrigin origin_; | 448 ContentOrigin origin_; |
| 415 | 449 |
| 450 // This should remain the last member so it'll be destroyed first and |
| 451 // invalidate its weak pointers before other members are destroyed. |
| 452 base::WeakPtrFactory<GDataDirectoryService> weak_ptr_factory_; |
| 453 |
| 416 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); | 454 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); |
| 417 }; | 455 }; |
| 418 | 456 |
| 419 } // namespace gdata | 457 } // namespace gdata |
| 420 | 458 |
| 421 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 459 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
| OLD | NEW |