Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync_file_system / drive_backend / local_to_remote_syncer.h
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_file_metadata.h"
17 #include "google_apis/drive/gdata_errorcode.h"
18
19 namespace drive {
20 class DriveServiceInterface;
21 class DriveUploaderInterface;
22 }
23
24 namespace google_apis {
25 class FileResource;
26 class ResourceList;
27 }
28
29 namespace sync_file_system {
30
31 class RemoteChangeProcessor;
32
33 namespace drive_backend {
34
35 class FileDetails;
36 class FileTracker;
37 class FolderCreator;
38 class MetadataDatabase;
39 class SyncEngineContext;
40
41 class LocalToRemoteSyncer : public SyncTask {
42  public:
43   typedef base::Callback<void(scoped_ptr<SyncTaskToken>)> Continuation;
44
45   LocalToRemoteSyncer(SyncEngineContext* sync_context,
46                       const SyncFileMetadata& local_metadata,
47                       const FileChange& local_change,
48                       const base::FilePath& local_path,
49                       const fileapi::FileSystemURL& url);
50   virtual ~LocalToRemoteSyncer();
51   virtual void RunPreflight(scoped_ptr<SyncTaskToken> token) OVERRIDE;
52
53   const fileapi::FileSystemURL& url() const { return url_; }
54   const base::FilePath& target_path() const { return target_path_; }
55   SyncAction sync_action() const { return sync_action_; }
56   bool needs_remote_change_listing() const {
57     return needs_remote_change_listing_;
58   }
59
60  private:
61   void MoveToBackground(const Continuation& continuation,
62                         scoped_ptr<SyncTaskToken> token);
63   void ContinueAsBackgroundTask(const Continuation& continuation,
64                                 scoped_ptr<SyncTaskToken> token);
65   void SyncCompleted(scoped_ptr<SyncTaskToken> token,
66                      SyncStatusCode status);
67
68   void HandleConflict(scoped_ptr<SyncTaskToken> token);
69   void HandleExistingRemoteFile(scoped_ptr<SyncTaskToken> token);
70
71   void UpdateTrackerForReusedFolder(const FileDetails& details,
72                                     scoped_ptr<SyncTaskToken> token);
73
74   void DeleteRemoteFile(scoped_ptr<SyncTaskToken> token);
75   void DidDeleteRemoteFile(scoped_ptr<SyncTaskToken> token,
76                            google_apis::GDataErrorCode error);
77
78   void UploadExistingFile(scoped_ptr<SyncTaskToken> token);
79   void DidUploadExistingFile(scoped_ptr<SyncTaskToken> token,
80                              google_apis::GDataErrorCode error,
81                              const GURL&,
82                              scoped_ptr<google_apis::FileResource>);
83   void DidUpdateDatabaseForUploadExistingFile(
84       scoped_ptr<SyncTaskToken> token,
85       SyncStatusCode status);
86   void UpdateRemoteMetadata(const std::string& file_id,
87                             scoped_ptr<SyncTaskToken> token);
88   void DidGetRemoteMetadata(const std::string& file_id,
89                             scoped_ptr<SyncTaskToken> token,
90                             google_apis::GDataErrorCode error,
91                             scoped_ptr<google_apis::FileResource> entry);
92
93   void UploadNewFile(scoped_ptr<SyncTaskToken> token);
94   void DidUploadNewFile(scoped_ptr<SyncTaskToken> token,
95                         google_apis::GDataErrorCode error,
96                         const GURL& upload_location,
97                         scoped_ptr<google_apis::FileResource> entry);
98
99   void CreateRemoteFolder(scoped_ptr<SyncTaskToken> token);
100   void DidCreateRemoteFolder(scoped_ptr<SyncTaskToken> token,
101                              const std::string& file_id,
102                              SyncStatusCode status);
103   void DidDetachResourceForCreationConflict(scoped_ptr<SyncTaskToken> token,
104                                             google_apis::GDataErrorCode error);
105
106   bool IsContextReady();
107   drive::DriveServiceInterface* drive_service();
108   drive::DriveUploaderInterface* drive_uploader();
109   MetadataDatabase* metadata_database();
110
111   SyncEngineContext* sync_context_;  // Not owned.
112
113   FileChange local_change_;
114   bool local_is_missing_;
115   base::FilePath local_path_;
116   fileapi::FileSystemURL url_;
117   SyncAction sync_action_;
118
119   scoped_ptr<FileTracker> remote_file_tracker_;
120   scoped_ptr<FileTracker> remote_parent_folder_tracker_;
121   base::FilePath target_path_;
122   int64 remote_file_change_id_;
123
124   bool retry_on_success_;
125   bool needs_remote_change_listing_;
126
127   scoped_ptr<FolderCreator> folder_creator_;
128
129   base::WeakPtrFactory<LocalToRemoteSyncer> weak_ptr_factory_;
130
131   DISALLOW_COPY_AND_ASSIGN(LocalToRemoteSyncer);
132 };
133
134 }  // namespace drive_backend
135 }  // namespace sync_file_system
136
137 #endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_LOCAL_TO_REMOTE_SYNCER_H_