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 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 }; | 115 }; |
116 | 116 |
117 // Used to receive the result from GetEntryInfoPairCallback(). | 117 // Used to receive the result from GetEntryInfoPairCallback(). |
118 typedef base::Callback<void(scoped_ptr<EntryInfoPairResult> pair_result)> | 118 typedef base::Callback<void(scoped_ptr<EntryInfoPairResult> pair_result)> |
119 GetEntryInfoPairCallback; | 119 GetEntryInfoPairCallback; |
120 | 120 |
121 // Base class for representing files and directories in gdata virtual file | 121 // Base class for representing files and directories in gdata virtual file |
122 // system. | 122 // system. |
123 class GDataEntry { | 123 class GDataEntry { |
124 public: | 124 public: |
125 // TODO(achuith): Remove |parent| from ctor. crbug.com/141494 | |
126 GDataEntry(GDataDirectory* parent, GDataDirectoryService* directory_service); | |
127 virtual ~GDataEntry(); | 125 virtual ~GDataEntry(); |
128 | 126 |
129 virtual GDataFile* AsGDataFile(); | 127 virtual GDataFile* AsGDataFile(); |
130 virtual GDataDirectory* AsGDataDirectory(); | 128 virtual GDataDirectory* AsGDataDirectory(); |
131 | 129 |
| 130 // Initializes from DocumentEntry. |
| 131 virtual void InitFromDocumentEntry(DocumentEntry* doc); |
| 132 |
132 // const versions of AsGDataFile and AsGDataDirectory. | 133 // const versions of AsGDataFile and AsGDataDirectory. |
133 const GDataFile* AsGDataFileConst() const; | 134 const GDataFile* AsGDataFileConst() const; |
134 const GDataDirectory* AsGDataDirectoryConst() const; | 135 const GDataDirectory* AsGDataDirectoryConst() const; |
135 | 136 |
136 // Converts DocumentEntry into GDataEntry. | |
137 static GDataEntry* FromDocumentEntry( | |
138 GDataDirectory* parent, | |
139 DocumentEntry* doc, | |
140 GDataDirectoryService* directory_service); | |
141 | |
142 // Serialize/Parse to/from string via proto classes. | 137 // Serialize/Parse to/from string via proto classes. |
143 void SerializeToString(std::string* serialized_proto) const; | 138 void SerializeToString(std::string* serialized_proto) const; |
144 | 139 |
145 // Converts the proto representation to the platform file. | 140 // Converts the proto representation to the platform file. |
146 static void ConvertProtoToPlatformFileInfo( | 141 static void ConvertProtoToPlatformFileInfo( |
147 const PlatformFileInfoProto& proto, | 142 const PlatformFileInfoProto& proto, |
148 base::PlatformFileInfo* file_info); | 143 base::PlatformFileInfo* file_info); |
149 | 144 |
150 // Converts the platform file info to the proto representation. | 145 // Converts the platform file info to the proto representation. |
151 static void ConvertPlatformFileInfoToProto( | 146 static void ConvertPlatformFileInfoToProto( |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 FilePath GetFilePath() const; | 209 FilePath GetFilePath() const; |
215 | 210 |
216 // Sets |base_name_| based on the value of |title_| without name | 211 // Sets |base_name_| based on the value of |title_| without name |
217 // de-duplication (see AddEntry() for details on de-duplication). | 212 // de-duplication (see AddEntry() for details on de-duplication). |
218 virtual void SetBaseNameFromTitle(); | 213 virtual void SetBaseNameFromTitle(); |
219 | 214 |
220 protected: | 215 protected: |
221 // For access to SetParent from AddEntry. | 216 // For access to SetParent from AddEntry. |
222 friend class GDataDirectory; | 217 friend class GDataDirectory; |
223 | 218 |
| 219 explicit GDataEntry(GDataDirectoryService* directory_service); |
| 220 |
224 // Sets the parent directory of this file system entry. | 221 // Sets the parent directory of this file system entry. |
225 // It is intended to be used by GDataDirectory::AddEntry() only. | 222 // It is intended to be used by GDataDirectory::AddEntry() only. |
226 void SetParent(GDataDirectory* parent); | 223 void SetParent(GDataDirectory* parent); |
227 | 224 |
228 base::PlatformFileInfo file_info_; | 225 base::PlatformFileInfo file_info_; |
229 // Title of this file (i.e. the 'title' attribute associated with a regular | 226 // Title of this file (i.e. the 'title' attribute associated with a regular |
230 // file, hosted document, or collection). The title is used to derive | 227 // file, hosted document, or collection). The title is used to derive |
231 // |base_name_| but may be different from |base_name_|. For example, | 228 // |base_name_| but may be different from |base_name_|. For example, |
232 // |base_name_| has an added .g<something> extension for hosted documents or | 229 // |base_name_| has an added .g<something> extension for hosted documents or |
233 // may have an extra suffix for name de-duplication on the gdata file system. | 230 // may have an extra suffix for name de-duplication on the gdata file system. |
(...skipping 24 matching lines...) Expand all Loading... |
258 }; | 255 }; |
259 | 256 |
260 typedef std::map<FilePath::StringType, GDataFile*> GDataFileCollection; | 257 typedef std::map<FilePath::StringType, GDataFile*> GDataFileCollection; |
261 typedef std::map<FilePath::StringType, GDataDirectory*> | 258 typedef std::map<FilePath::StringType, GDataDirectory*> |
262 GDataDirectoryCollection; | 259 GDataDirectoryCollection; |
263 | 260 |
264 // Represents "file" in in a GData virtual file system. On gdata feed side, | 261 // Represents "file" in in a GData virtual file system. On gdata feed side, |
265 // this could be either a regular file or a server side document. | 262 // this could be either a regular file or a server side document. |
266 class GDataFile : public GDataEntry { | 263 class GDataFile : public GDataEntry { |
267 public: | 264 public: |
268 // TODO(achuith): Remove |parent| from ctor. crbug.com/141494 | |
269 explicit GDataFile(GDataDirectory* parent, | |
270 GDataDirectoryService* directory_service); | |
271 virtual ~GDataFile(); | 265 virtual ~GDataFile(); |
272 virtual GDataFile* AsGDataFile() OVERRIDE; | |
273 | |
274 // Converts DocumentEntry into GDataEntry. | |
275 static GDataEntry* FromDocumentEntry( | |
276 GDataDirectory* parent, | |
277 DocumentEntry* doc, | |
278 GDataDirectoryService* directory_service); | |
279 | 266 |
280 // Converts to/from proto. | 267 // Converts to/from proto. |
281 bool FromProto(const GDataEntryProto& proto) WARN_UNUSED_RESULT; | 268 bool FromProto(const GDataEntryProto& proto) WARN_UNUSED_RESULT; |
282 void ToProto(GDataEntryProto* proto) const; | 269 void ToProto(GDataEntryProto* proto) const; |
283 | 270 |
284 DocumentEntry::EntryKind kind() const { return kind_; } | 271 DocumentEntry::EntryKind kind() const { return kind_; } |
285 const GURL& thumbnail_url() const { return thumbnail_url_; } | 272 const GURL& thumbnail_url() const { return thumbnail_url_; } |
286 const GURL& alternate_url() const { return alternate_url_; } | 273 const GURL& alternate_url() const { return alternate_url_; } |
287 const std::string& content_mime_type() const { return content_mime_type_; } | 274 const std::string& content_mime_type() const { return content_mime_type_; } |
288 const std::string& file_md5() const { return file_md5_; } | 275 const std::string& file_md5() const { return file_md5_; } |
289 void set_file_md5(const std::string& file_md5) { file_md5_ = file_md5; } | 276 void set_file_md5(const std::string& file_md5) { file_md5_ = file_md5; } |
290 const std::string& document_extension() const { return document_extension_; } | 277 const std::string& document_extension() const { return document_extension_; } |
291 bool is_hosted_document() const { return is_hosted_document_; } | 278 bool is_hosted_document() const { return is_hosted_document_; } |
292 void set_file_info(const base::PlatformFileInfo& info) { file_info_ = info; } | 279 void set_file_info(const base::PlatformFileInfo& info) { file_info_ = info; } |
293 | 280 |
294 // Overrides GDataEntry::SetBaseNameFromTitle() to set |base_name_| based | 281 // Overrides GDataEntry::SetBaseNameFromTitle() to set |base_name_| based |
295 // on the value of |title_| as well as |is_hosted_document_| and | 282 // on the value of |title_| as well as |is_hosted_document_| and |
296 // |document_extension_| for hosted documents. | 283 // |document_extension_| for hosted documents. |
297 virtual void SetBaseNameFromTitle() OVERRIDE; | 284 virtual void SetBaseNameFromTitle() OVERRIDE; |
298 | 285 |
299 private: | 286 private: |
| 287 friend class GDataDirectoryService; // For access to ctor. |
| 288 |
| 289 explicit GDataFile(GDataDirectoryService* directory_service); |
| 290 // Initializes from DocumentEntry. |
| 291 virtual void InitFromDocumentEntry(DocumentEntry* doc) OVERRIDE; |
| 292 |
| 293 virtual GDataFile* AsGDataFile() OVERRIDE; |
| 294 |
300 DocumentEntry::EntryKind kind_; // Not saved in proto. | 295 DocumentEntry::EntryKind kind_; // Not saved in proto. |
301 GURL thumbnail_url_; | 296 GURL thumbnail_url_; |
302 GURL alternate_url_; | 297 GURL alternate_url_; |
303 std::string content_mime_type_; | 298 std::string content_mime_type_; |
304 std::string file_md5_; | 299 std::string file_md5_; |
305 std::string document_extension_; | 300 std::string document_extension_; |
306 bool is_hosted_document_; | 301 bool is_hosted_document_; |
307 | 302 |
308 DISALLOW_COPY_AND_ASSIGN(GDataFile); | 303 DISALLOW_COPY_AND_ASSIGN(GDataFile); |
309 }; | 304 }; |
310 | 305 |
311 // Represents "directory" in a GData virtual file system. Maps to gdata | 306 // Represents "directory" in a GData virtual file system. Maps to gdata |
312 // collection element. | 307 // collection element. |
313 class GDataDirectory : public GDataEntry { | 308 class GDataDirectory : public GDataEntry { |
314 public: | 309 public: |
315 // TODO(achuith): Remove |parent| from ctor. crbug.com/141494 | |
316 GDataDirectory(GDataDirectory* parent, | |
317 GDataDirectoryService* directory_service); | |
318 virtual ~GDataDirectory(); | 310 virtual ~GDataDirectory(); |
319 virtual GDataDirectory* AsGDataDirectory() OVERRIDE; | |
320 | |
321 // Converts DocumentEntry into GDataEntry. | |
322 static GDataEntry* FromDocumentEntry( | |
323 GDataDirectory* parent, | |
324 DocumentEntry* doc, | |
325 GDataDirectoryService* directory_service); | |
326 | 311 |
327 // Converts to/from proto. | 312 // Converts to/from proto. |
328 bool FromProto(const GDataDirectoryProto& proto) WARN_UNUSED_RESULT; | 313 bool FromProto(const GDataDirectoryProto& proto) WARN_UNUSED_RESULT; |
329 void ToProto(GDataDirectoryProto* proto) const; | 314 void ToProto(GDataDirectoryProto* proto) const; |
330 | 315 |
331 // Converts the children as a vector of GDataEntryProto. | 316 // Converts the children as a vector of GDataEntryProto. |
332 scoped_ptr<GDataEntryProtoVector> ToProtoVector() const; | 317 scoped_ptr<GDataEntryProtoVector> ToProtoVector() const; |
333 | 318 |
334 // Collection of children files/directories. | 319 // Collection of children files/directories. |
335 const GDataFileCollection& child_files() const { return child_files_; } | 320 const GDataFileCollection& child_files() const { return child_files_; } |
336 const GDataDirectoryCollection& child_directories() const { | 321 const GDataDirectoryCollection& child_directories() const { |
337 return child_directories_; | 322 return child_directories_; |
338 } | 323 } |
339 | 324 |
340 private: | 325 private: |
341 // TODO(satorux): Remove the friend statements. crbug.com/139649 | 326 // TODO(satorux): Remove the friend statements. crbug.com/139649 |
342 friend class GDataDirectoryService; | 327 friend class GDataDirectoryService; |
343 friend class GDataFileSystem; | 328 friend class GDataFileSystem; |
344 friend class GDataWapiFeedProcessor; | 329 friend class GDataWapiFeedProcessor; |
345 | 330 |
| 331 explicit GDataDirectory(GDataDirectoryService* directory_service); |
| 332 |
| 333 // Initializes from DocumentEntry. |
| 334 virtual void InitFromDocumentEntry(DocumentEntry* doc) OVERRIDE; |
| 335 |
| 336 virtual GDataDirectory* AsGDataDirectory() OVERRIDE; |
| 337 |
346 // Adds child file to the directory and takes over the ownership of |file| | 338 // Adds child file to the directory and takes over the ownership of |file| |
347 // object. The method will also do name de-duplication to ensure that the | 339 // object. The method will also do name de-duplication to ensure that the |
348 // exposed presentation path does not have naming conflicts. Two files with | 340 // exposed presentation path does not have naming conflicts. Two files with |
349 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". | 341 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". |
350 // TODO(satorux): Remove this. crbug.com/139649 | 342 // TODO(satorux): Remove this. crbug.com/139649 |
351 void AddEntry(GDataEntry* entry); | 343 void AddEntry(GDataEntry* entry); |
352 | 344 |
353 // Removes the entry from its children list and destroys the entry instance. | 345 // Removes the entry from its children list and destroys the entry instance. |
354 // TODO(satorux): Remove this. crbug.com/139649 | 346 // TODO(satorux): Remove this. crbug.com/139649 |
355 void RemoveEntry(GDataEntry* entry); | 347 void RemoveEntry(GDataEntry* entry); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 398 |
407 // Largest change timestamp that was the source of content for the current | 399 // Largest change timestamp that was the source of content for the current |
408 // state of the root directory. | 400 // state of the root directory. |
409 const int64 largest_changestamp() const { return largest_changestamp_; } | 401 const int64 largest_changestamp() const { return largest_changestamp_; } |
410 void set_largest_changestamp(int64 value) { largest_changestamp_ = value; } | 402 void set_largest_changestamp(int64 value) { largest_changestamp_ = value; } |
411 | 403 |
412 // The root directory content origin. | 404 // The root directory content origin. |
413 const ContentOrigin origin() const { return origin_; } | 405 const ContentOrigin origin() const { return origin_; } |
414 void set_origin(ContentOrigin value) { origin_ = value; } | 406 void set_origin(ContentOrigin value) { origin_ = value; } |
415 | 407 |
| 408 // Creates a GDataEntry from a DocumentEntry. |
| 409 GDataEntry* FromDocumentEntry(DocumentEntry* doc); |
| 410 |
| 411 // Creates a GDataFile instance. |
| 412 GDataFile* CreateGDataFile(); |
| 413 |
| 414 // Creates a GDataDirectory instance. |
| 415 GDataDirectory* CreateGDataDirectory(); |
| 416 |
416 // Sets root directory resource id and initialize the root entry. | 417 // Sets root directory resource id and initialize the root entry. |
417 void InitializeRootEntry(const std::string& root_id); | 418 void InitializeRootEntry(const std::string& root_id); |
418 | 419 |
419 // Move |entry| to |directory_path| asynchronously. Removes entry from | 420 // Move |entry| to |directory_path| asynchronously. Removes entry from |
420 // previous parent. Must be called on UI thread. |callback| is called on the | 421 // previous parent. Must be called on UI thread. |callback| is called on the |
421 // UI thread. | 422 // UI thread. |
422 void MoveEntryToDirectory(const FilePath& directory_path, | 423 void MoveEntryToDirectory(const FilePath& directory_path, |
423 GDataEntry* entry, | 424 GDataEntry* entry, |
424 const FileMoveCallback& callback); | 425 const FileMoveCallback& callback); |
425 | 426 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 // This should remain the last member so it'll be destroyed first and | 537 // This should remain the last member so it'll be destroyed first and |
537 // invalidate its weak pointers before other members are destroyed. | 538 // invalidate its weak pointers before other members are destroyed. |
538 base::WeakPtrFactory<GDataDirectoryService> weak_ptr_factory_; | 539 base::WeakPtrFactory<GDataDirectoryService> weak_ptr_factory_; |
539 | 540 |
540 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); | 541 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); |
541 }; | 542 }; |
542 | 543 |
543 } // namespace gdata | 544 } // namespace gdata |
544 | 545 |
545 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 546 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
OLD | NEW |