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 <map> | |
9 #include <set> | 8 #include <set> |
10 #include <string> | 9 #include <string> |
11 #include <vector> | 10 #include <vector> |
12 | 11 |
13 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
14 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
15 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
17 #include "base/time/time.h" | 16 #include "base/time/time.h" |
18 #include "chrome/browser/chromeos/drive/file_errors.h" | 17 #include "chrome/browser/chromeos/drive/file_errors.h" |
19 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h" | 18 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h" |
20 | 19 |
21 namespace base { | 20 namespace base { |
22 class SequencedTaskRunner; | 21 class SequencedTaskRunner; |
23 } | 22 } |
24 | 23 |
25 namespace drive { | 24 namespace drive { |
26 | 25 |
27 class ResourceEntry; | 26 typedef std::vector<ResourceEntry> ResourceEntryVector; |
28 | 27 |
29 typedef std::vector<ResourceEntry> ResourceEntryVector; | |
30 typedef std::map<std::string /* resource_id */, ResourceEntry> | |
31 ResourceEntryMap; | |
32 | |
33 // Holds information needed to fetch contents of a directory. | |
34 // This object is copyable. | |
35 class DirectoryFetchInfo { | |
36 public: | |
37 DirectoryFetchInfo() : changestamp_(0) {} | |
38 DirectoryFetchInfo(const std::string& resource_id, | |
39 int64 changestamp) | |
40 : resource_id_(resource_id), | |
41 changestamp_(changestamp) { | |
42 } | |
43 | |
44 // Returns true if the object is empty. | |
45 bool empty() const { return resource_id_.empty(); } | |
46 | |
47 // Resource ID of the directory. | |
48 const std::string& resource_id() const { return resource_id_; } | |
49 | |
50 // Changestamp of the directory. The changestamp is used to determine if | |
51 // the directory contents should be fetched. | |
52 int64 changestamp() const { return changestamp_; } | |
53 | |
54 // Returns a string representation of this object. | |
55 std::string ToString() const; | |
56 | |
57 private: | |
58 const std::string resource_id_; | |
59 const int64 changestamp_; | |
60 }; | |
61 | 28 |
62 // Callback similar to FileOperationCallback but with a given |file_path|. | 29 // Callback similar to FileOperationCallback but with a given |file_path|. |
63 // Used for operations that change a file path like moving files. | 30 // Used for operations that change a file path like moving files. |
64 typedef base::Callback<void(FileError error, | 31 typedef base::Callback<void(FileError error, |
65 const base::FilePath& file_path)> | 32 const base::FilePath& file_path)> |
66 FileMoveCallback; | 33 FileMoveCallback; |
67 | 34 |
68 // Used to get a resource entry from the file system. | 35 // Used to get a resource entry from the file system. |
69 // If |error| is not FILE_ERROR_OK, |entry_info| is set to NULL. | 36 // If |error| is not FILE_ERROR_OK, |entry_info| is set to NULL. |
70 typedef base::Callback<void(FileError error, | 37 typedef base::Callback<void(FileError error, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // entry of |second_path|. |callback| must not be null. | 177 // entry of |second_path|. |callback| must not be null. |
211 // Must be called on the UI thread. | 178 // Must be called on the UI thread. |
212 void GetResourceEntryPairByPathsOnUIThread( | 179 void GetResourceEntryPairByPathsOnUIThread( |
213 const base::FilePath& first_path, | 180 const base::FilePath& first_path, |
214 const base::FilePath& second_path, | 181 const base::FilePath& second_path, |
215 const GetResourceEntryPairCallback& callback); | 182 const GetResourceEntryPairCallback& callback); |
216 | 183 |
217 // Replaces an existing entry whose ID is |entry.resource_id()| with |entry|. | 184 // Replaces an existing entry whose ID is |entry.resource_id()| with |entry|. |
218 FileError RefreshEntry(const ResourceEntry& entry); | 185 FileError RefreshEntry(const ResourceEntry& entry); |
219 | 186 |
220 // Updates the changestamp of a directory according to |directory_fetch_info|, | |
221 // and adds or refreshes the child entries from |entry_map|. | |
222 // |callback| is called with the directory path. |callback| must not be null. | |
223 // Must be called on the UI thread. | |
224 void RefreshDirectoryOnUIThread( | |
225 const DirectoryFetchInfo& directory_fetch_info, | |
226 const ResourceEntryMap& entry_map, | |
227 const FileMoveCallback& callback); | |
228 | |
229 // Recursively get child directories of entry pointed to by |resource_id|. | 187 // Recursively get child directories of entry pointed to by |resource_id|. |
230 void GetChildDirectories(const std::string& resource_id, | 188 void GetChildDirectories(const std::string& resource_id, |
231 std::set<base::FilePath>* child_directories); | 189 std::set<base::FilePath>* child_directories); |
232 | 190 |
233 // Returns the resource id of the resource named |base_name| directly under | 191 // Returns the resource id of the resource named |base_name| directly under |
234 // the directory with |parent_local_id|. | 192 // the directory with |parent_local_id|. |
235 // If not found, empty string will be returned. | 193 // If not found, empty string will be returned. |
236 std::string GetChildResourceId(const std::string& parent_local_id, | 194 std::string GetChildResourceId(const std::string& parent_local_id, |
237 const std::string& base_name); | 195 const std::string& base_name); |
238 | 196 |
(...skipping 16 matching lines...) Expand all Loading... |
255 // Used to implement MoveEntryToDirectoryOnUIThread(). | 213 // Used to implement MoveEntryToDirectoryOnUIThread(). |
256 FileError MoveEntryToDirectory(const base::FilePath& file_path, | 214 FileError MoveEntryToDirectory(const base::FilePath& file_path, |
257 const base::FilePath& directory_path, | 215 const base::FilePath& directory_path, |
258 base::FilePath* out_file_path); | 216 base::FilePath* out_file_path); |
259 | 217 |
260 // Used to implement RenameEntryOnUIThread(). | 218 // Used to implement RenameEntryOnUIThread(). |
261 FileError RenameEntry(const base::FilePath& file_path, | 219 FileError RenameEntry(const base::FilePath& file_path, |
262 const std::string& new_name, | 220 const std::string& new_name, |
263 base::FilePath* out_file_path); | 221 base::FilePath* out_file_path); |
264 | 222 |
265 // Used to implement RefreshDirectoryOnUIThread(). | |
266 FileError RefreshDirectory(const DirectoryFetchInfo& directory_fetch_info, | |
267 const ResourceEntryMap& entry_map, | |
268 base::FilePath* out_file_path); | |
269 | |
270 // Continues with GetResourceEntryPairByPathsOnUIThread after the first | 223 // Continues with GetResourceEntryPairByPathsOnUIThread after the first |
271 // entry has been asynchronously fetched. This fetches the second entry | 224 // entry has been asynchronously fetched. This fetches the second entry |
272 // only if the first was found. | 225 // only if the first was found. |
273 void GetResourceEntryPairByPathsOnUIThreadAfterGetFirst( | 226 void GetResourceEntryPairByPathsOnUIThreadAfterGetFirst( |
274 const base::FilePath& first_path, | 227 const base::FilePath& first_path, |
275 const base::FilePath& second_path, | 228 const base::FilePath& second_path, |
276 const GetResourceEntryPairCallback& callback, | 229 const GetResourceEntryPairCallback& callback, |
277 FileError error, | 230 FileError error, |
278 scoped_ptr<ResourceEntry> entry); | 231 scoped_ptr<ResourceEntry> entry); |
279 | 232 |
(...skipping 27 matching lines...) Expand all Loading... |
307 // invalidate its weak pointers before other members are destroyed. | 260 // invalidate its weak pointers before other members are destroyed. |
308 base::WeakPtrFactory<ResourceMetadata> weak_ptr_factory_; | 261 base::WeakPtrFactory<ResourceMetadata> weak_ptr_factory_; |
309 | 262 |
310 DISALLOW_COPY_AND_ASSIGN(ResourceMetadata); | 263 DISALLOW_COPY_AND_ASSIGN(ResourceMetadata); |
311 }; | 264 }; |
312 | 265 |
313 } // namespace internal | 266 } // namespace internal |
314 } // namespace drive | 267 } // namespace drive |
315 | 268 |
316 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_ | 269 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_ |
OLD | NEW |