Chromium Code Reviews| 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 22 matching lines...) Expand all Loading... | |
| 33 browser->profile()); | 33 browser->profile()); |
| 34 } | 34 } |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 MediaRouterAction::MediaRouterAction(Browser* browser, | 38 MediaRouterAction::MediaRouterAction(Browser* browser, |
| 39 ToolbarActionsBar* toolbar_actions_bar) | 39 ToolbarActionsBar* toolbar_actions_bar) |
| 40 : media_router::IssuesObserver(GetMediaRouter(browser)), | 40 : media_router::IssuesObserver(GetMediaRouter(browser)), |
| 41 media_router::MediaRoutesObserver(GetMediaRouter(browser)), | 41 media_router::MediaRoutesObserver(GetMediaRouter(browser)), |
| 42 current_icon_(gfx::VectorIconId::MEDIA_ROUTER_IDLE), | 42 current_icon_(gfx::VectorIconId::MEDIA_ROUTER_IDLE), |
| 43 has_issue_(false), | |
| 44 current_issue_severity_(media_router::Issue::Severity::NOTIFICATION), | |
| 43 has_local_display_route_(false), | 45 has_local_display_route_(false), |
| 44 delegate_(nullptr), | 46 delegate_(nullptr), |
| 45 browser_(browser), | 47 browser_(browser), |
| 46 toolbar_actions_bar_(toolbar_actions_bar), | 48 toolbar_actions_bar_(toolbar_actions_bar), |
| 47 platform_delegate_(MediaRouterActionPlatformDelegate::Create(browser)), | 49 platform_delegate_(MediaRouterActionPlatformDelegate::Create(browser)), |
| 48 contextual_menu_(browser), | 50 contextual_menu_(browser), |
| 49 tab_strip_model_observer_(this), | 51 tab_strip_model_observer_(this), |
| 50 weak_ptr_factory_(this) { | 52 weak_ptr_factory_(this) { |
| 51 DCHECK(browser_); | 53 DCHECK(browser_); |
| 52 DCHECK(toolbar_actions_bar_); | 54 DCHECK(toolbar_actions_bar_); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 | 146 |
| 145 void MediaRouterAction::UpdateState() { | 147 void MediaRouterAction::UpdateState() { |
| 146 if (delegate_) | 148 if (delegate_) |
| 147 delegate_->UpdateState(); | 149 delegate_->UpdateState(); |
| 148 } | 150 } |
| 149 | 151 |
| 150 bool MediaRouterAction::DisabledClickOpensMenu() const { | 152 bool MediaRouterAction::DisabledClickOpensMenu() const { |
| 151 return false; | 153 return false; |
| 152 } | 154 } |
| 153 | 155 |
| 154 void MediaRouterAction::OnIssueUpdated(const media_router::Issue* issue) { | 156 void MediaRouterAction::OnIssueUpdated(const media_router::Issue* issue) { |
|
mark a. foltz
2016/07/27 18:52:04
I don't think |issue| should be modified here. Ca
imcheng
2016/09/13 20:27:54
There was a similar comment in Takumi's patch. We
| |
| 155 issue_.reset(issue ? new media_router::Issue(*issue) : nullptr); | 157 bool new_has_issue = (issue != nullptr); |
| 156 | 158 media_router::Issue::Severity new_severity = |
| 157 MaybeUpdateIcon(); | 159 issue ? issue->severity() : |
| 160 media_router::Issue::Severity::NOTIFICATION; | |
| 161 if (has_issue_ != new_has_issue || current_issue_severity_ != new_severity) { | |
| 162 has_issue_ = new_has_issue; | |
| 163 current_issue_severity_ = new_severity; | |
| 164 MaybeUpdateIcon(); | |
| 165 } | |
| 158 } | 166 } |
| 159 | 167 |
| 160 void MediaRouterAction::OnRoutesUpdated( | 168 void MediaRouterAction::OnRoutesUpdated( |
| 161 const std::vector<media_router::MediaRoute>& routes, | 169 const std::vector<media_router::MediaRoute>& routes, |
| 162 const std::vector<media_router::MediaRoute::Id>& joinable_route_ids) { | 170 const std::vector<media_router::MediaRoute::Id>& joinable_route_ids) { |
| 163 has_local_display_route_ = | 171 has_local_display_route_ = |
| 164 std::find_if(routes.begin(), routes.end(), | 172 std::find_if(routes.begin(), routes.end(), |
| 165 [](const media_router::MediaRoute& route) { | 173 [](const media_router::MediaRoute& route) { |
| 166 return route.is_local() && route.for_display(); | 174 return route.is_local() && route.for_display(); |
| 167 }) != routes.end(); | 175 }) != routes.end(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 | 240 |
| 233 // Tell the associated view to update its icon to reflect the change made | 241 // Tell the associated view to update its icon to reflect the change made |
| 234 // above. | 242 // above. |
| 235 if (delegate_) | 243 if (delegate_) |
| 236 delegate_->UpdateState(); | 244 delegate_->UpdateState(); |
| 237 } | 245 } |
| 238 } | 246 } |
| 239 | 247 |
| 240 gfx::VectorIconId MediaRouterAction::GetCurrentIcon() const { | 248 gfx::VectorIconId MediaRouterAction::GetCurrentIcon() const { |
| 241 // Highest priority is to indicate whether there's an issue. | 249 // Highest priority is to indicate whether there's an issue. |
| 242 if (issue_) { | 250 if (has_issue_) { |
| 243 if (issue_->severity() == media_router::Issue::FATAL) | 251 if (current_issue_severity_ == media_router::Issue::Severity::FATAL) |
| 244 return gfx::VectorIconId::MEDIA_ROUTER_ERROR; | 252 return gfx::VectorIconId::MEDIA_ROUTER_ERROR; |
| 245 if (issue_->severity() == media_router::Issue::WARNING) | 253 else if (current_issue_severity_ == media_router::Issue::Severity::WARNING) |
| 246 return gfx::VectorIconId::MEDIA_ROUTER_WARNING; | 254 return gfx::VectorIconId::MEDIA_ROUTER_WARNING; |
| 255 // Fall through for Severity::NOTIFICATION. | |
| 247 } | 256 } |
| 248 | 257 |
| 249 return has_local_display_route_ ? gfx::VectorIconId::MEDIA_ROUTER_ACTIVE | 258 return has_local_display_route_ ? gfx::VectorIconId::MEDIA_ROUTER_ACTIVE |
| 250 : gfx::VectorIconId::MEDIA_ROUTER_IDLE; | 259 : gfx::VectorIconId::MEDIA_ROUTER_IDLE; |
| 251 } | 260 } |
| OLD | NEW |