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