| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/files/file_path.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/threading/thread_checker.h" | |
| 15 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h" | |
| 16 #include "components/drive/file_errors.h" | |
| 17 | |
| 18 namespace base { | |
| 19 class SequencedTaskRunner; | |
| 20 } | |
| 21 | |
| 22 namespace drive { | |
| 23 | |
| 24 typedef std::vector<ResourceEntry> ResourceEntryVector; | |
| 25 | |
| 26 namespace internal { | |
| 27 | |
| 28 class FileCache; | |
| 29 | |
| 30 // Storage for Drive Metadata. | |
| 31 // All methods except the constructor and Destroy() function must be run with | |
| 32 // |blocking_task_runner| unless otherwise noted. | |
| 33 class ResourceMetadata { | |
| 34 public: | |
| 35 typedef ResourceMetadataStorage::Iterator Iterator; | |
| 36 | |
| 37 ResourceMetadata( | |
| 38 ResourceMetadataStorage* storage, | |
| 39 FileCache* cache, | |
| 40 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); | |
| 41 | |
| 42 // Initializes this object. | |
| 43 // This method should be called before any other methods. | |
| 44 FileError Initialize() WARN_UNUSED_RESULT; | |
| 45 | |
| 46 // Destroys this object. This method posts a task to |blocking_task_runner_| | |
| 47 // to safely delete this object. | |
| 48 // Must be called on the UI thread. | |
| 49 void Destroy(); | |
| 50 | |
| 51 // Resets this object. | |
| 52 FileError Reset(); | |
| 53 | |
| 54 // Returns the largest changestamp. | |
| 55 FileError GetLargestChangestamp(int64* out_value); | |
| 56 | |
| 57 // Sets the largest changestamp. | |
| 58 FileError SetLargestChangestamp(int64 value); | |
| 59 | |
| 60 // Adds |entry| to the metadata tree based on its parent_local_id. | |
| 61 FileError AddEntry(const ResourceEntry& entry, std::string* out_id); | |
| 62 | |
| 63 // Removes entry with |id| from its parent. | |
| 64 FileError RemoveEntry(const std::string& id); | |
| 65 | |
| 66 // Finds an entry (a file or a directory) by |id|. | |
| 67 FileError GetResourceEntryById(const std::string& id, | |
| 68 ResourceEntry* out_entry); | |
| 69 | |
| 70 // Synchronous version of GetResourceEntryByPathOnUIThread(). | |
| 71 FileError GetResourceEntryByPath(const base::FilePath& file_path, | |
| 72 ResourceEntry* out_entry); | |
| 73 | |
| 74 // Finds and reads a directory by |file_path|. | |
| 75 FileError ReadDirectoryByPath(const base::FilePath& file_path, | |
| 76 ResourceEntryVector* out_entries); | |
| 77 | |
| 78 // Finds and reads a directory by |id|. | |
| 79 FileError ReadDirectoryById(const std::string& id, | |
| 80 ResourceEntryVector* out_entries); | |
| 81 | |
| 82 // Replaces an existing entry with the same local ID as |entry|. | |
| 83 FileError RefreshEntry(const ResourceEntry& entry); | |
| 84 | |
| 85 // Recursively gets directories under the entry pointed to by |id|. | |
| 86 FileError GetSubDirectoriesRecursively( | |
| 87 const std::string& id, | |
| 88 std::set<base::FilePath>* sub_directories); | |
| 89 | |
| 90 // Returns the id of the resource named |base_name| directly under | |
| 91 // the directory with |parent_local_id|. | |
| 92 // If not found, empty string will be returned. | |
| 93 FileError GetChildId(const std::string& parent_local_id, | |
| 94 const std::string& base_name, | |
| 95 std::string* out_child_id); | |
| 96 | |
| 97 // Returns an object to iterate over entries. | |
| 98 scoped_ptr<Iterator> GetIterator(); | |
| 99 | |
| 100 // Returns virtual file path of the entry. | |
| 101 FileError GetFilePath(const std::string& id, base::FilePath* out_file_path); | |
| 102 | |
| 103 // Returns ID of the entry at the given path. | |
| 104 FileError GetIdByPath(const base::FilePath& file_path, std::string* out_id); | |
| 105 | |
| 106 // Returns the local ID associated with the given resource ID. | |
| 107 FileError GetIdByResourceId(const std::string& resource_id, | |
| 108 std::string* out_local_id); | |
| 109 | |
| 110 private: | |
| 111 // Note: Use Destroy() to delete this object. | |
| 112 ~ResourceMetadata(); | |
| 113 | |
| 114 // Sets up entries which should be present by default. | |
| 115 FileError SetUpDefaultEntries(); | |
| 116 | |
| 117 // Used to implement Destroy(). | |
| 118 void DestroyOnBlockingPool(); | |
| 119 | |
| 120 // Puts an entry under its parent directory. Removes the child from the old | |
| 121 // parent if there is. This method will also do name de-duplication to ensure | |
| 122 // that the exposed presentation path does not have naming conflicts. Two | |
| 123 // files with the same name "Foo" will be renamed to "Foo (1)" and "Foo (2)". | |
| 124 FileError PutEntryUnderDirectory(const ResourceEntry& entry); | |
| 125 | |
| 126 // Returns an unused base name for |entry|. | |
| 127 FileError GetDeduplicatedBaseName(const ResourceEntry& entry, | |
| 128 std::string* base_name); | |
| 129 | |
| 130 // Removes the entry and its descendants. | |
| 131 FileError RemoveEntryRecursively(const std::string& id); | |
| 132 | |
| 133 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | |
| 134 | |
| 135 ResourceMetadataStorage* storage_; | |
| 136 FileCache* cache_; | |
| 137 | |
| 138 base::ThreadChecker thread_checker_; | |
| 139 | |
| 140 DISALLOW_COPY_AND_ASSIGN(ResourceMetadata); | |
| 141 }; | |
| 142 | |
| 143 } // namespace internal | |
| 144 } // namespace drive | |
| 145 | |
| 146 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_ | |
| OLD | NEW |