| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/drive/drive_notification_manager.h" | 5 #include "components/drive/drive_notification_manager.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "components/drive/drive_notification_observer.h" | 8 #include "components/drive/drive_notification_observer.h" |
| 9 #include "components/invalidation/public/invalidation_service.h" | 9 #include "components/invalidation/public/invalidation_service.h" |
| 10 #include "components/invalidation/public/object_id_invalidation_map.h" | 10 #include "components/invalidation/public/object_id_invalidation_map.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 | 55 |
| 56 void DriveNotificationManager::OnInvalidatorStateChange( | 56 void DriveNotificationManager::OnInvalidatorStateChange( |
| 57 syncer::InvalidatorState state) { | 57 syncer::InvalidatorState state) { |
| 58 push_notification_enabled_ = (state == syncer::INVALIDATIONS_ENABLED); | 58 push_notification_enabled_ = (state == syncer::INVALIDATIONS_ENABLED); |
| 59 if (push_notification_enabled_) { | 59 if (push_notification_enabled_) { |
| 60 DVLOG(1) << "XMPP Notifications enabled"; | 60 DVLOG(1) << "XMPP Notifications enabled"; |
| 61 } else { | 61 } else { |
| 62 DVLOG(1) << "XMPP Notifications disabled (state=" << state << ")"; | 62 DVLOG(1) << "XMPP Notifications disabled (state=" << state << ")"; |
| 63 } | 63 } |
| 64 FOR_EACH_OBSERVER(DriveNotificationObserver, observers_, | 64 for (auto& observer : observers_) |
| 65 OnPushNotificationEnabled(push_notification_enabled_)); | 65 observer.OnPushNotificationEnabled(push_notification_enabled_); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void DriveNotificationManager::OnIncomingInvalidation( | 68 void DriveNotificationManager::OnIncomingInvalidation( |
| 69 const syncer::ObjectIdInvalidationMap& invalidation_map) { | 69 const syncer::ObjectIdInvalidationMap& invalidation_map) { |
| 70 DVLOG(2) << "XMPP Drive Notification Received"; | 70 DVLOG(2) << "XMPP Drive Notification Received"; |
| 71 syncer::ObjectIdSet ids = invalidation_map.GetObjectIds(); | 71 syncer::ObjectIdSet ids = invalidation_map.GetObjectIds(); |
| 72 DCHECK_EQ(1U, ids.size()); | 72 DCHECK_EQ(1U, ids.size()); |
| 73 const invalidation::ObjectId object_id( | 73 const invalidation::ObjectId object_id( |
| 74 ipc::invalidation::ObjectSource::COSMO_CHANGELOG, | 74 ipc::invalidation::ObjectSource::COSMO_CHANGELOG, |
| 75 kDriveInvalidationObjectId); | 75 kDriveInvalidationObjectId); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 103 FROM_HERE, | 103 FROM_HERE, |
| 104 base::TimeDelta::FromSeconds(interval_secs), | 104 base::TimeDelta::FromSeconds(interval_secs), |
| 105 base::Bind(&DriveNotificationManager::NotifyObserversToUpdate, | 105 base::Bind(&DriveNotificationManager::NotifyObserversToUpdate, |
| 106 weak_ptr_factory_.GetWeakPtr(), | 106 weak_ptr_factory_.GetWeakPtr(), |
| 107 NOTIFICATION_POLLING)); | 107 NOTIFICATION_POLLING)); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void DriveNotificationManager::NotifyObserversToUpdate( | 110 void DriveNotificationManager::NotifyObserversToUpdate( |
| 111 NotificationSource source) { | 111 NotificationSource source) { |
| 112 DVLOG(1) << "Notifying observers: " << NotificationSourceToString(source); | 112 DVLOG(1) << "Notifying observers: " << NotificationSourceToString(source); |
| 113 FOR_EACH_OBSERVER(DriveNotificationObserver, observers_, | 113 for (auto& observer : observers_) |
| 114 OnNotificationReceived()); | 114 observer.OnNotificationReceived(); |
| 115 if (!observers_notified_) { | 115 if (!observers_notified_) { |
| 116 UMA_HISTOGRAM_BOOLEAN("Drive.PushNotificationInitiallyEnabled", | 116 UMA_HISTOGRAM_BOOLEAN("Drive.PushNotificationInitiallyEnabled", |
| 117 push_notification_enabled_); | 117 push_notification_enabled_); |
| 118 } | 118 } |
| 119 observers_notified_ = true; | 119 observers_notified_ = true; |
| 120 | 120 |
| 121 // Note that polling_timer_ is not a repeating timer. Restarting manually | 121 // Note that polling_timer_ is not a repeating timer. Restarting manually |
| 122 // here is better as XMPP may be received right before the polling timer is | 122 // here is better as XMPP may be received right before the polling timer is |
| 123 // fired (i.e. we don't notify observers twice in a row). | 123 // fired (i.e. we don't notify observers twice in a row). |
| 124 RestartPollingTimer(); | 124 RestartPollingTimer(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 151 return "NOTIFICATION_XMPP"; | 151 return "NOTIFICATION_XMPP"; |
| 152 case NOTIFICATION_POLLING: | 152 case NOTIFICATION_POLLING: |
| 153 return "NOTIFICATION_POLLING"; | 153 return "NOTIFICATION_POLLING"; |
| 154 } | 154 } |
| 155 | 155 |
| 156 NOTREACHED(); | 156 NOTREACHED(); |
| 157 return ""; | 157 return ""; |
| 158 } | 158 } |
| 159 | 159 |
| 160 } // namespace drive | 160 } // namespace drive |
| OLD | NEW |