Home | History | Annotate | Download | only in drive_backend
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_LOCAL_TO_REMOTE_SYNCER_H_
      6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_LOCAL_TO_REMOTE_SYNCER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/memory/scoped_ptr.h"
     11 #include "base/memory/scoped_vector.h"
     12 #include "base/memory/weak_ptr.h"
     13 #include "chrome/browser/sync_file_system/drive_backend/sync_task.h"
     14 #include "chrome/browser/sync_file_system/file_change.h"
     15 #include "chrome/browser/sync_file_system/sync_action.h"
     16 #include "chrome/browser/sync_file_system/sync_callbacks.h"
     17 #include "chrome/browser/sync_file_system/sync_file_metadata.h"
     18 #include "google_apis/drive/gdata_errorcode.h"
     19 
     20 namespace drive {
     21 class DriveServiceInterface;
     22 class DriveUploaderInterface;
     23 }
     24 
     25 namespace google_apis {
     26 class FileResource;
     27 class ResourceList;
     28 }
     29 
     30 namespace sync_file_system {
     31 
     32 class RemoteChangeProcessor;
     33 
     34 namespace drive_backend {
     35 
     36 class FileTracker;
     37 class FolderCreator;
     38 class MetadataDatabase;
     39 class SyncEngineContext;
     40 
     41 class LocalToRemoteSyncer : public SyncTask {
     42  public:
     43   LocalToRemoteSyncer(SyncEngineContext* sync_context,
     44                       const SyncFileMetadata& local_metadata,
     45                       const FileChange& local_change,
     46                       const base::FilePath& local_path,
     47                       const fileapi::FileSystemURL& url);
     48   virtual ~LocalToRemoteSyncer();
     49   virtual void RunPreflight(scoped_ptr<SyncTaskToken> token) OVERRIDE;
     50   void RunExclusive(scoped_ptr<SyncTaskToken> token);
     51 
     52   const fileapi::FileSystemURL& url() const { return url_; }
     53   const base::FilePath& target_path() const { return target_path_; }
     54   SyncAction sync_action() const { return sync_action_; }
     55   bool needs_remote_change_listing() const {
     56     return needs_remote_change_listing_;
     57   }
     58 
     59  private:
     60   void SyncCompleted(scoped_ptr<SyncTaskToken> token,
     61                      SyncStatusCode status);
     62 
     63   void HandleConflict(scoped_ptr<SyncTaskToken> token);
     64   void HandleExistingRemoteFile(scoped_ptr<SyncTaskToken> token);
     65 
     66   void DeleteRemoteFile(const SyncStatusCallback& callback);
     67   void DidDeleteRemoteFile(const SyncStatusCallback& callback,
     68                            google_apis::GDataErrorCode error);
     69 
     70   void UploadExistingFile(scoped_ptr<SyncTaskToken> token);
     71   void DidGetMD5ForUpload(scoped_ptr<SyncTaskToken> token,
     72                           const std::string& local_file_md5);
     73   void DidUploadExistingFile(scoped_ptr<SyncTaskToken> token,
     74                              google_apis::GDataErrorCode error,
     75                              const GURL&,
     76                              scoped_ptr<google_apis::FileResource>);
     77   void DidUpdateDatabaseForUploadExistingFile(
     78       scoped_ptr<SyncTaskToken> token,
     79       SyncStatusCode status);
     80   void UpdateRemoteMetadata(const std::string& file_id,
     81                             scoped_ptr<SyncTaskToken> token);
     82   void DidGetRemoteMetadata(const std::string& file_id,
     83                             scoped_ptr<SyncTaskToken> token,
     84                             google_apis::GDataErrorCode error,
     85                             scoped_ptr<google_apis::FileResource> entry);
     86 
     87   void UploadNewFile(scoped_ptr<SyncTaskToken> token);
     88   void DidUploadNewFile(scoped_ptr<SyncTaskToken> token,
     89                         google_apis::GDataErrorCode error,
     90                         const GURL& upload_location,
     91                         scoped_ptr<google_apis::FileResource> entry);
     92 
     93   void CreateRemoteFolder(scoped_ptr<SyncTaskToken> token);
     94   void DidCreateRemoteFolder(scoped_ptr<SyncTaskToken> token,
     95                              const std::string& file_id,
     96                              SyncStatusCode status);
     97   void DidDetachResourceForCreationConflict(scoped_ptr<SyncTaskToken> token,
     98                                             google_apis::GDataErrorCode error);
     99 
    100   bool IsContextReady();
    101   drive::DriveServiceInterface* drive_service();
    102   drive::DriveUploaderInterface* drive_uploader();
    103   MetadataDatabase* metadata_database();
    104 
    105   void CompleteWithRetryStatus(scoped_ptr<SyncTaskToken> token,
    106                                SyncStatusCode status);
    107 
    108   SyncEngineContext* sync_context_;  // Not owned.
    109 
    110   FileChange local_change_;
    111   bool local_is_missing_;
    112   base::FilePath local_path_;
    113   fileapi::FileSystemURL url_;
    114   SyncAction sync_action_;
    115 
    116   scoped_ptr<FileTracker> remote_file_tracker_;
    117   scoped_ptr<FileTracker> remote_parent_folder_tracker_;
    118   base::FilePath target_path_;
    119 
    120   bool needs_remote_change_listing_;
    121 
    122   scoped_ptr<FolderCreator> folder_creator_;
    123 
    124   base::WeakPtrFactory<LocalToRemoteSyncer> weak_ptr_factory_;
    125 
    126   DISALLOW_COPY_AND_ASSIGN(LocalToRemoteSyncer);
    127 };
    128 
    129 }  // namespace drive_backend
    130 }  // namespace sync_file_system
    131 
    132 #endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_LOCAL_TO_REMOTE_SYNCER_H_
    133