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_DRIVE_RESOURCE_METADATA_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "chrome/browser/chromeos/drive/file_errors.h" | 16 #include "chrome/browser/chromeos/drive/file_errors.h" |
17 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h" | 17 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class SequencedTaskRunner; | 20 class SequencedTaskRunner; |
21 } | 21 } |
22 | 22 |
23 namespace drive { | 23 namespace drive { |
24 | 24 |
25 typedef std::vector<ResourceEntry> ResourceEntryVector; | 25 typedef std::vector<ResourceEntry> ResourceEntryVector; |
26 | 26 |
27 | |
28 // Callback similar to FileOperationCallback but with a given |file_path|. | |
29 // Used for operations that change a file path like moving files. | |
30 typedef base::Callback<void(FileError error, | |
31 const base::FilePath& file_path)> | |
32 FileMoveCallback; | |
33 | |
34 // Used to get a resource entry from the file system. | 27 // Used to get a resource entry from the file system. |
35 // If |error| is not FILE_ERROR_OK, |entry_info| is set to NULL. | 28 // If |error| is not FILE_ERROR_OK, |entry_info| is set to NULL. |
36 typedef base::Callback<void(FileError error, | 29 typedef base::Callback<void(FileError error, |
37 scoped_ptr<ResourceEntry> entry)> | 30 scoped_ptr<ResourceEntry> entry)> |
38 GetResourceEntryCallback; | 31 GetResourceEntryCallback; |
39 | 32 |
40 typedef base::Callback<void(FileError error, | 33 typedef base::Callback<void(FileError error, |
41 scoped_ptr<ResourceEntryVector> entries)> | 34 scoped_ptr<ResourceEntryVector> entries)> |
42 ReadDirectoryCallback; | 35 ReadDirectoryCallback; |
43 | 36 |
44 typedef base::Callback<void(int64)> GetChangestampCallback; | 37 typedef base::Callback<void(int64)> GetChangestampCallback; |
45 | 38 |
46 // This is a part of EntryInfoPairResult. | |
47 struct EntryInfoResult { | |
48 EntryInfoResult(); | |
49 ~EntryInfoResult(); | |
50 | |
51 base::FilePath path; | |
52 FileError error; | |
53 scoped_ptr<ResourceEntry> entry; | |
54 }; | |
55 | |
56 // The result of GetResourceEntryPairCallback(). Used to get a pair of entries | |
57 // in one function call. | |
58 struct EntryInfoPairResult { | |
59 EntryInfoPairResult(); | |
60 ~EntryInfoPairResult(); | |
61 | |
62 EntryInfoResult first; | |
63 EntryInfoResult second; // Only filled if the first entry is found. | |
64 }; | |
65 | |
66 // Used to receive the result from GetResourceEntryPairCallback(). | |
67 typedef base::Callback<void(scoped_ptr<EntryInfoPairResult> pair_result)> | |
68 GetResourceEntryPairCallback; | |
69 | |
70 typedef base::Callback<void(const ResourceEntry& entry)> IterateCallback; | 39 typedef base::Callback<void(const ResourceEntry& entry)> IterateCallback; |
71 | 40 |
72 namespace internal { | 41 namespace internal { |
73 | 42 |
74 // Storage for Drive Metadata. | 43 // Storage for Drive Metadata. |
75 // All methods must be run with |blocking_task_runner| unless otherwise noted. | 44 // All methods must be run with |blocking_task_runner| unless otherwise noted. |
76 class ResourceMetadata { | 45 class ResourceMetadata { |
77 public: | 46 public: |
78 typedef ResourceMetadataStorage::Iterator Iterator; | 47 typedef ResourceMetadataStorage::Iterator Iterator; |
79 | 48 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // Finds and reads a directory by |file_path|. | 109 // Finds and reads a directory by |file_path|. |
141 // |callback| must not be null. | 110 // |callback| must not be null. |
142 // Must be called on the UI thread. | 111 // Must be called on the UI thread. |
143 void ReadDirectoryByPathOnUIThread(const base::FilePath& file_path, | 112 void ReadDirectoryByPathOnUIThread(const base::FilePath& file_path, |
144 const ReadDirectoryCallback& callback); | 113 const ReadDirectoryCallback& callback); |
145 | 114 |
146 // Synchronous version of ReadDirectoryByPathOnUIThread(). | 115 // Synchronous version of ReadDirectoryByPathOnUIThread(). |
147 FileError ReadDirectoryByPath(const base::FilePath& file_path, | 116 FileError ReadDirectoryByPath(const base::FilePath& file_path, |
148 ResourceEntryVector* out_entries); | 117 ResourceEntryVector* out_entries); |
149 | 118 |
150 // Similar to GetResourceEntryByPath() but this function finds a pair of | |
151 // entries by |first_path| and |second_path|. If the entry for | |
152 // |first_path| is not found, this function does not try to get the | |
153 // entry of |second_path|. |callback| must not be null. | |
154 // Must be called on the UI thread. | |
155 void GetResourceEntryPairByPathsOnUIThread( | |
156 const base::FilePath& first_path, | |
157 const base::FilePath& second_path, | |
158 const GetResourceEntryPairCallback& callback); | |
159 | |
160 // Replaces an existing entry whose ID is |id| with |entry|. | 119 // Replaces an existing entry whose ID is |id| with |entry|. |
161 FileError RefreshEntry(const std::string& id, const ResourceEntry& entry); | 120 FileError RefreshEntry(const std::string& id, const ResourceEntry& entry); |
162 | 121 |
163 // Recursively gets directories under the entry pointed to by |id|. | 122 // Recursively gets directories under the entry pointed to by |id|. |
164 void GetSubDirectoriesRecursively(const std::string& id, | 123 void GetSubDirectoriesRecursively(const std::string& id, |
165 std::set<base::FilePath>* sub_directories); | 124 std::set<base::FilePath>* sub_directories); |
166 | 125 |
167 // Returns the resource id of the resource named |base_name| directly under | 126 // Returns the resource id of the resource named |base_name| directly under |
168 // the directory with |parent_local_id|. | 127 // the directory with |parent_local_id|. |
169 // If not found, empty string will be returned. | 128 // If not found, empty string will be returned. |
(...skipping 16 matching lines...) Expand all Loading... |
186 private: | 145 private: |
187 // Note: Use Destroy() to delete this object. | 146 // Note: Use Destroy() to delete this object. |
188 ~ResourceMetadata(); | 147 ~ResourceMetadata(); |
189 | 148 |
190 // Sets up entries which should be present by default. | 149 // Sets up entries which should be present by default. |
191 bool SetUpDefaultEntries(); | 150 bool SetUpDefaultEntries(); |
192 | 151 |
193 // Used to implement Destroy(). | 152 // Used to implement Destroy(). |
194 void DestroyOnBlockingPool(); | 153 void DestroyOnBlockingPool(); |
195 | 154 |
196 // Continues with GetResourceEntryPairByPathsOnUIThread after the first | |
197 // entry has been asynchronously fetched. This fetches the second entry | |
198 // only if the first was found. | |
199 void GetResourceEntryPairByPathsOnUIThreadAfterGetFirst( | |
200 const base::FilePath& first_path, | |
201 const base::FilePath& second_path, | |
202 const GetResourceEntryPairCallback& callback, | |
203 FileError error, | |
204 scoped_ptr<ResourceEntry> entry); | |
205 | |
206 // Continues with GetResourceEntryPairByPathsOnUIThread after the second | |
207 // entry has been asynchronously fetched. | |
208 void GetResourceEntryPairByPathsOnUIThreadAfterGetSecond( | |
209 const base::FilePath& second_path, | |
210 const GetResourceEntryPairCallback& callback, | |
211 scoped_ptr<EntryInfoPairResult> result, | |
212 FileError error, | |
213 scoped_ptr<ResourceEntry> entry); | |
214 | |
215 // Puts an entry under its parent directory. Removes the child from the old | 155 // Puts an entry under its parent directory. Removes the child from the old |
216 // parent if there is. This method will also do name de-duplication to ensure | 156 // parent if there is. This method will also do name de-duplication to ensure |
217 // that the exposed presentation path does not have naming conflicts. Two | 157 // that the exposed presentation path does not have naming conflicts. Two |
218 // files with the same name "Foo" will be renamed to "Foo (1)" and "Foo (2)". | 158 // files with the same name "Foo" will be renamed to "Foo (1)" and "Foo (2)". |
219 // |id| is used as the ID of the entry. | 159 // |id| is used as the ID of the entry. |
220 bool PutEntryUnderDirectory(const std::string& id, | 160 bool PutEntryUnderDirectory(const std::string& id, |
221 const ResourceEntry& entry); | 161 const ResourceEntry& entry); |
222 | 162 |
223 // Removes the entry and its descendants. | 163 // Removes the entry and its descendants. |
224 bool RemoveEntryRecursively(const std::string& id); | 164 bool RemoveEntryRecursively(const std::string& id); |
225 | 165 |
226 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 166 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
227 | 167 |
228 ResourceMetadataStorage* storage_; | 168 ResourceMetadataStorage* storage_; |
229 | 169 |
230 // This should remain the last member so it'll be destroyed first and | 170 // This should remain the last member so it'll be destroyed first and |
231 // invalidate its weak pointers before other members are destroyed. | 171 // invalidate its weak pointers before other members are destroyed. |
232 base::WeakPtrFactory<ResourceMetadata> weak_ptr_factory_; | 172 base::WeakPtrFactory<ResourceMetadata> weak_ptr_factory_; |
233 | 173 |
234 DISALLOW_COPY_AND_ASSIGN(ResourceMetadata); | 174 DISALLOW_COPY_AND_ASSIGN(ResourceMetadata); |
235 }; | 175 }; |
236 | 176 |
237 } // namespace internal | 177 } // namespace internal |
238 } // namespace drive | 178 } // namespace drive |
239 | 179 |
240 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_ | 180 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_ |
OLD | NEW |