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_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_vector.h"
10 #include "base/memory/weak_ptr.h"
11 #include "chrome/browser/sync_file_system/file_change.h"
12 #include "chrome/browser/sync_file_system/sync_action.h"
13 #include "chrome/browser/sync_file_system/sync_callbacks.h"
14 #include "chrome/browser/sync_file_system/sync_file_metadata.h"
15 #include "chrome/browser/sync_file_system/sync_task.h"
16 #include "google_apis/drive/gdata_errorcode.h"
19 class DriveServiceInterface
;
20 class DriveUploaderInterface
;
23 namespace google_apis
{
28 namespace sync_file_system
{
30 class RemoteChangeProcessor
;
32 namespace drive_backend
{
36 class MetadataDatabase
;
37 class SyncEngineContext
;
39 class LocalToRemoteSyncer
: public SyncTask
{
41 LocalToRemoteSyncer(SyncEngineContext
* sync_context
,
42 const SyncFileMetadata
& local_metadata
,
43 const FileChange
& local_change
,
44 const base::FilePath
& local_path
,
45 const fileapi::FileSystemURL
& url
);
46 virtual ~LocalToRemoteSyncer();
47 virtual void Run(const SyncStatusCallback
& callback
) OVERRIDE
;
49 const fileapi::FileSystemURL
& url() const { return url_
; }
50 const base::FilePath
& target_path() const { return target_path_
; }
51 SyncAction
sync_action() const { return sync_action_
; }
52 bool needs_remote_change_listing() const {
53 return needs_remote_change_listing_
;
57 void SyncCompleted(const SyncStatusCallback
& callback
,
58 SyncStatusCode status
);
60 void HandleConflict(const SyncStatusCallback
& callback
);
61 void HandleExistingRemoteFile(const SyncStatusCallback
& callback
);
63 void DeleteRemoteFile(const SyncStatusCallback
& callback
);
64 void DidDeleteRemoteFile(const SyncStatusCallback
& callback
,
65 google_apis::GDataErrorCode error
);
67 void UploadExistingFile(const SyncStatusCallback
& callback
);
68 void DidGetMD5ForUpload(const SyncStatusCallback
& callback
,
69 const std::string
& local_file_md5
);
70 void DidUploadExistingFile(const SyncStatusCallback
& callback
,
71 google_apis::GDataErrorCode error
,
73 scoped_ptr
<google_apis::ResourceEntry
>);
74 void DidUpdateDatabaseForUploadExistingFile(
75 const SyncStatusCallback
& callback
,
76 SyncStatusCode status
);
77 void UpdateRemoteMetadata(const std::string
& file_id
,
78 const SyncStatusCallback
& callback
);
79 void DidGetRemoteMetadata(const std::string
& file_id
,
80 const SyncStatusCallback
& callback
,
81 google_apis::GDataErrorCode error
,
82 scoped_ptr
<google_apis::ResourceEntry
> entry
);
84 void DidDeleteForUploadNewFile(const SyncStatusCallback
& callback
,
85 SyncStatusCode status
);
86 void DidDeleteForCreateFolder(const SyncStatusCallback
& callback
,
87 SyncStatusCode status
);
89 void UploadNewFile(const SyncStatusCallback
& callback
);
90 void DidUploadNewFile(const SyncStatusCallback
& callback
,
91 google_apis::GDataErrorCode error
,
92 const GURL
& upload_location
,
93 scoped_ptr
<google_apis::ResourceEntry
> entry
);
95 void CreateRemoteFolder(const SyncStatusCallback
& callback
);
96 void DidCreateRemoteFolder(const SyncStatusCallback
& callback
,
97 const std::string
& file_id
,
98 SyncStatusCode status
);
99 void DidDetachResourceForCreationConflict(const SyncStatusCallback
& callback
,
100 google_apis::GDataErrorCode error
);
102 bool IsContextReady();
103 drive::DriveServiceInterface
* drive_service();
104 drive::DriveUploaderInterface
* drive_uploader();
105 MetadataDatabase
* metadata_database();
107 SyncEngineContext
* sync_context_
; // Not owned.
109 FileChange local_change_
;
110 bool local_is_missing_
;
111 base::FilePath local_path_
;
112 fileapi::FileSystemURL url_
;
113 SyncAction sync_action_
;
115 scoped_ptr
<FileTracker
> remote_file_tracker_
;
116 scoped_ptr
<FileTracker
> remote_parent_folder_tracker_
;
117 base::FilePath target_path_
;
119 bool needs_remote_change_listing_
;
121 scoped_ptr
<FolderCreator
> folder_creator_
;
123 base::WeakPtrFactory
<LocalToRemoteSyncer
> weak_ptr_factory_
;
125 DISALLOW_COPY_AND_ASSIGN(LocalToRemoteSyncer
);
128 } // namespace drive_backend
129 } // namespace sync_file_system
131 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_LOCAL_TO_REMOTE_SYNCER_H_