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.
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_
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"
20 class DriveServiceInterface
;
21 class DriveUploaderInterface
;
24 namespace google_apis
{
29 namespace sync_file_system
{
31 class RemoteChangeProcessor
;
33 namespace drive_backend
{
38 class MetadataDatabase
;
39 class SyncEngineContext
;
41 class LocalToRemoteSyncer
: public SyncTask
{
43 typedef base::Callback
<void(scoped_ptr
<SyncTaskToken
>)> Continuation
;
45 LocalToRemoteSyncer(SyncEngineContext
* sync_context
,
46 const SyncFileMetadata
& local_metadata
,
47 const FileChange
& local_change
,
48 const base::FilePath
& local_path
,
49 const storage::FileSystemURL
& url
);
50 ~LocalToRemoteSyncer() override
;
51 void RunPreflight(scoped_ptr
<SyncTaskToken
> token
) override
;
53 const storage::FileSystemURL
& url() const { return url_
; }
54 const base::FilePath
& target_path() const { return target_path_
; }
55 SyncFileType
file_type() const { return file_type_
; }
56 SyncAction
sync_action() const { return sync_action_
; }
57 bool needs_remote_change_listing() const {
58 return needs_remote_change_listing_
;
62 void MoveToBackground(const Continuation
& continuation
,
63 scoped_ptr
<SyncTaskToken
> token
);
64 void ContinueAsBackgroundTask(const Continuation
& continuation
,
65 scoped_ptr
<SyncTaskToken
> token
);
66 void SyncCompleted(scoped_ptr
<SyncTaskToken
> token
,
67 SyncStatusCode status
);
69 void HandleConflict(scoped_ptr
<SyncTaskToken
> token
);
70 void HandleExistingRemoteFile(scoped_ptr
<SyncTaskToken
> token
);
72 void UpdateTrackerForReusedFolder(const FileDetails
& details
,
73 scoped_ptr
<SyncTaskToken
> token
);
75 void DeleteRemoteFile(scoped_ptr
<SyncTaskToken
> token
);
76 void DidDeleteRemoteFile(scoped_ptr
<SyncTaskToken
> token
,
77 google_apis::GDataErrorCode error
);
79 void UploadExistingFile(scoped_ptr
<SyncTaskToken
> token
);
80 void DidUploadExistingFile(scoped_ptr
<SyncTaskToken
> token
,
81 google_apis::GDataErrorCode error
,
83 scoped_ptr
<google_apis::FileResource
>);
84 void UpdateRemoteMetadata(const std::string
& file_id
,
85 scoped_ptr
<SyncTaskToken
> token
);
86 void DidGetRemoteMetadata(const std::string
& file_id
,
87 scoped_ptr
<SyncTaskToken
> token
,
88 google_apis::GDataErrorCode error
,
89 scoped_ptr
<google_apis::FileResource
> entry
);
91 void UploadNewFile(scoped_ptr
<SyncTaskToken
> token
);
92 void DidUploadNewFile(scoped_ptr
<SyncTaskToken
> token
,
93 google_apis::GDataErrorCode error
,
94 const GURL
& upload_location
,
95 scoped_ptr
<google_apis::FileResource
> entry
);
97 void CreateRemoteFolder(scoped_ptr
<SyncTaskToken
> token
);
98 void DidCreateRemoteFolder(scoped_ptr
<SyncTaskToken
> token
,
99 const std::string
& file_id
,
100 SyncStatusCode status
);
101 void DidDetachResourceForCreationConflict(scoped_ptr
<SyncTaskToken
> token
,
102 google_apis::GDataErrorCode error
);
104 bool IsContextReady();
105 drive::DriveServiceInterface
* drive_service();
106 drive::DriveUploaderInterface
* drive_uploader();
107 MetadataDatabase
* metadata_database();
109 SyncEngineContext
* sync_context_
; // Not owned.
111 FileChange local_change_
;
112 bool local_is_missing_
;
113 base::FilePath local_path_
;
114 storage::FileSystemURL url_
;
115 SyncFileType file_type_
;
116 SyncAction sync_action_
;
118 scoped_ptr
<FileTracker
> remote_file_tracker_
;
119 scoped_ptr
<FileTracker
> remote_parent_folder_tracker_
;
120 base::FilePath target_path_
;
121 int64 remote_file_change_id_
;
123 bool retry_on_success_
;
124 bool needs_remote_change_listing_
;
126 scoped_ptr
<FolderCreator
> folder_creator_
;
128 base::WeakPtrFactory
<LocalToRemoteSyncer
> weak_ptr_factory_
;
130 DISALLOW_COPY_AND_ASSIGN(LocalToRemoteSyncer
);
133 } // namespace drive_backend
134 } // namespace sync_file_system
136 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_LOCAL_TO_REMOTE_SYNCER_H_