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

Side by Side Diff: chrome/browser/ui/toolbar/media_router_action_controller.cc

Issue 2294973002: Create MediaRouterActionController and MediaRouterUIService (Closed)
Patch Set: Add MediaRouterUIService (KeyedService) Created 4 years, 3 months 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 unified diff | Download patch
OLDNEW
(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/extensions/component_migration_helper.h"
8 #include "chrome/browser/media/router/media_router_factory.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h"
12 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
13 #include "chrome/common/pref_names.h"
14
15 MediaRouterActionController::MediaRouterActionController(Profile* profile)
16 : MediaRouterActionController(
17 profile,
18 media_router::MediaRouterFactory::GetApiForBrowserContext(profile),
19 ToolbarActionsModel::Get(profile),
20 ToolbarActionsModel::Get(profile)->component_migration_helper()) {}
21
22 MediaRouterActionController::MediaRouterActionController(
23 Profile* profile,
24 media_router::MediaRouter* router,
25 extensions::ComponentMigrationHelper::ComponentActionDelegate*
imcheng 2016/09/13 23:13:10 nit: I think we should extract ComponentActionDele
takumif 2016/09/14 04:00:52 I'm not sure where that'd go. ComponentMigrationHe
26 component_action_delegate,
27 extensions::ComponentMigrationHelper* component_migration_helper)
28 : media_router::IssuesObserver(router),
29 media_router::MediaRoutesObserver(router),
30 profile_(profile),
31 component_action_delegate_(component_action_delegate),
32 component_migration_helper_(component_migration_helper),
33 has_issue_(false),
34 has_local_display_route_(false) {
35 DCHECK(profile_);
36 DCHECK(component_action_delegate_);
37 RegisterObserver(); // media_router::IssuesObserver.
38 pref_change_registrar_.Init(profile->GetPrefs());
mark a. foltz 2016/09/13 18:23:05 I wonder if changing the pref in incognito affects
takumif 2016/09/14 04:00:52 Pref changes made while in incognito do persist. I
39 pref_change_registrar_.Add(
40 prefs::kToolbarMigratedComponentActionStatus,
41 base::Bind(&MediaRouterActionController::MaybeAddOrRemoveAction,
42 base::Unretained(this)));
43 }
44
45 MediaRouterActionController::~MediaRouterActionController() {
46 UnregisterObserver(); // media_router::IssuesObserver.
47 }
48
49 void MediaRouterActionController::OnIssueUpdated(
50 const media_router::Issue* issue) {
51 has_issue_ = issue != nullptr;
52 MaybeAddOrRemoveAction();
53 }
54
55 void MediaRouterActionController::OnRoutesUpdated(
56 const std::vector<media_router::MediaRoute>& routes,
57 const std::vector<media_router::MediaRoute::Id>& joinable_route_ids) {
58 has_local_display_route_ =
59 std::find_if(routes.begin(), routes.end(),
60 [](const media_router::MediaRoute& route) {
61 return route.is_local() && route.for_display();
62 }) != routes.end();
63
64 MaybeAddOrRemoveAction();
65 }
66
67 void MediaRouterActionController::MaybeAddOrRemoveAction() {
68 const std::string& action_id =
69 ComponentToolbarActionsFactory::kMediaRouterActionId;
mark a. foltz 2016/09/13 18:23:05 Can you write using ComponentToolbarActionsFacto
takumif 2016/09/14 04:00:52 using ComponentToolbarActionsFactory::kMediaRouter
70
71 if (IsActionEnabled()) {
72 if (!component_action_delegate_->HasComponentAction(action_id))
73 component_action_delegate_->AddComponentAction(action_id);
74 } else {
75 if (component_action_delegate_->HasComponentAction(action_id))
76 component_action_delegate_->RemoveComponentAction(action_id);
77 }
78 }
79
80 bool MediaRouterActionController::IsActionEnabled() {
imcheng 2016/09/13 23:13:10 I think this method makes more sense if it is name
takumif 2016/09/14 04:00:52 Renamed.
81 return component_migration_helper_->GetComponentActionPref(
imcheng 2016/09/13 23:13:10 nit: as a small optimization, we can reorder the s
takumif 2016/09/14 04:00:52 Done.
82 ComponentToolbarActionsFactory::kMediaRouterActionId) ||
83 has_local_display_route_ || has_issue_;
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698