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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 const FilePath::CharType kGDataRootDirectory[] = FILE_PATH_LITERAL("drive"); | 57 const FilePath::CharType kGDataRootDirectory[] = FILE_PATH_LITERAL("drive"); |
58 | 58 |
59 // The resource ID for the root directory is defined in the spec: | 59 // The resource ID for the root directory is defined in the spec: |
60 // https://developers.google.com/google-apps/documents-list/ | 60 // https://developers.google.com/google-apps/documents-list/ |
61 const char kGDataRootDirectoryResourceId[] = "folder:root"; | 61 const char kGDataRootDirectoryResourceId[] = "folder:root"; |
62 | 62 |
63 // This should be incremented when incompatibility change is made in | 63 // This should be incremented when incompatibility change is made in |
64 // gdata.proto. | 64 // gdata.proto. |
65 const int32 kProtoVersion = 1; | 65 const int32 kProtoVersion = 1; |
66 | 66 |
67 // Used for file operations like removing files. | |
68 typedef base::Callback<void(GDataFileError error)> | |
69 FileOperationCallback; | |
70 | |
67 // Base class for representing files and directories in gdata virtual file | 71 // Base class for representing files and directories in gdata virtual file |
68 // system. | 72 // system. |
69 class GDataEntry { | 73 class GDataEntry { |
70 public: | 74 public: |
71 GDataEntry(GDataDirectory* parent, GDataDirectoryService* directory_service); | 75 GDataEntry(GDataDirectory* parent, GDataDirectoryService* directory_service); |
72 virtual ~GDataEntry(); | 76 virtual ~GDataEntry(); |
73 | 77 |
74 virtual GDataFile* AsGDataFile(); | 78 virtual GDataFile* AsGDataFile(); |
75 virtual GDataDirectory* AsGDataDirectory(); | 79 virtual GDataDirectory* AsGDataDirectory(); |
76 | 80 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 // Converts DocumentEntry into GDataEntry. | 272 // Converts DocumentEntry into GDataEntry. |
269 static GDataEntry* FromDocumentEntry( | 273 static GDataEntry* FromDocumentEntry( |
270 GDataDirectory* parent, | 274 GDataDirectory* parent, |
271 DocumentEntry* doc, | 275 DocumentEntry* doc, |
272 GDataDirectoryService* directory_service); | 276 GDataDirectoryService* directory_service); |
273 | 277 |
274 // Converts to/from proto. | 278 // Converts to/from proto. |
275 bool FromProto(const GDataDirectoryProto& proto) WARN_UNUSED_RESULT; | 279 bool FromProto(const GDataDirectoryProto& proto) WARN_UNUSED_RESULT; |
276 void ToProto(GDataDirectoryProto* proto) const; | 280 void ToProto(GDataDirectoryProto* proto) const; |
277 | 281 |
278 // Adds child file to the directory and takes over the ownership of |file| | |
279 // object. The method will also do name de-duplication to ensure that the | |
280 // exposed presentation path does not have naming conflicts. Two files with | |
281 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". | |
282 void AddEntry(GDataEntry* entry); | |
283 | |
284 // Takes the ownership of |entry| from its current parent. If this directory | 282 // Takes the ownership of |entry| from its current parent. If this directory |
285 // is already the current parent of |file|, this method effectively goes | 283 // is already the current parent of |file|, this method effectively goes |
286 // through the name de-duplication for |file| based on the current state of | 284 // through the name de-duplication for |file| based on the current state of |
287 // the file system. | 285 // the file system. |
288 bool TakeEntry(GDataEntry* entry); | 286 bool TakeEntry(GDataEntry* entry); |
289 | 287 |
290 // Takes over all entries from |dir|. | 288 // Takes over all entries from |dir|. |
291 bool TakeOverEntries(GDataDirectory* dir); | 289 bool TakeOverEntries(GDataDirectory* dir); |
292 | 290 |
293 // Removes the entry from its children list and destroys the entry instance. | 291 // Removes the entry from its children list and destroys the entry instance. |
294 bool RemoveEntry(GDataEntry* entry); | 292 bool RemoveEntry(GDataEntry* entry); |
295 | 293 |
296 // Removes child elements. | 294 // Removes child elements. |
297 void RemoveChildren(); | 295 void RemoveChildren(); |
298 void RemoveChildFiles(); | 296 void RemoveChildFiles(); |
299 void RemoveChildDirectories(); | 297 void RemoveChildDirectories(); |
300 | 298 |
301 // Collection of children files/directories. | 299 // Collection of children files/directories. |
302 const GDataFileCollection& child_files() const { return child_files_; } | 300 const GDataFileCollection& child_files() const { return child_files_; } |
303 const GDataDirectoryCollection& child_directories() const { | 301 const GDataDirectoryCollection& child_directories() const { |
304 return child_directories_; | 302 return child_directories_; |
305 } | 303 } |
306 | 304 |
307 private: | 305 private: |
306 // TODO(satorux): Remove the friend statements. crbug.com/139649 | |
308 friend class GDataDirectoryService; | 307 friend class GDataDirectoryService; |
308 friend class GDataFileSystem; | |
309 | |
310 // Adds child file to the directory and takes over the ownership of |file| | |
311 // object. The method will also do name de-duplication to ensure that the | |
312 // exposed presentation path does not have naming conflicts. Two files with | |
313 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". | |
314 // TODO(satorux): Remove this. crbug.com/139649 | |
315 void AddEntry(GDataEntry* entry); | |
309 | 316 |
310 // Find a child by its name. | 317 // Find a child by its name. |
311 // TODO(satorux): Remove this. crbug.com/139649 | 318 // TODO(satorux): Remove this. crbug.com/139649 |
312 GDataEntry* FindChild(const FilePath::StringType& file_name) const; | 319 GDataEntry* FindChild(const FilePath::StringType& file_name) const; |
313 | 320 |
314 // Add |entry| to children. | 321 // Add |entry| to children. |
315 void AddChild(GDataEntry* entry); | 322 void AddChild(GDataEntry* entry); |
316 | 323 |
317 // Removes the entry from its children without destroying the | 324 // Removes the entry from its children without destroying the |
318 // entry instance. | 325 // entry instance. |
(...skipping 26 matching lines...) Expand all Loading... | |
345 | 352 |
346 // Largest change timestamp that was the source of content for the current | 353 // Largest change timestamp that was the source of content for the current |
347 // state of the root directory. | 354 // state of the root directory. |
348 const int largest_changestamp() const { return largest_changestamp_; } | 355 const int largest_changestamp() const { return largest_changestamp_; } |
349 void set_largest_changestamp(int value) { largest_changestamp_ = value; } | 356 void set_largest_changestamp(int value) { largest_changestamp_ = value; } |
350 | 357 |
351 // The root directory content origin. | 358 // The root directory content origin. |
352 const ContentOrigin origin() const { return origin_; } | 359 const ContentOrigin origin() const { return origin_; } |
353 void set_origin(ContentOrigin value) { origin_ = value; } | 360 void set_origin(ContentOrigin value) { origin_ = value; } |
354 | 361 |
362 // ... | |
achuithb
2012/07/31 00:06:52
I'm assuming comment is coming?
satorux1
2012/07/31 00:28:30
yes. sorry!
satorux1
2012/07/31 07:13:22
Done.
| |
363 void AddEntryAt(const FilePath& path, GDataEntry* entry, | |
achuithb
2012/07/31 00:06:52
Can we rename |path| to something more descriptive
satorux1
2012/07/31 00:28:30
Will change it to directory_path
satorux1
2012/07/31 07:13:22
Done. Renamed it to AddEntryToDirectory() as well
| |
364 const FileOperationCallback& callback); | |
365 | |
355 // Adds the entry to resource map. | 366 // Adds the entry to resource map. |
356 void AddEntryToResourceMap(GDataEntry* entry); | 367 void AddEntryToResourceMap(GDataEntry* entry); |
357 | 368 |
358 // Removes the entry from resource map. | 369 // Removes the entry from resource map. |
359 void RemoveEntryFromResourceMap(GDataEntry* entry); | 370 void RemoveEntryFromResourceMap(GDataEntry* entry); |
360 | 371 |
361 // Searches for |file_path| synchronously. | 372 // Searches for |file_path| synchronously. |
362 // TODO(satorux): Replace this with an async version crbug.com/137160 | 373 // TODO(satorux): Replace this with an async version crbug.com/137160 |
363 GDataEntry* FindEntryByPathSync(const FilePath& file_path); | 374 GDataEntry* FindEntryByPathSync(const FilePath& file_path); |
364 | 375 |
365 // Returns the GDataEntry* with the corresponding |resource_id|. | 376 // Returns the GDataEntry* with the corresponding |resource_id|. |
366 // TODO(achuith): Get rid of this in favor of async version crbug.com/13957. | 377 // TODO(achuith): Get rid of this in favor of async version crbug.com/13957. |
367 GDataEntry* GetEntryByResourceId(const std::string& resource_id); | 378 GDataEntry* GetEntryByResourceId(const std::string& resource_id); |
368 | 379 |
369 // Returns the GDataEntry* in the callback with the corresponding | 380 // Returns the GDataEntry* in the callback with the corresponding |
370 // |resource_id|. TODO(achuith): Rename this to GetEntryByResourceId. | 381 // |resource_id|. TODO(achuith): Rename this to GetEntryByResourceId. |
371 void GetEntryByResourceIdAsync(const std::string& resource_id, | 382 void GetEntryByResourceIdAsync(const std::string& resource_id, |
372 const GetEntryByResourceIdCallback& callback); | 383 const GetEntryByResourceIdCallback& callback); |
373 | 384 |
374 // Replaces file entry with the same resource id as |fresh_file| with its | 385 // Replaces file entry with the same resource id as |fresh_file| with its |
375 // fresh value |fresh_file|. | 386 // fresh value |fresh_file|. |
376 void RefreshFile(scoped_ptr<GDataFile> fresh_file); | 387 void RefreshFile(scoped_ptr<GDataFile> fresh_file); |
377 | 388 |
389 // Replaces file entry |old_entry| with its fresh value |fresh_file|. | |
390 static void RefreshFileInternal(scoped_ptr<GDataFile> fresh_file, | |
achuithb
2012/07/31 00:06:52
Why is this moved from anon namespace?
satorux1
2012/07/31 00:28:30
so that GDataDirectory::AddEntry() can be called.
| |
391 GDataEntry* old_entry); | |
392 | |
378 // Serializes/Parses to/from string via proto classes. | 393 // Serializes/Parses to/from string via proto classes. |
379 void SerializeToString(std::string* serialized_proto) const; | 394 void SerializeToString(std::string* serialized_proto) const; |
380 bool ParseFromString(const std::string& serialized_proto); | 395 bool ParseFromString(const std::string& serialized_proto); |
381 | 396 |
382 private: | 397 private: |
383 // A map table of file's resource string to its GDataFile* entry. | 398 // A map table of file's resource string to its GDataFile* entry. |
384 typedef std::map<std::string, GDataEntry*> ResourceMap; | 399 typedef std::map<std::string, GDataEntry*> ResourceMap; |
385 | 400 |
386 scoped_ptr<GDataDirectory> root_; // Stored in the serialized proto. | 401 scoped_ptr<GDataDirectory> root_; // Stored in the serialized proto. |
387 ResourceMap resource_map_; | 402 ResourceMap resource_map_; |
388 | 403 |
389 base::Time last_serialized_; | 404 base::Time last_serialized_; |
390 size_t serialized_size_; | 405 size_t serialized_size_; |
391 int largest_changestamp_; // Stored in the serialized proto. | 406 int largest_changestamp_; // Stored in the serialized proto. |
392 ContentOrigin origin_; | 407 ContentOrigin origin_; |
393 | 408 |
394 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); | 409 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); |
395 }; | 410 }; |
396 | 411 |
397 } // namespace gdata | 412 } // namespace gdata |
398 | 413 |
399 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 414 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
OLD | NEW |