| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/sync_file_system/drive_backend/sync_worker.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/sync_worker.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 (*status)[app_id] = SyncWorker::APP_STATUS_DISABLED; | 78 (*status)[app_id] = SyncWorker::APP_STATUS_DISABLED; |
| 79 else | 79 else |
| 80 (*status)[app_id] = SyncWorker::APP_STATUS_ENABLED; | 80 (*status)[app_id] = SyncWorker::APP_STATUS_ENABLED; |
| 81 } | 81 } |
| 82 | 82 |
| 83 callback.Run(); | 83 callback.Run(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 } // namespace | 86 } // namespace |
| 87 | 87 |
| 88 // static |
| 88 scoped_ptr<SyncWorker> SyncWorker::CreateOnWorker( | 89 scoped_ptr<SyncWorker> SyncWorker::CreateOnWorker( |
| 89 const base::FilePath& base_dir, | 90 const base::FilePath& base_dir, |
| 90 Observer* observer, | 91 Observer* observer, |
| 91 const base::WeakPtr<ExtensionServiceInterface>& extension_service, | 92 const base::WeakPtr<ExtensionServiceInterface>& extension_service, |
| 92 scoped_ptr<SyncEngineContext> sync_engine_context, | 93 scoped_ptr<SyncEngineContext> sync_engine_context, |
| 93 leveldb::Env* env_override) { | 94 leveldb::Env* env_override) { |
| 94 scoped_ptr<SyncWorker> sync_worker( | 95 scoped_ptr<SyncWorker> sync_worker( |
| 95 new SyncWorker(base_dir, | 96 new SyncWorker(base_dir, |
| 96 extension_service, | 97 extension_service, |
| 97 sync_engine_context.Pass(), | 98 sync_engine_context.Pass(), |
| 98 env_override)); | 99 env_override)); |
| 99 sync_worker->AddObserver(observer); | 100 sync_worker->AddObserver(observer); |
| 100 sync_worker->Initialize(); | |
| 101 | 101 |
| 102 return sync_worker.Pass(); | 102 return sync_worker.Pass(); |
| 103 } | 103 } |
| 104 | 104 |
| 105 SyncWorker::~SyncWorker() {} | 105 SyncWorker::~SyncWorker() {} |
| 106 | 106 |
| 107 void SyncWorker::Initialize() { | 107 void SyncWorker::Initialize() { |
| 108 DCHECK(!task_manager_); | 108 DCHECK(!task_manager_); |
| 109 | 109 |
| 110 task_manager_.reset(new SyncTaskManager( | 110 task_manager_.reset(new SyncTaskManager( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 126 PostInitializeTask(); | 126 PostInitializeTask(); |
| 127 | 127 |
| 128 scoped_ptr<RegisterAppTask> task( | 128 scoped_ptr<RegisterAppTask> task( |
| 129 new RegisterAppTask(context_.get(), origin.host())); | 129 new RegisterAppTask(context_.get(), origin.host())); |
| 130 if (task->CanFinishImmediately()) { | 130 if (task->CanFinishImmediately()) { |
| 131 context_->GetUITaskRunner()->PostTask( | 131 context_->GetUITaskRunner()->PostTask( |
| 132 FROM_HERE, base::Bind(callback, SYNC_STATUS_OK)); | 132 FROM_HERE, base::Bind(callback, SYNC_STATUS_OK)); |
| 133 return; | 133 return; |
| 134 } | 134 } |
| 135 | 135 |
| 136 // TODO(peria): Forward |callback| to UI thread. | |
| 137 task_manager_->ScheduleSyncTask( | 136 task_manager_->ScheduleSyncTask( |
| 138 FROM_HERE, | 137 FROM_HERE, |
| 139 task.PassAs<SyncTask>(), | 138 task.PassAs<SyncTask>(), |
| 140 SyncTaskManager::PRIORITY_HIGH, | 139 SyncTaskManager::PRIORITY_HIGH, |
| 141 callback); | 140 callback); |
| 142 } | 141 } |
| 143 | 142 |
| 144 void SyncWorker::EnableOrigin( | 143 void SyncWorker::EnableOrigin( |
| 145 const GURL& origin, | 144 const GURL& origin, |
| 146 const SyncStatusCallback& callback) { | 145 const SyncStatusCallback& callback) { |
| 147 // TODO(peria): Forward |callback| to UI thread. | |
| 148 task_manager_->ScheduleTask( | 146 task_manager_->ScheduleTask( |
| 149 FROM_HERE, | 147 FROM_HERE, |
| 150 base::Bind(&SyncWorker::DoEnableApp, | 148 base::Bind(&SyncWorker::DoEnableApp, |
| 151 weak_ptr_factory_.GetWeakPtr(), | 149 weak_ptr_factory_.GetWeakPtr(), |
| 152 origin.host()), | 150 origin.host()), |
| 153 SyncTaskManager::PRIORITY_HIGH, | 151 SyncTaskManager::PRIORITY_HIGH, |
| 154 callback); | 152 callback); |
| 155 } | 153 } |
| 156 | 154 |
| 157 void SyncWorker::DisableOrigin( | 155 void SyncWorker::DisableOrigin( |
| 158 const GURL& origin, | 156 const GURL& origin, |
| 159 const SyncStatusCallback& callback) { | 157 const SyncStatusCallback& callback) { |
| 160 // TODO(peria): Forward |callback| to UI thread. | |
| 161 task_manager_->ScheduleTask( | 158 task_manager_->ScheduleTask( |
| 162 FROM_HERE, | 159 FROM_HERE, |
| 163 base::Bind(&SyncWorker::DoDisableApp, | 160 base::Bind(&SyncWorker::DoDisableApp, |
| 164 weak_ptr_factory_.GetWeakPtr(), | 161 weak_ptr_factory_.GetWeakPtr(), |
| 165 origin.host()), | 162 origin.host()), |
| 166 SyncTaskManager::PRIORITY_HIGH, | 163 SyncTaskManager::PRIORITY_HIGH, |
| 167 callback); | 164 callback); |
| 168 } | 165 } |
| 169 | 166 |
| 170 void SyncWorker::UninstallOrigin( | 167 void SyncWorker::UninstallOrigin( |
| 171 const GURL& origin, | 168 const GURL& origin, |
| 172 RemoteFileSyncService::UninstallFlag flag, | 169 RemoteFileSyncService::UninstallFlag flag, |
| 173 const SyncStatusCallback& callback) { | 170 const SyncStatusCallback& callback) { |
| 174 // TODO(peria): Forward |callback| to UI thread. | |
| 175 task_manager_->ScheduleSyncTask( | 171 task_manager_->ScheduleSyncTask( |
| 176 FROM_HERE, | 172 FROM_HERE, |
| 177 scoped_ptr<SyncTask>( | 173 scoped_ptr<SyncTask>( |
| 178 new UninstallAppTask(context_.get(), origin.host(), flag)), | 174 new UninstallAppTask(context_.get(), origin.host(), flag)), |
| 179 SyncTaskManager::PRIORITY_HIGH, | 175 SyncTaskManager::PRIORITY_HIGH, |
| 180 callback); | 176 callback); |
| 181 } | 177 } |
| 182 | 178 |
| 183 void SyncWorker::ProcessRemoteChange( | 179 void SyncWorker::ProcessRemoteChange( |
| 184 const SyncFileCallback& callback) { | 180 const SyncFileCallback& callback) { |
| 185 RemoteToLocalSyncer* syncer = new RemoteToLocalSyncer(context_.get()); | 181 RemoteToLocalSyncer* syncer = new RemoteToLocalSyncer(context_.get()); |
| 186 task_manager_->ScheduleSyncTask( | 182 task_manager_->ScheduleSyncTask( |
| 187 FROM_HERE, | 183 FROM_HERE, |
| 188 scoped_ptr<SyncTask>(syncer), | 184 scoped_ptr<SyncTask>(syncer), |
| 189 SyncTaskManager::PRIORITY_MED, | 185 SyncTaskManager::PRIORITY_MED, |
| 190 base::Bind(&SyncWorker::DidProcessRemoteChange, | 186 base::Bind(&SyncWorker::DidProcessRemoteChange, |
| 191 weak_ptr_factory_.GetWeakPtr(), | 187 weak_ptr_factory_.GetWeakPtr(), |
| 192 syncer, callback)); | 188 syncer, |
| 189 callback)); |
| 193 } | 190 } |
| 194 | 191 |
| 195 void SyncWorker::SetRemoteChangeProcessor( | 192 void SyncWorker::SetRemoteChangeProcessor( |
| 196 RemoteChangeProcessorOnWorker* remote_change_processor_on_worker) { | 193 RemoteChangeProcessorOnWorker* remote_change_processor_on_worker) { |
| 197 context_->SetRemoteChangeProcessor(remote_change_processor_on_worker); | 194 context_->SetRemoteChangeProcessor(remote_change_processor_on_worker); |
| 198 } | 195 } |
| 199 | 196 |
| 200 RemoteServiceState SyncWorker::GetCurrentState() const { | 197 RemoteServiceState SyncWorker::GetCurrentState() const { |
| 201 if (!sync_enabled_) | 198 if (!sync_enabled_) |
| 202 return REMOTE_SERVICE_DISABLED; | 199 return REMOTE_SERVICE_DISABLED; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 const fileapi::FileSystemURL& url, | 281 const fileapi::FileSystemURL& url, |
| 285 const SyncStatusCallback& callback) { | 282 const SyncStatusCallback& callback) { |
| 286 LocalToRemoteSyncer* syncer = new LocalToRemoteSyncer( | 283 LocalToRemoteSyncer* syncer = new LocalToRemoteSyncer( |
| 287 context_.get(), local_metadata, local_change, local_path, url); | 284 context_.get(), local_metadata, local_change, local_path, url); |
| 288 task_manager_->ScheduleSyncTask( | 285 task_manager_->ScheduleSyncTask( |
| 289 FROM_HERE, | 286 FROM_HERE, |
| 290 scoped_ptr<SyncTask>(syncer), | 287 scoped_ptr<SyncTask>(syncer), |
| 291 SyncTaskManager::PRIORITY_MED, | 288 SyncTaskManager::PRIORITY_MED, |
| 292 base::Bind(&SyncWorker::DidApplyLocalChange, | 289 base::Bind(&SyncWorker::DidApplyLocalChange, |
| 293 weak_ptr_factory_.GetWeakPtr(), | 290 weak_ptr_factory_.GetWeakPtr(), |
| 294 syncer, callback)); | 291 syncer, |
| 292 callback)); |
| 295 } | 293 } |
| 296 | 294 |
| 297 void SyncWorker::MaybeScheduleNextTask() { | 295 void SyncWorker::MaybeScheduleNextTask() { |
| 298 if (GetCurrentState() == REMOTE_SERVICE_DISABLED) | 296 if (GetCurrentState() == REMOTE_SERVICE_DISABLED) |
| 299 return; | 297 return; |
| 300 | 298 |
| 301 // TODO(tzik): Notify observer of OnRemoteChangeQueueUpdated. | 299 // TODO(tzik): Notify observer of OnRemoteChangeQueueUpdated. |
| 302 // TODO(tzik): Add an interface to get the number of dirty trackers to | 300 // TODO(tzik): Add an interface to get the number of dirty trackers to |
| 303 // MetadataDatabase. | 301 // MetadataDatabase. |
| 304 | 302 |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 "Service state changed: %d->%d: %s", | 703 "Service state changed: %d->%d: %s", |
| 706 old_state, GetCurrentState(), description.c_str()); | 704 old_state, GetCurrentState(), description.c_str()); |
| 707 | 705 |
| 708 FOR_EACH_OBSERVER( | 706 FOR_EACH_OBSERVER( |
| 709 Observer, observers_, | 707 Observer, observers_, |
| 710 UpdateServiceState(GetCurrentState(), description)); | 708 UpdateServiceState(GetCurrentState(), description)); |
| 711 } | 709 } |
| 712 | 710 |
| 713 } // namespace drive_backend | 711 } // namespace drive_backend |
| 714 } // namespace sync_file_system | 712 } // namespace sync_file_system |
| OLD | NEW |