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