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

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

Issue 10829277: GDataFileSystem is no longer a friend of GDataDirectory. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: 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 #include <vector>
10 11
11 #include "base/callback.h" 12 #include "base/callback.h"
12 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/singleton.h" 15 #include "base/memory/singleton.h"
15 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
16 #include "base/platform_file.h" 17 #include "base/platform_file.h"
17 #include "base/synchronization/lock.h" 18 #include "base/synchronization/lock.h"
18 #include "chrome/browser/chromeos/gdata/gdata_params.h" 19 #include "chrome/browser/chromeos/gdata/gdata_params.h"
19 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" 20 #include "chrome/browser/chromeos/gdata/gdata_uploader.h"
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 319
319 // Collection of children files/directories. 320 // Collection of children files/directories.
320 const GDataFileCollection& child_files() const { return child_files_; } 321 const GDataFileCollection& child_files() const { return child_files_; }
321 const GDataDirectoryCollection& child_directories() const { 322 const GDataDirectoryCollection& child_directories() const {
322 return child_directories_; 323 return child_directories_;
323 } 324 }
324 325
325 private: 326 private:
326 // TODO(satorux): Remove the friend statements. crbug.com/139649 327 // TODO(satorux): Remove the friend statements. crbug.com/139649
327 friend class GDataDirectoryService; 328 friend class GDataDirectoryService;
328 friend class GDataFileSystem;
329 friend class GDataWapiFeedProcessor; 329 friend class GDataWapiFeedProcessor;
330 330
331 explicit GDataDirectory(GDataDirectoryService* directory_service); 331 explicit GDataDirectory(GDataDirectoryService* directory_service);
332 332
333 // Initializes from DocumentEntry. 333 // Initializes from DocumentEntry.
334 virtual void InitFromDocumentEntry(DocumentEntry* doc) OVERRIDE; 334 virtual void InitFromDocumentEntry(DocumentEntry* doc) OVERRIDE;
335 335
336 virtual GDataDirectory* AsGDataDirectory() OVERRIDE; 336 virtual GDataDirectory* AsGDataDirectory() OVERRIDE;
337 337
338 // Adds child file to the directory and takes over the ownership of |file| 338 // Adds child file to the directory and takes over the ownership of |file|
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 // TODO(achuith,hashimoto,satorux): Move this to a separate file. 376 // TODO(achuith,hashimoto,satorux): Move this to a separate file.
377 // crbug.com/140317. 377 // crbug.com/140317.
378 // Class to handle GDataEntry* lookups, add/remove GDataEntry*. 378 // Class to handle GDataEntry* lookups, add/remove GDataEntry*.
379 class GDataDirectoryService { 379 class GDataDirectoryService {
380 public: 380 public:
381 // Callback for GetEntryByResourceIdAsync. 381 // Callback for GetEntryByResourceIdAsync.
382 typedef base::Callback<void(GDataEntry* entry)> GetEntryByResourceIdCallback; 382 typedef base::Callback<void(GDataEntry* entry)> GetEntryByResourceIdCallback;
383 383
384 // Map of resource id and serialized GDataEntry. 384 // Map of resource id and serialized GDataEntry.
385 typedef std::map<std::string, std::string> SerializedMap; 385 typedef std::map<std::string, std::string> SerializedMap;
386 // Map of resource id strings to GDataEntry*.
387 typedef std::map<std::string, GDataEntry*> ResourceMap;
386 388
387 GDataDirectoryService(); 389 GDataDirectoryService();
388 ~GDataDirectoryService(); 390 ~GDataDirectoryService();
389 391
390 GDataDirectory* root() { return root_.get(); } 392 GDataDirectory* root() { return root_.get(); }
391 393
392 // Last time when we dumped serialized file system to disk. 394 // Last time when we dumped serialized file system to disk.
393 const base::Time& last_serialized() const { return last_serialized_; } 395 const base::Time& last_serialized() const { return last_serialized_; }
394 void set_last_serialized(const base::Time& time) { last_serialized_ = time; } 396 void set_last_serialized(const base::Time& time) { last_serialized_ = time; }
395 // Size of serialized file system on disk in bytes. 397 // Size of serialized file system on disk in bytes.
(...skipping 14 matching lines...) Expand all
410 412
411 // Creates a GDataFile instance. 413 // Creates a GDataFile instance.
412 GDataFile* CreateGDataFile(); 414 GDataFile* CreateGDataFile();
413 415
414 // Creates a GDataDirectory instance. 416 // Creates a GDataDirectory instance.
415 GDataDirectory* CreateGDataDirectory(); 417 GDataDirectory* CreateGDataDirectory();
416 418
417 // Sets root directory resource id and initialize the root entry. 419 // Sets root directory resource id and initialize the root entry.
418 void InitializeRootEntry(const std::string& root_id); 420 void InitializeRootEntry(const std::string& root_id);
419 421
422 // Add |new entry| to |directory| and invoke the callback asynchronously.
423 void AddEntryToDirectory(GDataDirectory* directory,
424 GDataEntry* new_entry,
425 const base::Closure& callback);
426
420 // Move |entry| to |directory_path| asynchronously. Removes entry from 427 // Move |entry| to |directory_path| asynchronously. Removes entry from
421 // previous parent. Must be called on UI thread. |callback| is called on the 428 // previous parent. Must be called on UI thread. |callback| is called on the
422 // UI thread. 429 // UI thread.
423 void MoveEntryToDirectory(const FilePath& directory_path, 430 void MoveEntryToDirectory(const FilePath& directory_path,
424 GDataEntry* entry, 431 GDataEntry* entry,
425 const FileMoveCallback& callback); 432 const FileMoveCallback& callback);
426 433
434 // Remove |entry| from its parent. Calls |callback|, which may be null.
435 void RemoveEntryFromParent(GDataEntry* entry,
436 const base::Closure& callback);
437
427 // Adds the entry to resource map. 438 // Adds the entry to resource map.
428 void AddEntryToResourceMap(GDataEntry* entry); 439 void AddEntryToResourceMap(GDataEntry* entry);
429 440
430 // Removes the entry from resource map. 441 // Removes the entry from resource map.
431 void RemoveEntryFromResourceMap(GDataEntry* entry); 442 void RemoveEntryFromResourceMap(GDataEntry* entry);
432 443
433 // Searches for |file_path| synchronously. 444 // Searches for |file_path| synchronously.
434 // TODO(satorux): Replace this with an async version crbug.com/137160 445 // TODO(satorux): Replace this with an async version crbug.com/137160
435 GDataEntry* FindEntryByPathSync(const FilePath& file_path); 446 GDataEntry* FindEntryByPathSync(const FilePath& file_path);
436 447
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 // Must be called from UI thread. |callback| is run on UI thread. 479 // Must be called from UI thread. |callback| is run on UI thread.
469 void GetEntryInfoPairByPaths( 480 void GetEntryInfoPairByPaths(
470 const FilePath& first_path, 481 const FilePath& first_path,
471 const FilePath& second_path, 482 const FilePath& second_path,
472 const GetEntryInfoPairCallback& callback); 483 const GetEntryInfoPairCallback& callback);
473 484
474 // Replaces file entry with the same resource id as |fresh_file| with its 485 // Replaces file entry with the same resource id as |fresh_file| with its
475 // fresh value |fresh_file|. 486 // fresh value |fresh_file|.
476 void RefreshFile(scoped_ptr<GDataFile> fresh_file); 487 void RefreshFile(scoped_ptr<GDataFile> fresh_file);
477 488
478 // Replaces file entry |old_entry| with its fresh value |fresh_file|. 489 // Remove all child files of |directory| and replace with file_map.
479 static void RefreshFileInternal(scoped_ptr<GDataFile> fresh_file, 490 // Note that |callback| is only called if the directory is successfully
480 GDataEntry* old_entry); 491 // refreshed.
satorux1 2012/08/10 16:14:44 please document if |callback| is optional or not.
achuithb 2012/08/11 00:37:45 Done here and elsewhere.
492 void RefreshDirectory(const std::string& directory_resource_id,
493 const ResourceMap& file_map,
494 const base::Closure& callback);
481 495
482 // Serializes/Parses to/from string via proto classes. 496 // Serializes/Parses to/from string via proto classes.
483 void SerializeToString(std::string* serialized_proto) const; 497 void SerializeToString(std::string* serialized_proto) const;
484 bool ParseFromString(const std::string& serialized_proto); 498 bool ParseFromString(const std::string& serialized_proto);
485 499
486 // Restores from and saves to database. 500 // Restores from and saves to database.
487 void InitFromDB(const FilePath& db_path, 501 void InitFromDB(const FilePath& db_path,
488 base::SequencedTaskRunner* blocking_task_runner, 502 base::SequencedTaskRunner* blocking_task_runner,
489 const FileOperationCallback& callback); 503 const FileOperationCallback& callback);
490 void SaveToDB(); 504 void SaveToDB();
491 505
492 private: 506 private:
493 // A map table of file's resource string to its GDataFile* entry.
494 typedef std::map<std::string, GDataEntry*> ResourceMap;
495
496 // Initializes the resource map using serialized_resources fetched from the 507 // Initializes the resource map using serialized_resources fetched from the
497 // database. 508 // database.
498 void InitResourceMap(CreateDBParams* create_params, 509 void InitResourceMap(CreateDBParams* create_params,
499 const FileOperationCallback& callback); 510 const FileOperationCallback& callback);
500 511
501 // Clears root_ and the resource map. 512 // Clears root_ and the resource map.
502 void ClearRoot(); 513 void ClearRoot();
503 514
504 // Creates GDataEntry from serialized string. 515 // Creates GDataEntry from serialized string.
505 scoped_ptr<GDataEntry> FromProtoString( 516 scoped_ptr<GDataEntry> FromProtoString(
506 const std::string& serialized_proto); 517 const std::string& serialized_proto);
507 518
508 // ... 519 // ...
509 void GetEntryInfoPairByPathsAfterGetFirst( 520 void GetEntryInfoPairByPathsAfterGetFirst(
510 const FilePath& first_path, 521 const FilePath& first_path,
511 const FilePath& second_path, 522 const FilePath& second_path,
512 const GetEntryInfoPairCallback& callback, 523 const GetEntryInfoPairCallback& callback,
513 GDataFileError error, 524 GDataFileError error,
514 scoped_ptr<GDataEntryProto> entry_proto); 525 scoped_ptr<GDataEntryProto> entry_proto);
515 526
516 // ... 527 // ...
517 void GetEntryInfoPairByPathsAfterGetSecond( 528 void GetEntryInfoPairByPathsAfterGetSecond(
518 const FilePath& second_path, 529 const FilePath& second_path,
519 const GetEntryInfoPairCallback& callback, 530 const GetEntryInfoPairCallback& callback,
520 scoped_ptr<EntryInfoPairResult> result, 531 scoped_ptr<EntryInfoPairResult> result,
521 GDataFileError error, 532 GDataFileError error,
522 scoped_ptr<GDataEntryProto> entry_proto); 533 scoped_ptr<GDataEntryProto> entry_proto);
523 534
535 // These internal functions need friend access to private GDataDirectory
536 // methods.
537 // Replaces file entry |old_entry| with its fresh value |fresh_file|.
538 static void RefreshFileInternal(scoped_ptr<GDataFile> fresh_file,
539 GDataEntry* old_entry);
540
541 // Remove all child files of |directory| and replace with file_map.
542 // Note that |callback| is only called if the directory is successfully
543 // refreshed.
544 static void RefreshDirectoryInternal(const ResourceMap& file_map,
545 const base::Closure& callback,
546 GDataEntry* directory_entry);
547
548
524 // Private data members. 549 // Private data members.
525 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 550 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
526 scoped_ptr<ResourceMetadataDB> directory_service_db_; 551 scoped_ptr<ResourceMetadataDB> directory_service_db_;
527 552
528 ResourceMap resource_map_; 553 ResourceMap resource_map_;
529 554
530 scoped_ptr<GDataDirectory> root_; // Stored in the serialized proto. 555 scoped_ptr<GDataDirectory> root_; // Stored in the serialized proto.
531 556
532 base::Time last_serialized_; 557 base::Time last_serialized_;
533 size_t serialized_size_; 558 size_t serialized_size_;
534 int64 largest_changestamp_; // Stored in the serialized proto. 559 int64 largest_changestamp_; // Stored in the serialized proto.
535 ContentOrigin origin_; 560 ContentOrigin origin_;
536 561
537 // This should remain the last member so it'll be destroyed first and 562 // This should remain the last member so it'll be destroyed first and
538 // invalidate its weak pointers before other members are destroyed. 563 // invalidate its weak pointers before other members are destroyed.
539 base::WeakPtrFactory<GDataDirectoryService> weak_ptr_factory_; 564 base::WeakPtrFactory<GDataDirectoryService> weak_ptr_factory_;
540 565
541 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); 566 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService);
542 }; 567 };
543 568
544 } // namespace gdata 569 } // namespace gdata
545 570
546 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ 571 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698