Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_engine.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/sync_engine.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/drive/drive_api_service.h" | 9 #include "chrome/browser/drive/drive_api_service.h" |
| 10 #include "chrome/browser/drive/drive_notification_manager.h" | 10 #include "chrome/browser/drive/drive_notification_manager.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | |
| 11 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants. h" | 12 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants. h" |
| 12 #include "chrome/browser/sync_file_system/drive_backend/list_changes_task.h" | 13 #include "chrome/browser/sync_file_system/drive_backend/list_changes_task.h" |
| 13 #include "chrome/browser/sync_file_system/drive_backend/local_to_remote_syncer.h " | 14 #include "chrome/browser/sync_file_system/drive_backend/local_to_remote_syncer.h " |
| 14 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" | 15 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" |
| 15 #include "chrome/browser/sync_file_system/drive_backend/register_app_task.h" | 16 #include "chrome/browser/sync_file_system/drive_backend/register_app_task.h" |
| 16 #include "chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.h " | 17 #include "chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.h " |
| 17 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_initializer. h" | 18 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_initializer. h" |
| 18 #include "chrome/browser/sync_file_system/drive_backend/uninstall_app_task.h" | 19 #include "chrome/browser/sync_file_system/drive_backend/uninstall_app_task.h" |
| 19 #include "chrome/browser/sync_file_system/logger.h" | 20 #include "chrome/browser/sync_file_system/logger.h" |
| 20 #include "chrome/browser/sync_file_system/sync_task.h" | 21 #include "chrome/browser/sync_file_system/sync_task.h" |
| 22 #include "extensions/common/extension.h" | |
| 21 | 23 |
| 22 namespace sync_file_system { | 24 namespace sync_file_system { |
| 23 namespace drive_backend { | 25 namespace drive_backend { |
| 24 | 26 |
| 27 namespace { | |
| 28 | |
| 29 void EmptyStatusCallback(SyncStatusCode status) {} | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 25 SyncEngine::SyncEngine( | 33 SyncEngine::SyncEngine( |
| 26 const base::FilePath& base_dir, | 34 const base::FilePath& base_dir, |
| 27 base::SequencedTaskRunner* task_runner, | 35 base::SequencedTaskRunner* task_runner, |
| 28 scoped_ptr<drive::DriveServiceInterface> drive_service, | 36 scoped_ptr<drive::DriveServiceInterface> drive_service, |
| 29 drive::DriveNotificationManager* notification_manager, | 37 drive::DriveNotificationManager* notification_manager, |
| 30 ExtensionService* extension_service) | 38 ExtensionServiceInterface* extension_service) |
| 31 : base_dir_(base_dir), | 39 : base_dir_(base_dir), |
| 32 task_runner_(task_runner), | 40 task_runner_(task_runner), |
| 33 drive_service_(drive_service.Pass()), | 41 drive_service_(drive_service.Pass()), |
| 34 notification_manager_(notification_manager), | 42 notification_manager_(notification_manager), |
| 35 extension_service_(extension_service), | 43 extension_service_(extension_service), |
| 36 remote_change_processor_(NULL), | 44 remote_change_processor_(NULL), |
| 37 service_state_(REMOTE_SERVICE_TEMPORARY_UNAVAILABLE), | 45 service_state_(REMOTE_SERVICE_TEMPORARY_UNAVAILABLE), |
| 38 should_check_remote_change_(true), | 46 should_check_remote_change_(true), |
| 39 sync_enabled_(false), | 47 sync_enabled_(false), |
| 40 conflict_resolution_policy_(CONFLICT_RESOLUTION_POLICY_LAST_WRITE_WIN), | 48 conflict_resolution_policy_(CONFLICT_RESOLUTION_POLICY_LAST_WRITE_WIN), |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 } | 289 } |
| 282 | 290 |
| 283 void SyncEngine::DoEnableApp(const std::string& app_id, | 291 void SyncEngine::DoEnableApp(const std::string& app_id, |
| 284 const SyncStatusCallback& callback) { | 292 const SyncStatusCallback& callback) { |
| 285 metadata_database_->EnableApp(app_id, callback); | 293 metadata_database_->EnableApp(app_id, callback); |
| 286 } | 294 } |
| 287 | 295 |
| 288 void SyncEngine::DidInitialize(SyncEngineInitializer* initializer, | 296 void SyncEngine::DidInitialize(SyncEngineInitializer* initializer, |
| 289 SyncStatusCode status) { | 297 SyncStatusCode status) { |
| 290 metadata_database_ = initializer->PassMetadataDatabase(); | 298 metadata_database_ = initializer->PassMetadataDatabase(); |
| 299 UpdateRegisteredApps(); | |
| 291 } | 300 } |
| 292 | 301 |
| 293 void SyncEngine::DidProcessRemoteChange(RemoteToLocalSyncer* syncer, | 302 void SyncEngine::DidProcessRemoteChange(RemoteToLocalSyncer* syncer, |
| 294 const SyncFileCallback& callback, | 303 const SyncFileCallback& callback, |
| 295 SyncStatusCode status) { | 304 SyncStatusCode status) { |
| 296 NOTIMPLEMENTED(); | 305 NOTIMPLEMENTED(); |
| 297 } | 306 } |
| 298 | 307 |
| 299 void SyncEngine::DidApplyLocalChange(LocalToRemoteSyncer* syncer, | 308 void SyncEngine::DidApplyLocalChange(LocalToRemoteSyncer* syncer, |
| 300 const SyncStatusCallback& callback, | 309 const SyncStatusCallback& callback, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 return; | 343 return; |
| 335 | 344 |
| 336 util::Log(logging::LOG_INFO, FROM_HERE, | 345 util::Log(logging::LOG_INFO, FROM_HERE, |
| 337 "Service state changed: %d->%d: %s", | 346 "Service state changed: %d->%d: %s", |
| 338 old_state, GetCurrentState(), description.c_str()); | 347 old_state, GetCurrentState(), description.c_str()); |
| 339 FOR_EACH_OBSERVER( | 348 FOR_EACH_OBSERVER( |
| 340 Observer, service_observers_, | 349 Observer, service_observers_, |
| 341 OnRemoteServiceStateUpdated(GetCurrentState(), description)); | 350 OnRemoteServiceStateUpdated(GetCurrentState(), description)); |
| 342 } | 351 } |
| 343 | 352 |
| 353 void SyncEngine::UpdateRegisteredApps() { | |
| 354 if (!extension_service_) | |
| 355 return; | |
| 356 | |
| 357 std::vector<std::string> app_ids; | |
| 358 metadata_database_->GetRegisteredAppIDs(&app_ids); | |
| 359 | |
| 360 // Update the status of every origin using status from ExtensionService. | |
| 361 for (std::vector<std::string>::const_iterator itr = app_ids.begin(); | |
| 362 itr != app_ids.end(); ++itr) { | |
| 363 const std::string& app_id = *itr; | |
| 364 GURL origin = | |
| 365 extensions::Extension::GetBaseURLFromExtensionId(app_id); | |
| 366 if (!extension_service_->GetInstalledExtension(app_id)) { | |
| 367 // Extension has been uninstalled. | |
| 368 // (At this stage we can't know if it was unpacked extension or not, | |
| 369 // so just purge the remote folder.) | |
| 370 UninstallOrigin(origin, | |
| 371 RemoteFileSyncService::UNINSTALL_AND_PURGE_REMOTE, | |
| 372 base::Bind(&EmptyStatusCallback)); | |
| 373 continue; | |
| 374 } | |
| 375 FileTracker tracker; | |
| 376 if (!metadata_database_->FindAppRootTracker(app_id, &tracker)) { | |
| 377 // App will register itself on first run. | |
| 378 return; | |
|
nhiroki
2013/11/18 09:09:52
Probably we need to do "continue" here.
keishi
2013/11/18 09:15:32
Done.
| |
| 379 } | |
| 380 bool is_app_enabled = extension_service_->IsExtensionEnabled(app_id); | |
| 381 bool is_app_root_tracker_enabled = | |
| 382 tracker.tracker_kind() == TRACKER_KIND_APP_ROOT; | |
| 383 if (is_app_enabled && !is_app_root_tracker_enabled) | |
| 384 EnableOrigin(origin, base::Bind(&EmptyStatusCallback)); | |
| 385 else if (!is_app_enabled && is_app_root_tracker_enabled) | |
| 386 DisableOrigin(origin, base::Bind(&EmptyStatusCallback)); | |
| 387 } | |
| 388 } | |
| 389 | |
| 344 } // namespace drive_backend | 390 } // namespace drive_backend |
| 345 } // namespace sync_file_system | 391 } // namespace sync_file_system |
| OLD | NEW |