| 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 <sys/stat.h> |
| 9 |
| 8 #include <map> | 10 #include <map> |
| 9 #include <sys/stat.h> | 11 #include <string> |
| 10 | 12 |
| 11 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 14 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 15 #include "base/platform_file.h" | 17 #include "base/platform_file.h" |
| 16 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
| 17 #include "chrome/browser/chromeos/gdata/gdata.h" | 19 #include "chrome/browser/chromeos/gdata/gdata.h" |
| 18 #include "chrome/browser/chromeos/gdata/gdata_parser.h" | 20 #include "chrome/browser/chromeos/gdata/gdata_parser.h" |
| 19 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" | 21 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 32 public: | 34 public: |
| 33 explicit GDataFileBase(GDataDirectory* parent); | 35 explicit GDataFileBase(GDataDirectory* parent); |
| 34 virtual ~GDataFileBase(); | 36 virtual ~GDataFileBase(); |
| 35 virtual GDataFile* AsGDataFile(); | 37 virtual GDataFile* AsGDataFile(); |
| 36 virtual GDataDirectory* AsGDataDirectory(); | 38 virtual GDataDirectory* AsGDataDirectory(); |
| 37 virtual GDataRootDirectory* AsGDataRootDirectory(); | 39 virtual GDataRootDirectory* AsGDataRootDirectory(); |
| 38 | 40 |
| 39 // Converts DocumentEntry into GDataFileBase. | 41 // Converts DocumentEntry into GDataFileBase. |
| 40 static GDataFileBase* FromDocumentEntry(GDataDirectory* parent, | 42 static GDataFileBase* FromDocumentEntry(GDataDirectory* parent, |
| 41 DocumentEntry* doc); | 43 DocumentEntry* doc); |
| 44 |
| 45 // Escapes forward slashes from file names with magic unicode character |
| 46 // \u2215 pretty much looks the same in UI. |
| 42 static std::string EscapeUtf8FileName(const std::string& input); | 47 static std::string EscapeUtf8FileName(const std::string& input); |
| 48 |
| 49 // Unescapes what was escaped in EScapeUtf8FileName. |
| 43 static std::string UnescapeUtf8FileName(const std::string& input); | 50 static std::string UnescapeUtf8FileName(const std::string& input); |
| 44 | 51 |
| 45 GDataDirectory* parent() { return parent_; } | 52 GDataDirectory* parent() { return parent_; } |
| 46 const base::PlatformFileInfo& file_info() const { return file_info_; } | 53 const base::PlatformFileInfo& file_info() const { return file_info_; } |
| 47 const FilePath::StringType& file_name() const { return file_name_; } | 54 const FilePath::StringType& file_name() const { return file_name_; } |
| 48 const FilePath::StringType& original_file_name() const { | 55 const FilePath::StringType& title() const { |
| 49 return original_file_name_; | 56 return title_; |
| 57 } |
| 58 void set_title(const FilePath::StringType& title) { |
| 59 title_ = title; |
| 50 } | 60 } |
| 51 void set_file_name(const FilePath::StringType& name) { file_name_ = name; } | 61 void set_file_name(const FilePath::StringType& name) { file_name_ = name; } |
| 52 | 62 |
| 63 // The unique resource ID associated with this file system entry. |
| 64 const std::string& resource_id() const { return resource_id_; } |
| 65 |
| 53 // The content URL is used for downloading regular files as is. | 66 // The content URL is used for downloading regular files as is. |
| 54 const GURL& content_url() const { return content_url_; } | 67 const GURL& content_url() const { return content_url_; } |
| 55 | 68 |
| 56 // The self URL is used for removing files and hosted documents. | 69 // The self URL is used for removing files and hosted documents. |
| 57 const GURL& self_url() const { return self_url_; } | 70 const GURL& self_url() const { return self_url_; } |
| 58 | 71 |
| 59 // Returns virtual file path representing this file system entry. This path | 72 // Returns virtual file path representing this file system entry. This path |
| 60 // corresponds to file path expected by public methods of GDataFileSyste | 73 // corresponds to file path expected by public methods of GDataFileSyste |
| 61 // class. | 74 // class. |
| 62 FilePath GetFilePath(); | 75 FilePath GetFilePath(); |
| 63 | 76 |
| 77 // Sets |file_name_| based on the value of |title_| without name |
| 78 // de-duplication (see AddFile() for details on de-duplication). |
| 79 virtual void SetFileNameFromTitle(); |
| 80 |
| 64 protected: | 81 protected: |
| 82 // GDataDirectory::TakeFile() needs to call GDataFileBase::set_parent(). |
| 83 friend class GDataDirectory; |
| 84 |
| 85 // Sets the parent directory of this file system entry. |
| 86 // It is intended to be used by GDataDirectory::TakeFile() only. |
| 87 void set_parent(GDataDirectory* parent) { parent_ = parent; } |
| 88 |
| 65 base::PlatformFileInfo file_info_; | 89 base::PlatformFileInfo file_info_; |
| 90 // Name of this file in the gdata virtual file system. |
| 66 FilePath::StringType file_name_; | 91 FilePath::StringType file_name_; |
| 67 FilePath::StringType original_file_name_; | 92 // Title of this file (i.e. the 'title' attribute associated with a regular |
| 68 // Files with the same original name will be uniquely identified with this | 93 // file, hosted document, or collection). The title is used to derive |
| 69 // field so we can represent them with unique URLs/paths in File API layer. | 94 // |file_name_| but may be different from |file_name_|. For example, |
| 95 // |file_name_| has an added .g<something> extension for hosted documents or |
| 96 // may have an extra suffix for name de-duplication on the gdata file system. |
| 97 FilePath::StringType title_; |
| 98 std::string resource_id_; |
| 99 // Files with the same title will be uniquely identified with this field |
| 100 // so we can represent them with unique URLs/paths in File API layer. |
| 70 // For example, two files in the same directory with the same name "Foo" | 101 // For example, two files in the same directory with the same name "Foo" |
| 71 // will show up in the virtual directory as "Foo" and "Foo (2)". | 102 // will show up in the virtual directory as "Foo" and "Foo (2)". |
| 72 GURL self_url_; | 103 GURL self_url_; |
| 73 GURL content_url_; | 104 GURL content_url_; |
| 74 GDataDirectory* parent_; | 105 GDataDirectory* parent_; |
| 75 GDataRootDirectory* root_; // Weak pointer to GDataRootDirectory. | 106 GDataRootDirectory* root_; // Weak pointer to GDataRootDirectory. |
| 76 | 107 |
| 77 private: | 108 private: |
| 78 DISALLOW_COPY_AND_ASSIGN(GDataFileBase); | 109 DISALLOW_COPY_AND_ASSIGN(GDataFileBase); |
| 79 }; | 110 }; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 97 virtual GDataFile* AsGDataFile() OVERRIDE; | 128 virtual GDataFile* AsGDataFile() OVERRIDE; |
| 98 | 129 |
| 99 static GDataFileBase* FromDocumentEntry(GDataDirectory* parent, | 130 static GDataFileBase* FromDocumentEntry(GDataDirectory* parent, |
| 100 DocumentEntry* doc); | 131 DocumentEntry* doc); |
| 101 | 132 |
| 102 DocumentEntry::EntryKind kind() const { return kind_; } | 133 DocumentEntry::EntryKind kind() const { return kind_; } |
| 103 const GURL& thumbnail_url() const { return thumbnail_url_; } | 134 const GURL& thumbnail_url() const { return thumbnail_url_; } |
| 104 const GURL& edit_url() const { return edit_url_; } | 135 const GURL& edit_url() const { return edit_url_; } |
| 105 const std::string& content_mime_type() const { return content_mime_type_; } | 136 const std::string& content_mime_type() const { return content_mime_type_; } |
| 106 const std::string& etag() const { return etag_; } | 137 const std::string& etag() const { return etag_; } |
| 107 const std::string& resource() const { return resource_id_; } | |
| 108 const std::string& id() const { return id_; } | 138 const std::string& id() const { return id_; } |
| 109 const std::string& file_md5() const { return file_md5_; } | 139 const std::string& file_md5() const { return file_md5_; } |
| 110 // Returns a bitmask of CacheState enum values. | 140 // Returns a bitmask of CacheState enum values. |
| 111 int GetCacheState(); | 141 int GetCacheState(); |
| 142 const std::string& document_extension() const { return document_extension_; } |
| 112 bool is_hosted_document() const { return is_hosted_document_; } | 143 bool is_hosted_document() const { return is_hosted_document_; } |
| 113 | 144 |
| 145 // Overrides GDataFileBase::SetFileNameFromTitle() to set |file_name_| based |
| 146 // on the value of |title_| as well as |is_hosted_document_| and |
| 147 // |document_extension_| for hosted documents. |
| 148 virtual void SetFileNameFromTitle() OVERRIDE; |
| 149 |
| 114 private: | 150 private: |
| 115 // Content URL for files. | 151 // Content URL for files. |
| 116 DocumentEntry::EntryKind kind_; | 152 DocumentEntry::EntryKind kind_; |
| 117 GURL thumbnail_url_; | 153 GURL thumbnail_url_; |
| 118 GURL edit_url_; | 154 GURL edit_url_; |
| 119 std::string content_mime_type_; | 155 std::string content_mime_type_; |
| 120 std::string etag_; | 156 std::string etag_; |
| 121 std::string resource_id_; | |
| 122 std::string id_; | 157 std::string id_; |
| 123 std::string file_md5_; | 158 std::string file_md5_; |
| 159 std::string document_extension_; |
| 124 bool is_hosted_document_; | 160 bool is_hosted_document_; |
| 125 | 161 |
| 126 DISALLOW_COPY_AND_ASSIGN(GDataFile); | 162 DISALLOW_COPY_AND_ASSIGN(GDataFile); |
| 127 }; | 163 }; |
| 128 | 164 |
| 129 // Represents "directory" in a GData virtual file system. Maps to gdata | 165 // Represents "directory" in a GData virtual file system. Maps to gdata |
| 130 // collection element. | 166 // collection element. |
| 131 class GDataDirectory : public GDataFileBase { | 167 class GDataDirectory : public GDataFileBase { |
| 132 public: | 168 public: |
| 133 explicit GDataDirectory(GDataDirectory* parent); | 169 explicit GDataDirectory(GDataDirectory* parent); |
| 134 virtual ~GDataDirectory(); | 170 virtual ~GDataDirectory(); |
| 135 virtual GDataDirectory* AsGDataDirectory() OVERRIDE; | 171 virtual GDataDirectory* AsGDataDirectory() OVERRIDE; |
| 136 | 172 |
| 137 static GDataFileBase* FromDocumentEntry(GDataDirectory* parent, | 173 static GDataFileBase* FromDocumentEntry(GDataDirectory* parent, |
| 138 DocumentEntry* doc); | 174 DocumentEntry* doc); |
| 139 | 175 |
| 140 // Adds child file to the directory and takes over the ownership of |file| | 176 // Adds child file to the directory and takes over the ownership of |file| |
| 141 // object. The method will also do name deduplication to ensure that the | 177 // object. The method will also do name de-duplication to ensure that the |
| 142 // exposed presentation path does not have naming conflicts. Two files with | 178 // exposed presentation path does not have naming conflicts. Two files with |
| 143 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". | 179 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". |
| 144 void AddFile(GDataFileBase* file); | 180 void AddFile(GDataFileBase* file); |
| 145 | 181 |
| 146 // Removes the file from its children list. | 182 // Takes the ownership of |file| from its current parent. If this directory |
| 183 // is already the current parent of |file|, this method effectively goes |
| 184 // through the name de-duplication for |file| based on the current state of |
| 185 // the file system. |
| 186 bool TakeFile(GDataFileBase* file); |
| 187 |
| 188 // Removes the file from its children list and destroys the file instance. |
| 147 bool RemoveFile(GDataFileBase* file); | 189 bool RemoveFile(GDataFileBase* file); |
| 148 | 190 |
| 149 // Removes children elements. | 191 // Removes children elements. |
| 150 void RemoveChildren(); | 192 void RemoveChildren(); |
| 151 | 193 |
| 152 // Checks if directory content needs to be retrieved again. If it does, | 194 // Checks if directory content needs to be retrieved again. If it does, |
| 153 // the function will return URL for next feed in |next_feed_url|. | 195 // the function will return URL for next feed in |next_feed_url|. |
| 154 bool NeedsRefresh(GURL* next_feed_url); | 196 bool NeedsRefresh(GURL* next_feed_url); |
| 155 | 197 |
| 156 // Last refresh time. | 198 // Last refresh time. |
| 157 const base::Time& refresh_time() const { return refresh_time_; } | 199 const base::Time& refresh_time() const { return refresh_time_; } |
| 158 void set_refresh_time(const base::Time& time) { refresh_time_ = time; } | 200 void set_refresh_time(const base::Time& time) { refresh_time_ = time; } |
| 159 // Url for this feed. | 201 // Url for this feed. |
| 160 const GURL& start_feed_url() const { return start_feed_url_; } | 202 const GURL& start_feed_url() const { return start_feed_url_; } |
| 161 void set_start_feed_url(const GURL& url) { start_feed_url_ = url; } | 203 void set_start_feed_url(const GURL& url) { start_feed_url_ = url; } |
| 162 // Continuing feed's url. | 204 // Continuing feed's url. |
| 163 const GURL& next_feed_url() const { return next_feed_url_; } | 205 const GURL& next_feed_url() const { return next_feed_url_; } |
| 164 void set_next_feed_url(const GURL& url) { next_feed_url_ = url; } | 206 void set_next_feed_url(const GURL& url) { next_feed_url_ = url; } |
| 165 // Upload url is an entry point for initialization of file upload. | 207 // Upload url is an entry point for initialization of file upload. |
| 166 // It corresponds to resumable-create-media link from gdata feed. | 208 // It corresponds to resumable-create-media link from gdata feed. |
| 167 const GURL& upload_url() const { return upload_url_; } | 209 const GURL& upload_url() const { return upload_url_; } |
| 168 void set_upload_url(const GURL& url) { upload_url_ = url; } | 210 void set_upload_url(const GURL& url) { upload_url_ = url; } |
| 169 // Collection of children GDataFileBase items. | 211 // Collection of children GDataFileBase items. |
| 170 const GDataFileCollection& children() const { return children_; } | 212 const GDataFileCollection& children() const { return children_; } |
| 171 | 213 |
| 172 private: | 214 private: |
| 215 // Removes the file from its children list without destroying the |
| 216 // file instance. |
| 217 bool RemoveFileFromChildrenList(GDataFileBase* file); |
| 218 |
| 173 base::Time refresh_time_; | 219 base::Time refresh_time_; |
| 174 // Url for this feed. | 220 // Url for this feed. |
| 175 GURL start_feed_url_; | 221 GURL start_feed_url_; |
| 176 // Continuing feed's url. | 222 // Continuing feed's url. |
| 177 GURL next_feed_url_; | 223 GURL next_feed_url_; |
| 178 // Upload url, corresponds to resumable-create-media link for feed | 224 // Upload url, corresponds to resumable-create-media link for feed |
| 179 // representing this directory. | 225 // representing this directory. |
| 180 GURL upload_url_; | 226 GURL upload_url_; |
| 181 // Collection of children GDataFileBase items. | 227 // Collection of children GDataFileBase items. |
| 182 GDataFileCollection children_; | 228 GDataFileCollection children_; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 ResourceMap resource_map_; | 310 ResourceMap resource_map_; |
| 265 | 311 |
| 266 CacheMap cache_map_; | 312 CacheMap cache_map_; |
| 267 | 313 |
| 268 DISALLOW_COPY_AND_ASSIGN(GDataRootDirectory); | 314 DISALLOW_COPY_AND_ASSIGN(GDataRootDirectory); |
| 269 }; | 315 }; |
| 270 | 316 |
| 271 } // namespace gdata | 317 } // namespace gdata |
| 272 | 318 |
| 273 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 319 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
| OLD | NEW |