| 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& original_file_name() const { |
| 49 return original_file_name_; | 56 return original_file_name_; |
| 50 } | 57 } |
| 58 void set_original_file_name(const FilePath::StringType& name) { |
| 59 original_file_name_ = name; |
| 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 // Restores |file_name_| to the original file name before de-duplication. |
| 78 virtual void UseOriginalFileName(); |
| 79 |
| 64 protected: | 80 protected: |
| 81 // GDataDirectory::TakeFile() needs to call GDataFileBase::set_parent(). |
| 82 friend class GDataDirectory; |
| 83 |
| 84 // Sets the parent directory of this file system entry. |
| 85 // It is intended to be used by GDataDirectory::TakeFile() only. |
| 86 void set_parent(GDataDirectory* parent) { parent_ = parent; } |
| 87 |
| 65 base::PlatformFileInfo file_info_; | 88 base::PlatformFileInfo file_info_; |
| 89 // Name of this file in the gdata virtual file system. |
| 66 FilePath::StringType file_name_; | 90 FilePath::StringType file_name_; |
| 91 // Original name of this file, which is used to refer to the 'title' of |
| 92 // a regular file or hosted document. The original name may be different |
| 93 // from |file_name_| due to the added .g<something> extension for hosted |
| 94 // documents or name de-duplication on the gdata file system. |
| 67 FilePath::StringType original_file_name_; | 95 FilePath::StringType original_file_name_; |
| 96 std::string resource_id_; |
| 68 // Files with the same original name will be uniquely identified with this | 97 // Files with the same original name will be uniquely identified with this |
| 69 // field so we can represent them with unique URLs/paths in File API layer. | 98 // field 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" | 99 // 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)". | 100 // will show up in the virtual directory as "Foo" and "Foo (2)". |
| 72 GURL self_url_; | 101 GURL self_url_; |
| 73 GURL content_url_; | 102 GURL content_url_; |
| 74 GDataDirectory* parent_; | 103 GDataDirectory* parent_; |
| 75 GDataRootDirectory* root_; // Weak pointer to GDataRootDirectory. | 104 GDataRootDirectory* root_; // Weak pointer to GDataRootDirectory. |
| 76 | 105 |
| 77 private: | 106 private: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 97 virtual GDataFile* AsGDataFile() OVERRIDE; | 126 virtual GDataFile* AsGDataFile() OVERRIDE; |
| 98 | 127 |
| 99 static GDataFileBase* FromDocumentEntry(GDataDirectory* parent, | 128 static GDataFileBase* FromDocumentEntry(GDataDirectory* parent, |
| 100 DocumentEntry* doc); | 129 DocumentEntry* doc); |
| 101 | 130 |
| 102 DocumentEntry::EntryKind kind() const { return kind_; } | 131 DocumentEntry::EntryKind kind() const { return kind_; } |
| 103 const GURL& thumbnail_url() const { return thumbnail_url_; } | 132 const GURL& thumbnail_url() const { return thumbnail_url_; } |
| 104 const GURL& edit_url() const { return edit_url_; } | 133 const GURL& edit_url() const { return edit_url_; } |
| 105 const std::string& content_mime_type() const { return content_mime_type_; } | 134 const std::string& content_mime_type() const { return content_mime_type_; } |
| 106 const std::string& etag() const { return etag_; } | 135 const std::string& etag() const { return etag_; } |
| 107 const std::string& resource() const { return resource_id_; } | |
| 108 const std::string& id() const { return id_; } | 136 const std::string& id() const { return id_; } |
| 109 const std::string& file_md5() const { return file_md5_; } | 137 const std::string& file_md5() const { return file_md5_; } |
| 110 // Returns a bitmask of CacheState enum values. | 138 // Returns a bitmask of CacheState enum values. |
| 111 int GetCacheState(); | 139 int GetCacheState(); |
| 140 const std::string& document_extension() const { return document_extension_; } |
| 112 bool is_hosted_document() const { return is_hosted_document_; } | 141 bool is_hosted_document() const { return is_hosted_document_; } |
| 113 | 142 |
| 143 // GDataFileBase override. |
| 144 virtual void UseOriginalFileName() OVERRIDE; |
| 145 |
| 114 private: | 146 private: |
| 115 // Content URL for files. | 147 // Content URL for files. |
| 116 DocumentEntry::EntryKind kind_; | 148 DocumentEntry::EntryKind kind_; |
| 117 GURL thumbnail_url_; | 149 GURL thumbnail_url_; |
| 118 GURL edit_url_; | 150 GURL edit_url_; |
| 119 std::string content_mime_type_; | 151 std::string content_mime_type_; |
| 120 std::string etag_; | 152 std::string etag_; |
| 121 std::string resource_id_; | |
| 122 std::string id_; | 153 std::string id_; |
| 123 std::string file_md5_; | 154 std::string file_md5_; |
| 155 std::string document_extension_; |
| 124 bool is_hosted_document_; | 156 bool is_hosted_document_; |
| 125 | 157 |
| 126 DISALLOW_COPY_AND_ASSIGN(GDataFile); | 158 DISALLOW_COPY_AND_ASSIGN(GDataFile); |
| 127 }; | 159 }; |
| 128 | 160 |
| 129 // Represents "directory" in a GData virtual file system. Maps to gdata | 161 // Represents "directory" in a GData virtual file system. Maps to gdata |
| 130 // collection element. | 162 // collection element. |
| 131 class GDataDirectory : public GDataFileBase { | 163 class GDataDirectory : public GDataFileBase { |
| 132 public: | 164 public: |
| 133 explicit GDataDirectory(GDataDirectory* parent); | 165 explicit GDataDirectory(GDataDirectory* parent); |
| 134 virtual ~GDataDirectory(); | 166 virtual ~GDataDirectory(); |
| 135 virtual GDataDirectory* AsGDataDirectory() OVERRIDE; | 167 virtual GDataDirectory* AsGDataDirectory() OVERRIDE; |
| 136 | 168 |
| 137 static GDataFileBase* FromDocumentEntry(GDataDirectory* parent, | 169 static GDataFileBase* FromDocumentEntry(GDataDirectory* parent, |
| 138 DocumentEntry* doc); | 170 DocumentEntry* doc); |
| 139 | 171 |
| 140 // Adds child file to the directory and takes over the ownership of |file| | 172 // 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 | 173 // 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 | 174 // 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)". | 175 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". |
| 144 void AddFile(GDataFileBase* file); | 176 void AddFile(GDataFileBase* file); |
| 145 | 177 |
| 146 // Removes the file from its children list. | 178 // Takes the ownership of |file| from its current parent. If this directory |
| 179 // is already the current parent of |file|, this method effectively goes |
| 180 // through the name de-duplication for |file| based on the current state of |
| 181 // the file system. |
| 182 bool TakeFile(GDataFileBase* file); |
| 183 |
| 184 // Removes the file from its children list and destroys the file instance. |
| 147 bool RemoveFile(GDataFileBase* file); | 185 bool RemoveFile(GDataFileBase* file); |
| 148 | 186 |
| 149 // Removes children elements. | 187 // Removes children elements. |
| 150 void RemoveChildren(); | 188 void RemoveChildren(); |
| 151 | 189 |
| 152 // Checks if directory content needs to be retrieved again. If it does, | 190 // 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|. | 191 // the function will return URL for next feed in |next_feed_url|. |
| 154 bool NeedsRefresh(GURL* next_feed_url); | 192 bool NeedsRefresh(GURL* next_feed_url); |
| 155 | 193 |
| 156 // Last refresh time. | 194 // Last refresh time. |
| 157 const base::Time& refresh_time() const { return refresh_time_; } | 195 const base::Time& refresh_time() const { return refresh_time_; } |
| 158 void set_refresh_time(const base::Time& time) { refresh_time_ = time; } | 196 void set_refresh_time(const base::Time& time) { refresh_time_ = time; } |
| 159 // Url for this feed. | 197 // Url for this feed. |
| 160 const GURL& start_feed_url() const { return start_feed_url_; } | 198 const GURL& start_feed_url() const { return start_feed_url_; } |
| 161 void set_start_feed_url(const GURL& url) { start_feed_url_ = url; } | 199 void set_start_feed_url(const GURL& url) { start_feed_url_ = url; } |
| 162 // Continuing feed's url. | 200 // Continuing feed's url. |
| 163 const GURL& next_feed_url() const { return next_feed_url_; } | 201 const GURL& next_feed_url() const { return next_feed_url_; } |
| 164 void set_next_feed_url(const GURL& url) { next_feed_url_ = url; } | 202 void set_next_feed_url(const GURL& url) { next_feed_url_ = url; } |
| 165 // Upload url is an entry point for initialization of file upload. | 203 // Upload url is an entry point for initialization of file upload. |
| 166 // It corresponds to resumable-create-media link from gdata feed. | 204 // It corresponds to resumable-create-media link from gdata feed. |
| 167 const GURL& upload_url() const { return upload_url_; } | 205 const GURL& upload_url() const { return upload_url_; } |
| 168 void set_upload_url(const GURL& url) { upload_url_ = url; } | 206 void set_upload_url(const GURL& url) { upload_url_ = url; } |
| 169 // Collection of children GDataFileBase items. | 207 // Collection of children GDataFileBase items. |
| 170 const GDataFileCollection& children() const { return children_; } | 208 const GDataFileCollection& children() const { return children_; } |
| 171 | 209 |
| 172 private: | 210 private: |
| 211 // Removes the file from its children list without destroying the |
| 212 // file instance. |
| 213 bool RemoveFileFromChildrenList(GDataFileBase* file); |
| 214 |
| 173 base::Time refresh_time_; | 215 base::Time refresh_time_; |
| 174 // Url for this feed. | 216 // Url for this feed. |
| 175 GURL start_feed_url_; | 217 GURL start_feed_url_; |
| 176 // Continuing feed's url. | 218 // Continuing feed's url. |
| 177 GURL next_feed_url_; | 219 GURL next_feed_url_; |
| 178 // Upload url, corresponds to resumable-create-media link for feed | 220 // Upload url, corresponds to resumable-create-media link for feed |
| 179 // representing this directory. | 221 // representing this directory. |
| 180 GURL upload_url_; | 222 GURL upload_url_; |
| 181 // Collection of children GDataFileBase items. | 223 // Collection of children GDataFileBase items. |
| 182 GDataFileCollection children_; | 224 GDataFileCollection children_; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 ResourceMap resource_map_; | 306 ResourceMap resource_map_; |
| 265 | 307 |
| 266 CacheMap cache_map_; | 308 CacheMap cache_map_; |
| 267 | 309 |
| 268 DISALLOW_COPY_AND_ASSIGN(GDataRootDirectory); | 310 DISALLOW_COPY_AND_ASSIGN(GDataRootDirectory); |
| 269 }; | 311 }; |
| 270 | 312 |
| 271 } // namespace gdata | 313 } // namespace gdata |
| 272 | 314 |
| 273 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 315 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
| OLD | NEW |