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