Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sync_file_system_service.h" | 5 #include "chrome/browser/sync_file_system/sync_file_system_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 ProfileSyncServiceFactory::GetForProfile(profile_); | 189 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 190 if (profile_sync_service) { | 190 if (profile_sync_service) { |
| 191 UpdateSyncEnabledStatus(profile_sync_service); | 191 UpdateSyncEnabledStatus(profile_sync_service); |
| 192 profile_sync_service->AddObserver(this); | 192 profile_sync_service->AddObserver(this); |
| 193 } | 193 } |
| 194 | 194 |
| 195 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 195 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 196 content::Source<Profile>(profile_)); | 196 content::Source<Profile>(profile_)); |
| 197 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 197 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 198 content::Source<Profile>(profile_)); | 198 content::Source<Profile>(profile_)); |
| 199 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_ENABLED, | |
| 200 content::Source<Profile>(profile_)); | |
| 199 } | 201 } |
| 200 | 202 |
| 201 void SyncFileSystemService::DidInitializeFileSystem( | 203 void SyncFileSystemService::DidInitializeFileSystem( |
| 202 const GURL& app_origin, | 204 const GURL& app_origin, |
| 203 const SyncStatusCallback& callback, | 205 const SyncStatusCallback& callback, |
| 204 SyncStatusCode status) { | 206 SyncStatusCode status) { |
| 205 DVLOG(1) << "DidInitializeFileSystem: " | 207 DVLOG(1) << "DidInitializeFileSystem: " |
| 206 << app_origin.spec() << " " << status; | 208 << app_origin.spec() << " " << status; |
| 207 | 209 |
| 208 if (status != SYNC_STATUS_OK) { | 210 if (status != SYNC_STATUS_OK) { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 SyncEventObserver, observers_, | 393 SyncEventObserver, observers_, |
| 392 OnSyncStateUpdated(GURL(), | 394 OnSyncStateUpdated(GURL(), |
| 393 RemoteStateToSyncServiceState(state), | 395 RemoteStateToSyncServiceState(state), |
| 394 description)); | 396 description)); |
| 395 } | 397 } |
| 396 | 398 |
| 397 void SyncFileSystemService::Observe( | 399 void SyncFileSystemService::Observe( |
| 398 int type, | 400 int type, |
| 399 const content::NotificationSource& source, | 401 const content::NotificationSource& source, |
| 400 const content::NotificationDetails& details) { | 402 const content::NotificationDetails& details) { |
| 401 if (chrome::NOTIFICATION_EXTENSION_UNLOADED == type) { | 403 switch (type) { |
|
kinuko
2013/03/16 23:16:51
Can you add a comment about when each event is del
nhiroki
2013/03/18 09:40:18
Done.
| |
| 402 // Unregister origin for remote synchronization. | 404 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
| 403 std::string extension_id = | 405 HandleExtensionUnloaded(type, details); |
| 404 content::Details<const extensions::UnloadedExtensionInfo>( | 406 break; |
| 405 details)->extension->id(); | 407 case chrome::NOTIFICATION_EXTENSION_LOADED: |
| 406 GURL app_origin = extensions::Extension::GetBaseURLFromExtensionId( | 408 HandleExtensionLoaded(details); |
| 407 extension_id); | 409 break; |
| 408 remote_file_service_->UnregisterOriginForTrackingChanges( | 410 case chrome::NOTIFICATION_EXTENSION_ENABLED: |
| 409 app_origin, base::Bind(&DidHandleOriginForExtensionEvent, | 411 HandleExtensionEnabled(type, details); |
| 410 type, app_origin)); | 412 break; |
| 411 local_file_service_->SetOriginEnabled(app_origin, false); | 413 default: |
| 412 } else if (chrome::NOTIFICATION_EXTENSION_LOADED == type) { | 414 NOTREACHED() << "Unknown notification."; |
| 413 std::string extension_id = | 415 break; |
| 414 content::Details<const extensions::Extension>( | |
| 415 details)->id(); | |
| 416 GURL app_origin = extensions::Extension::GetBaseURLFromExtensionId( | |
| 417 extension_id); | |
| 418 local_file_service_->SetOriginEnabled(app_origin, true); | |
| 419 } else { | |
| 420 NOTREACHED() << "Unknown notification."; | |
| 421 } | 416 } |
| 422 } | 417 } |
| 423 | 418 |
| 419 void SyncFileSystemService::HandleExtensionUnloaded( | |
| 420 int type, | |
| 421 const content::NotificationDetails& details) { | |
| 422 content::Details<const extensions::UnloadedExtensionInfo> info = | |
| 423 content::Details<const extensions::UnloadedExtensionInfo>(details); | |
| 424 std::string extension_id = info->extension->id(); | |
| 425 GURL app_origin = | |
| 426 extensions::Extension::GetBaseURLFromExtensionId(extension_id); | |
| 427 | |
| 428 switch (info->reason) { | |
| 429 case extension_misc::UNLOAD_REASON_DISABLE: | |
| 430 DVLOG(1) << "Handle extension notification for UNLOAD(DISABLE): " | |
| 431 << app_origin; | |
| 432 remote_file_service_->DisableOriginForTrackingChanges( | |
| 433 app_origin, | |
| 434 base::Bind(&DidHandleOriginForExtensionEvent, type, app_origin)); | |
| 435 break; | |
| 436 case extension_misc::UNLOAD_REASON_UNINSTALL: | |
| 437 DVLOG(1) << "Handle extension notification for UNLOAD(UNINSTALL): " | |
| 438 << app_origin; | |
| 439 remote_file_service_->UnregisterOriginForTrackingChanges( | |
| 440 app_origin, | |
| 441 base::Bind(&DidHandleOriginForExtensionEvent, type, app_origin)); | |
| 442 break; | |
| 443 default: | |
| 444 // Nothing to do. | |
| 445 break; | |
| 446 } | |
| 447 | |
| 448 local_file_service_->SetOriginEnabled(app_origin, false); | |
| 449 } | |
| 450 | |
| 451 void SyncFileSystemService::HandleExtensionLoaded( | |
| 452 const content::NotificationDetails& details) { | |
| 453 std::string extension_id = | |
| 454 content::Details<const extensions::Extension>(details)->id(); | |
| 455 GURL app_origin = | |
| 456 extensions::Extension::GetBaseURLFromExtensionId(extension_id); | |
| 457 DVLOG(1) << "Handle extension notification for LOADED: " << app_origin; | |
| 458 local_file_service_->SetOriginEnabled(app_origin, true); | |
| 459 } | |
| 460 | |
| 461 void SyncFileSystemService::HandleExtensionEnabled( | |
| 462 int type, | |
| 463 const content::NotificationDetails& details) { | |
| 464 std::string extension_id = | |
| 465 content::Details<const extensions::Extension>(details)->id(); | |
| 466 GURL app_origin = | |
| 467 extensions::Extension::GetBaseURLFromExtensionId(extension_id); | |
| 468 DVLOG(1) << "Handle extension notification for ENABLED: " << app_origin; | |
| 469 remote_file_service_->EnableOriginForTrackingChanges( | |
| 470 app_origin, | |
| 471 base::Bind(&DidHandleOriginForExtensionEvent, type, app_origin)); | |
|
kinuko
2013/03/16 23:16:51
Looking into the table in https://code.google.com/
nhiroki
2013/03/18 09:40:18
Removed HandleExtensionLoaded and DCHECK from Loca
| |
| 472 } | |
| 473 | |
| 424 void SyncFileSystemService::OnStateChanged() { | 474 void SyncFileSystemService::OnStateChanged() { |
| 425 ProfileSyncServiceBase* profile_sync_service = | 475 ProfileSyncServiceBase* profile_sync_service = |
| 426 ProfileSyncServiceFactory::GetForProfile(profile_); | 476 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 427 if (profile_sync_service) | 477 if (profile_sync_service) |
| 428 UpdateSyncEnabledStatus(profile_sync_service); | 478 UpdateSyncEnabledStatus(profile_sync_service); |
| 429 } | 479 } |
| 430 | 480 |
| 431 void SyncFileSystemService::OnFileStatusChanged( | 481 void SyncFileSystemService::OnFileStatusChanged( |
| 432 const FileSystemURL& url, | 482 const FileSystemURL& url, |
| 433 SyncFileStatus sync_status, | 483 SyncFileStatus sync_status, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 446 syncer::APPS); | 496 syncer::APPS); |
| 447 remote_file_service_->SetSyncEnabled(sync_enabled_); | 497 remote_file_service_->SetSyncEnabled(sync_enabled_); |
| 448 if (sync_enabled_) { | 498 if (sync_enabled_) { |
| 449 base::MessageLoopProxy::current()->PostTask( | 499 base::MessageLoopProxy::current()->PostTask( |
| 450 FROM_HERE, base::Bind(&SyncFileSystemService::MaybeStartSync, | 500 FROM_HERE, base::Bind(&SyncFileSystemService::MaybeStartSync, |
| 451 AsWeakPtr())); | 501 AsWeakPtr())); |
| 452 } | 502 } |
| 453 } | 503 } |
| 454 | 504 |
| 455 } // namespace sync_file_system | 505 } // namespace sync_file_system |
| OLD | NEW |