File: media_router_action_controller.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (88 lines) | stat: -rw-r--r-- 3,549 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_
#define CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_

#include <vector>

#include "chrome/browser/extensions/component_migration_helper.h"
#include "chrome/browser/media/router/issues_observer.h"
#include "chrome/browser/media/router/media_routes_observer.h"
#include "chrome/browser/profiles/profile.h"
#include "components/prefs/pref_change_registrar.h"

using extensions::ComponentMigrationHelper;

// Controller for MediaRouterAction that determines when to show and hide the
// action icon on the toolbar. There should be one instance of this class per
// profile, and it should only be used on the UI thread.
class MediaRouterActionController : public media_router::IssuesObserver,
                                    public media_router::MediaRoutesObserver {
 public:
  explicit MediaRouterActionController(Profile* profile);
  // Constructor for injecting dependencies in tests.
  MediaRouterActionController(
      Profile* profile,
      media_router::MediaRouter* router,
      ComponentMigrationHelper::ComponentActionDelegate*
          component_action_delegate,
      ComponentMigrationHelper* component_migration_helper);
  ~MediaRouterActionController() override;

  // media_router::IssuesObserver:
  void OnIssue(const media_router::Issue& issue) override;
  void OnIssuesCleared() override;

  // media_router::MediaRoutesObserver:
  void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes,
                       const std::vector<media_router::MediaRoute::Id>&
                           joinable_route_ids) override;

  // Called when a Media Router dialog is shown or hidden, and updates the
  // visibility of the action icon. Overridden in tests.
  virtual void OnDialogShown();
  virtual void OnDialogHidden();

 private:
  friend class MediaRouterActionControllerUnitTest;
  FRIEND_TEST_ALL_PREFIXES(MediaRouterActionControllerUnitTest,
                           EphemeralIconForRoutesAndIssues);
  FRIEND_TEST_ALL_PREFIXES(MediaRouterActionControllerUnitTest,
                           EphemeralIconForDialog);

  // Adds or removes the Media Router action icon to/from
  // |component_action_delegate_| if necessary, depending on whether or not
  // we have issues, local routes or a dialog.
  virtual void MaybeAddOrRemoveAction();

  // Returns |true| if the Media Router action should be present on the toolbar
  // or the overflow menu.
  bool ShouldEnableAction() const;

  // The profile |this| is associated with. There should be one instance of this
  // class per profile.
  Profile* const profile_;

  // The delegate that is responsible for showing and hiding the icon on the
  // toolbar. It outlives |this|.
  ComponentMigrationHelper::ComponentActionDelegate* const
      component_action_delegate_;

  // Responsible for changing the pref to always show or hide component actions.
  // It is owned by ToolbarActionsModel and outlives |this|.
  ComponentMigrationHelper* const component_migration_helper_;

  bool has_issue_ = false;
  bool has_local_display_route_ = false;

  // The number of dialogs that are currently open.
  size_t dialog_count_ = 0;

  PrefChangeRegistrar pref_change_registrar_;

  DISALLOW_COPY_AND_ASSIGN(MediaRouterActionController);
};

#endif  // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_