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_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 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 GetEntryInfoCallback; | 81 GetEntryInfoCallback; |
| 82 | 82 |
| 83 // Used to read a directory from the file system. | 83 // Used to read a directory from the file system. |
| 84 // If |error| is not GDATA_FILE_OK, |entries| is set to NULL. | 84 // If |error| is not GDATA_FILE_OK, |entries| is set to NULL. |
| 85 // |entries| are contents, both files and directories, of the directory. | 85 // |entries| are contents, both files and directories, of the directory. |
| 86 typedef std::vector<GDataEntryProto> GDataEntryProtoVector; | 86 typedef std::vector<GDataEntryProto> GDataEntryProtoVector; |
| 87 typedef base::Callback<void(GDataFileError error, | 87 typedef base::Callback<void(GDataFileError error, |
| 88 scoped_ptr<GDataEntryProtoVector> entries)> | 88 scoped_ptr<GDataEntryProtoVector> entries)> |
| 89 ReadDirectoryCallback; | 89 ReadDirectoryCallback; |
| 90 | 90 |
| 91 // The result of GetEntryInfoPairCallback(). Used to get a pair of entries | |
| 92 // in one function call. | |
| 93 struct EntryInfoPairResult { | |
| 94 EntryInfoPairResult(); | |
| 95 ~EntryInfoPairResult(); | |
| 96 | |
| 97 FilePath first_path; | |
|
achuithb
2012/08/08 20:50:32
Have you considered creating another struct like
s
satorux1
2012/08/08 21:21:21
Considered but I was too lazy to rewrite. :) Recon
| |
| 98 GDataFileError first_error; | |
| 99 scoped_ptr<GDataEntryProto> first_proto; | |
| 100 | |
| 101 // The following fields are filled only if the first path is found. | |
| 102 FilePath second_path; | |
| 103 GDataFileError second_error; | |
| 104 scoped_ptr<GDataEntryProto> second_proto; | |
| 105 }; | |
| 106 | |
| 107 // Used to receive the result from GetEntryInfoPairCallback(). | |
| 108 typedef base::Callback<void(scoped_ptr<EntryInfoPairResult> pair_result)> | |
| 109 GetEntryInfoPairCallback; | |
| 110 | |
| 91 // Base class for representing files and directories in gdata virtual file | 111 // Base class for representing files and directories in gdata virtual file |
| 92 // system. | 112 // system. |
| 93 class GDataEntry { | 113 class GDataEntry { |
| 94 public: | 114 public: |
| 95 GDataEntry(GDataDirectory* parent, GDataDirectoryService* directory_service); | 115 GDataEntry(GDataDirectory* parent, GDataDirectoryService* directory_service); |
| 96 virtual ~GDataEntry(); | 116 virtual ~GDataEntry(); |
| 97 | 117 |
| 98 virtual GDataFile* AsGDataFile(); | 118 virtual GDataFile* AsGDataFile(); |
| 99 virtual GDataDirectory* AsGDataDirectory(); | 119 virtual GDataDirectory* AsGDataDirectory(); |
| 100 | 120 |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 // Must be called from UI thread. |callback| is run on UI thread. | 442 // Must be called from UI thread. |callback| is run on UI thread. |
| 423 void GetEntryInfoByPath(const FilePath& file_path, | 443 void GetEntryInfoByPath(const FilePath& file_path, |
| 424 const GetEntryInfoCallback& callback); | 444 const GetEntryInfoCallback& callback); |
| 425 | 445 |
| 426 // Finds and reads a directory by |file_path|. | 446 // Finds and reads a directory by |file_path|. |
| 427 // | 447 // |
| 428 // Must be called from UI thread. |callback| is run on UI thread. | 448 // Must be called from UI thread. |callback| is run on UI thread. |
| 429 void ReadDirectoryByPath(const FilePath& file_path, | 449 void ReadDirectoryByPath(const FilePath& file_path, |
| 430 const ReadDirectoryCallback& callback); | 450 const ReadDirectoryCallback& callback); |
| 431 | 451 |
| 452 // Similar to GetEntryInfoByPath() but this function finds a pair of | |
| 453 // entries by |first_path| and |second_path|. If the entry for | |
| 454 // |first_path| is not found, this function does not try to get the | |
| 455 // entry of |second_path|. | |
| 456 // | |
| 457 // Must be called from UI thread. |callback| is run on UI thread. | |
| 458 void GetEntryInfoPairByPaths( | |
| 459 const FilePath& first_path, | |
| 460 const FilePath& second_path, | |
| 461 const GetEntryInfoPairCallback& callback); | |
| 462 | |
| 432 // Replaces file entry with the same resource id as |fresh_file| with its | 463 // Replaces file entry with the same resource id as |fresh_file| with its |
| 433 // fresh value |fresh_file|. | 464 // fresh value |fresh_file|. |
| 434 void RefreshFile(scoped_ptr<GDataFile> fresh_file); | 465 void RefreshFile(scoped_ptr<GDataFile> fresh_file); |
| 435 | 466 |
| 436 // Replaces file entry |old_entry| with its fresh value |fresh_file|. | 467 // Replaces file entry |old_entry| with its fresh value |fresh_file|. |
| 437 static void RefreshFileInternal(scoped_ptr<GDataFile> fresh_file, | 468 static void RefreshFileInternal(scoped_ptr<GDataFile> fresh_file, |
| 438 GDataEntry* old_entry); | 469 GDataEntry* old_entry); |
| 439 | 470 |
| 440 // Serializes/Parses to/from string via proto classes. | 471 // Serializes/Parses to/from string via proto classes. |
| 441 void SerializeToString(std::string* serialized_proto) const; | 472 void SerializeToString(std::string* serialized_proto) const; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 456 void InitResourceMap(CreateDBParams* create_params, | 487 void InitResourceMap(CreateDBParams* create_params, |
| 457 const FileOperationCallback& callback); | 488 const FileOperationCallback& callback); |
| 458 | 489 |
| 459 // Clears root_ and the resource map. | 490 // Clears root_ and the resource map. |
| 460 void ClearRoot(); | 491 void ClearRoot(); |
| 461 | 492 |
| 462 // Creates GDataEntry from serialized string. | 493 // Creates GDataEntry from serialized string. |
| 463 scoped_ptr<GDataEntry> FromProtoString( | 494 scoped_ptr<GDataEntry> FromProtoString( |
| 464 const std::string& serialized_proto); | 495 const std::string& serialized_proto); |
| 465 | 496 |
| 497 // ... | |
| 498 void GetEntryInfoPairByPathsAfterGetFirst( | |
| 499 const FilePath& first_path, | |
| 500 const FilePath& second_path, | |
| 501 const GetEntryInfoPairCallback& callback, | |
| 502 GDataFileError error, | |
| 503 scoped_ptr<GDataEntryProto> entry_proto); | |
| 504 | |
| 505 // ... | |
| 506 void GetEntryInfoPairByPathsAfterGetSecond( | |
| 507 const FilePath& second_path, | |
| 508 const GetEntryInfoPairCallback& callback, | |
| 509 scoped_ptr<EntryInfoPairResult> result, | |
| 510 GDataFileError error, | |
| 511 scoped_ptr<GDataEntryProto> entry_proto); | |
| 512 | |
| 466 // Private data members. | 513 // Private data members. |
| 467 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 514 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 468 scoped_ptr<ResourceMetadataDB> directory_service_db_; | 515 scoped_ptr<ResourceMetadataDB> directory_service_db_; |
| 469 | 516 |
| 470 ResourceMap resource_map_; | 517 ResourceMap resource_map_; |
| 471 | 518 |
| 472 scoped_ptr<GDataDirectory> root_; // Stored in the serialized proto. | 519 scoped_ptr<GDataDirectory> root_; // Stored in the serialized proto. |
| 473 | 520 |
| 474 base::Time last_serialized_; | 521 base::Time last_serialized_; |
| 475 size_t serialized_size_; | 522 size_t serialized_size_; |
| 476 int largest_changestamp_; // Stored in the serialized proto. | 523 int largest_changestamp_; // Stored in the serialized proto. |
| 477 ContentOrigin origin_; | 524 ContentOrigin origin_; |
| 478 | 525 |
| 479 // This should remain the last member so it'll be destroyed first and | 526 // This should remain the last member so it'll be destroyed first and |
| 480 // invalidate its weak pointers before other members are destroyed. | 527 // invalidate its weak pointers before other members are destroyed. |
| 481 base::WeakPtrFactory<GDataDirectoryService> weak_ptr_factory_; | 528 base::WeakPtrFactory<GDataDirectoryService> weak_ptr_factory_; |
| 482 | 529 |
| 483 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); | 530 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); |
| 484 }; | 531 }; |
| 485 | 532 |
| 486 } // namespace gdata | 533 } // namespace gdata |
| 487 | 534 |
| 488 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 535 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
| OLD | NEW |