| Index: chrome/browser/media/router/issue_manager.cc
|
| diff --git a/chrome/browser/media/router/issue_manager.cc b/chrome/browser/media/router/issue_manager.cc
|
| index d3cb9d4f3b5a18fd30765c7c8eeaa24d20718e2d..5068cd230bc65ee5aac30f0557d8ff5a2209fae7 100644
|
| --- a/chrome/browser/media/router/issue_manager.cc
|
| +++ b/chrome/browser/media/router/issue_manager.cc
|
| @@ -10,7 +10,7 @@
|
|
|
| namespace media_router {
|
|
|
| -IssueManager::IssueManager() {
|
| +IssueManager::IssueManager() : top_issue_(nullptr) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| }
|
|
|
| @@ -20,11 +20,9 @@ IssueManager::~IssueManager() {
|
|
|
| void IssueManager::AddIssue(const Issue& issue) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| - for (const Issue& next_issue : issues_) {
|
| - if (next_issue.Equals(issue)) {
|
| - return;
|
| - }
|
| - }
|
| + if (ContainsValue(issues_, issue))
|
| + return;
|
| +
|
| issues_.push_back(issue);
|
| MaybeUpdateTopIssue();
|
| }
|
| @@ -53,9 +51,9 @@ void IssueManager::ClearAllIssues() {
|
| void IssueManager::ClearGlobalIssues() {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| issues_.erase(
|
| - std::remove_if(issues_.begin(), issues_.end(), [](const Issue& issue) {
|
| - return issue.is_global();
|
| - }), issues_.end());
|
| + std::remove_if(issues_.begin(), issues_.end(),
|
| + [](const Issue& issue) { return issue.IsGlobal(); }),
|
| + issues_.end());
|
| MaybeUpdateTopIssue();
|
| }
|
|
|
| @@ -75,15 +73,8 @@ void IssueManager::RegisterObserver(IssuesObserver* observer) {
|
| DCHECK(!issues_observers_.HasObserver(observer));
|
|
|
| issues_observers_.AddObserver(observer);
|
| - if (top_issue_id_.empty())
|
| - return;
|
| -
|
| - // Find the current top issue and report it to the observer.
|
| - for (const auto& next_issue : issues_) {
|
| - if (next_issue.id() == top_issue_id_) {
|
| - observer->OnIssueUpdated(&next_issue);
|
| - }
|
| - }
|
| + if (top_issue_)
|
| + observer->OnIssueUpdated(top_issue_);
|
| }
|
|
|
| void IssueManager::UnregisterObserver(IssuesObserver* observer) {
|
| @@ -93,29 +84,22 @@ void IssueManager::UnregisterObserver(IssuesObserver* observer) {
|
|
|
| void IssueManager::MaybeUpdateTopIssue() {
|
| const Issue* new_top_issue = nullptr;
|
| -
|
| - if (issues_.empty()) {
|
| - FOR_EACH_OBSERVER(IssuesObserver, issues_observers_,
|
| - OnIssueUpdated(new_top_issue));
|
| - return;
|
| + if (!issues_.empty()) {
|
| + // Select the first blocking issue in the list of issues.
|
| + // If there are none, simply select the first issue in the list.
|
| + auto it =
|
| + std::find_if(issues_.begin(), issues_.end(),
|
| + [](const Issue& issue) { return issue.IsBlocking(); });
|
| + if (it == issues_.end())
|
| + it = issues_.begin();
|
| +
|
| + new_top_issue = &*it;
|
| }
|
| -
|
| - // Select the first blocking issue in the list of issues.
|
| - // If there are none, simply select the first issue in the list.
|
| - new_top_issue = &(issues_.front());
|
| - for (const auto& issue : issues_) {
|
| - // The first blocking issue is of higher priority than the first issue.
|
| - if (issue.is_blocking()) {
|
| - new_top_issue = &issue;
|
| - break;
|
| - }
|
| - }
|
| -
|
| // If we've found a new top issue, then report it via the observer.
|
| - if (new_top_issue->id() != top_issue_id_) {
|
| - top_issue_id_ = new_top_issue->id();
|
| + if (new_top_issue != top_issue_) {
|
| + top_issue_ = new_top_issue;
|
| FOR_EACH_OBSERVER(IssuesObserver, issues_observers_,
|
| - OnIssueUpdated(new_top_issue));
|
| + OnIssueUpdated(top_issue_));
|
| }
|
| }
|
|
|
|
|