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