| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/message_center/message_center_impl.h" | 5 #include "ui/message_center/message_center_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // Change represents an operation made on a notification. Since it contains | 39 // Change represents an operation made on a notification. Since it contains |
| 40 // the final state of the notification, we only keep the last change for a | 40 // the final state of the notification, we only keep the last change for a |
| 41 // particular notification that is in the notification list around. There are | 41 // particular notification that is in the notification list around. There are |
| 42 // two ids; |id_| is the newest notification id that has been assigned by an | 42 // two ids; |id_| is the newest notification id that has been assigned by an |
| 43 // update, and |notification_list_id_| is the id of the notification it should | 43 // update, and |notification_list_id_| is the id of the notification it should |
| 44 // be updating as it exists in the notification list. | 44 // be updating as it exists in the notification list. |
| 45 class Change { | 45 class Change { |
| 46 public: | 46 public: |
| 47 Change(ChangeType type, | 47 Change(ChangeType type, |
| 48 const std::string& id, | 48 const std::string& id, |
| 49 scoped_ptr<Notification> notification); | 49 std::unique_ptr<Notification> notification); |
| 50 ~Change(); | 50 ~Change(); |
| 51 | 51 |
| 52 // Used to transfer ownership of the contained notification. | 52 // Used to transfer ownership of the contained notification. |
| 53 scoped_ptr<Notification> PassNotification(); | 53 std::unique_ptr<Notification> PassNotification(); |
| 54 | 54 |
| 55 Notification* notification() const { return notification_.get(); } | 55 Notification* notification() const { return notification_.get(); } |
| 56 // Returns the post-update ID. It means: | 56 // Returns the post-update ID. It means: |
| 57 // - ADD event: ID of the notification to be added. | 57 // - ADD event: ID of the notification to be added. |
| 58 // - UPDATE event: ID of the notification after the change. If the change | 58 // - UPDATE event: ID of the notification after the change. If the change |
| 59 // doesn't update its ID, this value is same as |notification_list_id|. | 59 // doesn't update its ID, this value is same as |notification_list_id|. |
| 60 // - DELETE event: ID of the notification to be deleted. | 60 // - DELETE event: ID of the notification to be deleted. |
| 61 const std::string& id() const { return id_; } | 61 const std::string& id() const { return id_; } |
| 62 ChangeType type() const { return type_; } | 62 ChangeType type() const { return type_; } |
| 63 bool by_user() const { return by_user_; } | 63 bool by_user() const { return by_user_; } |
| 64 void set_by_user(bool by_user) { by_user_ = by_user; } | 64 void set_by_user(bool by_user) { by_user_ = by_user; } |
| 65 // Returns the ID which is used in the notification list. In other word, it | 65 // Returns the ID which is used in the notification list. In other word, it |
| 66 // means the ID before the change. | 66 // means the ID before the change. |
| 67 const std::string& notification_list_id() const { | 67 const std::string& notification_list_id() const { |
| 68 return notification_list_id_; | 68 return notification_list_id_; |
| 69 } | 69 } |
| 70 void set_type(const ChangeType new_type) { | 70 void set_type(const ChangeType new_type) { |
| 71 type_ = new_type; | 71 type_ = new_type; |
| 72 } | 72 } |
| 73 void ReplaceNotification(scoped_ptr<Notification> new_notification); | 73 void ReplaceNotification(std::unique_ptr<Notification> new_notification); |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 ChangeType type_; | 76 ChangeType type_; |
| 77 std::string id_; | 77 std::string id_; |
| 78 std::string notification_list_id_; | 78 std::string notification_list_id_; |
| 79 bool by_user_; | 79 bool by_user_; |
| 80 scoped_ptr<Notification> notification_; | 80 std::unique_ptr<Notification> notification_; |
| 81 | 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(Change); | 82 DISALLOW_COPY_AND_ASSIGN(Change); |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 ChangeQueue(); | 85 ChangeQueue(); |
| 86 ~ChangeQueue(); | 86 ~ChangeQueue(); |
| 87 | 87 |
| 88 // Called when the message center has appropriate visibility. Modifies | 88 // Called when the message center has appropriate visibility. Modifies |
| 89 // |message_center| but does not retain it. This also causes the queue to | 89 // |message_center| but does not retain it. This also causes the queue to |
| 90 // empty itself. | 90 // empty itself. |
| 91 void ApplyChanges(MessageCenterImpl* message_center); | 91 void ApplyChanges(MessageCenterImpl* message_center); |
| 92 | 92 |
| 93 // Applies only the changes of the given ID. | 93 // Applies only the changes of the given ID. |
| 94 void ApplyChangesForId(MessageCenterImpl* message_center, | 94 void ApplyChangesForId(MessageCenterImpl* message_center, |
| 95 const std::string& id); | 95 const std::string& id); |
| 96 | 96 |
| 97 // Causes a TYPE_ADD change to be added to the queue. | 97 // Causes a TYPE_ADD change to be added to the queue. |
| 98 void AddNotification(scoped_ptr<Notification> notification); | 98 void AddNotification(std::unique_ptr<Notification> notification); |
| 99 | 99 |
| 100 // Causes a TYPE_UPDATE change to be added to the queue. | 100 // Causes a TYPE_UPDATE change to be added to the queue. |
| 101 void UpdateNotification(const std::string& old_id, | 101 void UpdateNotification(const std::string& old_id, |
| 102 scoped_ptr<Notification> notification); | 102 std::unique_ptr<Notification> notification); |
| 103 | 103 |
| 104 // Causes a TYPE_DELETE change to be added to the queue. | 104 // Causes a TYPE_DELETE change to be added to the queue. |
| 105 void EraseNotification(const std::string& id, bool by_user); | 105 void EraseNotification(const std::string& id, bool by_user); |
| 106 | 106 |
| 107 // Returns whether the queue matches an id. The id given will be matched | 107 // Returns whether the queue matches an id. The id given will be matched |
| 108 // against the ID of all changes post-update, not the id of the notification | 108 // against the ID of all changes post-update, not the id of the notification |
| 109 // as it stands in the notification list. | 109 // as it stands in the notification list. |
| 110 bool Has(const std::string& id) const; | 110 bool Has(const std::string& id) const; |
| 111 | 111 |
| 112 // Returns a Change that can be modified by the caller. ChangeQueue retains | 112 // Returns a Change that can be modified by the caller. ChangeQueue retains |
| 113 // ownership of the Change; pointers should not be retained. | 113 // ownership of the Change; pointers should not be retained. |
| 114 Notification* GetLatestNotification(const std::string& id) const; | 114 Notification* GetLatestNotification(const std::string& id) const; |
| 115 | 115 |
| 116 private: | 116 private: |
| 117 void ApplyChangeInternal(MessageCenterImpl* message_center, | 117 void ApplyChangeInternal(MessageCenterImpl* message_center, |
| 118 scoped_ptr<Change> change); | 118 std::unique_ptr<Change> change); |
| 119 | 119 |
| 120 ScopedVector<Change> changes_; | 120 ScopedVector<Change> changes_; |
| 121 | 121 |
| 122 DISALLOW_COPY_AND_ASSIGN(ChangeQueue); | 122 DISALLOW_COPY_AND_ASSIGN(ChangeQueue); |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 //////////////////////////////////////////////////////////////////////////////// | 125 //////////////////////////////////////////////////////////////////////////////// |
| 126 // ChangeFinder | 126 // ChangeFinder |
| 127 | 127 |
| 128 struct ChangeFinder { | 128 struct ChangeFinder { |
| 129 explicit ChangeFinder(const std::string& id) : id(id) {} | 129 explicit ChangeFinder(const std::string& id) : id(id) {} |
| 130 bool operator()(ChangeQueue::Change* change) { return change->id() == id; } | 130 bool operator()(ChangeQueue::Change* change) { return change->id() == id; } |
| 131 | 131 |
| 132 std::string id; | 132 std::string id; |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 //////////////////////////////////////////////////////////////////////////////// | 135 //////////////////////////////////////////////////////////////////////////////// |
| 136 // ChangeQueue::Change | 136 // ChangeQueue::Change |
| 137 | 137 |
| 138 ChangeQueue::Change::Change(ChangeType type, | 138 ChangeQueue::Change::Change(ChangeType type, |
| 139 const std::string& id, | 139 const std::string& id, |
| 140 scoped_ptr<Notification> notification) | 140 std::unique_ptr<Notification> notification) |
| 141 : type_(type), | 141 : type_(type), |
| 142 notification_list_id_(id), | 142 notification_list_id_(id), |
| 143 by_user_(false), | 143 by_user_(false), |
| 144 notification_(std::move(notification)) { | 144 notification_(std::move(notification)) { |
| 145 DCHECK(!id.empty()); | 145 DCHECK(!id.empty()); |
| 146 DCHECK(type != CHANGE_TYPE_DELETE || notification_.get() == NULL); | 146 DCHECK(type != CHANGE_TYPE_DELETE || notification_.get() == NULL); |
| 147 | 147 |
| 148 id_ = notification_ ? notification_->id() : notification_list_id_; | 148 id_ = notification_ ? notification_->id() : notification_list_id_; |
| 149 } | 149 } |
| 150 | 150 |
| 151 ChangeQueue::Change::~Change() {} | 151 ChangeQueue::Change::~Change() {} |
| 152 | 152 |
| 153 scoped_ptr<Notification> ChangeQueue::Change::PassNotification() { | 153 std::unique_ptr<Notification> ChangeQueue::Change::PassNotification() { |
| 154 return std::move(notification_); | 154 return std::move(notification_); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void ChangeQueue::Change::ReplaceNotification( | 157 void ChangeQueue::Change::ReplaceNotification( |
| 158 scoped_ptr<Notification> new_notification) { | 158 std::unique_ptr<Notification> new_notification) { |
| 159 id_ = new_notification ? new_notification->id() : notification_list_id_; | 159 id_ = new_notification ? new_notification->id() : notification_list_id_; |
| 160 notification_.swap(new_notification); | 160 notification_.swap(new_notification); |
| 161 } | 161 } |
| 162 | 162 |
| 163 //////////////////////////////////////////////////////////////////////////////// | 163 //////////////////////////////////////////////////////////////////////////////// |
| 164 // ChangeQueue | 164 // ChangeQueue |
| 165 | 165 |
| 166 ChangeQueue::ChangeQueue() {} | 166 ChangeQueue::ChangeQueue() {} |
| 167 | 167 |
| 168 ChangeQueue::~ChangeQueue() {} | 168 ChangeQueue::~ChangeQueue() {} |
| 169 | 169 |
| 170 void ChangeQueue::ApplyChanges(MessageCenterImpl* message_center) { | 170 void ChangeQueue::ApplyChanges(MessageCenterImpl* message_center) { |
| 171 // This method is re-entrant. | 171 // This method is re-entrant. |
| 172 while (!changes_.empty()) { | 172 while (!changes_.empty()) { |
| 173 ScopedVector<Change>::iterator iter = changes_.begin(); | 173 ScopedVector<Change>::iterator iter = changes_.begin(); |
| 174 scoped_ptr<Change> change(*iter); | 174 std::unique_ptr<Change> change(*iter); |
| 175 // TODO(dewittj): Replace changes_ with a deque. | 175 // TODO(dewittj): Replace changes_ with a deque. |
| 176 changes_.weak_erase(iter); | 176 changes_.weak_erase(iter); |
| 177 ApplyChangeInternal(message_center, std::move(change)); | 177 ApplyChangeInternal(message_center, std::move(change)); |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 | 180 |
| 181 void ChangeQueue::ApplyChangesForId(MessageCenterImpl* message_center, | 181 void ChangeQueue::ApplyChangesForId(MessageCenterImpl* message_center, |
| 182 const std::string& id) { | 182 const std::string& id) { |
| 183 std::deque<Change*> changes_for_id; | 183 std::deque<Change*> changes_for_id; |
| 184 std::string interesting_id = id; | 184 std::string interesting_id = id; |
| 185 | 185 |
| 186 // Traverses the queue in reverse so shat we can track changes which change | 186 // Traverses the queue in reverse so shat we can track changes which change |
| 187 // the notification's ID. | 187 // the notification's ID. |
| 188 ScopedVector<Change>::iterator iter = changes_.end(); | 188 ScopedVector<Change>::iterator iter = changes_.end(); |
| 189 while (iter != changes_.begin()) { | 189 while (iter != changes_.begin()) { |
| 190 --iter; | 190 --iter; |
| 191 if (interesting_id != (*iter)->id()) | 191 if (interesting_id != (*iter)->id()) |
| 192 continue; | 192 continue; |
| 193 scoped_ptr<Change> change(*iter); | 193 std::unique_ptr<Change> change(*iter); |
| 194 | 194 |
| 195 interesting_id = change->notification_list_id(); | 195 interesting_id = change->notification_list_id(); |
| 196 | 196 |
| 197 iter = changes_.weak_erase(iter); | 197 iter = changes_.weak_erase(iter); |
| 198 changes_for_id.push_back(change.release()); | 198 changes_for_id.push_back(change.release()); |
| 199 } | 199 } |
| 200 | 200 |
| 201 while (!changes_for_id.empty()) { | 201 while (!changes_for_id.empty()) { |
| 202 ApplyChangeInternal( | 202 ApplyChangeInternal(message_center, |
| 203 message_center, scoped_ptr<Change>(changes_for_id.back())); | 203 std::unique_ptr<Change>(changes_for_id.back())); |
| 204 changes_for_id.pop_back(); | 204 changes_for_id.pop_back(); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 void ChangeQueue::AddNotification(scoped_ptr<Notification> notification) { | 208 void ChangeQueue::AddNotification(std::unique_ptr<Notification> notification) { |
| 209 std::string id = notification->id(); | 209 std::string id = notification->id(); |
| 210 changes_.push_back(new Change(CHANGE_TYPE_ADD, id, std::move(notification))); | 210 changes_.push_back(new Change(CHANGE_TYPE_ADD, id, std::move(notification))); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void ChangeQueue::UpdateNotification(const std::string& old_id, | 213 void ChangeQueue::UpdateNotification( |
| 214 scoped_ptr<Notification> notification) { | 214 const std::string& old_id, |
| 215 std::unique_ptr<Notification> notification) { |
| 215 ScopedVector<Change>::reverse_iterator iter = | 216 ScopedVector<Change>::reverse_iterator iter = |
| 216 std::find_if(changes_.rbegin(), changes_.rend(), ChangeFinder(old_id)); | 217 std::find_if(changes_.rbegin(), changes_.rend(), ChangeFinder(old_id)); |
| 217 if (iter == changes_.rend()) { | 218 if (iter == changes_.rend()) { |
| 218 changes_.push_back( | 219 changes_.push_back( |
| 219 new Change(CHANGE_TYPE_UPDATE, old_id, std::move(notification))); | 220 new Change(CHANGE_TYPE_UPDATE, old_id, std::move(notification))); |
| 220 return; | 221 return; |
| 221 } | 222 } |
| 222 | 223 |
| 223 Change* change = *iter; | 224 Change* change = *iter; |
| 224 switch (change->type()) { | 225 switch (change->type()) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 255 break; | 256 break; |
| 256 default: | 257 default: |
| 257 NOTREACHED(); | 258 NOTREACHED(); |
| 258 } | 259 } |
| 259 } | 260 } |
| 260 | 261 |
| 261 void ChangeQueue::EraseNotification(const std::string& id, bool by_user) { | 262 void ChangeQueue::EraseNotification(const std::string& id, bool by_user) { |
| 262 ScopedVector<Change>::reverse_iterator iter = | 263 ScopedVector<Change>::reverse_iterator iter = |
| 263 std::find_if(changes_.rbegin(), changes_.rend(), ChangeFinder(id)); | 264 std::find_if(changes_.rbegin(), changes_.rend(), ChangeFinder(id)); |
| 264 if (iter == changes_.rend()) { | 265 if (iter == changes_.rend()) { |
| 265 scoped_ptr<Change> change(new Change(CHANGE_TYPE_DELETE, id, nullptr)); | 266 std::unique_ptr<Change> change(new Change(CHANGE_TYPE_DELETE, id, nullptr)); |
| 266 change->set_by_user(by_user); | 267 change->set_by_user(by_user); |
| 267 changes_.push_back(std::move(change)); | 268 changes_.push_back(std::move(change)); |
| 268 return; | 269 return; |
| 269 } | 270 } |
| 270 | 271 |
| 271 Change* change = *iter; | 272 Change* change = *iter; |
| 272 switch (change->type()) { | 273 switch (change->type()) { |
| 273 case CHANGE_TYPE_ADD: | 274 case CHANGE_TYPE_ADD: |
| 274 // ADD -> DELETE. Just removes both. | 275 // ADD -> DELETE. Just removes both. |
| 275 changes_.erase(--(iter.base())); | 276 changes_.erase(--(iter.base())); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 299 Notification* ChangeQueue::GetLatestNotification(const std::string& id) const { | 300 Notification* ChangeQueue::GetLatestNotification(const std::string& id) const { |
| 300 ScopedVector<Change>::const_iterator iter = | 301 ScopedVector<Change>::const_iterator iter = |
| 301 std::find_if(changes_.begin(), changes_.end(), ChangeFinder(id)); | 302 std::find_if(changes_.begin(), changes_.end(), ChangeFinder(id)); |
| 302 if (iter == changes_.end()) | 303 if (iter == changes_.end()) |
| 303 return NULL; | 304 return NULL; |
| 304 | 305 |
| 305 return (*iter)->notification(); | 306 return (*iter)->notification(); |
| 306 } | 307 } |
| 307 | 308 |
| 308 void ChangeQueue::ApplyChangeInternal(MessageCenterImpl* message_center, | 309 void ChangeQueue::ApplyChangeInternal(MessageCenterImpl* message_center, |
| 309 scoped_ptr<Change> change) { | 310 std::unique_ptr<Change> change) { |
| 310 switch (change->type()) { | 311 switch (change->type()) { |
| 311 case CHANGE_TYPE_ADD: | 312 case CHANGE_TYPE_ADD: |
| 312 message_center->AddNotificationImmediately(change->PassNotification()); | 313 message_center->AddNotificationImmediately(change->PassNotification()); |
| 313 break; | 314 break; |
| 314 case CHANGE_TYPE_UPDATE: | 315 case CHANGE_TYPE_UPDATE: |
| 315 message_center->UpdateNotificationImmediately( | 316 message_center->UpdateNotificationImmediately( |
| 316 change->notification_list_id(), change->PassNotification()); | 317 change->notification_list_id(), change->PassNotification()); |
| 317 break; | 318 break; |
| 318 case CHANGE_TYPE_DELETE: | 319 case CHANGE_TYPE_DELETE: |
| 319 message_center->RemoveNotificationImmediately( | 320 message_center->RemoveNotificationImmediately( |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 return notification_list_->GetPopupNotifications(blockers_, NULL); | 502 return notification_list_->GetPopupNotifications(blockers_, NULL); |
| 502 } | 503 } |
| 503 | 504 |
| 504 void MessageCenterImpl::ForceNotificationFlush(const std::string& id) { | 505 void MessageCenterImpl::ForceNotificationFlush(const std::string& id) { |
| 505 if (notification_queue_) | 506 if (notification_queue_) |
| 506 notification_queue_->ApplyChangesForId(this, id); | 507 notification_queue_->ApplyChangesForId(this, id); |
| 507 } | 508 } |
| 508 | 509 |
| 509 //------------------------------------------------------------------------------ | 510 //------------------------------------------------------------------------------ |
| 510 // Client code interface. | 511 // Client code interface. |
| 511 void MessageCenterImpl::AddNotification(scoped_ptr<Notification> notification) { | 512 void MessageCenterImpl::AddNotification( |
| 513 std::unique_ptr<Notification> notification) { |
| 512 DCHECK(notification); | 514 DCHECK(notification); |
| 513 const std::string id = notification->id(); | 515 const std::string id = notification->id(); |
| 514 for (size_t i = 0; i < blockers_.size(); ++i) | 516 for (size_t i = 0; i < blockers_.size(); ++i) |
| 515 blockers_[i]->CheckState(); | 517 blockers_[i]->CheckState(); |
| 516 | 518 |
| 517 if (notification_queue_ && | 519 if (notification_queue_ && |
| 518 notification_list_->is_message_center_visible()) { | 520 notification_list_->is_message_center_visible()) { |
| 519 notification_queue_->AddNotification(std::move(notification)); | 521 notification_queue_->AddNotification(std::move(notification)); |
| 520 return; | 522 return; |
| 521 } | 523 } |
| 522 | 524 |
| 523 AddNotificationImmediately(std::move(notification)); | 525 AddNotificationImmediately(std::move(notification)); |
| 524 } | 526 } |
| 525 | 527 |
| 526 void MessageCenterImpl::AddNotificationImmediately( | 528 void MessageCenterImpl::AddNotificationImmediately( |
| 527 scoped_ptr<Notification> notification) { | 529 std::unique_ptr<Notification> notification) { |
| 528 const std::string id = notification->id(); | 530 const std::string id = notification->id(); |
| 529 | 531 |
| 530 // Sometimes the notification can be added with the same id and the | 532 // Sometimes the notification can be added with the same id and the |
| 531 // |notification_list| will replace the notification instead of adding new. | 533 // |notification_list| will replace the notification instead of adding new. |
| 532 // This is essentially an update rather than addition. | 534 // This is essentially an update rather than addition. |
| 533 bool already_exists = (notification_list_->GetNotificationById(id) != NULL); | 535 bool already_exists = (notification_list_->GetNotificationById(id) != NULL); |
| 534 notification_list_->AddNotification(std::move(notification)); | 536 notification_list_->AddNotification(std::move(notification)); |
| 535 notification_cache_.Rebuild( | 537 notification_cache_.Rebuild( |
| 536 notification_list_->GetVisibleNotifications(blockers_)); | 538 notification_list_->GetVisibleNotifications(blockers_)); |
| 537 | 539 |
| 538 if (already_exists) { | 540 if (already_exists) { |
| 539 FOR_EACH_OBSERVER( | 541 FOR_EACH_OBSERVER( |
| 540 MessageCenterObserver, observer_list_, OnNotificationUpdated(id)); | 542 MessageCenterObserver, observer_list_, OnNotificationUpdated(id)); |
| 541 } else { | 543 } else { |
| 542 FOR_EACH_OBSERVER( | 544 FOR_EACH_OBSERVER( |
| 543 MessageCenterObserver, observer_list_, OnNotificationAdded(id)); | 545 MessageCenterObserver, observer_list_, OnNotificationAdded(id)); |
| 544 } | 546 } |
| 545 } | 547 } |
| 546 | 548 |
| 547 void MessageCenterImpl::UpdateNotification( | 549 void MessageCenterImpl::UpdateNotification( |
| 548 const std::string& old_id, | 550 const std::string& old_id, |
| 549 scoped_ptr<Notification> new_notification) { | 551 std::unique_ptr<Notification> new_notification) { |
| 550 for (size_t i = 0; i < blockers_.size(); ++i) | 552 for (size_t i = 0; i < blockers_.size(); ++i) |
| 551 blockers_[i]->CheckState(); | 553 blockers_[i]->CheckState(); |
| 552 | 554 |
| 553 if (notification_queue_ && | 555 if (notification_queue_ && |
| 554 notification_list_->is_message_center_visible()) { | 556 notification_list_->is_message_center_visible()) { |
| 555 // We will allow notifications that are progress types (and stay progress | 557 // We will allow notifications that are progress types (and stay progress |
| 556 // types) to be updated even if the message center is open. There are 3 | 558 // types) to be updated even if the message center is open. There are 3 |
| 557 // requirements here: | 559 // requirements here: |
| 558 // * Notification of type PROGRESS exists with same ID in the center | 560 // * Notification of type PROGRESS exists with same ID in the center |
| 559 // * There are no queued updates for this notification (they imply a change | 561 // * There are no queued updates for this notification (they imply a change |
| (...skipping 13 matching lines...) Expand all Loading... |
| 573 std::move(new_notification)); | 575 std::move(new_notification)); |
| 574 return; | 576 return; |
| 575 } | 577 } |
| 576 } | 578 } |
| 577 | 579 |
| 578 UpdateNotificationImmediately(old_id, std::move(new_notification)); | 580 UpdateNotificationImmediately(old_id, std::move(new_notification)); |
| 579 } | 581 } |
| 580 | 582 |
| 581 void MessageCenterImpl::UpdateNotificationImmediately( | 583 void MessageCenterImpl::UpdateNotificationImmediately( |
| 582 const std::string& old_id, | 584 const std::string& old_id, |
| 583 scoped_ptr<Notification> new_notification) { | 585 std::unique_ptr<Notification> new_notification) { |
| 584 std::string new_id = new_notification->id(); | 586 std::string new_id = new_notification->id(); |
| 585 notification_list_->UpdateNotificationMessage(old_id, | 587 notification_list_->UpdateNotificationMessage(old_id, |
| 586 std::move(new_notification)); | 588 std::move(new_notification)); |
| 587 notification_cache_.Rebuild( | 589 notification_cache_.Rebuild( |
| 588 notification_list_->GetVisibleNotifications(blockers_)); | 590 notification_list_->GetVisibleNotifications(blockers_)); |
| 589 if (old_id == new_id) { | 591 if (old_id == new_id) { |
| 590 FOR_EACH_OBSERVER( | 592 FOR_EACH_OBSERVER( |
| 591 MessageCenterObserver, observer_list_, OnNotificationUpdated(new_id)); | 593 MessageCenterObserver, observer_list_, OnNotificationUpdated(new_id)); |
| 592 } else { | 594 } else { |
| 593 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, | 595 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 } | 889 } |
| 888 | 890 |
| 889 void MessageCenterImpl::EnableChangeQueueForTest(bool enable) { | 891 void MessageCenterImpl::EnableChangeQueueForTest(bool enable) { |
| 890 if (enable) | 892 if (enable) |
| 891 notification_queue_.reset(new internal::ChangeQueue()); | 893 notification_queue_.reset(new internal::ChangeQueue()); |
| 892 else | 894 else |
| 893 notification_queue_.reset(); | 895 notification_queue_.reset(); |
| 894 } | 896 } |
| 895 | 897 |
| 896 } // namespace message_center | 898 } // namespace message_center |
| OLD | NEW |