Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: chrome/browser/chromeos/gdata/drive_files.h

Issue 10873005: Rename GDataDirectoryService to DriveResourceMetadata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DriveDirectoryService to DriveResourceMetadata Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_DRIVE_FILES_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_FILES_H_
6 #define CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_FILES_H_ 6 #define CHROME_BROWSER_CHROMEOS_GDATA_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.h" 13 #include "base/callback.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/gdata/gdata_wapi_parser.h" 17 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h"
18 18
19 namespace gdata { 19 namespace gdata {
20 20
21 class DriveDirectory; 21 class DriveDirectory;
22 class DriveDirectoryProto; 22 class DriveDirectoryProto;
23 class DriveEntryProto; 23 class DriveEntryProto;
24 class DriveFile; 24 class DriveFile;
25 class GDataDirectoryService; 25 class DriveResourceMetadata;
26 class PlatformFileInfoProto; 26 class PlatformFileInfoProto;
27 27
28 // Used to read a directory from the file system. 28 // Used to read a directory from the file system.
29 // If |error| is not GDATA_FILE_OK, |entries| is set to NULL. 29 // If |error| is not GDATA_FILE_OK, |entries| is set to NULL.
30 // |entries| are contents, both files and directories, of the directory. 30 // |entries| are contents, both files and directories, of the directory.
31 typedef std::vector<DriveEntryProto> DriveEntryProtoVector; 31 typedef std::vector<DriveEntryProto> DriveEntryProtoVector;
32 32
33 // Base class for representing files and directories in Drive virtual file 33 // Base class for representing files and directories in Drive virtual file
34 // system. 34 // system.
35 class DriveEntry { 35 class DriveEntry {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 // Upload URL is used for uploading files. See drive.proto for details. 103 // Upload URL is used for uploading files. See drive.proto for details.
104 const GURL& upload_url() const { return upload_url_; } 104 const GURL& upload_url() const { return upload_url_; }
105 void set_upload_url(const GURL& url) { upload_url_ = url; } 105 void set_upload_url(const GURL& url) { upload_url_ = url; }
106 106
107 // The edit URL is used for removing files and hosted documents. 107 // The edit URL is used for removing files and hosted documents.
108 const GURL& edit_url() const { return edit_url_; } 108 const GURL& edit_url() const { return edit_url_; }
109 109
110 // The resource id of the parent folder. This piece of information is needed 110 // The resource id of the parent folder. This piece of information is needed
111 // to pair files from change feeds with their directory parents withing the 111 // to pair files from change feeds with their directory parents withing the
112 // existing file system snapshot (GDataDirectoryService::resource_map_). 112 // existing file system snapshot (DriveResourceMetadata::resource_map_).
113 const std::string& parent_resource_id() const { return parent_resource_id_; } 113 const std::string& parent_resource_id() const { return parent_resource_id_; }
114 114
115 // True if file was deleted. Used only for instances that are generated from 115 // True if file was deleted. Used only for instances that are generated from
116 // delta feeds. 116 // delta feeds.
117 bool is_deleted() const { return deleted_; } 117 bool is_deleted() const { return deleted_; }
118 118
119 // Returns virtual file path representing this file system entry. This path 119 // Returns virtual file path representing this file system entry. This path
120 // corresponds to file path expected by public methods of GDataFileSystem 120 // corresponds to file path expected by public methods of GDataFileSystem
121 // class. 121 // class.
122 FilePath GetFilePath() const; 122 FilePath GetFilePath() const;
123 123
124 // Sets |base_name_| based on the value of |title_| without name 124 // Sets |base_name_| based on the value of |title_| without name
125 // de-duplication (see AddEntry() for details on de-duplication). 125 // de-duplication (see AddEntry() for details on de-duplication).
126 virtual void SetBaseNameFromTitle(); 126 virtual void SetBaseNameFromTitle();
127 127
128 protected: 128 protected:
129 // For access to SetParent from AddEntry. 129 // For access to SetParent from AddEntry.
130 friend class DriveDirectory; 130 friend class DriveDirectory;
131 131
132 explicit DriveEntry(GDataDirectoryService* directory_service); 132 explicit DriveEntry(DriveResourceMetadata* resource_metadata);
133 133
134 // Sets the parent directory of this file system entry. 134 // Sets the parent directory of this file system entry.
135 // It is intended to be used by DriveDirectory::AddEntry() only. 135 // It is intended to be used by DriveDirectory::AddEntry() only.
136 void SetParent(DriveDirectory* parent); 136 void SetParent(DriveDirectory* parent);
137 137
138 base::PlatformFileInfo file_info_; 138 base::PlatformFileInfo file_info_;
139 // Title of this file (i.e. the 'title' attribute associated with a regular 139 // Title of this file (i.e. the 'title' attribute associated with a regular
140 // file, hosted document, or collection). The title is used to derive 140 // file, hosted document, or collection). The title is used to derive
141 // |base_name_| but may be different from |base_name_|. For example, 141 // |base_name_| but may be different from |base_name_|. For example,
142 // |base_name_| has an added .g<something> extension for hosted documents or 142 // |base_name_| has an added .g<something> extension for hosted documents or
143 // may have an extra suffix for name de-duplication on the gdata file system. 143 // may have an extra suffix for name de-duplication on the gdata file system.
achuithb 2012/08/22 09:41:06 drive file system
kochi 2012/08/22 10:04:56 Done.
144 FilePath::StringType title_; 144 FilePath::StringType title_;
145 std::string resource_id_; 145 std::string resource_id_;
146 std::string parent_resource_id_; 146 std::string parent_resource_id_;
147 // Files with the same title will be uniquely identified with this field 147 // Files with the same title will be uniquely identified with this field
148 // so we can represent them with unique URLs/paths in File API layer. 148 // so we can represent them with unique URLs/paths in File API layer.
149 // For example, two files in the same directory with the same name "Foo" 149 // For example, two files in the same directory with the same name "Foo"
150 // will show up in the virtual directory as "Foo" and "Foo (2)". 150 // will show up in the virtual directory as "Foo" and "Foo (2)".
151 GURL edit_url_; 151 GURL edit_url_;
152 GURL content_url_; 152 GURL content_url_;
153 GURL upload_url_; 153 GURL upload_url_;
154 154
155 // Remaining fields are not serialized. 155 // Remaining fields are not serialized.
156 156
157 // Name of this file in the gdata virtual file system. This can change 157 // Name of this file in the gdata virtual file system. This can change
achuithb 2012/08/22 09:41:06 drive file system
kochi 2012/08/22 10:04:56 Done.
158 // due to de-duplication (See AddEntry). 158 // due to de-duplication (See AddEntry).
159 FilePath::StringType base_name_; 159 FilePath::StringType base_name_;
160 160
161 DriveDirectory* parent_; 161 DriveDirectory* parent_;
162 // Weak pointer to GDataDirectoryService. 162 // Weak pointer to DriveResourceMetadata.
163 GDataDirectoryService* directory_service_; 163 DriveResourceMetadata* resource_metadata_;
164 bool deleted_; 164 bool deleted_;
165 165
166 private: 166 private:
167 DISALLOW_COPY_AND_ASSIGN(DriveEntry); 167 DISALLOW_COPY_AND_ASSIGN(DriveEntry);
168 }; 168 };
169 169
170 // Represents "file" in in a GData virtual file system. On gdata feed side, 170 // Represents "file" in in a GData virtual file system. On gdata feed side,
achuithb 2012/08/22 09:41:06 drive file system.
kochi 2012/08/22 10:04:56 Done.
171 // this could be either a regular file or a server side document. 171 // this could be either a regular file or a server side document.
172 class DriveFile : public DriveEntry { 172 class DriveFile : public DriveEntry {
173 public: 173 public:
174 virtual ~DriveFile(); 174 virtual ~DriveFile();
175 175
176 // Converts to/from proto. 176 // Converts to/from proto.
177 void FromProto(const DriveEntryProto& proto); 177 void FromProto(const DriveEntryProto& proto);
178 void ToProto(DriveEntryProto* proto) const; 178 void ToProto(DriveEntryProto* proto) const;
179 179
180 DocumentEntry::EntryKind kind() const { return kind_; } 180 DocumentEntry::EntryKind kind() const { return kind_; }
181 const GURL& thumbnail_url() const { return thumbnail_url_; } 181 const GURL& thumbnail_url() const { return thumbnail_url_; }
182 const GURL& alternate_url() const { return alternate_url_; } 182 const GURL& alternate_url() const { return alternate_url_; }
183 const std::string& content_mime_type() const { return content_mime_type_; } 183 const std::string& content_mime_type() const { return content_mime_type_; }
184 const std::string& file_md5() const { return file_md5_; } 184 const std::string& file_md5() const { return file_md5_; }
185 void set_file_md5(const std::string& file_md5) { file_md5_ = file_md5; } 185 void set_file_md5(const std::string& file_md5) { file_md5_ = file_md5; }
186 const std::string& document_extension() const { return document_extension_; } 186 const std::string& document_extension() const { return document_extension_; }
187 bool is_hosted_document() const { return is_hosted_document_; } 187 bool is_hosted_document() const { return is_hosted_document_; }
188 void set_file_info(const base::PlatformFileInfo& info) { file_info_ = info; } 188 void set_file_info(const base::PlatformFileInfo& info) { file_info_ = info; }
189 189
190 // Overrides DriveEntry::SetBaseNameFromTitle() to set |base_name_| based 190 // Overrides DriveEntry::SetBaseNameFromTitle() to set |base_name_| based
191 // on the value of |title_| as well as |is_hosted_document_| and 191 // on the value of |title_| as well as |is_hosted_document_| and
192 // |document_extension_| for hosted documents. 192 // |document_extension_| for hosted documents.
193 virtual void SetBaseNameFromTitle() OVERRIDE; 193 virtual void SetBaseNameFromTitle() OVERRIDE;
194 194
195 private: 195 private:
196 friend class GDataDirectoryService; // For access to ctor. 196 friend class DriveResourceMetadata; // For access to ctor.
197 197
198 explicit DriveFile(GDataDirectoryService* directory_service); 198 explicit DriveFile(DriveResourceMetadata* resource_metadata);
199 // Initializes from DocumentEntry. 199 // Initializes from DocumentEntry.
200 virtual void InitFromDocumentEntry(const DocumentEntry& doc) OVERRIDE; 200 virtual void InitFromDocumentEntry(const DocumentEntry& doc) OVERRIDE;
201 201
202 virtual DriveFile* AsDriveFile() OVERRIDE; 202 virtual DriveFile* AsDriveFile() OVERRIDE;
203 203
204 DocumentEntry::EntryKind kind_; // Not saved in proto. 204 DocumentEntry::EntryKind kind_; // Not saved in proto.
205 GURL thumbnail_url_; 205 GURL thumbnail_url_;
206 GURL alternate_url_; 206 GURL alternate_url_;
207 std::string content_mime_type_; 207 std::string content_mime_type_;
208 std::string file_md5_; 208 std::string file_md5_;
209 std::string document_extension_; 209 std::string document_extension_;
210 bool is_hosted_document_; 210 bool is_hosted_document_;
211 211
212 DISALLOW_COPY_AND_ASSIGN(DriveFile); 212 DISALLOW_COPY_AND_ASSIGN(DriveFile);
213 }; 213 };
214 214
215 // Represents "directory" in a GData virtual file system. Maps to gdata 215 // Represents "directory" in a GData virtual file system. Maps to gdata
achuithb 2012/08/22 09:41:06 drive file system. drive collection element.
kochi 2012/08/22 10:04:56 Done.
216 // collection element. 216 // collection element.
217 class DriveDirectory : public DriveEntry { 217 class DriveDirectory : public DriveEntry {
218 public: 218 public:
219 virtual ~DriveDirectory(); 219 virtual ~DriveDirectory();
220 220
221 // Converts to/from proto. 221 // Converts to/from proto.
222 void FromProto(const DriveDirectoryProto& proto); 222 void FromProto(const DriveDirectoryProto& proto);
223 void ToProto(DriveDirectoryProto* proto) const; 223 void ToProto(DriveDirectoryProto* proto) const;
224 224
225 // Converts the children as a vector of DriveEntryProto. 225 // Converts the children as a vector of DriveEntryProto.
226 scoped_ptr<DriveEntryProtoVector> ToProtoVector() const; 226 scoped_ptr<DriveEntryProtoVector> ToProtoVector() const;
227 227
228 private: 228 private:
229 // TODO(satorux): Remove the friend statements. crbug.com/139649 229 // TODO(satorux): Remove the friend statements. crbug.com/139649
230 friend class GDataDirectoryService; 230 friend class DriveResourceMetadata;
231 friend class GDataWapiFeedProcessor; 231 friend class GDataWapiFeedProcessor;
232 232
233 explicit DriveDirectory(GDataDirectoryService* directory_service); 233 explicit DriveDirectory(DriveResourceMetadata* resource_metadata);
234 234
235 // Initializes from DocumentEntry. 235 // Initializes from DocumentEntry.
236 virtual void InitFromDocumentEntry(const DocumentEntry& doc) OVERRIDE; 236 virtual void InitFromDocumentEntry(const DocumentEntry& doc) OVERRIDE;
237 237
238 virtual DriveDirectory* AsDriveDirectory() OVERRIDE; 238 virtual DriveDirectory* AsDriveDirectory() OVERRIDE;
239 239
240 // Adds child file to the directory and takes over the ownership of |file| 240 // Adds child file to the directory and takes over the ownership of |file|
241 // object. The method will also do name de-duplication to ensure that the 241 // object. The method will also do name de-duplication to ensure that the
242 // exposed presentation path does not have naming conflicts. Two files with 242 // exposed presentation path does not have naming conflicts. Two files with
243 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". 243 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)".
(...skipping 22 matching lines...) Expand all
266 266
267 // Removes child elements. 267 // Removes child elements.
268 void RemoveChildren(); 268 void RemoveChildren();
269 void RemoveChildFiles(); 269 void RemoveChildFiles();
270 void RemoveChildDirectories(); 270 void RemoveChildDirectories();
271 271
272 // Recursively extracts the paths set of all sub-directories. 272 // Recursively extracts the paths set of all sub-directories.
273 void GetChildDirectoryPaths(std::set<FilePath>* child_dirs); 273 void GetChildDirectoryPaths(std::set<FilePath>* child_dirs);
274 274
275 // Map between base_name and resource_id of files and directories. 275 // Map between base_name and resource_id of files and directories.
276 typedef std::map<FilePath::StringType, std::string> GDataChildMap; 276 typedef std::map<FilePath::StringType, std::string> GDataChildMap;
achuithb 2012/08/22 09:41:06 Could you rename this to ChildMap?
kochi 2012/08/22 10:04:56 Done.
277 // Collection of children. 277 // Collection of children.
278 GDataChildMap child_files_; 278 GDataChildMap child_files_;
279 GDataChildMap child_directories_; 279 GDataChildMap child_directories_;
280 280
281 DISALLOW_COPY_AND_ASSIGN(DriveDirectory); 281 DISALLOW_COPY_AND_ASSIGN(DriveDirectory);
282 }; 282 };
283 283
284 } // namespace gdata 284 } // namespace gdata
285 285
286 #endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_FILES_H_ 286 #endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_FILES_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/gdata/drive_files.cc » ('j') | chrome/browser/chromeos/gdata/drive_resource_metadata.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698