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

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

Issue 2176613003: [Media Router] Clean up issues related code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IssueObserver init behavior and use StructTraits Created 4 years, 2 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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_controller.h" 5 #include "chrome/browser/ui/toolbar/media_router_action_controller.h"
6 6
7 #include "chrome/browser/media/router/media_router_factory.h" 7 #include "chrome/browser/media/router/media_router_factory.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" 9 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h"
10 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h" 10 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
11 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
12 12
13 MediaRouterActionController::MediaRouterActionController(Profile* profile) 13 MediaRouterActionController::MediaRouterActionController(Profile* profile)
14 : MediaRouterActionController( 14 : MediaRouterActionController(
15 profile, 15 profile,
16 media_router::MediaRouterFactory::GetApiForBrowserContext(profile), 16 media_router::MediaRouterFactory::GetApiForBrowserContext(profile),
17 ToolbarActionsModel::Get(profile), 17 ToolbarActionsModel::Get(profile),
18 ToolbarActionsModel::Get(profile)->component_migration_helper()) {} 18 ToolbarActionsModel::Get(profile)->component_migration_helper()) {}
19 19
20 MediaRouterActionController::~MediaRouterActionController() { 20 MediaRouterActionController::~MediaRouterActionController() {
21 UnregisterObserver(); // media_router::IssuesObserver.
22 } 21 }
23 22
24 void MediaRouterActionController::OnIssueUpdated( 23 void MediaRouterActionController::OnIssueUpdated(
25 const media_router::Issue* issue) { 24 const media_router::Issue* issue) {
26 has_issue_ = issue != nullptr; 25 has_issue_ = issue != nullptr;
27 MaybeAddOrRemoveAction(); 26 MaybeAddOrRemoveAction();
28 } 27 }
29 28
30 void MediaRouterActionController::OnRoutesUpdated( 29 void MediaRouterActionController::OnRoutesUpdated(
31 const std::vector<media_router::MediaRoute>& routes, 30 const std::vector<media_router::MediaRoute>& routes,
(...skipping 13 matching lines...) Expand all
45 extensions::ComponentMigrationHelper::ComponentActionDelegate* 44 extensions::ComponentMigrationHelper::ComponentActionDelegate*
46 component_action_delegate, 45 component_action_delegate,
47 extensions::ComponentMigrationHelper* component_migration_helper) 46 extensions::ComponentMigrationHelper* component_migration_helper)
48 : media_router::IssuesObserver(router), 47 : media_router::IssuesObserver(router),
49 media_router::MediaRoutesObserver(router), 48 media_router::MediaRoutesObserver(router),
50 profile_(profile), 49 profile_(profile),
51 component_action_delegate_(component_action_delegate), 50 component_action_delegate_(component_action_delegate),
52 component_migration_helper_(component_migration_helper) { 51 component_migration_helper_(component_migration_helper) {
53 DCHECK(profile_); 52 DCHECK(profile_);
54 DCHECK(component_action_delegate_); 53 DCHECK(component_action_delegate_);
55 RegisterObserver(); // media_router::IssuesObserver. 54 media_router::IssuesObserver::Init();
56 pref_change_registrar_.Init(profile->GetPrefs()); 55 pref_change_registrar_.Init(profile->GetPrefs());
57 pref_change_registrar_.Add( 56 pref_change_registrar_.Add(
58 prefs::kToolbarMigratedComponentActionStatus, 57 prefs::kToolbarMigratedComponentActionStatus,
59 base::Bind(&MediaRouterActionController::MaybeAddOrRemoveAction, 58 base::Bind(&MediaRouterActionController::MaybeAddOrRemoveAction,
60 base::Unretained(this))); 59 base::Unretained(this)));
61 } 60 }
62 61
63 void MediaRouterActionController::MaybeAddOrRemoveAction() { 62 void MediaRouterActionController::MaybeAddOrRemoveAction() {
64 if (ShouldEnableAction()) { 63 if (ShouldEnableAction()) {
65 if (!component_action_delegate_->HasComponentAction( 64 if (!component_action_delegate_->HasComponentAction(
66 ComponentToolbarActionsFactory::kMediaRouterActionId)) 65 ComponentToolbarActionsFactory::kMediaRouterActionId))
67 component_action_delegate_->AddComponentAction( 66 component_action_delegate_->AddComponentAction(
68 ComponentToolbarActionsFactory::kMediaRouterActionId); 67 ComponentToolbarActionsFactory::kMediaRouterActionId);
69 } else if (component_action_delegate_->HasComponentAction( 68 } else if (component_action_delegate_->HasComponentAction(
70 ComponentToolbarActionsFactory::kMediaRouterActionId)) { 69 ComponentToolbarActionsFactory::kMediaRouterActionId)) {
71 component_action_delegate_->RemoveComponentAction( 70 component_action_delegate_->RemoveComponentAction(
72 ComponentToolbarActionsFactory::kMediaRouterActionId); 71 ComponentToolbarActionsFactory::kMediaRouterActionId);
73 } 72 }
74 } 73 }
75 74
76 bool MediaRouterActionController::ShouldEnableAction() const { 75 bool MediaRouterActionController::ShouldEnableAction() const {
77 return has_local_display_route_ || has_issue_ || 76 return has_local_display_route_ || has_issue_ ||
78 component_migration_helper_->GetComponentActionPref( 77 component_migration_helper_->GetComponentActionPref(
79 ComponentToolbarActionsFactory::kMediaRouterActionId); 78 ComponentToolbarActionsFactory::kMediaRouterActionId);
80 } 79 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698