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

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

Issue 10828083: gdata: Add GDataDirectoryService::AddEntryToDirectory() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments 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_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
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
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
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 // Adds |entry| to |directory_path| asynchronously.
363 // Must be called on UI thread. |callback| is called/ on the UI thread.
364 void AddEntryToDirectory(const FilePath& directory_path,
365 GDataEntry* entry,
366 const FileOperationCallback& callback);
367
355 // Adds the entry to resource map. 368 // Adds the entry to resource map.
356 void AddEntryToResourceMap(GDataEntry* entry); 369 void AddEntryToResourceMap(GDataEntry* entry);
357 370
358 // Removes the entry from resource map. 371 // Removes the entry from resource map.
359 void RemoveEntryFromResourceMap(GDataEntry* entry); 372 void RemoveEntryFromResourceMap(GDataEntry* entry);
360 373
361 // Searches for |file_path| synchronously. 374 // Searches for |file_path| synchronously.
362 // TODO(satorux): Replace this with an async version crbug.com/137160 375 // TODO(satorux): Replace this with an async version crbug.com/137160
363 GDataEntry* FindEntryByPathSync(const FilePath& file_path); 376 GDataEntry* FindEntryByPathSync(const FilePath& file_path);
364 377
365 // Returns the GDataEntry* with the corresponding |resource_id|. 378 // Returns the GDataEntry* with the corresponding |resource_id|.
366 // TODO(achuith): Get rid of this in favor of async version crbug.com/13957. 379 // TODO(achuith): Get rid of this in favor of async version crbug.com/13957.
367 GDataEntry* GetEntryByResourceId(const std::string& resource_id); 380 GDataEntry* GetEntryByResourceId(const std::string& resource_id);
368 381
369 // Returns the GDataEntry* in the callback with the corresponding 382 // Returns the GDataEntry* in the callback with the corresponding
370 // |resource_id|. TODO(achuith): Rename this to GetEntryByResourceId. 383 // |resource_id|. TODO(achuith): Rename this to GetEntryByResourceId.
371 void GetEntryByResourceIdAsync(const std::string& resource_id, 384 void GetEntryByResourceIdAsync(const std::string& resource_id,
372 const GetEntryByResourceIdCallback& callback); 385 const GetEntryByResourceIdCallback& callback);
373 386
374 // Replaces file entry with the same resource id as |fresh_file| with its 387 // Replaces file entry with the same resource id as |fresh_file| with its
375 // fresh value |fresh_file|. 388 // fresh value |fresh_file|.
376 void RefreshFile(scoped_ptr<GDataFile> fresh_file); 389 void RefreshFile(scoped_ptr<GDataFile> fresh_file);
377 390
391 // Replaces file entry |old_entry| with its fresh value |fresh_file|.
392 static void RefreshFileInternal(scoped_ptr<GDataFile> fresh_file,
393 GDataEntry* old_entry);
394
378 // Serializes/Parses to/from string via proto classes. 395 // Serializes/Parses to/from string via proto classes.
379 void SerializeToString(std::string* serialized_proto) const; 396 void SerializeToString(std::string* serialized_proto) const;
380 bool ParseFromString(const std::string& serialized_proto); 397 bool ParseFromString(const std::string& serialized_proto);
381 398
382 private: 399 private:
383 // A map table of file's resource string to its GDataFile* entry. 400 // A map table of file's resource string to its GDataFile* entry.
384 typedef std::map<std::string, GDataEntry*> ResourceMap; 401 typedef std::map<std::string, GDataEntry*> ResourceMap;
385 402
386 scoped_ptr<GDataDirectory> root_; // Stored in the serialized proto. 403 scoped_ptr<GDataDirectory> root_; // Stored in the serialized proto.
387 ResourceMap resource_map_; 404 ResourceMap resource_map_;
388 405
389 base::Time last_serialized_; 406 base::Time last_serialized_;
390 size_t serialized_size_; 407 size_t serialized_size_;
391 int largest_changestamp_; // Stored in the serialized proto. 408 int largest_changestamp_; // Stored in the serialized proto.
392 ContentOrigin origin_; 409 ContentOrigin origin_;
393 410
394 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); 411 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService);
395 }; 412 };
396 413
397 } // namespace gdata 414 } // namespace gdata
398 415
399 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ 416 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system_interface.h ('k') | chrome/browser/chromeos/gdata/gdata_files.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698