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/weak_ptr.h"
12 #include "chrome/browser/sync_file_system/drive_backend/sync_task.h"
13 #include "chrome/browser/sync_file_system/file_change.h"
14 #include "chrome/browser/sync_file_system/sync_action.h"
15 #include "chrome/browser/sync_file_system/sync_file_metadata.h"
16 #include "google_apis/drive/drive_api_error_codes.h"
19 class DriveServiceInterface
;
20 class DriveUploaderInterface
;
23 namespace google_apis
{
27 namespace sync_file_system
{
29 class RemoteChangeProcessor
;
31 namespace drive_backend
{
36 class MetadataDatabase
;
37 class SyncEngineContext
;
39 class LocalToRemoteSyncer
: public SyncTask
{
41 typedef base::Callback
<void(scoped_ptr
<SyncTaskToken
>)> Continuation
;
43 LocalToRemoteSyncer(SyncEngineContext
* sync_context
,
44 const SyncFileMetadata
& local_metadata
,
45 const FileChange
& local_change
,
46 const base::FilePath
& local_path
,
47 const storage::FileSystemURL
& url
);
48 ~LocalToRemoteSyncer() override
;
49 void RunPreflight(scoped_ptr
<SyncTaskToken
> token
) override
;
51 const storage::FileSystemURL
& url() const { return url_
; }
52 const base::FilePath
& target_path() const { return target_path_
; }
53 SyncFileType
file_type() const { return file_type_
; }
54 SyncAction
sync_action() const { return sync_action_
; }
55 bool needs_remote_change_listing() const {
56 return needs_remote_change_listing_
;
60 void MoveToBackground(const Continuation
& continuation
,
61 scoped_ptr
<SyncTaskToken
> token
);
62 void ContinueAsBackgroundTask(const Continuation
& continuation
,
63 scoped_ptr
<SyncTaskToken
> token
);
64 void SyncCompleted(scoped_ptr
<SyncTaskToken
> token
,
65 SyncStatusCode status
);
67 void HandleConflict(scoped_ptr
<SyncTaskToken
> token
);
68 void HandleExistingRemoteFile(scoped_ptr
<SyncTaskToken
> token
);
70 void UpdateTrackerForReusedFolder(const FileDetails
& details
,
71 scoped_ptr
<SyncTaskToken
> token
);
73 void DeleteRemoteFile(scoped_ptr
<SyncTaskToken
> token
);
74 void DidDeleteRemoteFile(scoped_ptr
<SyncTaskToken
> token
,
75 google_apis::DriveApiErrorCode error
);
77 void UploadExistingFile(scoped_ptr
<SyncTaskToken
> token
);
78 void DidUploadExistingFile(scoped_ptr
<SyncTaskToken
> token
,
79 google_apis::DriveApiErrorCode error
,
81 scoped_ptr
<google_apis::FileResource
>);
82 void UpdateRemoteMetadata(const std::string
& file_id
,
83 scoped_ptr
<SyncTaskToken
> token
);
84 void DidGetRemoteMetadata(const std::string
& file_id
,
85 scoped_ptr
<SyncTaskToken
> token
,
86 google_apis::DriveApiErrorCode error
,
87 scoped_ptr
<google_apis::FileResource
> entry
);
89 void UploadNewFile(scoped_ptr
<SyncTaskToken
> token
);
90 void DidUploadNewFile(scoped_ptr
<SyncTaskToken
> token
,
91 google_apis::DriveApiErrorCode error
,
92 const GURL
& upload_location
,
93 scoped_ptr
<google_apis::FileResource
> entry
);
95 void CreateRemoteFolder(scoped_ptr
<SyncTaskToken
> token
);
96 void DidCreateRemoteFolder(scoped_ptr
<SyncTaskToken
> token
,
97 const std::string
& file_id
,
98 SyncStatusCode status
);
99 void DidDetachResourceForCreationConflict(
100 scoped_ptr
<SyncTaskToken
> token
,
101 google_apis::DriveApiErrorCode error
);
103 bool IsContextReady();
104 drive::DriveServiceInterface
* drive_service();
105 drive::DriveUploaderInterface
* drive_uploader();
106 MetadataDatabase
* metadata_database();
108 SyncEngineContext
* sync_context_
; // Not owned.
110 FileChange local_change_
;
111 bool local_is_missing_
;
112 base::FilePath local_path_
;
113 storage::FileSystemURL url_
;
114 SyncFileType file_type_
;
115 SyncAction sync_action_
;
117 scoped_ptr
<FileTracker
> remote_file_tracker_
;
118 scoped_ptr
<FileTracker
> remote_parent_folder_tracker_
;
119 base::FilePath target_path_
;
120 int64 remote_file_change_id_
;
122 bool retry_on_success_
;
123 bool needs_remote_change_listing_
;
125 scoped_ptr
<FolderCreator
> folder_creator_
;
127 base::WeakPtrFactory
<LocalToRemoteSyncer
> weak_ptr_factory_
;
129 DISALLOW_COPY_AND_ASSIGN(LocalToRemoteSyncer
);
132 } // namespace drive_backend
133 } // namespace sync_file_system
135 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_LOCAL_TO_REMOTE_SYNCER_H_