| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/toolbar/media_router_action.h" | 5 #include "chrome/browser/ui/toolbar/media_router_action.h" |
| 6 | 6 |
| 7 #include "base/metrics/user_metrics.h" | 7 #include "base/metrics/user_metrics.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/media/router/issue.h" | 9 #include "chrome/browser/media/router/issue.h" |
| 10 #include "chrome/browser/media/router/media_route.h" | 10 #include "chrome/browser/media/router/media_route.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 toolbar_actions_bar_(toolbar_actions_bar), | 47 toolbar_actions_bar_(toolbar_actions_bar), |
| 48 platform_delegate_(MediaRouterActionPlatformDelegate::Create(browser)), | 48 platform_delegate_(MediaRouterActionPlatformDelegate::Create(browser)), |
| 49 contextual_menu_(browser), | 49 contextual_menu_(browser), |
| 50 tab_strip_model_observer_(this), | 50 tab_strip_model_observer_(this), |
| 51 toolbar_actions_bar_observer_(this), | 51 toolbar_actions_bar_observer_(this), |
| 52 weak_ptr_factory_(this) { | 52 weak_ptr_factory_(this) { |
| 53 DCHECK(browser_); | 53 DCHECK(browser_); |
| 54 DCHECK(toolbar_actions_bar_); | 54 DCHECK(toolbar_actions_bar_); |
| 55 tab_strip_model_observer_.Add(browser_->tab_strip_model()); | 55 tab_strip_model_observer_.Add(browser_->tab_strip_model()); |
| 56 toolbar_actions_bar_observer_.Add(toolbar_actions_bar_); | 56 toolbar_actions_bar_observer_.Add(toolbar_actions_bar_); |
| 57 RegisterObserver(); | 57 IssuesObserver::Init(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 MediaRouterAction::~MediaRouterAction() { | 60 MediaRouterAction::~MediaRouterAction() { |
| 61 UnregisterObserver(); | |
| 62 } | 61 } |
| 63 | 62 |
| 64 // static | 63 // static |
| 65 SkColor MediaRouterAction::GetIconColor(gfx::VectorIconId icon_id) { | 64 SkColor MediaRouterAction::GetIconColor(gfx::VectorIconId icon_id) { |
| 66 switch (icon_id) { | 65 switch (icon_id) { |
| 67 case gfx::VectorIconId::MEDIA_ROUTER_IDLE: | 66 case gfx::VectorIconId::MEDIA_ROUTER_IDLE: |
| 68 return gfx::kChromeIconGrey; | 67 return gfx::kChromeIconGrey; |
| 69 case gfx::VectorIconId::MEDIA_ROUTER_ACTIVE: | 68 case gfx::VectorIconId::MEDIA_ROUTER_ACTIVE: |
| 70 return gfx::kGoogleBlue500; | 69 return gfx::kGoogleBlue500; |
| 71 case gfx::VectorIconId::MEDIA_ROUTER_WARNING: | 70 case gfx::VectorIconId::MEDIA_ROUTER_WARNING: |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 158 |
| 160 void MediaRouterAction::UpdateState() { | 159 void MediaRouterAction::UpdateState() { |
| 161 delegate_->UpdateState(); | 160 delegate_->UpdateState(); |
| 162 } | 161 } |
| 163 | 162 |
| 164 bool MediaRouterAction::DisabledClickOpensMenu() const { | 163 bool MediaRouterAction::DisabledClickOpensMenu() const { |
| 165 return false; | 164 return false; |
| 166 } | 165 } |
| 167 | 166 |
| 168 void MediaRouterAction::OnIssueUpdated(const media_router::Issue* issue) { | 167 void MediaRouterAction::OnIssueUpdated(const media_router::Issue* issue) { |
| 169 issue_.reset(issue ? new media_router::Issue(*issue) : nullptr); | 168 if (!issue) |
| 169 current_issue_severity_.reset(); |
| 170 else |
| 171 current_issue_severity_ = issue->info().severity; |
| 172 |
| 170 MaybeUpdateIcon(); | 173 MaybeUpdateIcon(); |
| 171 } | 174 } |
| 172 | 175 |
| 173 void MediaRouterAction::OnRoutesUpdated( | 176 void MediaRouterAction::OnRoutesUpdated( |
| 174 const std::vector<media_router::MediaRoute>& routes, | 177 const std::vector<media_router::MediaRoute>& routes, |
| 175 const std::vector<media_router::MediaRoute::Id>& joinable_route_ids) { | 178 const std::vector<media_router::MediaRoute::Id>& joinable_route_ids) { |
| 176 has_local_display_route_ = | 179 has_local_display_route_ = |
| 177 std::find_if(routes.begin(), routes.end(), | 180 std::find_if(routes.begin(), routes.end(), |
| 178 [](const media_router::MediaRoute& route) { | 181 [](const media_router::MediaRoute& route) { |
| 179 return route.is_local() && route.for_display(); | 182 return route.is_local() && route.for_display(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 // Tell the associated view to update its icon to reflect the change made | 262 // Tell the associated view to update its icon to reflect the change made |
| 260 // above. If MaybeUpdateIcon() was called as a result of instantiating | 263 // above. If MaybeUpdateIcon() was called as a result of instantiating |
| 261 // |this|, then |delegate_| may not be set yet. | 264 // |this|, then |delegate_| may not be set yet. |
| 262 if (delegate_) | 265 if (delegate_) |
| 263 UpdateState(); | 266 UpdateState(); |
| 264 } | 267 } |
| 265 } | 268 } |
| 266 | 269 |
| 267 gfx::VectorIconId MediaRouterAction::GetCurrentIcon() const { | 270 gfx::VectorIconId MediaRouterAction::GetCurrentIcon() const { |
| 268 // Highest priority is to indicate whether there's an issue. | 271 // Highest priority is to indicate whether there's an issue. |
| 269 if (issue_) { | 272 if (current_issue_severity_.has_value()) { |
| 270 if (issue_->severity() == media_router::Issue::FATAL) | 273 if (*current_issue_severity_ == media_router::IssueInfo::Severity::FATAL) |
| 271 return gfx::VectorIconId::MEDIA_ROUTER_ERROR; | 274 return gfx::VectorIconId::MEDIA_ROUTER_ERROR; |
| 272 if (issue_->severity() == media_router::Issue::WARNING) | 275 else if (*current_issue_severity_ == |
| 276 media_router::IssueInfo::Severity::WARNING) |
| 273 return gfx::VectorIconId::MEDIA_ROUTER_WARNING; | 277 return gfx::VectorIconId::MEDIA_ROUTER_WARNING; |
| 278 // Fall through for Severity::NOTIFICATION. |
| 274 } | 279 } |
| 275 | 280 |
| 276 return has_local_display_route_ ? gfx::VectorIconId::MEDIA_ROUTER_ACTIVE | 281 return has_local_display_route_ ? gfx::VectorIconId::MEDIA_ROUTER_ACTIVE |
| 277 : gfx::VectorIconId::MEDIA_ROUTER_IDLE; | 282 : gfx::VectorIconId::MEDIA_ROUTER_IDLE; |
| 278 } | 283 } |
| OLD | NEW |