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