| 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/extensions/app_notification_manager.h" | 5 #include "chrome/browser/extensions/app_notification_manager.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 // Sync model has a notification that local model does not, add it. | 331 // Sync model has a notification that local model does not, add it. |
| 332 Add(sync_notif.release()); | 332 Add(sync_notif.release()); |
| 333 } | 333 } |
| 334 } | 334 } |
| 335 | 335 |
| 336 // TODO(munjal): crbug.com/10059. Work with Lingesh/Antony to resolve. | 336 // TODO(munjal): crbug.com/10059. Work with Lingesh/Antony to resolve. |
| 337 syncer::SyncChangeList new_changes; | 337 syncer::SyncChangeList new_changes; |
| 338 for (SyncDataMap::const_iterator iter = local_data_map.begin(); | 338 for (SyncDataMap::const_iterator iter = local_data_map.begin(); |
| 339 iter != local_data_map.end(); ++iter) { | 339 iter != local_data_map.end(); ++iter) { |
| 340 new_changes.push_back( | 340 new_changes.push_back( |
| 341 syncer::SyncChange(syncer::SyncChange::ACTION_ADD, iter->second)); | 341 syncer::SyncChange(FROM_HERE, |
| 342 syncer::SyncChange::ACTION_ADD, |
| 343 iter->second)); |
| 342 } | 344 } |
| 343 | 345 |
| 344 syncer::SyncError error; | 346 syncer::SyncError error; |
| 345 if (new_changes.size() > 0) | 347 if (new_changes.size() > 0) |
| 346 error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); | 348 error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); |
| 347 models_associated_ = !error.IsSet(); | 349 models_associated_ = !error.IsSet(); |
| 348 return error; | 350 return error; |
| 349 } | 351 } |
| 350 | 352 |
| 351 void AppNotificationManager::StopSyncing(syncer::ModelType type) { | 353 void AppNotificationManager::StopSyncing(syncer::ModelType type) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 // - Sync is not enabled by user. | 489 // - Sync is not enabled by user. |
| 488 // - Change is generated from within the manager. | 490 // - Change is generated from within the manager. |
| 489 if (notif.is_local() || !models_associated_ || processing_syncer_changes_) | 491 if (notif.is_local() || !models_associated_ || processing_syncer_changes_) |
| 490 return; | 492 return; |
| 491 | 493 |
| 492 // TODO(munjal): crbug.com/10059. Work with Lingesh/Antony to resolve. | 494 // TODO(munjal): crbug.com/10059. Work with Lingesh/Antony to resolve. |
| 493 | 495 |
| 494 syncer::SyncChangeList changes; | 496 syncer::SyncChangeList changes; |
| 495 syncer::SyncData sync_data = CreateSyncDataFromNotification(notif); | 497 syncer::SyncData sync_data = CreateSyncDataFromNotification(notif); |
| 496 changes.push_back( | 498 changes.push_back( |
| 497 syncer::SyncChange(syncer::SyncChange::ACTION_ADD, sync_data)); | 499 syncer::SyncChange(FROM_HERE, |
| 500 syncer::SyncChange::ACTION_ADD, |
| 501 sync_data)); |
| 498 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); | 502 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
| 499 } | 503 } |
| 500 | 504 |
| 501 void AppNotificationManager::SyncRemoveChange(const AppNotification& notif) { | 505 void AppNotificationManager::SyncRemoveChange(const AppNotification& notif) { |
| 502 // Skip if either: | 506 // Skip if either: |
| 503 // - Sync is not enabled by user. | 507 // - Sync is not enabled by user. |
| 504 // - Change is generated from within the manager. | 508 // - Change is generated from within the manager. |
| 505 if (notif.is_local() || !models_associated_) { | 509 if (notif.is_local() || !models_associated_) { |
| 506 return; | 510 return; |
| 507 } | 511 } |
| 508 | 512 |
| 509 syncer::SyncChangeList changes; | 513 syncer::SyncChangeList changes; |
| 510 syncer::SyncData sync_data = CreateSyncDataFromNotification(notif); | 514 syncer::SyncData sync_data = CreateSyncDataFromNotification(notif); |
| 511 changes.push_back( | 515 changes.push_back( |
| 512 syncer::SyncChange(syncer::SyncChange::ACTION_DELETE, sync_data)); | 516 syncer::SyncChange(FROM_HERE, |
| 517 syncer::SyncChange::ACTION_DELETE, |
| 518 sync_data)); |
| 513 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); | 519 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
| 514 } | 520 } |
| 515 | 521 |
| 516 void AppNotificationManager::SyncClearAllChange( | 522 void AppNotificationManager::SyncClearAllChange( |
| 517 const AppNotificationList& list) { | 523 const AppNotificationList& list) { |
| 518 // Skip if either: | 524 // Skip if either: |
| 519 // - Sync is not enabled by user. | 525 // - Sync is not enabled by user. |
| 520 // - Change is generated from within the manager. | 526 // - Change is generated from within the manager. |
| 521 if (!models_associated_ || processing_syncer_changes_) | 527 if (!models_associated_ || processing_syncer_changes_) |
| 522 return; | 528 return; |
| 523 | 529 |
| 524 syncer::SyncChangeList changes; | 530 syncer::SyncChangeList changes; |
| 525 for (AppNotificationList::const_iterator iter = list.begin(); | 531 for (AppNotificationList::const_iterator iter = list.begin(); |
| 526 iter != list.end(); ++iter) { | 532 iter != list.end(); ++iter) { |
| 527 const AppNotification& notif = *iter->get(); | 533 const AppNotification& notif = *iter->get(); |
| 528 // Skip notifications marked as local. | 534 // Skip notifications marked as local. |
| 529 if (notif.is_local()) | 535 if (notif.is_local()) |
| 530 continue; | 536 continue; |
| 531 changes.push_back(syncer::SyncChange( | 537 changes.push_back(syncer::SyncChange( |
| 538 FROM_HERE, |
| 532 syncer::SyncChange::ACTION_DELETE, | 539 syncer::SyncChange::ACTION_DELETE, |
| 533 CreateSyncDataFromNotification(notif))); | 540 CreateSyncDataFromNotification(notif))); |
| 534 } | 541 } |
| 535 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); | 542 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
| 536 } | 543 } |
| 537 | 544 |
| 538 // static | 545 // static |
| 539 syncer::SyncData AppNotificationManager::CreateSyncDataFromNotification( | 546 syncer::SyncData AppNotificationManager::CreateSyncDataFromNotification( |
| 540 const AppNotification& notification) { | 547 const AppNotification& notification) { |
| 541 DCHECK(!notification.is_local()); | 548 DCHECK(!notification.is_local()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 570 AppNotification* notification = new AppNotification( | 577 AppNotification* notification = new AppNotification( |
| 571 false, base::Time::FromInternalValue(specifics.creation_timestamp_ms()), | 578 false, base::Time::FromInternalValue(specifics.creation_timestamp_ms()), |
| 572 specifics.guid(), specifics.app_id(), | 579 specifics.guid(), specifics.app_id(), |
| 573 specifics.title(), specifics.body_text()); | 580 specifics.title(), specifics.body_text()); |
| 574 if (specifics.has_link_text()) | 581 if (specifics.has_link_text()) |
| 575 notification->set_link_text(specifics.link_text()); | 582 notification->set_link_text(specifics.link_text()); |
| 576 if (specifics.has_link_url()) | 583 if (specifics.has_link_url()) |
| 577 notification->set_link_url(GURL(specifics.link_url())); | 584 notification->set_link_url(GURL(specifics.link_url())); |
| 578 return notification; | 585 return notification; |
| 579 } | 586 } |
| OLD | NEW |