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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 return SyncEventObserver::SYNC_SERVICE_TEMPORARY_UNAVAILABLE; | 46 return SyncEventObserver::SYNC_SERVICE_TEMPORARY_UNAVAILABLE; |
47 case REMOTE_SERVICE_AUTHENTICATION_REQUIRED: | 47 case REMOTE_SERVICE_AUTHENTICATION_REQUIRED: |
48 return SyncEventObserver::SYNC_SERVICE_AUTHENTICATION_REQUIRED; | 48 return SyncEventObserver::SYNC_SERVICE_AUTHENTICATION_REQUIRED; |
49 case REMOTE_SERVICE_DISABLED: | 49 case REMOTE_SERVICE_DISABLED: |
50 return SyncEventObserver::SYNC_SERVICE_DISABLED; | 50 return SyncEventObserver::SYNC_SERVICE_DISABLED; |
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 DidHandleOriginForExtensionUnloadedEvent( |
| 57 int type, |
| 58 extension_misc::UnloadedExtensionReason reason, |
| 59 const GURL& origin, |
| 60 SyncStatusCode code) { |
| 61 DCHECK(chrome::NOTIFICATION_EXTENSION_UNLOADED == type); |
| 62 DCHECK(extension_misc::UNLOAD_REASON_DISABLE == reason || |
| 63 extension_misc::UNLOAD_REASON_UNINSTALL == reason); |
| 64 if (code != SYNC_STATUS_OK) { |
| 65 switch (reason) { |
| 66 case extension_misc::UNLOAD_REASON_DISABLE: |
| 67 LOG(WARNING) << "Disabling origin for UNLOAD(DISABLE) failed: " |
| 68 << origin.spec(); |
| 69 break; |
| 70 case extension_misc::UNLOAD_REASON_UNINSTALL: |
| 71 LOG(WARNING) << "Unregistering origin for UNLOAD(UNINSTALL) failed: " |
| 72 << origin.spec(); |
| 73 break; |
| 74 default: |
| 75 break; |
| 76 } |
| 77 } |
| 78 } |
| 79 |
| 80 void DidHandleOriginForExtensionEnabledEvent( |
57 int type, | 81 int type, |
58 const GURL& origin, | 82 const GURL& origin, |
59 SyncStatusCode code) { | 83 SyncStatusCode code) { |
60 if (code != SYNC_STATUS_OK) { | 84 DCHECK(chrome::NOTIFICATION_EXTENSION_ENABLED == type); |
61 DCHECK(chrome::NOTIFICATION_EXTENSION_UNLOADED == type || | 85 if (code != SYNC_STATUS_OK) |
62 chrome::NOTIFICATION_EXTENSION_LOADED == type); | 86 LOG(WARNING) << "Enabling origin for ENABLED failed: " << origin.spec(); |
63 const char* event = | |
64 (chrome::NOTIFICATION_EXTENSION_UNLOADED == type) ? "UNLOAD" : "LOAD"; | |
65 LOG(WARNING) << "Register/Unregistering origin for " << event << " failed:" | |
66 << origin.spec(); | |
67 } | |
68 } | 87 } |
69 | 88 |
70 } // namespace | 89 } // namespace |
71 | 90 |
72 void SyncFileSystemService::Shutdown() { | 91 void SyncFileSystemService::Shutdown() { |
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
74 | 93 |
75 local_file_service_->Shutdown(); | 94 local_file_service_->Shutdown(); |
76 local_file_service_.reset(); | 95 local_file_service_.reset(); |
77 | 96 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 206 |
188 ProfileSyncServiceBase* profile_sync_service = | 207 ProfileSyncServiceBase* profile_sync_service = |
189 ProfileSyncServiceFactory::GetForProfile(profile_); | 208 ProfileSyncServiceFactory::GetForProfile(profile_); |
190 if (profile_sync_service) { | 209 if (profile_sync_service) { |
191 UpdateSyncEnabledStatus(profile_sync_service); | 210 UpdateSyncEnabledStatus(profile_sync_service); |
192 profile_sync_service->AddObserver(this); | 211 profile_sync_service->AddObserver(this); |
193 } | 212 } |
194 | 213 |
195 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 214 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
196 content::Source<Profile>(profile_)); | 215 content::Source<Profile>(profile_)); |
197 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 216 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_ENABLED, |
198 content::Source<Profile>(profile_)); | 217 content::Source<Profile>(profile_)); |
199 } | 218 } |
200 | 219 |
201 void SyncFileSystemService::DidInitializeFileSystem( | 220 void SyncFileSystemService::DidInitializeFileSystem( |
202 const GURL& app_origin, | 221 const GURL& app_origin, |
203 const SyncStatusCallback& callback, | 222 const SyncStatusCallback& callback, |
204 SyncStatusCode status) { | 223 SyncStatusCode status) { |
205 DVLOG(1) << "DidInitializeFileSystem: " | 224 DVLOG(1) << "DidInitializeFileSystem: " |
206 << app_origin.spec() << " " << status; | 225 << app_origin.spec() << " " << status; |
207 | 226 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 SyncEventObserver, observers_, | 410 SyncEventObserver, observers_, |
392 OnSyncStateUpdated(GURL(), | 411 OnSyncStateUpdated(GURL(), |
393 RemoteStateToSyncServiceState(state), | 412 RemoteStateToSyncServiceState(state), |
394 description)); | 413 description)); |
395 } | 414 } |
396 | 415 |
397 void SyncFileSystemService::Observe( | 416 void SyncFileSystemService::Observe( |
398 int type, | 417 int type, |
399 const content::NotificationSource& source, | 418 const content::NotificationSource& source, |
400 const content::NotificationDetails& details) { | 419 const content::NotificationDetails& details) { |
401 if (chrome::NOTIFICATION_EXTENSION_UNLOADED == type) { | 420 switch (type) { |
402 // Unregister origin for remote synchronization. | 421 // Delivered when an app is disabled, reloaded or restarted. |
403 std::string extension_id = | 422 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
404 content::Details<const extensions::UnloadedExtensionInfo>( | 423 HandleExtensionUnloaded(type, details); |
405 details)->extension->id(); | 424 break; |
406 GURL app_origin = extensions::Extension::GetBaseURLFromExtensionId( | 425 // Delivered when an app is enabled, reloaded or restarted. |
407 extension_id); | 426 case chrome::NOTIFICATION_EXTENSION_ENABLED: |
408 remote_file_service_->UnregisterOriginForTrackingChanges( | 427 HandleExtensionEnabled(type, details); |
409 app_origin, base::Bind(&DidHandleOriginForExtensionEvent, | 428 break; |
410 type, app_origin)); | 429 default: |
411 local_file_service_->SetOriginEnabled(app_origin, false); | 430 NOTREACHED() << "Unknown notification."; |
412 } else if (chrome::NOTIFICATION_EXTENSION_LOADED == type) { | 431 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 } | 432 } |
422 } | 433 } |
423 | 434 |
| 435 void SyncFileSystemService::HandleExtensionUnloaded( |
| 436 int type, |
| 437 const content::NotificationDetails& details) { |
| 438 content::Details<const extensions::UnloadedExtensionInfo> info = |
| 439 content::Details<const extensions::UnloadedExtensionInfo>(details); |
| 440 std::string extension_id = info->extension->id(); |
| 441 GURL app_origin = |
| 442 extensions::Extension::GetBaseURLFromExtensionId(extension_id); |
| 443 |
| 444 switch (info->reason) { |
| 445 case extension_misc::UNLOAD_REASON_DISABLE: |
| 446 DVLOG(1) << "Handle extension notification for UNLOAD(DISABLE): " |
| 447 << app_origin; |
| 448 remote_file_service_->DisableOriginForTrackingChanges( |
| 449 app_origin, |
| 450 base::Bind(&DidHandleOriginForExtensionUnloadedEvent, |
| 451 type, info->reason, app_origin)); |
| 452 local_file_service_->SetOriginEnabled(app_origin, false); |
| 453 break; |
| 454 case extension_misc::UNLOAD_REASON_UNINSTALL: |
| 455 DVLOG(1) << "Handle extension notification for UNLOAD(UNINSTALL): " |
| 456 << app_origin; |
| 457 remote_file_service_->UnregisterOriginForTrackingChanges( |
| 458 app_origin, |
| 459 base::Bind(&DidHandleOriginForExtensionUnloadedEvent, |
| 460 type, info->reason, app_origin)); |
| 461 local_file_service_->SetOriginEnabled(app_origin, false); |
| 462 break; |
| 463 default: |
| 464 // Nothing to do. |
| 465 break; |
| 466 } |
| 467 } |
| 468 |
| 469 void SyncFileSystemService::HandleExtensionEnabled( |
| 470 int type, |
| 471 const content::NotificationDetails& details) { |
| 472 std::string extension_id = |
| 473 content::Details<const extensions::Extension>(details)->id(); |
| 474 GURL app_origin = |
| 475 extensions::Extension::GetBaseURLFromExtensionId(extension_id); |
| 476 DVLOG(1) << "Handle extension notification for ENABLED: " << app_origin; |
| 477 remote_file_service_->EnableOriginForTrackingChanges( |
| 478 app_origin, |
| 479 base::Bind(&DidHandleOriginForExtensionEnabledEvent, type, app_origin)); |
| 480 local_file_service_->SetOriginEnabled(app_origin, true); |
| 481 } |
| 482 |
424 void SyncFileSystemService::OnStateChanged() { | 483 void SyncFileSystemService::OnStateChanged() { |
425 ProfileSyncServiceBase* profile_sync_service = | 484 ProfileSyncServiceBase* profile_sync_service = |
426 ProfileSyncServiceFactory::GetForProfile(profile_); | 485 ProfileSyncServiceFactory::GetForProfile(profile_); |
427 if (profile_sync_service) | 486 if (profile_sync_service) |
428 UpdateSyncEnabledStatus(profile_sync_service); | 487 UpdateSyncEnabledStatus(profile_sync_service); |
429 } | 488 } |
430 | 489 |
431 void SyncFileSystemService::OnFileStatusChanged( | 490 void SyncFileSystemService::OnFileStatusChanged( |
432 const FileSystemURL& url, | 491 const FileSystemURL& url, |
433 SyncFileStatus sync_status, | 492 SyncFileStatus sync_status, |
(...skipping 12 matching lines...) Expand all Loading... |
446 syncer::APPS); | 505 syncer::APPS); |
447 remote_file_service_->SetSyncEnabled(sync_enabled_); | 506 remote_file_service_->SetSyncEnabled(sync_enabled_); |
448 if (sync_enabled_) { | 507 if (sync_enabled_) { |
449 base::MessageLoopProxy::current()->PostTask( | 508 base::MessageLoopProxy::current()->PostTask( |
450 FROM_HERE, base::Bind(&SyncFileSystemService::MaybeStartSync, | 509 FROM_HERE, base::Bind(&SyncFileSystemService::MaybeStartSync, |
451 AsWeakPtr())); | 510 AsWeakPtr())); |
452 } | 511 } |
453 } | 512 } |
454 | 513 |
455 } // namespace sync_file_system | 514 } // namespace sync_file_system |
OLD | NEW |