| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 REGULAR_FILE, | 52 REGULAR_FILE, |
| 53 HOSTED_DOCUMENT, | 53 HOSTED_DOCUMENT, |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // Base class for representing files and directories in gdata virtual file | 56 // Base class for representing files and directories in gdata virtual file |
| 57 // system. | 57 // system. |
| 58 class GDataEntry { | 58 class GDataEntry { |
| 59 public: | 59 public: |
| 60 explicit GDataEntry(GDataDirectory* parent, GDataRootDirectory* root); | 60 explicit GDataEntry(GDataDirectory* parent, GDataRootDirectory* root); |
| 61 virtual ~GDataEntry(); | 61 virtual ~GDataEntry(); |
| 62 |
| 62 virtual GDataFile* AsGDataFile(); | 63 virtual GDataFile* AsGDataFile(); |
| 63 virtual GDataDirectory* AsGDataDirectory(); | 64 virtual GDataDirectory* AsGDataDirectory(); |
| 64 virtual GDataRootDirectory* AsGDataRootDirectory(); | 65 virtual GDataRootDirectory* AsGDataRootDirectory(); |
| 65 | 66 |
| 67 // const versions of AsGDataFile and AsGDataDirectory. |
| 68 const GDataFile* AsGDataFileConst() const; |
| 69 const GDataDirectory* AsGDataDirectoryConst() const; |
| 70 |
| 66 // Converts DocumentEntry into GDataEntry. | 71 // Converts DocumentEntry into GDataEntry. |
| 67 static GDataEntry* FromDocumentEntry(GDataDirectory* parent, | 72 static GDataEntry* FromDocumentEntry(GDataDirectory* parent, |
| 68 DocumentEntry* doc, | 73 DocumentEntry* doc, |
| 69 GDataRootDirectory* root); | 74 GDataRootDirectory* root); |
| 70 | 75 |
| 76 // Serialize/Parse to/from string via proto classes. |
| 77 void SerializeToString(std::string* serialized_proto) const; |
| 78 static scoped_ptr<GDataEntry> FromProtoString( |
| 79 const std::string& serialized_proto); |
| 80 |
| 71 // Convert to/from proto. | 81 // Convert to/from proto. |
| 72 void FromProto(const GDataEntryProto& proto); | 82 void FromProto(const GDataEntryProto& proto); |
| 73 void ToProto(GDataEntryProto* proto) const; | 83 void ToProto(GDataEntryProto* proto) const; |
| 74 | 84 |
| 75 // Escapes forward slashes from file names with magic unicode character | 85 // Escapes forward slashes from file names with magic unicode character |
| 76 // \u2215 pretty much looks the same in UI. | 86 // \u2215 pretty much looks the same in UI. |
| 77 static std::string EscapeUtf8FileName(const std::string& input); | 87 static std::string EscapeUtf8FileName(const std::string& input); |
| 78 | 88 |
| 79 // Unescapes what was escaped in EScapeUtf8FileName. | 89 // Unescapes what was escaped in EScapeUtf8FileName. |
| 80 static std::string UnescapeUtf8FileName(const std::string& input); | 90 static std::string UnescapeUtf8FileName(const std::string& input); |
| 81 | 91 |
| 82 GDataDirectory* parent() { return parent_; } | 92 GDataDirectory* parent() { return parent_; } |
| 83 const base::PlatformFileInfo& file_info() const { return file_info_; } | 93 const base::PlatformFileInfo& file_info() const { return file_info_; } |
| 94 |
| 84 const FilePath::StringType& file_name() const { return file_name_; } | 95 const FilePath::StringType& file_name() const { return file_name_; } |
| 85 const FilePath::StringType& title() const { | |
| 86 return title_; | |
| 87 } | |
| 88 void set_title(const FilePath::StringType& title) { | |
| 89 title_ = title; | |
| 90 } | |
| 91 void set_file_name(const FilePath::StringType& name) { file_name_ = name; } | 96 void set_file_name(const FilePath::StringType& name) { file_name_ = name; } |
| 92 | 97 |
| 98 const FilePath::StringType& title() const { return title_; } |
| 99 void set_title(const FilePath::StringType& title) { title_ = title; } |
| 100 |
| 93 // The unique resource ID associated with this file system entry. | 101 // The unique resource ID associated with this file system entry. |
| 94 const std::string& resource_id() const { return resource_id_; } | 102 const std::string& resource_id() const { return resource_id_; } |
| 103 void set_resource_id(const std::string& res_id) { resource_id_ = res_id; } |
| 95 | 104 |
| 96 // The content URL is used for downloading regular files as is. | 105 // The content URL is used for downloading regular files as is. |
| 97 const GURL& content_url() const { return content_url_; } | 106 const GURL& content_url() const { return content_url_; } |
| 107 void set_content_url(const GURL& url) { content_url_ = url; } |
| 98 | 108 |
| 99 // The edit URL is used for removing files and hosted documents. | 109 // The edit URL is used for removing files and hosted documents. |
| 100 const GURL& edit_url() const { return edit_url_; } | 110 const GURL& edit_url() const { return edit_url_; } |
| 101 | 111 |
| 102 // The resource id of the parent folder. This piece of information is needed | 112 // The resource id of the parent folder. This piece of information is needed |
| 103 // to pair files from change feeds with their directory parents withing the | 113 // to pair files from change feeds with their directory parents withing the |
| 104 // existing file system snapshot (GDataRootDirectory::resource_map_). | 114 // existing file system snapshot (GDataRootDirectory::resource_map_). |
| 105 const std::string& parent_resource_id() const { return parent_resource_id_; } | 115 const std::string& parent_resource_id() const { return parent_resource_id_; } |
| 106 | 116 |
| 107 // True if file was deleted. Used only for instances that are generated from | 117 // True if file was deleted. Used only for instances that are generated from |
| 108 // delta feeds. | 118 // delta feeds. |
| 109 bool is_deleted() const { return deleted_; } | 119 bool is_deleted() const { return deleted_; } |
| 110 | 120 |
| 111 // Returns virtual file path representing this file system entry. This path | 121 // Returns virtual file path representing this file system entry. This path |
| 112 // corresponds to file path expected by public methods of GDataFileSyste | 122 // corresponds to file path expected by public methods of GDataFileSyste |
| 113 // class. | 123 // class. |
| 114 FilePath GetFilePath(); | 124 FilePath GetFilePath() const; |
| 115 | 125 |
| 116 // Sets |file_name_| based on the value of |title_| without name | 126 // Sets |file_name_| based on the value of |title_| without name |
| 117 // de-duplication (see AddEntry() for details on de-duplication). | 127 // de-duplication (see AddEntry() for details on de-duplication). |
| 118 virtual void SetFileNameFromTitle(); | 128 virtual void SetFileNameFromTitle(); |
| 119 | 129 |
| 120 protected: | 130 protected: |
| 121 // GDataDirectory::TakeEntry() needs to call GDataEntry::set_parent(). | 131 // GDataDirectory::TakeEntry() needs to call GDataEntry::set_parent(). |
| 122 friend class GDataDirectory; | 132 friend class GDataDirectory; |
| 123 | 133 |
| 124 // Sets the parent directory of this file system entry. | 134 // Sets the parent directory of this file system entry. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 return cache_state &= ~CACHE_STATE_MOUNTED; | 224 return cache_state &= ~CACHE_STATE_MOUNTED; |
| 215 } | 225 } |
| 216 | 226 |
| 217 DocumentEntry::EntryKind kind() const { return kind_; } | 227 DocumentEntry::EntryKind kind() const { return kind_; } |
| 218 const GURL& thumbnail_url() const { return thumbnail_url_; } | 228 const GURL& thumbnail_url() const { return thumbnail_url_; } |
| 219 const GURL& alternate_url() const { return alternate_url_; } | 229 const GURL& alternate_url() const { return alternate_url_; } |
| 220 const std::string& content_mime_type() const { return content_mime_type_; } | 230 const std::string& content_mime_type() const { return content_mime_type_; } |
| 221 const std::string& etag() const { return etag_; } | 231 const std::string& etag() const { return etag_; } |
| 222 const std::string& id() const { return id_; } | 232 const std::string& id() const { return id_; } |
| 223 const std::string& file_md5() const { return file_md5_; } | 233 const std::string& file_md5() const { return file_md5_; } |
| 234 void set_file_md5(const std::string& file_md5) { file_md5_ = file_md5; } |
| 224 const std::string& document_extension() const { return document_extension_; } | 235 const std::string& document_extension() const { return document_extension_; } |
| 225 bool is_hosted_document() const { return is_hosted_document_; } | 236 bool is_hosted_document() const { return is_hosted_document_; } |
| 226 | 237 |
| 227 // Overrides GDataEntry::SetFileNameFromTitle() to set |file_name_| based | 238 // Overrides GDataEntry::SetFileNameFromTitle() to set |file_name_| based |
| 228 // on the value of |title_| as well as |is_hosted_document_| and | 239 // on the value of |title_| as well as |is_hosted_document_| and |
| 229 // |document_extension_| for hosted documents. | 240 // |document_extension_| for hosted documents. |
| 230 virtual void SetFileNameFromTitle() OVERRIDE; | 241 virtual void SetFileNameFromTitle() OVERRIDE; |
| 231 | 242 |
| 232 private: | 243 private: |
| 233 // Content URL for files. | 244 // Content URL for files. |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 int largest_changestamp() const { return largest_changestamp_; } | 402 int largest_changestamp() const { return largest_changestamp_; } |
| 392 void set_largest_changestamp(int value) { largest_changestamp_ = value; } | 403 void set_largest_changestamp(int value) { largest_changestamp_ = value; } |
| 393 // Last time when we dumped serialized file system to disk. | 404 // Last time when we dumped serialized file system to disk. |
| 394 const base::Time& last_serialized() const { return last_serialized_; } | 405 const base::Time& last_serialized() const { return last_serialized_; } |
| 395 void set_last_serialized(const base::Time& time) { last_serialized_ = time; } | 406 void set_last_serialized(const base::Time& time) { last_serialized_ = time; } |
| 396 // Size of serialized file system on disk in bytes. | 407 // Size of serialized file system on disk in bytes. |
| 397 const size_t serialized_size() const { return serialized_size_; } | 408 const size_t serialized_size() const { return serialized_size_; } |
| 398 void set_serialized_size(size_t size) { serialized_size_ = size; } | 409 void set_serialized_size(size_t size) { serialized_size_ = size; } |
| 399 | 410 |
| 400 // GDataEntry implementation. | 411 // GDataEntry implementation. |
| 401 | |
| 402 virtual GDataRootDirectory* AsGDataRootDirectory() OVERRIDE; | 412 virtual GDataRootDirectory* AsGDataRootDirectory() OVERRIDE; |
| 403 | 413 |
| 404 // Add the entry to resource map. | 414 // Add the entry to resource map. |
| 405 void AddEntryToResourceMap(GDataEntry* entry); | 415 void AddEntryToResourceMap(GDataEntry* entry); |
| 406 | 416 |
| 407 // Remove the entry from resource map. | 417 // Remove the entry from resource map. |
| 408 void RemoveEntryFromResourceMap(GDataEntry* entry); | 418 void RemoveEntryFromResourceMap(GDataEntry* entry); |
| 409 | 419 |
| 410 // Remove the entries from resource map. | 420 // Remove the entries from resource map. |
| 411 void RemoveEntriesFromResourceMap(const GDataFileCollection& children); | 421 void RemoveEntriesFromResourceMap(const GDataFileCollection& children); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 base::Time last_serialized_; | 462 base::Time last_serialized_; |
| 453 int largest_changestamp_; | 463 int largest_changestamp_; |
| 454 size_t serialized_size_; | 464 size_t serialized_size_; |
| 455 | 465 |
| 456 DISALLOW_COPY_AND_ASSIGN(GDataRootDirectory); | 466 DISALLOW_COPY_AND_ASSIGN(GDataRootDirectory); |
| 457 }; | 467 }; |
| 458 | 468 |
| 459 } // namespace gdata | 469 } // namespace gdata |
| 460 | 470 |
| 461 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 471 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
| OLD | NEW |