Chromium Code Reviews| Index: chrome/browser/sync_file_system/sync_file_system_service.cc |
| diff --git a/chrome/browser/sync_file_system/sync_file_system_service.cc b/chrome/browser/sync_file_system/sync_file_system_service.cc |
| index 4774edfd17356c0671bac3a9545616a7a76f8d55..6205e14f1025d429ed07564d78b81c3e3cde16d1 100644 |
| --- a/chrome/browser/sync_file_system/sync_file_system_service.cc |
| +++ b/chrome/browser/sync_file_system/sync_file_system_service.cc |
| @@ -58,8 +58,7 @@ void DidHandleOriginForExtensionEvent( |
| const GURL& origin, |
| SyncStatusCode code) { |
| if (code != SYNC_STATUS_OK) { |
| - DCHECK(chrome::NOTIFICATION_EXTENSION_UNLOADED == type || |
| - chrome::NOTIFICATION_EXTENSION_LOADED == type); |
| + DCHECK(chrome::NOTIFICATION_EXTENSION_UNLOADED == type); |
|
kinuko
2013/03/18 18:09:43
type == UNLOADED || type == ENABLED?
nhiroki
2013/03/19 02:35:42
Done.
|
| const char* event = |
| (chrome::NOTIFICATION_EXTENSION_UNLOADED == type) ? "UNLOAD" : "LOAD"; |
|
kinuko
2013/03/18 18:09:43
"LOAD" -> "ENABLE" ?
nhiroki
2013/03/19 02:35:42
Done.
|
| LOG(WARNING) << "Register/Unregistering origin for " << event << " failed:" |
| @@ -194,7 +193,7 @@ void SyncFileSystemService::Initialize( |
| registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| content::Source<Profile>(profile_)); |
| - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| + registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_ENABLED, |
| content::Source<Profile>(profile_)); |
| } |
| @@ -398,29 +397,67 @@ void SyncFileSystemService::Observe( |
| int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| - if (chrome::NOTIFICATION_EXTENSION_UNLOADED == type) { |
| - // Unregister origin for remote synchronization. |
| - std::string extension_id = |
| - content::Details<const extensions::UnloadedExtensionInfo>( |
| - details)->extension->id(); |
| - GURL app_origin = extensions::Extension::GetBaseURLFromExtensionId( |
| - extension_id); |
| - remote_file_service_->UnregisterOriginForTrackingChanges( |
| - app_origin, base::Bind(&DidHandleOriginForExtensionEvent, |
| - type, app_origin)); |
| - local_file_service_->SetOriginEnabled(app_origin, false); |
| - } else if (chrome::NOTIFICATION_EXTENSION_LOADED == type) { |
| - std::string extension_id = |
| - content::Details<const extensions::Extension>( |
| - details)->id(); |
| - GURL app_origin = extensions::Extension::GetBaseURLFromExtensionId( |
| - extension_id); |
| - local_file_service_->SetOriginEnabled(app_origin, true); |
| - } else { |
| - NOTREACHED() << "Unknown notification."; |
| + switch (type) { |
| + // Delivered when an app is disabled, reloaded or restarted. |
| + case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
| + HandleExtensionUnloaded(type, details); |
| + break; |
| + // Delivered when an app is enabled, reloaded or restarted. |
| + case chrome::NOTIFICATION_EXTENSION_ENABLED: |
| + HandleExtensionEnabled(type, details); |
| + break; |
| + default: |
| + NOTREACHED() << "Unknown notification."; |
| + break; |
| } |
| } |
| +void SyncFileSystemService::HandleExtensionUnloaded( |
| + int type, |
| + const content::NotificationDetails& details) { |
| + content::Details<const extensions::UnloadedExtensionInfo> info = |
| + content::Details<const extensions::UnloadedExtensionInfo>(details); |
| + std::string extension_id = info->extension->id(); |
| + GURL app_origin = |
| + extensions::Extension::GetBaseURLFromExtensionId(extension_id); |
| + |
| + switch (info->reason) { |
| + case extension_misc::UNLOAD_REASON_DISABLE: |
| + DVLOG(1) << "Handle extension notification for UNLOAD(DISABLE): " |
| + << app_origin; |
| + remote_file_service_->DisableOriginForTrackingChanges( |
| + app_origin, |
| + base::Bind(&DidHandleOriginForExtensionEvent, type, app_origin)); |
| + local_file_service_->SetOriginEnabled(app_origin, false); |
| + break; |
| + case extension_misc::UNLOAD_REASON_UNINSTALL: |
| + DVLOG(1) << "Handle extension notification for UNLOAD(UNINSTALL): " |
| + << app_origin; |
| + remote_file_service_->UnregisterOriginForTrackingChanges( |
| + app_origin, |
| + base::Bind(&DidHandleOriginForExtensionEvent, type, app_origin)); |
| + local_file_service_->SetOriginEnabled(app_origin, false); |
| + break; |
| + default: |
| + // Nothing to do. |
| + break; |
| + } |
| +} |
| + |
| +void SyncFileSystemService::HandleExtensionEnabled( |
| + int type, |
| + const content::NotificationDetails& details) { |
| + std::string extension_id = |
| + content::Details<const extensions::Extension>(details)->id(); |
| + GURL app_origin = |
| + extensions::Extension::GetBaseURLFromExtensionId(extension_id); |
| + DVLOG(1) << "Handle extension notification for ENABLED: " << app_origin; |
| + remote_file_service_->EnableOriginForTrackingChanges( |
| + app_origin, |
| + base::Bind(&DidHandleOriginForExtensionEvent, type, app_origin)); |
| + local_file_service_->SetOriginEnabled(app_origin, true); |
| +} |
| + |
| void SyncFileSystemService::OnStateChanged() { |
| ProfileSyncServiceBase* profile_sync_service = |
| ProfileSyncServiceFactory::GetForProfile(profile_); |