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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 virtual GDataFile* AsGDataFile(); | 64 virtual GDataFile* AsGDataFile(); |
65 virtual GDataDirectory* AsGDataDirectory(); | 65 virtual GDataDirectory* AsGDataDirectory(); |
66 virtual GDataRootDirectory* AsGDataRootDirectory(); | 66 virtual GDataRootDirectory* AsGDataRootDirectory(); |
67 | 67 |
68 // const versions of AsGDataFile and AsGDataDirectory. | 68 // const versions of AsGDataFile and AsGDataDirectory. |
69 const GDataFile* AsGDataFileConst() const; | 69 const GDataFile* AsGDataFileConst() const; |
70 const GDataDirectory* AsGDataDirectoryConst() const; | 70 const GDataDirectory* AsGDataDirectoryConst() const; |
71 | 71 |
72 // Converts DocumentEntry into GDataEntry. | 72 // Converts DocumentEntry into GDataEntry. |
73 static GDataEntry* FromDocumentEntry(GDataDirectory* parent, | 73 static GDataEntry* FromDocumentEntry(GDataDirectory* parent, |
74 DocumentEntry* doc, | 74 DocumentEntry* doc, |
75 GDataRootDirectory* root); | 75 GDataRootDirectory* root); |
76 | 76 |
77 // Serialize/Parse to/from string via proto classes. | 77 // Serialize/Parse to/from string via proto classes. |
78 // TODO(achuith): Correctly set up parent_ and root_ links in | 78 // TODO(achuith): Correctly set up parent_ and root_ links in |
79 // FromProtoString. | 79 // FromProtoString. |
80 void SerializeToString(std::string* serialized_proto) const; | 80 void SerializeToString(std::string* serialized_proto) const; |
81 static scoped_ptr<GDataEntry> FromProtoString( | 81 static scoped_ptr<GDataEntry> FromProtoString( |
82 const std::string& serialized_proto); | 82 const std::string& serialized_proto); |
83 | 83 |
84 // Converts to/from proto. | 84 // Converts to/from proto. |
85 void FromProto(const GDataEntryProto& proto); | 85 void FromProto(const GDataEntryProto& proto); |
86 void ToProto(GDataEntryProto* proto) const; | 86 void ToProto(GDataEntryProto* proto) const; |
87 | 87 |
88 // Escapes forward slashes from file names with magic unicode character | 88 // Escapes forward slashes from file names with magic unicode character |
89 // \u2215 pretty much looks the same in UI. | 89 // \u2215 pretty much looks the same in UI. |
90 static std::string EscapeUtf8FileName(const std::string& input); | 90 static std::string EscapeUtf8FileName(const std::string& input); |
91 | 91 |
92 // Unescapes what was escaped in EScapeUtf8FileName. | 92 // Unescapes what was escaped in EScapeUtf8FileName. |
93 static std::string UnescapeUtf8FileName(const std::string& input); | 93 static std::string UnescapeUtf8FileName(const std::string& input); |
94 | 94 |
95 GDataDirectory* parent() { return parent_; } | 95 // Return the parent of this entry. NULL for root. |
96 GDataDirectory* parent() const { return parent_; } | |
96 const base::PlatformFileInfo& file_info() const { return file_info_; } | 97 const base::PlatformFileInfo& file_info() const { return file_info_; } |
97 | 98 |
98 const FilePath::StringType& file_name() const { return file_name_; } | 99 const FilePath::StringType& file_name() const { return file_name_; } |
100 // Sets the file name. file_name_ gets reset by SetFileNameFromTitle(). | |
99 void set_file_name(const FilePath::StringType& name) { file_name_ = name; } | 101 void set_file_name(const FilePath::StringType& name) { file_name_ = name; } |
satorux1
2012/04/27 21:35:41
Could you also emphasize that this does not contai
achuithb
2012/04/27 22:15:03
I have added the comment.
I use it in gdata_db_un
satorux1
2012/04/27 22:29:41
Please do it in a separate patch! :)
| |
100 | 102 |
101 const FilePath::StringType& title() const { return title_; } | 103 const FilePath::StringType& title() const { return title_; } |
102 void set_title(const FilePath::StringType& title) { title_ = title; } | 104 void set_title(const FilePath::StringType& title) { title_ = title; } |
103 | 105 |
104 // The unique resource ID associated with this file system entry. | 106 // The unique resource ID associated with this file system entry. |
105 const std::string& resource_id() const { return resource_id_; } | 107 const std::string& resource_id() const { return resource_id_; } |
106 void set_resource_id(const std::string& res_id) { resource_id_ = res_id; } | 108 void set_resource_id(const std::string& res_id) { resource_id_ = res_id; } |
107 | 109 |
108 // The content URL is used for downloading regular files as is. | 110 // The content URL is used for downloading regular files as is. |
109 const GURL& content_url() const { return content_url_; } | 111 const GURL& content_url() const { return content_url_; } |
(...skipping 14 matching lines...) Expand all Loading... | |
124 // Returns virtual file path representing this file system entry. This path | 126 // Returns virtual file path representing this file system entry. This path |
125 // corresponds to file path expected by public methods of GDataFileSyste | 127 // corresponds to file path expected by public methods of GDataFileSyste |
126 // class. | 128 // class. |
127 FilePath GetFilePath() const; | 129 FilePath GetFilePath() const; |
128 | 130 |
129 // Sets |file_name_| based on the value of |title_| without name | 131 // Sets |file_name_| based on the value of |title_| without name |
130 // de-duplication (see AddEntry() for details on de-duplication). | 132 // de-duplication (see AddEntry() for details on de-duplication). |
131 virtual void SetFileNameFromTitle(); | 133 virtual void SetFileNameFromTitle(); |
132 | 134 |
133 protected: | 135 protected: |
134 // GDataDirectory::TakeEntry() needs to call GDataEntry::set_parent(). | 136 // For access to SetParent from AddEntry. |
135 friend class GDataDirectory; | 137 friend class GDataDirectory; |
136 | 138 |
137 // Sets the parent directory of this file system entry. | 139 // Sets the parent directory of this file system entry. |
138 // It is intended to be used by GDataDirectory::AddEntry() only. | 140 // It is intended to be used by GDataDirectory::AddEntry() only. |
139 void set_parent(GDataDirectory* parent) { parent_ = parent; } | 141 void SetParent(GDataDirectory* parent); |
140 | 142 |
141 base::PlatformFileInfo file_info_; | 143 base::PlatformFileInfo file_info_; |
142 // Name of this file in the gdata virtual file system. | |
143 FilePath::StringType file_name_; | |
144 // Title of this file (i.e. the 'title' attribute associated with a regular | 144 // Title of this file (i.e. the 'title' attribute associated with a regular |
145 // file, hosted document, or collection). The title is used to derive | 145 // file, hosted document, or collection). The title is used to derive |
146 // |file_name_| but may be different from |file_name_|. For example, | 146 // |file_name_| but may be different from |file_name_|. For example, |
147 // |file_name_| has an added .g<something> extension for hosted documents or | 147 // |file_name_| has an added .g<something> extension for hosted documents or |
148 // may have an extra suffix for name de-duplication on the gdata file system. | 148 // may have an extra suffix for name de-duplication on the gdata file system. |
149 FilePath::StringType title_; | 149 FilePath::StringType title_; |
150 std::string resource_id_; | 150 std::string resource_id_; |
151 std::string parent_resource_id_; | |
151 // Files with the same title will be uniquely identified with this field | 152 // Files with the same title will be uniquely identified with this field |
152 // so we can represent them with unique URLs/paths in File API layer. | 153 // so we can represent them with unique URLs/paths in File API layer. |
153 // For example, two files in the same directory with the same name "Foo" | 154 // For example, two files in the same directory with the same name "Foo" |
154 // will show up in the virtual directory as "Foo" and "Foo (2)". | 155 // will show up in the virtual directory as "Foo" and "Foo (2)". |
155 GURL edit_url_; | 156 GURL edit_url_; |
156 GURL content_url_; | 157 GURL content_url_; |
158 | |
159 // Remaining fields are not serialized. | |
160 | |
161 // Name of this file in the gdata virtual file system. This can change | |
162 // due to de-duplication (See AddEntry). | |
163 FilePath::StringType file_name_; | |
164 | |
157 GDataDirectory* parent_; | 165 GDataDirectory* parent_; |
158 GDataRootDirectory* root_; // Weak pointer to GDataRootDirectory. | 166 GDataRootDirectory* root_; // Weak pointer to GDataRootDirectory. |
159 bool deleted_; | 167 bool deleted_; |
160 std::string parent_resource_id_; | |
161 | 168 |
162 private: | 169 private: |
163 DISALLOW_COPY_AND_ASSIGN(GDataEntry); | 170 DISALLOW_COPY_AND_ASSIGN(GDataEntry); |
164 }; | 171 }; |
165 | 172 |
166 typedef std::map<FilePath::StringType, GDataEntry*> GDataFileCollection; | 173 typedef std::map<FilePath::StringType, GDataFile*> GDataFileCollection; |
174 typedef std::map<FilePath::StringType, GDataDirectory*> | |
175 GDataDirectoryCollection; | |
167 | 176 |
168 // Represents "file" in in a GData virtual file system. On gdata feed side, | 177 // Represents "file" in in a GData virtual file system. On gdata feed side, |
169 // this could be either a regular file or a server side document. | 178 // this could be either a regular file or a server side document. |
170 class GDataFile : public GDataEntry { | 179 class GDataFile : public GDataEntry { |
171 public: | 180 public: |
172 // This is used as a bitmask for the cache state. | 181 // This is used as a bitmask for the cache state. |
173 enum CacheState { | 182 enum CacheState { |
174 CACHE_STATE_NONE = 0x0, | 183 CACHE_STATE_NONE = 0x0, |
175 CACHE_STATE_PINNED = 0x1 << 0, | 184 CACHE_STATE_PINNED = 0x1 << 0, |
176 CACHE_STATE_PRESENT = 0x1 << 1, | 185 CACHE_STATE_PRESENT = 0x1 << 1, |
177 CACHE_STATE_DIRTY = 0x1 << 2, | 186 CACHE_STATE_DIRTY = 0x1 << 2, |
178 CACHE_STATE_MOUNTED = 0x1 << 3, | 187 CACHE_STATE_MOUNTED = 0x1 << 3, |
179 }; | 188 }; |
180 | 189 |
181 explicit GDataFile(GDataDirectory* parent, GDataRootDirectory* root); | 190 explicit GDataFile(GDataDirectory* parent, GDataRootDirectory* root); |
182 virtual ~GDataFile(); | 191 virtual ~GDataFile(); |
183 virtual GDataFile* AsGDataFile() OVERRIDE; | 192 virtual GDataFile* AsGDataFile() OVERRIDE; |
184 | 193 |
194 // Converts DocumentEntry into GDataEntry. | |
185 static GDataEntry* FromDocumentEntry(GDataDirectory* parent, | 195 static GDataEntry* FromDocumentEntry(GDataDirectory* parent, |
186 DocumentEntry* doc, | 196 DocumentEntry* doc, |
187 GDataRootDirectory* root); | 197 GDataRootDirectory* root); |
188 | 198 |
189 // Converts to/from proto. | 199 // Converts to/from proto. |
190 void FromProto(const GDataFileProto& proto); | 200 void FromProto(const GDataFileProto& proto); |
191 void ToProto(GDataFileProto* proto) const; | 201 void ToProto(GDataFileProto* proto) const; |
192 | 202 |
193 static bool IsCachePresent(int cache_state) { | 203 static bool IsCachePresent(int cache_state) { |
194 return cache_state & CACHE_STATE_PRESENT; | 204 return cache_state & CACHE_STATE_PRESENT; |
195 } | 205 } |
196 static bool IsCachePinned(int cache_state) { | 206 static bool IsCachePinned(int cache_state) { |
197 return cache_state & CACHE_STATE_PINNED; | 207 return cache_state & CACHE_STATE_PINNED; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 }; | 269 }; |
260 | 270 |
261 // Represents "directory" in a GData virtual file system. Maps to gdata | 271 // Represents "directory" in a GData virtual file system. Maps to gdata |
262 // collection element. | 272 // collection element. |
263 class GDataDirectory : public GDataEntry { | 273 class GDataDirectory : public GDataEntry { |
264 public: | 274 public: |
265 GDataDirectory(GDataDirectory* parent, GDataRootDirectory* root); | 275 GDataDirectory(GDataDirectory* parent, GDataRootDirectory* root); |
266 virtual ~GDataDirectory(); | 276 virtual ~GDataDirectory(); |
267 virtual GDataDirectory* AsGDataDirectory() OVERRIDE; | 277 virtual GDataDirectory* AsGDataDirectory() OVERRIDE; |
268 | 278 |
279 // Converts DocumentEntry into GDataEntry. | |
269 static GDataEntry* FromDocumentEntry(GDataDirectory* parent, | 280 static GDataEntry* FromDocumentEntry(GDataDirectory* parent, |
270 DocumentEntry* doc, | 281 DocumentEntry* doc, |
271 GDataRootDirectory* root); | 282 GDataRootDirectory* root); |
272 | 283 |
273 // Converts to/from proto. | 284 // Converts to/from proto. |
274 void FromProto(const GDataDirectoryProto& proto); | 285 void FromProto(const GDataDirectoryProto& proto); |
275 void ToProto(GDataDirectoryProto* proto) const; | 286 void ToProto(GDataDirectoryProto* proto) const; |
276 | 287 |
277 // Adds child file to the directory and takes over the ownership of |file| | 288 // Adds child file to the directory and takes over the ownership of |file| |
278 // object. The method will also do name de-duplication to ensure that the | 289 // object. The method will also do name de-duplication to ensure that the |
279 // exposed presentation path does not have naming conflicts. Two files with | 290 // exposed presentation path does not have naming conflicts. Two files with |
280 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". | 291 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". |
281 void AddEntry(GDataEntry* entry); | 292 void AddEntry(GDataEntry* entry); |
282 | 293 |
283 // Takes the ownership of |entry| from its current parent. If this directory | 294 // Takes the ownership of |entry| from its current parent. If this directory |
284 // is already the current parent of |file|, this method effectively goes | 295 // is already the current parent of |file|, this method effectively goes |
285 // through the name de-duplication for |file| based on the current state of | 296 // through the name de-duplication for |file| based on the current state of |
286 // the file system. | 297 // the file system. |
287 bool TakeEntry(GDataEntry* entry); | 298 bool TakeEntry(GDataEntry* entry); |
288 | 299 |
289 // Takes over all entries from |dir|. | 300 // Takes over all entries from |dir|. |
290 bool TakeOverEntries(GDataDirectory* dir); | 301 bool TakeOverEntries(GDataDirectory* dir); |
291 | 302 |
303 // Find a child by its name. | |
304 GDataEntry* FindChild(const FilePath::StringType& file_name) const; | |
305 | |
292 // Removes the entry from its children list and destroys the entry instance. | 306 // Removes the entry from its children list and destroys the entry instance. |
293 bool RemoveEntry(GDataEntry* entry); | 307 bool RemoveEntry(GDataEntry* entry); |
294 | 308 |
295 // Removes children elements. | 309 // Removes children elements. |
296 void RemoveChildren(); | 310 void RemoveChildren(); |
297 | 311 |
298 // Checks if directory content needs to be refreshed from the server. | 312 // Checks if directory content needs to be refreshed from the server. |
299 bool NeedsRefresh() const; | 313 bool NeedsRefresh() const; |
300 | 314 |
301 // Last refresh time. | 315 // Last refresh time. |
302 const base::Time& refresh_time() const { return refresh_time_; } | 316 const base::Time& refresh_time() const { return refresh_time_; } |
303 void set_refresh_time(const base::Time& time) { refresh_time_ = time; } | 317 void set_refresh_time(const base::Time& time) { refresh_time_ = time; } |
304 // Url for this feed. | 318 // Url for this feed. |
305 const GURL& start_feed_url() const { return start_feed_url_; } | 319 const GURL& start_feed_url() const { return start_feed_url_; } |
306 void set_start_feed_url(const GURL& url) { start_feed_url_ = url; } | 320 void set_start_feed_url(const GURL& url) { start_feed_url_ = url; } |
307 // Continuing feed's url. | 321 // Continuing feed's url. |
308 const GURL& next_feed_url() const { return next_feed_url_; } | 322 const GURL& next_feed_url() const { return next_feed_url_; } |
309 void set_next_feed_url(const GURL& url) { next_feed_url_ = url; } | 323 void set_next_feed_url(const GURL& url) { next_feed_url_ = url; } |
310 // Upload url is an entry point for initialization of file upload. | 324 // Upload url is an entry point for initialization of file upload. |
311 // It corresponds to resumable-create-media link from gdata feed. | 325 // It corresponds to resumable-create-media link from gdata feed. |
312 const GURL& upload_url() const { return upload_url_; } | 326 const GURL& upload_url() const { return upload_url_; } |
313 void set_upload_url(const GURL& url) { upload_url_ = url; } | 327 void set_upload_url(const GURL& url) { upload_url_ = url; } |
314 // Collection of children GDataEntry items. | 328 // Collection of children files/directories. |
315 const GDataFileCollection& children() const { return children_; } | 329 const GDataFileCollection& child_files() const { return child_files_; } |
330 const GDataDirectoryCollection& child_directories() const { | |
331 return child_directories_; | |
332 } | |
316 // Directory content origin. | 333 // Directory content origin. |
317 const ContentOrigin origin() const { return origin_; } | 334 const ContentOrigin origin() const { return origin_; } |
318 void set_origin(ContentOrigin value) { origin_ = value; } | 335 void set_origin(ContentOrigin value) { origin_ = value; } |
319 | 336 |
320 private: | 337 private: |
321 // Removes the entry from its children list without destroying the | 338 // Add |entry| to children. |
339 void AddChild(GDataEntry* entry); | |
340 | |
341 // Removes the entry from its children without destroying the | |
322 // entry instance. | 342 // entry instance. |
323 bool RemoveEntryFromChildrenList(GDataEntry* entry); | 343 bool RemoveChild(GDataEntry* entry); |
324 | 344 |
325 base::Time refresh_time_; | 345 base::Time refresh_time_; |
326 // Url for this feed. | 346 // Url for this feed. |
327 GURL start_feed_url_; | 347 GURL start_feed_url_; |
328 // Continuing feed's url. | 348 // Continuing feed's url. |
329 GURL next_feed_url_; | 349 GURL next_feed_url_; |
330 // Upload url, corresponds to resumable-create-media link for feed | 350 // Upload url, corresponds to resumable-create-media link for feed |
331 // representing this directory. | 351 // representing this directory. |
332 GURL upload_url_; | 352 GURL upload_url_; |
333 | 353 |
334 // Directory content origin. | 354 // Directory content origin. |
335 ContentOrigin origin_; | 355 ContentOrigin origin_; |
336 | 356 |
337 // Collection of children GDataEntry items. | 357 // Collection of children GDataEntry items. |
338 GDataFileCollection children_; | 358 GDataFileCollection child_files_; |
359 GDataDirectoryCollection child_directories_; | |
339 | 360 |
340 DISALLOW_COPY_AND_ASSIGN(GDataDirectory); | 361 DISALLOW_COPY_AND_ASSIGN(GDataDirectory); |
341 }; | 362 }; |
342 | 363 |
343 class GDataRootDirectory : public GDataDirectory { | 364 class GDataRootDirectory : public GDataDirectory { |
344 public: | 365 public: |
345 // Enum defining GCache subdirectory location. | 366 // Enum defining GCache subdirectory location. |
346 // This indexes into |GDataFileSystem::cache_paths_| vector. | 367 // This indexes into |GDataFileSystem::cache_paths_| vector. |
347 enum CacheSubDirectoryType { | 368 enum CacheSubDirectoryType { |
348 CACHE_TYPE_META = 0, // Downloaded feeds. | 369 CACHE_TYPE_META = 0, // Downloaded feeds. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 | 434 |
414 // GDataEntry implementation. | 435 // GDataEntry implementation. |
415 virtual GDataRootDirectory* AsGDataRootDirectory() OVERRIDE; | 436 virtual GDataRootDirectory* AsGDataRootDirectory() OVERRIDE; |
416 | 437 |
417 // Adds the entry to resource map. | 438 // Adds the entry to resource map. |
418 void AddEntryToResourceMap(GDataEntry* entry); | 439 void AddEntryToResourceMap(GDataEntry* entry); |
419 | 440 |
420 // Removes the entry from resource map. | 441 // Removes the entry from resource map. |
421 void RemoveEntryFromResourceMap(GDataEntry* entry); | 442 void RemoveEntryFromResourceMap(GDataEntry* entry); |
422 | 443 |
423 // Removes the entries from resource map. | |
424 void RemoveEntriesFromResourceMap(const GDataFileCollection& children); | |
425 | |
426 // Searches for |file_path| triggering callback in |delegate|. | 444 // Searches for |file_path| triggering callback in |delegate|. |
427 void FindEntryByPath(const FilePath& file_path, | 445 void FindEntryByPath(const FilePath& file_path, |
428 FindEntryDelegate* delegate); | 446 FindEntryDelegate* delegate); |
429 | 447 |
430 // Returns the GDataEntry* with the corresponding |resource_id|. | 448 // Returns the GDataEntry* with the corresponding |resource_id|. |
431 GDataEntry* GetEntryByResourceId(const std::string& resource_id); | 449 GDataEntry* GetEntryByResourceId(const std::string& resource_id); |
432 | 450 |
433 // Sets |cache_map_| data member to formal parameter |new_cache_map|. | 451 // Sets |cache_map_| data member to formal parameter |new_cache_map|. |
434 void SetCacheMap(const CacheMap& new_cache_map); | 452 void SetCacheMap(const CacheMap& new_cache_map); |
435 | 453 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 base::Time last_serialized_; | 487 base::Time last_serialized_; |
470 int largest_changestamp_; | 488 int largest_changestamp_; |
471 size_t serialized_size_; | 489 size_t serialized_size_; |
472 | 490 |
473 DISALLOW_COPY_AND_ASSIGN(GDataRootDirectory); | 491 DISALLOW_COPY_AND_ASSIGN(GDataRootDirectory); |
474 }; | 492 }; |
475 | 493 |
476 } // namespace gdata | 494 } // namespace gdata |
477 | 495 |
478 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 496 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
OLD | NEW |