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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 } | 51 } |
| 52 NOTREACHED(); | 52 NOTREACHED(); |
| 53 return SyncEventObserver::SYNC_SERVICE_DISABLED; | 53 return SyncEventObserver::SYNC_SERVICE_DISABLED; |
| 54 } | 54 } |
| 55 | 55 |
| 56 void DidHandleOriginForExtensionEvent( | 56 void DidHandleOriginForExtensionEvent( |
| 57 int type, | 57 int type, |
| 58 const GURL& origin, | 58 const GURL& origin, |
| 59 SyncStatusCode code) { | 59 SyncStatusCode code) { |
| 60 if (code != SYNC_STATUS_OK) { | 60 if (code != SYNC_STATUS_OK) { |
| 61 DCHECK(chrome::NOTIFICATION_EXTENSION_UNLOADED == type || | 61 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.
| |
| 62 chrome::NOTIFICATION_EXTENSION_LOADED == type); | |
| 63 const char* event = | 62 const char* event = |
| 64 (chrome::NOTIFICATION_EXTENSION_UNLOADED == type) ? "UNLOAD" : "LOAD"; | 63 (chrome::NOTIFICATION_EXTENSION_UNLOADED == type) ? "UNLOAD" : "LOAD"; |
|
kinuko
2013/03/18 18:09:43
"LOAD" -> "ENABLE" ?
nhiroki
2013/03/19 02:35:42
Done.
| |
| 65 LOG(WARNING) << "Register/Unregistering origin for " << event << " failed:" | 64 LOG(WARNING) << "Register/Unregistering origin for " << event << " failed:" |
| 66 << origin.spec(); | 65 << origin.spec(); |
| 67 } | 66 } |
| 68 } | 67 } |
| 69 | 68 |
| 70 } // namespace | 69 } // namespace |
| 71 | 70 |
| 72 void SyncFileSystemService::Shutdown() { | 71 void SyncFileSystemService::Shutdown() { |
| 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 74 | 73 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 | 186 |
| 188 ProfileSyncServiceBase* profile_sync_service = | 187 ProfileSyncServiceBase* profile_sync_service = |
| 189 ProfileSyncServiceFactory::GetForProfile(profile_); | 188 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 190 if (profile_sync_service) { | 189 if (profile_sync_service) { |
| 191 UpdateSyncEnabledStatus(profile_sync_service); | 190 UpdateSyncEnabledStatus(profile_sync_service); |
| 192 profile_sync_service->AddObserver(this); | 191 profile_sync_service->AddObserver(this); |
| 193 } | 192 } |
| 194 | 193 |
| 195 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 194 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 196 content::Source<Profile>(profile_)); | 195 content::Source<Profile>(profile_)); |
| 197 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 196 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_ENABLED, |
| 198 content::Source<Profile>(profile_)); | 197 content::Source<Profile>(profile_)); |
| 199 } | 198 } |
| 200 | 199 |
| 201 void SyncFileSystemService::DidInitializeFileSystem( | 200 void SyncFileSystemService::DidInitializeFileSystem( |
| 202 const GURL& app_origin, | 201 const GURL& app_origin, |
| 203 const SyncStatusCallback& callback, | 202 const SyncStatusCallback& callback, |
| 204 SyncStatusCode status) { | 203 SyncStatusCode status) { |
| 205 DVLOG(1) << "DidInitializeFileSystem: " | 204 DVLOG(1) << "DidInitializeFileSystem: " |
| 206 << app_origin.spec() << " " << status; | 205 << app_origin.spec() << " " << status; |
| 207 | 206 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 SyncEventObserver, observers_, | 390 SyncEventObserver, observers_, |
| 392 OnSyncStateUpdated(GURL(), | 391 OnSyncStateUpdated(GURL(), |
| 393 RemoteStateToSyncServiceState(state), | 392 RemoteStateToSyncServiceState(state), |
| 394 description)); | 393 description)); |
| 395 } | 394 } |
| 396 | 395 |
| 397 void SyncFileSystemService::Observe( | 396 void SyncFileSystemService::Observe( |
| 398 int type, | 397 int type, |
| 399 const content::NotificationSource& source, | 398 const content::NotificationSource& source, |
| 400 const content::NotificationDetails& details) { | 399 const content::NotificationDetails& details) { |
| 401 if (chrome::NOTIFICATION_EXTENSION_UNLOADED == type) { | 400 switch (type) { |
| 402 // Unregister origin for remote synchronization. | 401 // Delivered when an app is disabled, reloaded or restarted. |
| 403 std::string extension_id = | 402 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
| 404 content::Details<const extensions::UnloadedExtensionInfo>( | 403 HandleExtensionUnloaded(type, details); |
| 405 details)->extension->id(); | 404 break; |
| 406 GURL app_origin = extensions::Extension::GetBaseURLFromExtensionId( | 405 // Delivered when an app is enabled, reloaded or restarted. |
| 407 extension_id); | 406 case chrome::NOTIFICATION_EXTENSION_ENABLED: |
| 408 remote_file_service_->UnregisterOriginForTrackingChanges( | 407 HandleExtensionEnabled(type, details); |
| 409 app_origin, base::Bind(&DidHandleOriginForExtensionEvent, | 408 break; |
| 410 type, app_origin)); | 409 default: |
| 411 local_file_service_->SetOriginEnabled(app_origin, false); | 410 NOTREACHED() << "Unknown notification."; |
| 412 } else if (chrome::NOTIFICATION_EXTENSION_LOADED == type) { | 411 break; |
| 413 std::string extension_id = | |
| 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 } | 412 } |
| 422 } | 413 } |
| 423 | 414 |
| 415 void SyncFileSystemService::HandleExtensionUnloaded( | |
| 416 int type, | |
| 417 const content::NotificationDetails& details) { | |
| 418 content::Details<const extensions::UnloadedExtensionInfo> info = | |
| 419 content::Details<const extensions::UnloadedExtensionInfo>(details); | |
| 420 std::string extension_id = info->extension->id(); | |
| 421 GURL app_origin = | |
| 422 extensions::Extension::GetBaseURLFromExtensionId(extension_id); | |
| 423 | |
| 424 switch (info->reason) { | |
| 425 case extension_misc::UNLOAD_REASON_DISABLE: | |
| 426 DVLOG(1) << "Handle extension notification for UNLOAD(DISABLE): " | |
| 427 << app_origin; | |
| 428 remote_file_service_->DisableOriginForTrackingChanges( | |
| 429 app_origin, | |
| 430 base::Bind(&DidHandleOriginForExtensionEvent, type, app_origin)); | |
| 431 local_file_service_->SetOriginEnabled(app_origin, false); | |
| 432 break; | |
| 433 case extension_misc::UNLOAD_REASON_UNINSTALL: | |
| 434 DVLOG(1) << "Handle extension notification for UNLOAD(UNINSTALL): " | |
| 435 << app_origin; | |
| 436 remote_file_service_->UnregisterOriginForTrackingChanges( | |
| 437 app_origin, | |
| 438 base::Bind(&DidHandleOriginForExtensionEvent, type, app_origin)); | |
| 439 local_file_service_->SetOriginEnabled(app_origin, false); | |
| 440 break; | |
| 441 default: | |
| 442 // Nothing to do. | |
| 443 break; | |
| 444 } | |
| 445 } | |
| 446 | |
| 447 void SyncFileSystemService::HandleExtensionEnabled( | |
| 448 int type, | |
| 449 const content::NotificationDetails& details) { | |
| 450 std::string extension_id = | |
| 451 content::Details<const extensions::Extension>(details)->id(); | |
| 452 GURL app_origin = | |
| 453 extensions::Extension::GetBaseURLFromExtensionId(extension_id); | |
| 454 DVLOG(1) << "Handle extension notification for ENABLED: " << app_origin; | |
| 455 remote_file_service_->EnableOriginForTrackingChanges( | |
| 456 app_origin, | |
| 457 base::Bind(&DidHandleOriginForExtensionEvent, type, app_origin)); | |
| 458 local_file_service_->SetOriginEnabled(app_origin, true); | |
| 459 } | |
| 460 | |
| 424 void SyncFileSystemService::OnStateChanged() { | 461 void SyncFileSystemService::OnStateChanged() { |
| 425 ProfileSyncServiceBase* profile_sync_service = | 462 ProfileSyncServiceBase* profile_sync_service = |
| 426 ProfileSyncServiceFactory::GetForProfile(profile_); | 463 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 427 if (profile_sync_service) | 464 if (profile_sync_service) |
| 428 UpdateSyncEnabledStatus(profile_sync_service); | 465 UpdateSyncEnabledStatus(profile_sync_service); |
| 429 } | 466 } |
| 430 | 467 |
| 431 void SyncFileSystemService::OnFileStatusChanged( | 468 void SyncFileSystemService::OnFileStatusChanged( |
| 432 const FileSystemURL& url, | 469 const FileSystemURL& url, |
| 433 SyncFileStatus sync_status, | 470 SyncFileStatus sync_status, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 446 syncer::APPS); | 483 syncer::APPS); |
| 447 remote_file_service_->SetSyncEnabled(sync_enabled_); | 484 remote_file_service_->SetSyncEnabled(sync_enabled_); |
| 448 if (sync_enabled_) { | 485 if (sync_enabled_) { |
| 449 base::MessageLoopProxy::current()->PostTask( | 486 base::MessageLoopProxy::current()->PostTask( |
| 450 FROM_HERE, base::Bind(&SyncFileSystemService::MaybeStartSync, | 487 FROM_HERE, base::Bind(&SyncFileSystemService::MaybeStartSync, |
| 451 AsWeakPtr())); | 488 AsWeakPtr())); |
| 452 } | 489 } |
| 453 } | 490 } |
| 454 | 491 |
| 455 } // namespace sync_file_system | 492 } // namespace sync_file_system |
| OLD | NEW |