| 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 // Used for operations that change a file path like moving files. |
| 79 typedef base::Callback<void(GDataFileError error, |
| 80 const FilePath& file_path)> |
| 81 FileMoveCallback; |
| 82 |
| 77 // Used to get entry info from the file system. | 83 // Used to get entry info from the file system. |
| 78 // If |error| is not GDATA_FILE_OK, |entry_info| is set to NULL. | 84 // If |error| is not GDATA_FILE_OK, |entry_info| is set to NULL. |
| 79 typedef base::Callback<void(GDataFileError error, | 85 typedef base::Callback<void(GDataFileError error, |
| 80 scoped_ptr<GDataEntryProto> entry_proto)> | 86 scoped_ptr<GDataEntryProto> entry_proto)> |
| 81 GetEntryInfoCallback; | 87 GetEntryInfoCallback; |
| 82 | 88 |
| 83 // Used to read a directory from the file system. | 89 // Used to read a directory from the file system. |
| 84 // If |error| is not GDATA_FILE_OK, |entries| is set to NULL. | 90 // If |error| is not GDATA_FILE_OK, |entries| is set to NULL. |
| 85 // |entries| are contents, both files and directories, of the directory. | 91 // |entries| are contents, both files and directories, of the directory. |
| 86 typedef std::vector<GDataEntryProto> GDataEntryProtoVector; | 92 typedef std::vector<GDataEntryProto> GDataEntryProtoVector; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 109 }; | 115 }; |
| 110 | 116 |
| 111 // Used to receive the result from GetEntryInfoPairCallback(). | 117 // Used to receive the result from GetEntryInfoPairCallback(). |
| 112 typedef base::Callback<void(scoped_ptr<EntryInfoPairResult> pair_result)> | 118 typedef base::Callback<void(scoped_ptr<EntryInfoPairResult> pair_result)> |
| 113 GetEntryInfoPairCallback; | 119 GetEntryInfoPairCallback; |
| 114 | 120 |
| 115 // Base class for representing files and directories in gdata virtual file | 121 // Base class for representing files and directories in gdata virtual file |
| 116 // system. | 122 // system. |
| 117 class GDataEntry { | 123 class GDataEntry { |
| 118 public: | 124 public: |
| 125 // TODO(achuith): Remove |parent| from ctor. crbug.com/141494 |
| 119 GDataEntry(GDataDirectory* parent, GDataDirectoryService* directory_service); | 126 GDataEntry(GDataDirectory* parent, GDataDirectoryService* directory_service); |
| 120 virtual ~GDataEntry(); | 127 virtual ~GDataEntry(); |
| 121 | 128 |
| 122 virtual GDataFile* AsGDataFile(); | 129 virtual GDataFile* AsGDataFile(); |
| 123 virtual GDataDirectory* AsGDataDirectory(); | 130 virtual GDataDirectory* AsGDataDirectory(); |
| 124 | 131 |
| 125 // const versions of AsGDataFile and AsGDataDirectory. | 132 // const versions of AsGDataFile and AsGDataDirectory. |
| 126 const GDataFile* AsGDataFileConst() const; | 133 const GDataFile* AsGDataFileConst() const; |
| 127 const GDataDirectory* AsGDataDirectoryConst() const; | 134 const GDataDirectory* AsGDataDirectoryConst() const; |
| 128 | 135 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 }; | 258 }; |
| 252 | 259 |
| 253 typedef std::map<FilePath::StringType, GDataFile*> GDataFileCollection; | 260 typedef std::map<FilePath::StringType, GDataFile*> GDataFileCollection; |
| 254 typedef std::map<FilePath::StringType, GDataDirectory*> | 261 typedef std::map<FilePath::StringType, GDataDirectory*> |
| 255 GDataDirectoryCollection; | 262 GDataDirectoryCollection; |
| 256 | 263 |
| 257 // Represents "file" in in a GData virtual file system. On gdata feed side, | 264 // Represents "file" in in a GData virtual file system. On gdata feed side, |
| 258 // this could be either a regular file or a server side document. | 265 // this could be either a regular file or a server side document. |
| 259 class GDataFile : public GDataEntry { | 266 class GDataFile : public GDataEntry { |
| 260 public: | 267 public: |
| 268 // TODO(achuith): Remove |parent| from ctor. crbug.com/141494 |
| 261 explicit GDataFile(GDataDirectory* parent, | 269 explicit GDataFile(GDataDirectory* parent, |
| 262 GDataDirectoryService* directory_service); | 270 GDataDirectoryService* directory_service); |
| 263 virtual ~GDataFile(); | 271 virtual ~GDataFile(); |
| 264 virtual GDataFile* AsGDataFile() OVERRIDE; | 272 virtual GDataFile* AsGDataFile() OVERRIDE; |
| 265 | 273 |
| 266 // Converts DocumentEntry into GDataEntry. | 274 // Converts DocumentEntry into GDataEntry. |
| 267 static GDataEntry* FromDocumentEntry( | 275 static GDataEntry* FromDocumentEntry( |
| 268 GDataDirectory* parent, | 276 GDataDirectory* parent, |
| 269 DocumentEntry* doc, | 277 DocumentEntry* doc, |
| 270 GDataDirectoryService* directory_service); | 278 GDataDirectoryService* directory_service); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 297 std::string document_extension_; | 305 std::string document_extension_; |
| 298 bool is_hosted_document_; | 306 bool is_hosted_document_; |
| 299 | 307 |
| 300 DISALLOW_COPY_AND_ASSIGN(GDataFile); | 308 DISALLOW_COPY_AND_ASSIGN(GDataFile); |
| 301 }; | 309 }; |
| 302 | 310 |
| 303 // Represents "directory" in a GData virtual file system. Maps to gdata | 311 // Represents "directory" in a GData virtual file system. Maps to gdata |
| 304 // collection element. | 312 // collection element. |
| 305 class GDataDirectory : public GDataEntry { | 313 class GDataDirectory : public GDataEntry { |
| 306 public: | 314 public: |
| 315 // TODO(achuith): Remove |parent| from ctor. crbug.com/141494 |
| 307 GDataDirectory(GDataDirectory* parent, | 316 GDataDirectory(GDataDirectory* parent, |
| 308 GDataDirectoryService* directory_service); | 317 GDataDirectoryService* directory_service); |
| 309 virtual ~GDataDirectory(); | 318 virtual ~GDataDirectory(); |
| 310 virtual GDataDirectory* AsGDataDirectory() OVERRIDE; | 319 virtual GDataDirectory* AsGDataDirectory() OVERRIDE; |
| 311 | 320 |
| 312 // Converts DocumentEntry into GDataEntry. | 321 // Converts DocumentEntry into GDataEntry. |
| 313 static GDataEntry* FromDocumentEntry( | 322 static GDataEntry* FromDocumentEntry( |
| 314 GDataDirectory* parent, | 323 GDataDirectory* parent, |
| 315 DocumentEntry* doc, | 324 DocumentEntry* doc, |
| 316 GDataDirectoryService* directory_service); | 325 GDataDirectoryService* directory_service); |
| 317 | 326 |
| 318 // Converts to/from proto. | 327 // Converts to/from proto. |
| 319 bool FromProto(const GDataDirectoryProto& proto) WARN_UNUSED_RESULT; | 328 bool FromProto(const GDataDirectoryProto& proto) WARN_UNUSED_RESULT; |
| 320 void ToProto(GDataDirectoryProto* proto) const; | 329 void ToProto(GDataDirectoryProto* proto) const; |
| 321 | 330 |
| 322 // Converts the children as a vector of GDataEntryProto. | 331 // Converts the children as a vector of GDataEntryProto. |
| 323 scoped_ptr<GDataEntryProtoVector> ToProtoVector() const; | 332 scoped_ptr<GDataEntryProtoVector> ToProtoVector() const; |
| 324 | 333 |
| 325 // Removes child elements. | |
| 326 void RemoveChildren(); | |
| 327 void RemoveChildFiles(); | |
| 328 void RemoveChildDirectories(); | |
| 329 | |
| 330 // Collection of children files/directories. | 334 // Collection of children files/directories. |
| 331 const GDataFileCollection& child_files() const { return child_files_; } | 335 const GDataFileCollection& child_files() const { return child_files_; } |
| 332 const GDataDirectoryCollection& child_directories() const { | 336 const GDataDirectoryCollection& child_directories() const { |
| 333 return child_directories_; | 337 return child_directories_; |
| 334 } | 338 } |
| 335 | 339 |
| 336 private: | 340 private: |
| 337 // TODO(satorux): Remove the friend statements. crbug.com/139649 | 341 // TODO(satorux): Remove the friend statements. crbug.com/139649 |
| 338 friend class GDataDirectoryService; | 342 friend class GDataDirectoryService; |
| 339 friend class GDataFileSystem; | 343 friend class GDataFileSystem; |
| 340 friend class GDataWapiFeedProcessor; | 344 friend class GDataWapiFeedProcessor; |
| 341 | 345 |
| 342 // Adds child file to the directory and takes over the ownership of |file| | 346 // Adds child file to the directory and takes over the ownership of |file| |
| 343 // object. The method will also do name de-duplication to ensure that the | 347 // object. The method will also do name de-duplication to ensure that the |
| 344 // exposed presentation path does not have naming conflicts. Two files with | 348 // exposed presentation path does not have naming conflicts. Two files with |
| 345 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". | 349 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". |
| 346 // TODO(satorux): Remove this. crbug.com/139649 | 350 // TODO(satorux): Remove this. crbug.com/139649 |
| 347 void AddEntry(GDataEntry* entry); | 351 void AddEntry(GDataEntry* entry); |
| 348 | 352 |
| 349 // Removes the entry from its children list and destroys the entry instance. | 353 // Removes the entry from its children list and destroys the entry instance. |
| 350 // TODO(satorux): Remove this. crbug.com/139649 | 354 // TODO(satorux): Remove this. crbug.com/139649 |
| 351 void RemoveEntry(GDataEntry* entry); | 355 void RemoveEntry(GDataEntry* entry); |
| 352 | 356 |
| 353 // Takes the ownership of |entry| from its current parent. If this directory | |
| 354 // is already the current parent of |file|, this method effectively goes | |
| 355 // through the name de-duplication for |file| based on the current state of | |
| 356 // the file system. | |
| 357 // TODO(satorux): Remove this. crbug.com/139649 | |
| 358 bool TakeEntry(GDataEntry* entry); | |
| 359 | |
| 360 // Takes over all entries from |dir|. | 357 // Takes over all entries from |dir|. |
| 361 // TODO(satorux): Remove this. crbug.com/139649 | 358 // TODO(satorux): Remove this. crbug.com/139649 |
| 362 bool TakeOverEntries(GDataDirectory* dir); | 359 bool TakeOverEntries(GDataDirectory* dir); |
| 363 | 360 |
| 364 // Find a child by its name. | 361 // Find a child by its name. |
| 365 // TODO(satorux): Remove this. crbug.com/139649 | 362 // TODO(satorux): Remove this. crbug.com/139649 |
| 366 GDataEntry* FindChild(const FilePath::StringType& file_name) const; | 363 GDataEntry* FindChild(const FilePath::StringType& file_name) const; |
| 367 | 364 |
| 368 // Add |entry| to children. | 365 // Add |entry| to children. |
| 369 void AddChild(GDataEntry* entry); | 366 void AddChild(GDataEntry* entry); |
| 370 | 367 |
| 371 // Removes the entry from its children without destroying the | 368 // Removes the entry from its children without destroying the |
| 372 // entry instance. | 369 // entry instance. |
| 373 void RemoveChild(GDataEntry* entry); | 370 void RemoveChild(GDataEntry* entry); |
| 374 | 371 |
| 372 // Removes child elements. |
| 373 void RemoveChildren(); |
| 374 void RemoveChildFiles(); |
| 375 void RemoveChildDirectories(); |
| 376 |
| 375 // Collection of children GDataEntry items. | 377 // Collection of children GDataEntry items. |
| 376 GDataFileCollection child_files_; | 378 GDataFileCollection child_files_; |
| 377 GDataDirectoryCollection child_directories_; | 379 GDataDirectoryCollection child_directories_; |
| 378 | 380 |
| 379 DISALLOW_COPY_AND_ASSIGN(GDataDirectory); | 381 DISALLOW_COPY_AND_ASSIGN(GDataDirectory); |
| 380 }; | 382 }; |
| 381 | 383 |
| 382 // TODO(achuith,hashimoto,satorux): Move this to a separate file. | 384 // TODO(achuith,hashimoto,satorux): Move this to a separate file. |
| 383 // crbug.com/140317. | 385 // crbug.com/140317. |
| 384 // Class to handle GDataEntry* lookups, add/remove GDataEntry*. | 386 // Class to handle GDataEntry* lookups, add/remove GDataEntry*. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 404 | 406 |
| 405 // Largest change timestamp that was the source of content for the current | 407 // Largest change timestamp that was the source of content for the current |
| 406 // state of the root directory. | 408 // state of the root directory. |
| 407 const int largest_changestamp() const { return largest_changestamp_; } | 409 const int largest_changestamp() const { return largest_changestamp_; } |
| 408 void set_largest_changestamp(int value) { largest_changestamp_ = value; } | 410 void set_largest_changestamp(int value) { largest_changestamp_ = value; } |
| 409 | 411 |
| 410 // The root directory content origin. | 412 // The root directory content origin. |
| 411 const ContentOrigin origin() const { return origin_; } | 413 const ContentOrigin origin() const { return origin_; } |
| 412 void set_origin(ContentOrigin value) { origin_ = value; } | 414 void set_origin(ContentOrigin value) { origin_ = value; } |
| 413 | 415 |
| 414 // Adds |entry| to |directory_path| asynchronously. | 416 // Move |entry| to |directory_path| asynchronously. Removes entry from |
| 415 // Must be called on UI thread. |callback| is called on the UI thread. | 417 // previous parent. Must be called on UI thread. |callback| is called on the |
| 416 void AddEntryToDirectory(const FilePath& directory_path, | 418 // UI thread. |
| 417 GDataEntry* entry, | 419 void MoveEntryToDirectory(const FilePath& directory_path, |
| 418 const FileOperationCallback& callback); | 420 GDataEntry* entry, |
| 421 const FileMoveCallback& callback); |
| 419 | 422 |
| 420 // Adds the entry to resource map. | 423 // Adds the entry to resource map. |
| 421 void AddEntryToResourceMap(GDataEntry* entry); | 424 void AddEntryToResourceMap(GDataEntry* entry); |
| 422 | 425 |
| 423 // Removes the entry from resource map. | 426 // Removes the entry from resource map. |
| 424 void RemoveEntryFromResourceMap(GDataEntry* entry); | 427 void RemoveEntryFromResourceMap(GDataEntry* entry); |
| 425 | 428 |
| 426 // Searches for |file_path| synchronously. | 429 // Searches for |file_path| synchronously. |
| 427 // TODO(satorux): Replace this with an async version crbug.com/137160 | 430 // TODO(satorux): Replace this with an async version crbug.com/137160 |
| 428 GDataEntry* FindEntryByPathSync(const FilePath& file_path); | 431 GDataEntry* FindEntryByPathSync(const FilePath& file_path); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 // This should remain the last member so it'll be destroyed first and | 533 // This should remain the last member so it'll be destroyed first and |
| 531 // invalidate its weak pointers before other members are destroyed. | 534 // invalidate its weak pointers before other members are destroyed. |
| 532 base::WeakPtrFactory<GDataDirectoryService> weak_ptr_factory_; | 535 base::WeakPtrFactory<GDataDirectoryService> weak_ptr_factory_; |
| 533 | 536 |
| 534 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); | 537 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); |
| 535 }; | 538 }; |
| 536 | 539 |
| 537 } // namespace gdata | 540 } // namespace gdata |
| 538 | 541 |
| 539 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 542 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
| OLD | NEW |