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_DRIVE_RESOURCE_METADATA_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_RESOURCE_METADATA_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_RESOURCE_METADATA_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_RESOURCE_METADATA_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 277 |
278 // Searches for |file_path| synchronously. | 278 // Searches for |file_path| synchronously. |
279 DriveEntryProto* FindEntryByPathSync(const base::FilePath& file_path); | 279 DriveEntryProto* FindEntryByPathSync(const base::FilePath& file_path); |
280 | 280 |
281 // Helper function to get a directory given |resource_id|. |resource_id| can | 281 // Helper function to get a directory given |resource_id|. |resource_id| can |
282 // not be empty. Returns NULL if it finds no corresponding entry, or the | 282 // not be empty. Returns NULL if it finds no corresponding entry, or the |
283 // corresponding entry is not a directory. | 283 // corresponding entry is not a directory. |
284 DriveEntryProto* GetDirectory(const std::string& resource_id); | 284 DriveEntryProto* GetDirectory(const std::string& resource_id); |
285 | 285 |
286 // Returns virtual file path of the entry. | 286 // Returns virtual file path of the entry. |
287 base::FilePath GetFilePath(const DriveEntryProto& entry); | 287 base::FilePath GetFilePath(const std::string& resource_id); |
288 | 288 |
289 // Recursively extracts the paths set of all sub-directories. | 289 // Recursively extracts the paths set of all sub-directories. |
290 void GetDescendantDirectoryPaths(const DriveEntryProto& directory, | 290 void GetDescendantDirectoryPaths(const std::string& resource_id, |
291 std::set<base::FilePath>* child_directories); | 291 std::set<base::FilePath>* child_directories); |
292 | 292 |
293 // Adds child file to the directory and takes over the ownership of |entry| | 293 // Adds child file to its parent and takes over the ownership of |entry| |
294 // object. The method will also do name de-duplication to ensure that the | 294 // object. The method will also do name de-duplication to ensure that the |
295 // exposed presentation path does not have naming conflicts. Two files with | 295 // exposed presentation path does not have naming conflicts. Two files with |
296 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". | 296 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". |
297 void AddEntryToDirectory(DriveEntryProto* directory, DriveEntryProto* entry); | 297 void AddEntryToDirectory(DriveEntryProto* entry); |
298 | 298 |
299 // Removes the entry from its children list and destroys the entry instance. | 299 // Removes the entry from its parent and destroys the entry instance. |
300 void RemoveDirectoryChild(DriveEntryProto* directory, DriveEntryProto* entry); | 300 void RemoveDirectoryChild(const std::string& child_resource_id); |
301 | 301 |
302 // Find a child's resource_id by its name. Returns the empty string if not | 302 // Find a child's resource_id by its name. Returns the empty string if not |
303 // found. | 303 // found. |
304 std::string FindDirectoryChild(DriveEntryProto* directory, | 304 std::string FindDirectoryChild(const std::string& directory_resource_id, |
305 const base::FilePath::StringType& file_name); | 305 const base::FilePath::StringType& file_name); |
306 | 306 |
307 // Removes the entry from its children without destroying the | 307 // Detaches the entry from its parent without destroying the entry instance. |
308 // entry instance. | 308 void DetachEntryFromDirectory(const std::string& child_resource_id); |
309 void DetachEntryFromDirectory(DriveEntryProto* directory, | |
310 DriveEntryProto* entry); | |
311 | 309 |
312 // Removes child elements of directory. | 310 // Removes child elements of directory. |
313 void RemoveDirectoryChildren(DriveEntryProto* directory); | 311 void RemoveDirectoryChildren(const std::string& directory_resource_id); |
314 | 312 |
315 // Converts directory to proto, and vice versa. | 313 // Sets up directory based on |proto|. |
316 void ProtoToDirectory(const DriveDirectoryProto& proto, | 314 void ProtoToDirectory(const DriveDirectoryProto& proto); |
317 DriveEntryProto* directory); | 315 |
318 void DirectoryToProto(DriveEntryProto* directory, | 316 // Converts directory to proto. |
| 317 void DirectoryToProto(const std::string& directory_resource_id, |
319 DriveDirectoryProto* proto); | 318 DriveDirectoryProto* proto); |
320 | 319 |
321 // Converts the children as a vector of DriveEntryProto. | 320 // Converts the children as a vector of DriveEntryProto. |
322 scoped_ptr<DriveEntryProtoVector> DirectoryChildrenToProtoVector( | 321 scoped_ptr<DriveEntryProtoVector> DirectoryChildrenToProtoVector( |
323 DriveEntryProto* directory); | 322 const std::string& directory_resource_id); |
324 | 323 |
325 // Private data members. | 324 // Private data members. |
326 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 325 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
327 | 326 |
328 ResourceMap resource_map_; | 327 ResourceMap resource_map_; |
329 | 328 |
330 ChildMaps child_maps_; | 329 ChildMaps child_maps_; |
331 | 330 |
332 scoped_ptr<DriveEntryProto> root_; | 331 scoped_ptr<DriveEntryProto> root_; |
333 | 332 |
334 base::Time last_serialized_; | 333 base::Time last_serialized_; |
335 size_t serialized_size_; | 334 size_t serialized_size_; |
336 int64 largest_changestamp_; // Stored in the serialized proto. | 335 int64 largest_changestamp_; // Stored in the serialized proto. |
337 bool loaded_; | 336 bool loaded_; |
338 | 337 |
339 // This should remain the last member so it'll be destroyed first and | 338 // This should remain the last member so it'll be destroyed first and |
340 // invalidate its weak pointers before other members are destroyed. | 339 // invalidate its weak pointers before other members are destroyed. |
341 base::WeakPtrFactory<DriveResourceMetadata> weak_ptr_factory_; | 340 base::WeakPtrFactory<DriveResourceMetadata> weak_ptr_factory_; |
342 | 341 |
343 DISALLOW_COPY_AND_ASSIGN(DriveResourceMetadata); | 342 DISALLOW_COPY_AND_ASSIGN(DriveResourceMetadata); |
344 }; | 343 }; |
345 | 344 |
346 } // namespace drive | 345 } // namespace drive |
347 | 346 |
348 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_RESOURCE_METADATA_H_ | 347 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_RESOURCE_METADATA_H_ |
OLD | NEW |