| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } | 157 } |
| 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::OnIssue(const media_router::Issue& issue) { |
| 169 issue_.reset(issue ? new media_router::Issue(*issue) : nullptr); | 168 current_issue_.reset(new media_router::IssueInfo(issue.info())); |
| 170 MaybeUpdateIcon(); | 169 MaybeUpdateIcon(); |
| 171 } | 170 } |
| 172 | 171 |
| 172 void MediaRouterAction::OnIssuesCleared() { |
| 173 current_issue_.reset(); |
| 174 MaybeUpdateIcon(); |
| 175 } |
| 176 |
| 173 void MediaRouterAction::OnRoutesUpdated( | 177 void MediaRouterAction::OnRoutesUpdated( |
| 174 const std::vector<media_router::MediaRoute>& routes, | 178 const std::vector<media_router::MediaRoute>& routes, |
| 175 const std::vector<media_router::MediaRoute::Id>& joinable_route_ids) { | 179 const std::vector<media_router::MediaRoute::Id>& joinable_route_ids) { |
| 176 has_local_display_route_ = | 180 has_local_display_route_ = |
| 177 std::find_if(routes.begin(), routes.end(), | 181 std::find_if(routes.begin(), routes.end(), |
| 178 [](const media_router::MediaRoute& route) { | 182 [](const media_router::MediaRoute& route) { |
| 179 return route.is_local() && route.for_display(); | 183 return route.is_local() && route.for_display(); |
| 180 }) != routes.end(); | 184 }) != routes.end(); |
| 181 MaybeUpdateIcon(); | 185 MaybeUpdateIcon(); |
| 182 } | 186 } |
| (...skipping 76 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 | 263 // Tell the associated view to update its icon to reflect the change made |
| 260 // above. If MaybeUpdateIcon() was called as a result of instantiating | 264 // above. If MaybeUpdateIcon() was called as a result of instantiating |
| 261 // |this|, then |delegate_| may not be set yet. | 265 // |this|, then |delegate_| may not be set yet. |
| 262 if (delegate_) | 266 if (delegate_) |
| 263 UpdateState(); | 267 UpdateState(); |
| 264 } | 268 } |
| 265 } | 269 } |
| 266 | 270 |
| 267 gfx::VectorIconId MediaRouterAction::GetCurrentIcon() const { | 271 gfx::VectorIconId MediaRouterAction::GetCurrentIcon() const { |
| 268 // Highest priority is to indicate whether there's an issue. | 272 // Highest priority is to indicate whether there's an issue. |
| 269 if (issue_) { | 273 if (current_issue_) { |
| 270 if (issue_->severity() == media_router::Issue::FATAL) | 274 media_router::IssueInfo::Severity severity = current_issue_->severity; |
| 275 if (severity == media_router::IssueInfo::Severity::FATAL) |
| 271 return gfx::VectorIconId::MEDIA_ROUTER_ERROR; | 276 return gfx::VectorIconId::MEDIA_ROUTER_ERROR; |
| 272 if (issue_->severity() == media_router::Issue::WARNING) | 277 if (severity == media_router::IssueInfo::Severity::WARNING) |
| 273 return gfx::VectorIconId::MEDIA_ROUTER_WARNING; | 278 return gfx::VectorIconId::MEDIA_ROUTER_WARNING; |
| 279 // Fall through for Severity::NOTIFICATION. |
| 274 } | 280 } |
| 275 | 281 |
| 276 return has_local_display_route_ ? gfx::VectorIconId::MEDIA_ROUTER_ACTIVE | 282 return has_local_display_route_ ? gfx::VectorIconId::MEDIA_ROUTER_ACTIVE |
| 277 : gfx::VectorIconId::MEDIA_ROUTER_IDLE; | 283 : gfx::VectorIconId::MEDIA_ROUTER_IDLE; |
| 278 } | 284 } |
| OLD | NEW |