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 <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 const char kGDataRootDirectoryResourceId[] = "folder:root"; | 67 const char kGDataRootDirectoryResourceId[] = "folder:root"; |
68 | 68 |
69 // This should be incremented when incompatibility change is made in | 69 // This should be incremented when incompatibility change is made in |
70 // gdata.proto. | 70 // gdata.proto. |
71 const int32 kProtoVersion = 1; | 71 const int32 kProtoVersion = 1; |
72 | 72 |
73 // Used for file operations like removing files. | 73 // Used for file operations like removing files. |
74 typedef base::Callback<void(GDataFileError error)> | 74 typedef base::Callback<void(GDataFileError error)> |
75 FileOperationCallback; | 75 FileOperationCallback; |
76 | 76 |
77 // Callback similar to FileOperationCallback but with a given |file_path|. | |
satorux1
2012/08/08 23:25:01
let's add:
// Used for operations that change a f
achuithb
2012/08/09 00:12:51
Done.
| |
78 typedef base::Callback<void(GDataFileError error, | |
79 const FilePath& file_path)> | |
80 FilePathUpdateCallback; | |
satorux1
2012/08/08 23:25:01
Maybe FilePathChangeCallback?
satorux1
2012/08/08 23:40:57
Better idea. This callback seems to be only used f
achuithb
2012/08/09 00:12:51
Done.
| |
81 | |
77 // Base class for representing files and directories in gdata virtual file | 82 // Base class for representing files and directories in gdata virtual file |
78 // system. | 83 // system. |
79 class GDataEntry { | 84 class GDataEntry { |
80 public: | 85 public: |
86 // TODO(achuith): Remove |parent| from ctor. crbug.com/141494 | |
81 GDataEntry(GDataDirectory* parent, GDataDirectoryService* directory_service); | 87 GDataEntry(GDataDirectory* parent, GDataDirectoryService* directory_service); |
82 virtual ~GDataEntry(); | 88 virtual ~GDataEntry(); |
83 | 89 |
84 virtual GDataFile* AsGDataFile(); | 90 virtual GDataFile* AsGDataFile(); |
85 virtual GDataDirectory* AsGDataDirectory(); | 91 virtual GDataDirectory* AsGDataDirectory(); |
86 | 92 |
87 // const versions of AsGDataFile and AsGDataDirectory. | 93 // const versions of AsGDataFile and AsGDataDirectory. |
88 const GDataFile* AsGDataFileConst() const; | 94 const GDataFile* AsGDataFileConst() const; |
89 const GDataDirectory* AsGDataDirectoryConst() const; | 95 const GDataDirectory* AsGDataDirectoryConst() const; |
90 | 96 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 }; | 219 }; |
214 | 220 |
215 typedef std::map<FilePath::StringType, GDataFile*> GDataFileCollection; | 221 typedef std::map<FilePath::StringType, GDataFile*> GDataFileCollection; |
216 typedef std::map<FilePath::StringType, GDataDirectory*> | 222 typedef std::map<FilePath::StringType, GDataDirectory*> |
217 GDataDirectoryCollection; | 223 GDataDirectoryCollection; |
218 | 224 |
219 // Represents "file" in in a GData virtual file system. On gdata feed side, | 225 // Represents "file" in in a GData virtual file system. On gdata feed side, |
220 // this could be either a regular file or a server side document. | 226 // this could be either a regular file or a server side document. |
221 class GDataFile : public GDataEntry { | 227 class GDataFile : public GDataEntry { |
222 public: | 228 public: |
229 // TODO(achuith): Remove |parent| from ctor. crbug.com/141494 | |
223 explicit GDataFile(GDataDirectory* parent, | 230 explicit GDataFile(GDataDirectory* parent, |
224 GDataDirectoryService* directory_service); | 231 GDataDirectoryService* directory_service); |
225 virtual ~GDataFile(); | 232 virtual ~GDataFile(); |
226 virtual GDataFile* AsGDataFile() OVERRIDE; | 233 virtual GDataFile* AsGDataFile() OVERRIDE; |
227 | 234 |
228 // Converts DocumentEntry into GDataEntry. | 235 // Converts DocumentEntry into GDataEntry. |
229 static GDataEntry* FromDocumentEntry( | 236 static GDataEntry* FromDocumentEntry( |
230 GDataDirectory* parent, | 237 GDataDirectory* parent, |
231 DocumentEntry* doc, | 238 DocumentEntry* doc, |
232 GDataDirectoryService* directory_service); | 239 GDataDirectoryService* directory_service); |
(...skipping 26 matching lines...) Expand all Loading... | |
259 std::string document_extension_; | 266 std::string document_extension_; |
260 bool is_hosted_document_; | 267 bool is_hosted_document_; |
261 | 268 |
262 DISALLOW_COPY_AND_ASSIGN(GDataFile); | 269 DISALLOW_COPY_AND_ASSIGN(GDataFile); |
263 }; | 270 }; |
264 | 271 |
265 // Represents "directory" in a GData virtual file system. Maps to gdata | 272 // Represents "directory" in a GData virtual file system. Maps to gdata |
266 // collection element. | 273 // collection element. |
267 class GDataDirectory : public GDataEntry { | 274 class GDataDirectory : public GDataEntry { |
268 public: | 275 public: |
276 // TODO(achuith): Remove |parent| from ctor. crbug.com/141494 | |
269 GDataDirectory(GDataDirectory* parent, | 277 GDataDirectory(GDataDirectory* parent, |
270 GDataDirectoryService* directory_service); | 278 GDataDirectoryService* directory_service); |
271 virtual ~GDataDirectory(); | 279 virtual ~GDataDirectory(); |
272 virtual GDataDirectory* AsGDataDirectory() OVERRIDE; | 280 virtual GDataDirectory* AsGDataDirectory() OVERRIDE; |
273 | 281 |
274 // Converts DocumentEntry into GDataEntry. | 282 // Converts DocumentEntry into GDataEntry. |
275 static GDataEntry* FromDocumentEntry( | 283 static GDataEntry* FromDocumentEntry( |
276 GDataDirectory* parent, | 284 GDataDirectory* parent, |
277 DocumentEntry* doc, | 285 DocumentEntry* doc, |
278 GDataDirectoryService* directory_service); | 286 GDataDirectoryService* directory_service); |
279 | 287 |
280 // Converts to/from proto. | 288 // Converts to/from proto. |
281 bool FromProto(const GDataDirectoryProto& proto) WARN_UNUSED_RESULT; | 289 bool FromProto(const GDataDirectoryProto& proto) WARN_UNUSED_RESULT; |
282 void ToProto(GDataDirectoryProto* proto) const; | 290 void ToProto(GDataDirectoryProto* proto) const; |
283 | 291 |
284 // Removes child elements. | |
285 void RemoveChildren(); | |
286 void RemoveChildFiles(); | |
287 void RemoveChildDirectories(); | |
288 | |
289 // Collection of children files/directories. | 292 // Collection of children files/directories. |
290 const GDataFileCollection& child_files() const { return child_files_; } | 293 const GDataFileCollection& child_files() const { return child_files_; } |
291 const GDataDirectoryCollection& child_directories() const { | 294 const GDataDirectoryCollection& child_directories() const { |
292 return child_directories_; | 295 return child_directories_; |
293 } | 296 } |
294 | 297 |
295 private: | 298 private: |
296 // TODO(satorux): Remove the friend statements. crbug.com/139649 | 299 // TODO(satorux): Remove the friend statements. crbug.com/139649 |
297 friend class GDataDirectoryService; | 300 friend class GDataDirectoryService; |
298 friend class GDataFileSystem; | 301 friend class GDataFileSystem; |
299 friend class GDataWapiFeedProcessor; | 302 friend class GDataWapiFeedProcessor; |
300 | 303 |
301 // Adds child file to the directory and takes over the ownership of |file| | 304 // Adds child file to the directory and takes over the ownership of |file| |
302 // object. The method will also do name de-duplication to ensure that the | 305 // object. The method will also do name de-duplication to ensure that the |
303 // exposed presentation path does not have naming conflicts. Two files with | 306 // exposed presentation path does not have naming conflicts. Two files with |
304 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". | 307 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". |
305 // TODO(satorux): Remove this. crbug.com/139649 | 308 // TODO(satorux): Remove this. crbug.com/139649 |
306 void AddEntry(GDataEntry* entry); | 309 void AddEntry(GDataEntry* entry); |
307 | 310 |
308 // Removes the entry from its children list and destroys the entry instance. | 311 // Removes the entry from its children list and destroys the entry instance. |
309 // TODO(satorux): Remove this. crbug.com/139649 | 312 // TODO(satorux): Remove this. crbug.com/139649 |
310 void RemoveEntry(GDataEntry* entry); | 313 void RemoveEntry(GDataEntry* entry); |
311 | 314 |
312 // Takes the ownership of |entry| from its current parent. If this directory | |
313 // is already the current parent of |file|, this method effectively goes | |
314 // through the name de-duplication for |file| based on the current state of | |
315 // the file system. | |
316 // TODO(satorux): Remove this. crbug.com/139649 | |
317 bool TakeEntry(GDataEntry* entry); | |
318 | |
319 // Takes over all entries from |dir|. | 315 // Takes over all entries from |dir|. |
320 // TODO(satorux): Remove this. crbug.com/139649 | 316 // TODO(satorux): Remove this. crbug.com/139649 |
321 bool TakeOverEntries(GDataDirectory* dir); | 317 bool TakeOverEntries(GDataDirectory* dir); |
322 | 318 |
323 // Find a child by its name. | 319 // Find a child by its name. |
324 // TODO(satorux): Remove this. crbug.com/139649 | 320 // TODO(satorux): Remove this. crbug.com/139649 |
325 GDataEntry* FindChild(const FilePath::StringType& file_name) const; | 321 GDataEntry* FindChild(const FilePath::StringType& file_name) const; |
326 | 322 |
327 // Add |entry| to children. | 323 // Add |entry| to children. |
328 void AddChild(GDataEntry* entry); | 324 void AddChild(GDataEntry* entry); |
329 | 325 |
330 // Removes the entry from its children without destroying the | 326 // Removes the entry from its children without destroying the |
331 // entry instance. | 327 // entry instance. |
332 void RemoveChild(GDataEntry* entry); | 328 void RemoveChild(GDataEntry* entry); |
333 | 329 |
330 // Removes child elements. | |
331 void RemoveChildren(); | |
332 void RemoveChildFiles(); | |
333 void RemoveChildDirectories(); | |
334 | |
334 // Collection of children GDataEntry items. | 335 // Collection of children GDataEntry items. |
335 GDataFileCollection child_files_; | 336 GDataFileCollection child_files_; |
336 GDataDirectoryCollection child_directories_; | 337 GDataDirectoryCollection child_directories_; |
337 | 338 |
338 DISALLOW_COPY_AND_ASSIGN(GDataDirectory); | 339 DISALLOW_COPY_AND_ASSIGN(GDataDirectory); |
339 }; | 340 }; |
340 | 341 |
341 // TODO(achuith,hashimoto,satorux): Move this to a separate file. | 342 // TODO(achuith,hashimoto,satorux): Move this to a separate file. |
342 // crbug.com/140317. | 343 // crbug.com/140317. |
343 // Class to handle GDataEntry* lookups, add/remove GDataEntry*. | 344 // Class to handle GDataEntry* lookups, add/remove GDataEntry*. |
(...skipping 19 matching lines...) Expand all Loading... | |
363 | 364 |
364 // Largest change timestamp that was the source of content for the current | 365 // Largest change timestamp that was the source of content for the current |
365 // state of the root directory. | 366 // state of the root directory. |
366 const int largest_changestamp() const { return largest_changestamp_; } | 367 const int largest_changestamp() const { return largest_changestamp_; } |
367 void set_largest_changestamp(int value) { largest_changestamp_ = value; } | 368 void set_largest_changestamp(int value) { largest_changestamp_ = value; } |
368 | 369 |
369 // The root directory content origin. | 370 // The root directory content origin. |
370 const ContentOrigin origin() const { return origin_; } | 371 const ContentOrigin origin() const { return origin_; } |
371 void set_origin(ContentOrigin value) { origin_ = value; } | 372 void set_origin(ContentOrigin value) { origin_ = value; } |
372 | 373 |
373 // Adds |entry| to |directory_path| asynchronously. | 374 // Adds |entry| to |directory_path| asynchronously. Removes entry from |
374 // Must be called on UI thread. |callback| is called on the UI thread. | 375 // previous parent. Must be called on UI thread. |callback| is called on the |
satorux1
2012/08/08 23:40:58
Per the description, "MoveEntryToDirectory" may be
achuithb
2012/08/09 00:12:51
Done.
| |
376 // UI thread. | |
375 void AddEntryToDirectory(const FilePath& directory_path, | 377 void AddEntryToDirectory(const FilePath& directory_path, |
376 GDataEntry* entry, | 378 GDataEntry* entry, |
satorux1
2012/08/08 23:25:01
Not in this patch, but I think we should change th
achuithb
2012/08/09 00:12:51
Yup
| |
377 const FileOperationCallback& callback); | 379 const FilePathUpdateCallback& callback); |
378 | 380 |
379 // Adds the entry to resource map. | 381 // Adds the entry to resource map. |
380 void AddEntryToResourceMap(GDataEntry* entry); | 382 void AddEntryToResourceMap(GDataEntry* entry); |
381 | 383 |
382 // Removes the entry from resource map. | 384 // Removes the entry from resource map. |
383 void RemoveEntryFromResourceMap(GDataEntry* entry); | 385 void RemoveEntryFromResourceMap(GDataEntry* entry); |
384 | 386 |
385 // Searches for |file_path| synchronously. | 387 // Searches for |file_path| synchronously. |
386 // TODO(satorux): Replace this with an async version crbug.com/137160 | 388 // TODO(satorux): Replace this with an async version crbug.com/137160 |
387 GDataEntry* FindEntryByPathSync(const FilePath& file_path); | 389 GDataEntry* FindEntryByPathSync(const FilePath& file_path); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 // This should remain the last member so it'll be destroyed first and | 452 // This should remain the last member so it'll be destroyed first and |
451 // invalidate its weak pointers before other members are destroyed. | 453 // invalidate its weak pointers before other members are destroyed. |
452 base::WeakPtrFactory<GDataDirectoryService> weak_ptr_factory_; | 454 base::WeakPtrFactory<GDataDirectoryService> weak_ptr_factory_; |
453 | 455 |
454 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); | 456 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); |
455 }; | 457 }; |
456 | 458 |
457 } // namespace gdata | 459 } // namespace gdata |
458 | 460 |
459 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 461 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
OLD | NEW |