Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2034)

Unified Diff: chrome/browser/media/router/issue_manager.cc

Issue 2176613003: [Media Router] Clean up issues related code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 53d74c8cd7fc49f9fd2ae3483160a3096fa4d28b..ca99aab763d77160530c1f8318bc2c2c9af5d348 100644
--- a/chrome/browser/media/router/issue_manager.cc
+++ b/chrome/browser/media/router/issue_manager.cc
@@ -6,11 +6,12 @@
#include <algorithm>
+#include "base/memory/ptr_util.h"
dcheng 2016/12/07 18:58:02 Nit: remove this, as it's unused
imcheng 2016/12/09 23:19:53 Done.
#include "content/public/browser/browser_thread.h"
namespace media_router {
-IssueManager::IssueManager() {
+IssueManager::IssueManager() : top_issue_(nullptr) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
}
@@ -18,14 +19,15 @@ IssueManager::~IssueManager() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
}
-void IssueManager::AddIssue(const Issue& issue) {
+void IssueManager::AddIssue(const IssueInfo& issue_info) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- for (const Issue& next_issue : issues_) {
- if (next_issue.Equals(issue)) {
- return;
- }
- }
- issues_.push_back(issue);
+ auto it = std::find_if(
+ issues_.begin(), issues_.end(),
+ [&issue_info](const Issue& issue) { return issue_info == issue.info(); });
+ if (it != issues_.end())
+ return;
+
+ issues_.push_back(Issue(issue_info));
MaybeUpdateTopIssue();
}
@@ -39,51 +41,14 @@ void IssueManager::ClearIssue(const Issue::Id& issue_id) {
MaybeUpdateTopIssue();
}
-size_t IssueManager::GetIssueCount() const {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- return issues_.size();
-}
-
-void IssueManager::ClearAllIssues() {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- issues_.clear();
- MaybeUpdateTopIssue();
-}
-
-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());
- MaybeUpdateTopIssue();
-}
-
-void IssueManager::ClearIssuesWithRouteId(const MediaRoute::Id& route_id) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- issues_.erase(std::remove_if(issues_.begin(), issues_.end(),
- [&route_id](const Issue& issue) {
- return route_id == issue.route_id();
- }),
- issues_.end());
- MaybeUpdateTopIssue();
-}
-
void IssueManager::RegisterObserver(IssuesObserver* observer) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(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->OnIssue(*top_issue_);
}
void IssueManager::UnregisterObserver(IssuesObserver* observer) {
@@ -93,29 +58,27 @@ void IssueManager::UnregisterObserver(IssuesObserver* observer) {
void IssueManager::MaybeUpdateTopIssue() {
const Issue* new_top_issue = nullptr;
-
- if (issues_.empty()) {
- for (auto& observer : issues_observers_)
- observer.OnIssueUpdated(new_top_issue);
- return;
- }
-
- // 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 (!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.info().is_blocking; });
+ if (it == issues_.end())
+ it = issues_.begin();
+
+ new_top_issue = &*it;
}
// 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();
- for (auto& observer : issues_observers_)
- observer.OnIssueUpdated(new_top_issue);
+ if (new_top_issue != top_issue_) {
+ top_issue_ = new_top_issue;
+ for (auto& observer : issues_observers_) {
+ if (top_issue_)
+ observer.OnIssue(*top_issue_);
+ else
+ observer.OnIssuesCleared();
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698