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 // Used to get entry info from the file system. |
| 78 // If |error| is not GDATA_FILE_OK, |entry_info| is set to NULL. |
| 79 typedef base::Callback<void(GDataFileError error, |
| 80 scoped_ptr<GDataEntryProto> entry_proto)> |
| 81 GetEntryInfoCallback; |
| 82 |
| 83 // Used to read a directory from the file system. |
| 84 // If |error| is not GDATA_FILE_OK, |entries| is set to NULL. |
| 85 // |entries| are contents, both files and directories, of the directory. |
| 86 typedef std::vector<GDataEntryProto> GDataEntryProtoVector; |
| 87 typedef base::Callback<void(GDataFileError error, |
| 88 scoped_ptr<GDataEntryProtoVector> entries)> |
| 89 ReadDirectoryCallback; |
77 // Base class for representing files and directories in gdata virtual file | 90 // Base class for representing files and directories in gdata virtual file |
78 // system. | 91 // system. |
79 class GDataEntry { | 92 class GDataEntry { |
80 public: | 93 public: |
81 GDataEntry(GDataDirectory* parent, GDataDirectoryService* directory_service); | 94 GDataEntry(GDataDirectory* parent, GDataDirectoryService* directory_service); |
82 virtual ~GDataEntry(); | 95 virtual ~GDataEntry(); |
83 | 96 |
84 virtual GDataFile* AsGDataFile(); | 97 virtual GDataFile* AsGDataFile(); |
85 virtual GDataDirectory* AsGDataDirectory(); | 98 virtual GDataDirectory* AsGDataDirectory(); |
86 | 99 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 // Converts DocumentEntry into GDataEntry. | 287 // Converts DocumentEntry into GDataEntry. |
275 static GDataEntry* FromDocumentEntry( | 288 static GDataEntry* FromDocumentEntry( |
276 GDataDirectory* parent, | 289 GDataDirectory* parent, |
277 DocumentEntry* doc, | 290 DocumentEntry* doc, |
278 GDataDirectoryService* directory_service); | 291 GDataDirectoryService* directory_service); |
279 | 292 |
280 // Converts to/from proto. | 293 // Converts to/from proto. |
281 bool FromProto(const GDataDirectoryProto& proto) WARN_UNUSED_RESULT; | 294 bool FromProto(const GDataDirectoryProto& proto) WARN_UNUSED_RESULT; |
282 void ToProto(GDataDirectoryProto* proto) const; | 295 void ToProto(GDataDirectoryProto* proto) const; |
283 | 296 |
| 297 // Converts the children as a vector of GDataEntryProto. |
| 298 scoped_ptr<GDataEntryProtoVector> ToProtoVector() const; |
| 299 |
284 // Removes child elements. | 300 // Removes child elements. |
285 void RemoveChildren(); | 301 void RemoveChildren(); |
286 void RemoveChildFiles(); | 302 void RemoveChildFiles(); |
287 void RemoveChildDirectories(); | 303 void RemoveChildDirectories(); |
288 | 304 |
289 // Collection of children files/directories. | 305 // Collection of children files/directories. |
290 const GDataFileCollection& child_files() const { return child_files_; } | 306 const GDataFileCollection& child_files() const { return child_files_; } |
291 const GDataDirectoryCollection& child_directories() const { | 307 const GDataDirectoryCollection& child_directories() const { |
292 return child_directories_; | 308 return child_directories_; |
293 } | 309 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 | 409 |
394 // Returns the GDataEntry* with the corresponding |resource_id|. | 410 // Returns the GDataEntry* with the corresponding |resource_id|. |
395 // TODO(achuith): Get rid of this in favor of async version crbug.com/13957. | 411 // TODO(achuith): Get rid of this in favor of async version crbug.com/13957. |
396 GDataEntry* GetEntryByResourceId(const std::string& resource_id); | 412 GDataEntry* GetEntryByResourceId(const std::string& resource_id); |
397 | 413 |
398 // Returns the GDataEntry* in the callback with the corresponding | 414 // Returns the GDataEntry* in the callback with the corresponding |
399 // |resource_id|. TODO(achuith): Rename this to GetEntryByResourceId. | 415 // |resource_id|. TODO(achuith): Rename this to GetEntryByResourceId. |
400 void GetEntryByResourceIdAsync(const std::string& resource_id, | 416 void GetEntryByResourceIdAsync(const std::string& resource_id, |
401 const GetEntryByResourceIdCallback& callback); | 417 const GetEntryByResourceIdCallback& callback); |
402 | 418 |
| 419 // Finds an entry (a file or a directory) by |file_path|. |
| 420 // |
| 421 // Must be called from UI thread. |callback| is run on UI thread. |
| 422 void GetEntryInfoByPath(const FilePath& file_path, |
| 423 const GetEntryInfoCallback& callback); |
| 424 |
| 425 // Finds and reads a directory by |file_path|. |
| 426 // |
| 427 // Must be called from UI thread. |callback| is run on UI thread. |
| 428 void ReadDirectoryByPath(const FilePath& file_path, |
| 429 const ReadDirectoryCallback& callback); |
| 430 |
403 // Replaces file entry with the same resource id as |fresh_file| with its | 431 // Replaces file entry with the same resource id as |fresh_file| with its |
404 // fresh value |fresh_file|. | 432 // fresh value |fresh_file|. |
405 void RefreshFile(scoped_ptr<GDataFile> fresh_file); | 433 void RefreshFile(scoped_ptr<GDataFile> fresh_file); |
406 | 434 |
407 // Replaces file entry |old_entry| with its fresh value |fresh_file|. | 435 // Replaces file entry |old_entry| with its fresh value |fresh_file|. |
408 static void RefreshFileInternal(scoped_ptr<GDataFile> fresh_file, | 436 static void RefreshFileInternal(scoped_ptr<GDataFile> fresh_file, |
409 GDataEntry* old_entry); | 437 GDataEntry* old_entry); |
410 | 438 |
411 // Serializes/Parses to/from string via proto classes. | 439 // Serializes/Parses to/from string via proto classes. |
412 void SerializeToString(std::string* serialized_proto) const; | 440 void SerializeToString(std::string* serialized_proto) const; |
(...skipping 37 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 | 478 // This should remain the last member so it'll be destroyed first and |
451 // invalidate its weak pointers before other members are destroyed. | 479 // invalidate its weak pointers before other members are destroyed. |
452 base::WeakPtrFactory<GDataDirectoryService> weak_ptr_factory_; | 480 base::WeakPtrFactory<GDataDirectoryService> weak_ptr_factory_; |
453 | 481 |
454 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); | 482 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); |
455 }; | 483 }; |
456 | 484 |
457 } // namespace gdata | 485 } // namespace gdata |
458 | 486 |
459 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 487 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
OLD | NEW |