| 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_DRIVE_DRIVE_FILES_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_FILES_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_FILES_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_FILES_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/platform_file.h" | 16 #include "base/platform_file.h" |
| 17 #include "chrome/browser/chromeos/drive/drive.pb.h" | 17 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 18 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 18 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
| 19 | 19 |
| 20 namespace gdata { | 20 namespace drive { |
| 21 | 21 |
| 22 class DriveDirectory; | 22 class DriveDirectory; |
| 23 class DriveDirectoryProto; | 23 class DriveDirectoryProto; |
| 24 class DriveEntryProto; | 24 class DriveEntryProto; |
| 25 class DriveFile; | 25 class DriveFile; |
| 26 class DriveResourceMetadata; | 26 class DriveResourceMetadata; |
| 27 class PlatformFileInfoProto; | 27 class PlatformFileInfoProto; |
| 28 | 28 |
| 29 // Used to read a directory from the file system. | 29 // Used to read a directory from the file system. |
| 30 // If |error| is not DRIVE_FILE_OK, |entries| is set to NULL. | 30 // If |error| is not DRIVE_FILE_OK, |entries| is set to NULL. |
| 31 // |entries| are contents, both files and directories, of the directory. | 31 // |entries| are contents, both files and directories, of the directory. |
| 32 typedef std::vector<DriveEntryProto> DriveEntryProtoVector; | 32 typedef std::vector<DriveEntryProto> DriveEntryProtoVector; |
| 33 | 33 |
| 34 // Base class for representing files and directories in Drive virtual file | 34 // Base class for representing files and directories in Drive virtual file |
| 35 // system. | 35 // system. |
| 36 class DriveEntry { | 36 class DriveEntry { |
| 37 public: | 37 public: |
| 38 virtual ~DriveEntry(); | 38 virtual ~DriveEntry(); |
| 39 | 39 |
| 40 virtual DriveFile* AsDriveFile(); | 40 virtual DriveFile* AsDriveFile(); |
| 41 virtual DriveDirectory* AsDriveDirectory(); | 41 virtual DriveDirectory* AsDriveDirectory(); |
| 42 | 42 |
| 43 // Initializes from DocumentEntry. | 43 // Initializes from gdata::DocumentEntry. |
| 44 virtual void InitFromDocumentEntry(const DocumentEntry& doc); | 44 virtual void InitFromDocumentEntry(const gdata::DocumentEntry& doc); |
| 45 | 45 |
| 46 // const versions of AsDriveFile and AsDriveDirectory. | 46 // const versions of AsDriveFile and AsDriveDirectory. |
| 47 const DriveFile* AsDriveFileConst() const; | 47 const DriveFile* AsDriveFileConst() const; |
| 48 const DriveDirectory* AsDriveDirectoryConst() const; | 48 const DriveDirectory* AsDriveDirectoryConst() const; |
| 49 | 49 |
| 50 // Serialize/Parse to/from string via proto classes. | 50 // Serialize/Parse to/from string via proto classes. |
| 51 void SerializeToString(std::string* serialized_proto) const; | 51 void SerializeToString(std::string* serialized_proto) const; |
| 52 | 52 |
| 53 // Converts the proto representation to the platform file. | 53 // Converts the proto representation to the platform file. |
| 54 static void ConvertProtoToPlatformFileInfo( | 54 static void ConvertProtoToPlatformFileInfo( |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 // Represents "file" in in a drive virtual file system. On gdata feed side, | 164 // Represents "file" in in a drive virtual file system. On gdata feed side, |
| 165 // this could be either a regular file or a server side document. | 165 // this could be either a regular file or a server side document. |
| 166 class DriveFile : public DriveEntry { | 166 class DriveFile : public DriveEntry { |
| 167 public: | 167 public: |
| 168 virtual ~DriveFile(); | 168 virtual ~DriveFile(); |
| 169 | 169 |
| 170 // Converts to/from proto. | 170 // Converts to/from proto. |
| 171 void FromProto(const DriveEntryProto& proto); | 171 void FromProto(const DriveEntryProto& proto); |
| 172 void ToProto(DriveEntryProto* proto) const; | 172 void ToProto(DriveEntryProto* proto) const; |
| 173 | 173 |
| 174 DriveEntryKind kind() const { return kind_; } | 174 gdata::DriveEntryKind kind() const { return kind_; } |
| 175 const GURL& thumbnail_url() const { return thumbnail_url_; } | 175 const GURL& thumbnail_url() const { return thumbnail_url_; } |
| 176 const GURL& alternate_url() const { return alternate_url_; } | 176 const GURL& alternate_url() const { return alternate_url_; } |
| 177 const std::string& content_mime_type() const { return content_mime_type_; } | 177 const std::string& content_mime_type() const { return content_mime_type_; } |
| 178 const std::string& file_md5() const { return file_md5_; } | 178 const std::string& file_md5() const { return file_md5_; } |
| 179 void set_file_md5(const std::string& file_md5) { file_md5_ = file_md5; } | 179 void set_file_md5(const std::string& file_md5) { file_md5_ = file_md5; } |
| 180 const std::string& document_extension() const { return document_extension_; } | 180 const std::string& document_extension() const { return document_extension_; } |
| 181 bool is_hosted_document() const { return is_hosted_document_; } | 181 bool is_hosted_document() const { return is_hosted_document_; } |
| 182 void set_file_info(const base::PlatformFileInfo& info) { file_info_ = info; } | 182 void set_file_info(const base::PlatformFileInfo& info) { file_info_ = info; } |
| 183 | 183 |
| 184 // Overrides DriveEntry::SetBaseNameFromTitle() to set |base_name_| based | 184 // Overrides DriveEntry::SetBaseNameFromTitle() to set |base_name_| based |
| 185 // on the value of |title_| as well as |is_hosted_document_| and | 185 // on the value of |title_| as well as |is_hosted_document_| and |
| 186 // |document_extension_| for hosted documents. | 186 // |document_extension_| for hosted documents. |
| 187 virtual void SetBaseNameFromTitle() OVERRIDE; | 187 virtual void SetBaseNameFromTitle() OVERRIDE; |
| 188 | 188 |
| 189 private: | 189 private: |
| 190 friend class DriveResourceMetadata; // For access to ctor. | 190 friend class DriveResourceMetadata; // For access to ctor. |
| 191 | 191 |
| 192 explicit DriveFile(DriveResourceMetadata* resource_metadata); | 192 explicit DriveFile(DriveResourceMetadata* resource_metadata); |
| 193 // Initializes from DocumentEntry. | 193 // Initializes from gdata::DocumentEntry. |
| 194 virtual void InitFromDocumentEntry(const DocumentEntry& doc) OVERRIDE; | 194 virtual void InitFromDocumentEntry(const gdata::DocumentEntry& doc) OVERRIDE; |
| 195 | 195 |
| 196 virtual DriveFile* AsDriveFile() OVERRIDE; | 196 virtual DriveFile* AsDriveFile() OVERRIDE; |
| 197 | 197 |
| 198 DriveEntryKind kind_; // Not saved in proto. | 198 gdata::DriveEntryKind kind_; // Not saved in proto. |
| 199 GURL thumbnail_url_; | 199 GURL thumbnail_url_; |
| 200 GURL alternate_url_; | 200 GURL alternate_url_; |
| 201 std::string content_mime_type_; | 201 std::string content_mime_type_; |
| 202 std::string file_md5_; | 202 std::string file_md5_; |
| 203 std::string document_extension_; | 203 std::string document_extension_; |
| 204 bool is_hosted_document_; | 204 bool is_hosted_document_; |
| 205 | 205 |
| 206 DISALLOW_COPY_AND_ASSIGN(DriveFile); | 206 DISALLOW_COPY_AND_ASSIGN(DriveFile); |
| 207 }; | 207 }; |
| 208 | 208 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 220 scoped_ptr<DriveEntryProtoVector> ToProtoVector() const; | 220 scoped_ptr<DriveEntryProtoVector> ToProtoVector() const; |
| 221 | 221 |
| 222 private: | 222 private: |
| 223 // TODO(satorux): Remove the friend statements. crbug.com/139649 | 223 // TODO(satorux): Remove the friend statements. crbug.com/139649 |
| 224 friend class DriveResourceMetadata; | 224 friend class DriveResourceMetadata; |
| 225 friend class DriveResourceMetadataTest; | 225 friend class DriveResourceMetadataTest; |
| 226 friend class GDataWapiFeedProcessor; | 226 friend class GDataWapiFeedProcessor; |
| 227 | 227 |
| 228 explicit DriveDirectory(DriveResourceMetadata* resource_metadata); | 228 explicit DriveDirectory(DriveResourceMetadata* resource_metadata); |
| 229 | 229 |
| 230 // Initializes from DocumentEntry. | 230 // Initializes from gdata::DocumentEntry. |
| 231 virtual void InitFromDocumentEntry(const DocumentEntry& doc) OVERRIDE; | 231 virtual void InitFromDocumentEntry(const gdata::DocumentEntry& doc) OVERRIDE; |
| 232 | 232 |
| 233 virtual DriveDirectory* AsDriveDirectory() OVERRIDE; | 233 virtual DriveDirectory* AsDriveDirectory() OVERRIDE; |
| 234 | 234 |
| 235 // Adds child file to the directory and takes over the ownership of |file| | 235 // Adds child file to the directory and takes over the ownership of |file| |
| 236 // object. The method will also do name de-duplication to ensure that the | 236 // object. The method will also do name de-duplication to ensure that the |
| 237 // exposed presentation path does not have naming conflicts. Two files with | 237 // exposed presentation path does not have naming conflicts. Two files with |
| 238 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". | 238 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". |
| 239 // TODO(satorux): Remove this. crbug.com/139649 | 239 // TODO(satorux): Remove this. crbug.com/139649 |
| 240 void AddEntry(DriveEntry* entry); | 240 void AddEntry(DriveEntry* entry); |
| 241 | 241 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 269 | 269 |
| 270 // Map between base_name and resource_id of files and directories. | 270 // Map between base_name and resource_id of files and directories. |
| 271 typedef std::map<FilePath::StringType, std::string> ChildMap; | 271 typedef std::map<FilePath::StringType, std::string> ChildMap; |
| 272 // Collection of children. | 272 // Collection of children. |
| 273 ChildMap child_files_; | 273 ChildMap child_files_; |
| 274 ChildMap child_directories_; | 274 ChildMap child_directories_; |
| 275 | 275 |
| 276 DISALLOW_COPY_AND_ASSIGN(DriveDirectory); | 276 DISALLOW_COPY_AND_ASSIGN(DriveDirectory); |
| 277 }; | 277 }; |
| 278 | 278 |
| 279 } // namespace gdata | 279 } // namespace drive |
| 280 | 280 |
| 281 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_FILES_H_ | 281 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_FILES_H_ |
| OLD | NEW |