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