OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/toolbar/media_router_action_controller.h" | |
6 | |
7 #include "chrome/browser/profiles/profile.h" | |
8 #include "chrome/browser/ui/browser.h" | |
9 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | |
10 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h" | |
11 #include "chrome/common/pref_names.h" | |
12 | |
13 MediaRouterActionController::MediaRouterActionController( | |
14 Profile* profile, | |
15 media_router::MediaRouter* router) | |
16 : MediaRouterActionController(profile, | |
17 router, | |
mark a. foltz
2016/09/09 17:48:28
MediaRouterFactory::GetApiForBrowserContext(profil
takumif
2016/09/12 19:01:31
Done.
| |
18 ToolbarActionsModel::Get(profile)) {} | |
19 | |
20 MediaRouterActionController::MediaRouterActionController( | |
21 Profile* profile, | |
22 media_router::MediaRouter* router, | |
23 extensions::ComponentMigrationHelper::ComponentActionDelegate* | |
24 component_action_delegate) | |
25 : media_router::IssuesObserver(router), | |
26 media_router::MediaRoutesObserver(router), | |
27 profile_(profile), | |
28 component_action_delegate_(component_action_delegate), | |
29 has_local_display_route_(false) { | |
30 DCHECK(profile_); | |
31 DCHECK(component_action_delegate_); | |
32 pref_change_registrar_.Init(profile->GetPrefs()); | |
33 pref_change_registrar_.Add( | |
34 prefs::kMediaRouterAlwaysShowActionIcon, | |
35 base::Bind(&MediaRouterActionController::MaybeAddOrRemoveAction, | |
36 base::Unretained(this))); | |
37 } | |
38 | |
39 MediaRouterActionController::~MediaRouterActionController() {} | |
mark a. foltz
2016/09/09 17:48:28
Will the pref_change_registar_ dtor unregister our
takumif
2016/09/12 19:01:31
Yes, it does.
| |
40 | |
41 void MediaRouterActionController::OnIssueUpdated( | |
42 const media_router::Issue* issue) { | |
43 issue_.reset(issue ? new media_router::Issue(*issue) : nullptr); | |
44 MaybeAddOrRemoveAction(); | |
45 FOR_EACH_OBSERVER(Observer, observers_, OnIssueUpdated(issue_.get())); | |
46 } | |
47 | |
48 void MediaRouterActionController::OnRoutesUpdated( | |
49 const std::vector<media_router::MediaRoute>& routes, | |
50 const std::vector<media_router::MediaRoute::Id>& joinable_route_ids) { | |
51 has_local_display_route_ = | |
52 std::find_if(routes.begin(), routes.end(), | |
53 [](const media_router::MediaRoute& route) { | |
54 return route.is_local() && route.for_display(); | |
55 }) != routes.end(); | |
56 | |
57 MaybeAddOrRemoveAction(); | |
58 FOR_EACH_OBSERVER(Observer, observers_, | |
59 OnLocalRouteUpdated(has_local_display_route_)); | |
60 } | |
61 | |
62 void MediaRouterActionController::SetAlwaysShowActionPref(bool always_show) { | |
63 profile_->GetPrefs()->SetBoolean(prefs::kMediaRouterAlwaysShowActionIcon, | |
mark a. foltz
2016/09/09 17:48:28
Check the implementation of SetBoolean() to see if
takumif
2016/09/12 19:01:31
Yes they do check for equality before setting it.
| |
64 always_show); | |
65 MaybeAddOrRemoveAction(); | |
66 } | |
67 | |
68 bool MediaRouterActionController::HasLocalRoute() const { | |
69 return has_local_display_route_; | |
70 } | |
71 | |
72 media_router::Issue* MediaRouterActionController::GetIssue() const { | |
73 return issue_.get(); | |
74 } | |
75 | |
76 void MediaRouterActionController::AddObserver( | |
77 MediaRouterActionController::Observer* observer) { | |
78 observers_.AddObserver(observer); | |
79 } | |
80 | |
81 void MediaRouterActionController::RemoveObserver( | |
82 MediaRouterActionController::Observer* observer) { | |
83 observers_.RemoveObserver(observer); | |
84 } | |
85 | |
86 void MediaRouterActionController::MaybeAddOrRemoveAction() { | |
87 const std::string& action_id = | |
mark a. foltz
2016/09/09 17:48:28
Super nit: Use a using declaration or type alias i
takumif
2016/09/12 19:01:31
Sorry, I'm not sure what you mean. ComponentToolba
| |
88 ComponentToolbarActionsFactory::kMediaRouterActionId; | |
89 | |
90 if (IsActionEnabled()) { | |
91 if (!component_action_delegate_->HasComponentAction(action_id)) | |
92 component_action_delegate_->AddComponentAction(action_id); | |
93 } else { | |
94 if (component_action_delegate_->HasComponentAction(action_id)) | |
95 component_action_delegate_->RemoveComponentAction(action_id); | |
96 } | |
97 } | |
98 | |
99 bool MediaRouterActionController::GetAlwaysShowActionPref() { | |
100 return profile_->GetPrefs()->GetBoolean( | |
101 prefs::kMediaRouterAlwaysShowActionIcon); | |
102 } | |
103 | |
104 bool MediaRouterActionController::IsActionEnabled() { | |
105 return GetAlwaysShowActionPref() || has_local_display_route_ || issue_; | |
mark a. foltz
2016/09/09 17:48:28
You're not actually calling anything on |issue_|;
takumif
2016/09/12 19:01:31
Changed to has_issue_.
| |
106 } | |
OLD | NEW |