Chromium Code Reviews| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 const char kGDataRootDirectoryResourceId[] = "folder:root"; | 67 const char kGDataRootDirectoryResourceId[] = "folder:root"; |
| 68 | 68 |
| 69 // This should be incremented when incompatibility change is made in | 69 // This should be incremented when incompatibility change is made in |
| 70 // gdata.proto. | 70 // gdata.proto. |
| 71 const int32 kProtoVersion = 1; | 71 const int32 kProtoVersion = 1; |
| 72 | 72 |
| 73 // Used for file operations like removing files. | 73 // Used for file operations like removing files. |
| 74 typedef base::Callback<void(GDataFileError error)> | 74 typedef base::Callback<void(GDataFileError error)> |
| 75 FileOperationCallback; | 75 FileOperationCallback; |
| 76 | 76 |
| 77 // Callback similar to FileOperationCallback but with a given |file_path|. | |
| 78 typedef base::Callback<void(GDataFileError error, | |
| 79 const FilePath& file_path)> | |
| 80 FilePathUpdateCallback; | |
| 81 | |
| 77 // Base class for representing files and directories in gdata virtual file | 82 // Base class for representing files and directories in gdata virtual file |
| 78 // system. | 83 // system. |
| 79 class GDataEntry { | 84 class GDataEntry { |
| 80 public: | 85 public: |
| 81 GDataEntry(GDataDirectory* parent, GDataDirectoryService* directory_service); | 86 GDataEntry(GDataDirectory* parent, GDataDirectoryService* directory_service); |
| 82 virtual ~GDataEntry(); | 87 virtual ~GDataEntry(); |
| 83 | 88 |
| 84 virtual GDataFile* AsGDataFile(); | 89 virtual GDataFile* AsGDataFile(); |
| 85 virtual GDataDirectory* AsGDataDirectory(); | 90 virtual GDataDirectory* AsGDataDirectory(); |
| 86 | 91 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 // Converts DocumentEntry into GDataEntry. | 279 // Converts DocumentEntry into GDataEntry. |
| 275 static GDataEntry* FromDocumentEntry( | 280 static GDataEntry* FromDocumentEntry( |
| 276 GDataDirectory* parent, | 281 GDataDirectory* parent, |
| 277 DocumentEntry* doc, | 282 DocumentEntry* doc, |
| 278 GDataDirectoryService* directory_service); | 283 GDataDirectoryService* directory_service); |
| 279 | 284 |
| 280 // Converts to/from proto. | 285 // Converts to/from proto. |
| 281 bool FromProto(const GDataDirectoryProto& proto) WARN_UNUSED_RESULT; | 286 bool FromProto(const GDataDirectoryProto& proto) WARN_UNUSED_RESULT; |
| 282 void ToProto(GDataDirectoryProto* proto) const; | 287 void ToProto(GDataDirectoryProto* proto) const; |
| 283 | 288 |
| 284 // Removes child elements. | |
| 285 void RemoveChildren(); | |
| 286 void RemoveChildFiles(); | |
| 287 void RemoveChildDirectories(); | |
| 288 | |
| 289 // Collection of children files/directories. | 289 // Collection of children files/directories. |
| 290 const GDataFileCollection& child_files() const { return child_files_; } | 290 const GDataFileCollection& child_files() const { return child_files_; } |
| 291 const GDataDirectoryCollection& child_directories() const { | 291 const GDataDirectoryCollection& child_directories() const { |
| 292 return child_directories_; | 292 return child_directories_; |
| 293 } | 293 } |
| 294 | 294 |
| 295 private: | 295 private: |
| 296 // TODO(satorux): Remove the friend statements. crbug.com/139649 | 296 // TODO(satorux): Remove the friend statements. crbug.com/139649 |
| 297 friend class GDataDirectoryService; | 297 friend class GDataDirectoryService; |
| 298 friend class GDataFileSystem; | 298 friend class GDataFileSystem; |
| 299 friend class GDataWapiFeedProcessor; | 299 friend class GDataWapiFeedProcessor; |
| 300 | 300 |
| 301 // Adds child file to the directory and takes over the ownership of |file| | 301 // Adds child file to the directory and takes over the ownership of |file| |
| 302 // object. The method will also do name de-duplication to ensure that the | 302 // object. The method will also do name de-duplication to ensure that the |
| 303 // exposed presentation path does not have naming conflicts. Two files with | 303 // exposed presentation path does not have naming conflicts. Two files with |
| 304 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". | 304 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". |
| 305 // TODO(satorux): Remove this. crbug.com/139649 | 305 // TODO(satorux): Remove this. crbug.com/139649 |
| 306 void AddEntry(GDataEntry* entry); | 306 void AddEntry(GDataEntry* entry); |
| 307 | 307 |
| 308 // Removes the entry from its children list and destroys the entry instance. | 308 // Removes the entry from its children list and destroys the entry instance. |
| 309 // TODO(satorux): Remove this. crbug.com/139649 | 309 // TODO(satorux): Remove this. crbug.com/139649 |
| 310 void RemoveEntry(GDataEntry* entry); | 310 void RemoveEntry(GDataEntry* entry); |
| 311 | 311 |
| 312 // Takes the ownership of |entry| from its current parent. If this directory | |
| 313 // is already the current parent of |file|, this method effectively goes | |
| 314 // through the name de-duplication for |file| based on the current state of | |
| 315 // the file system. | |
| 316 // TODO(satorux): Remove this. crbug.com/139649 | |
| 317 bool TakeEntry(GDataEntry* entry); | |
| 318 | |
| 319 // Takes over all entries from |dir|. | 312 // Takes over all entries from |dir|. |
| 320 // TODO(satorux): Remove this. crbug.com/139649 | 313 // TODO(satorux): Remove this. crbug.com/139649 |
| 321 bool TakeOverEntries(GDataDirectory* dir); | 314 bool TakeOverEntries(GDataDirectory* dir); |
| 322 | 315 |
| 323 // Find a child by its name. | 316 // Find a child by its name. |
| 324 // TODO(satorux): Remove this. crbug.com/139649 | 317 // TODO(satorux): Remove this. crbug.com/139649 |
| 325 GDataEntry* FindChild(const FilePath::StringType& file_name) const; | 318 GDataEntry* FindChild(const FilePath::StringType& file_name) const; |
| 326 | 319 |
| 327 // Add |entry| to children. | 320 // Add |entry| to children. |
| 328 void AddChild(GDataEntry* entry); | 321 void AddChild(GDataEntry* entry); |
| 329 | 322 |
| 330 // Removes the entry from its children without destroying the | 323 // Removes the entry from its children without destroying the |
| 331 // entry instance. | 324 // entry instance. |
| 332 void RemoveChild(GDataEntry* entry); | 325 void RemoveChild(GDataEntry* entry); |
| 333 | 326 |
| 327 // Removes child elements. | |
| 328 void RemoveChildren(); | |
| 329 void RemoveChildFiles(); | |
| 330 void RemoveChildDirectories(); | |
| 331 | |
| 334 // Collection of children GDataEntry items. | 332 // Collection of children GDataEntry items. |
| 335 GDataFileCollection child_files_; | 333 GDataFileCollection child_files_; |
| 336 GDataDirectoryCollection child_directories_; | 334 GDataDirectoryCollection child_directories_; |
| 337 | 335 |
| 338 DISALLOW_COPY_AND_ASSIGN(GDataDirectory); | 336 DISALLOW_COPY_AND_ASSIGN(GDataDirectory); |
| 339 }; | 337 }; |
| 340 | 338 |
| 341 // TODO(achuith,hashimoto,satorux): Move this to a separate file. | 339 // TODO(achuith,hashimoto,satorux): Move this to a separate file. |
| 342 // crbug.com/140317. | 340 // crbug.com/140317. |
| 343 // Class to handle GDataEntry* lookups, add/remove GDataEntry*. | 341 // Class to handle GDataEntry* lookups, add/remove GDataEntry*. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 364 // Largest change timestamp that was the source of content for the current | 362 // Largest change timestamp that was the source of content for the current |
| 365 // state of the root directory. | 363 // state of the root directory. |
| 366 const int largest_changestamp() const { return largest_changestamp_; } | 364 const int largest_changestamp() const { return largest_changestamp_; } |
| 367 void set_largest_changestamp(int value) { largest_changestamp_ = value; } | 365 void set_largest_changestamp(int value) { largest_changestamp_ = value; } |
| 368 | 366 |
| 369 // The root directory content origin. | 367 // The root directory content origin. |
| 370 const ContentOrigin origin() const { return origin_; } | 368 const ContentOrigin origin() const { return origin_; } |
| 371 void set_origin(ContentOrigin value) { origin_ = value; } | 369 void set_origin(ContentOrigin value) { origin_ = value; } |
| 372 | 370 |
| 373 // Adds |entry| to |directory_path| asynchronously. | 371 // Adds |entry| to |directory_path| asynchronously. |
| 374 // Must be called on UI thread. |callback| is called on the UI thread. | 372 // Must be called on UI thread. |callback| is called on the UI thread. |
|
satorux1
2012/08/08 14:09:06
The semantics of the function seems to be changed.
achuithb
2012/08/08 22:08:41
I can update the comment to state that the entry i
| |
| 375 void AddEntryToDirectory(const FilePath& directory_path, | 373 void AddEntryToDirectory(const FilePath& directory_path, |
| 376 GDataEntry* entry, | 374 GDataEntry* entry, |
| 377 const FileOperationCallback& callback); | 375 const FilePathUpdateCallback& callback); |
| 378 | 376 |
| 379 // Adds the entry to resource map. | 377 // Adds the entry to resource map. |
| 380 void AddEntryToResourceMap(GDataEntry* entry); | 378 void AddEntryToResourceMap(GDataEntry* entry); |
| 381 | 379 |
| 382 // Removes the entry from resource map. | 380 // Removes the entry from resource map. |
| 383 void RemoveEntryFromResourceMap(GDataEntry* entry); | 381 void RemoveEntryFromResourceMap(GDataEntry* entry); |
| 384 | 382 |
| 385 // Searches for |file_path| synchronously. | 383 // Searches for |file_path| synchronously. |
| 386 // TODO(satorux): Replace this with an async version crbug.com/137160 | 384 // TODO(satorux): Replace this with an async version crbug.com/137160 |
| 387 GDataEntry* FindEntryByPathSync(const FilePath& file_path); | 385 GDataEntry* FindEntryByPathSync(const FilePath& file_path); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 // This should remain the last member so it'll be destroyed first and | 448 // This should remain the last member so it'll be destroyed first and |
| 451 // invalidate its weak pointers before other members are destroyed. | 449 // invalidate its weak pointers before other members are destroyed. |
| 452 base::WeakPtrFactory<GDataDirectoryService> weak_ptr_factory_; | 450 base::WeakPtrFactory<GDataDirectoryService> weak_ptr_factory_; |
| 453 | 451 |
| 454 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); | 452 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); |
| 455 }; | 453 }; |
| 456 | 454 |
| 457 } // namespace gdata | 455 } // namespace gdata |
| 458 | 456 |
| 459 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 457 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
| OLD | NEW |