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

Unified Diff: chrome/browser/ui/toolbar/media_router_action_controller.h

Issue 2294973002: Create MediaRouterActionController and MediaRouterUIService (Closed)
Patch Set: Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/toolbar/media_router_action_controller.h
diff --git a/chrome/browser/ui/toolbar/media_router_action_controller.h b/chrome/browser/ui/toolbar/media_router_action_controller.h
new file mode 100644
index 0000000000000000000000000000000000000000..8e3ecf64a062f993d8684d48e0b4206a30219f11
--- /dev/null
+++ b/chrome/browser/ui/toolbar/media_router_action_controller.h
@@ -0,0 +1,85 @@
+// 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_
mark a. foltz 2016/09/02 22:19:09 I wonder if we should put this in its own folder,
+#define CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "base/observer_list.h"
+#include "chrome/browser/extensions/component_migration_helper.h"
+#include "chrome/browser/media/router/issues_observer.h"
+#include "chrome/browser/media/router/media_router_factory.h"
+#include "chrome/browser/media/router/media_routes_observer.h"
+#include "chrome/browser/profiles/profile.h"
+
+class MediaRouterActionControllerUnitTest;
+
+// 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.
imcheng 2016/08/31 05:39:48 If it were really the case, would it be better to
mark a. foltz 2016/09/02 22:19:09 Takumi and I discussed this. This code didn't see
+class MediaRouterActionController
+ : public media_router::IssuesObserver,
+ public media_router::MediaRoutesObserver {
+ public:
+ class Observer {
mark a. foltz 2016/09/02 22:19:09 I don't see any observers implemented in this chan
takumif 2016/09/07 21:48:33 It's for MRAction to observe MRActionController. A
+ public:
+ virtual void OnIssueUpdated(const media_router::Issue* issue);
imcheng 2016/08/31 05:39:49 Should these be pure virtual methods, i.e. Observe
mark a. foltz 2016/09/02 22:19:10 Pass by const reference
takumif 2016/09/07 21:48:33 MediaRouterActions will be observing |this|, rathe
takumif 2016/09/07 21:48:33 I'd like to be able to pass a nullptr to indicate
+ virtual void OnLocalRouteUpdated(bool has_local_route);
mark a. foltz 2016/09/02 22:19:10 Bikeshed: slightly prefer an API OnNumLocalRoutes
takumif 2016/09/07 21:48:33 Do we expect to ever have more than one local rout
+ };
+
+ MediaRouterActionController(
+ Profile* profile, media_router::MediaRouter* router);
mark a. foltz 2016/09/02 22:19:09 I'm not a huge fan of the circular dependency betw
imcheng 2016/09/08 20:49:31 I would suggest not having MediaRouter depend on M
+ ~MediaRouterActionController() override;
+
+ // media_router::IssuesObserver:
+ void OnIssueUpdated(const media_router::Issue* issue) override;
+
+ // media_router::MediaRoutesObserver:
+ void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes,
+ const std::vector<media_router::MediaRoute::Id>&
+ joinable_route_ids) override;
+
+ // Toggles the preferences to always show the Media Router action icon on the
+ // toolbar.
+ void ToggleActionVisibilityPreference();
mark a. foltz 2016/09/02 22:19:09 This API is error prone: - You have to check the s
takumif 2016/09/07 21:48:33 I've changed it to SetAlwaysShowActionPref(bool al
+
+ bool HasLocalRoute() const;
+
+ // Returns the current issue, or a nullptr if there is none.
+ media_router::Issue* GetIssue() const;
mark a. foltz 2016/09/02 22:19:09 If a caller wants to find the current issue should
takumif 2016/09/07 21:48:33 When a MRAction is instantiated, it needs to know
+
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ private:
+ friend class MediaRouterActionControllerUnitTest;
mark a. foltz 2016/09/02 22:19:09 The pattern I've seen is to use FRIEND_TEST_ALL_PR
takumif 2016/09/07 21:48:33 I wanted to give the base class access to private
+
+ // Adds or removes the Media Router action icon to/from the |delegate_|,
+ // depending on whether we have issues or local routes.
+ void UpdateActionVisibility();
mark a. foltz 2016/09/02 22:19:09 Bikeshed: 1. This may be a no-op if the action is
takumif 2016/09/07 21:48:33 Done.
+
+ // Whether the preference to always show the Media Router action icon is
+ // turned on for the current profile.
+ bool ShouldAlwaysShowIcon();
mark a. foltz 2016/09/02 22:19:09 Nit: Please use 'Action' consistently to refer to
takumif 2016/09/07 21:48:33 Done.
+
+ // The profile |this| is associated with. There should be one instance of this
+ // class per profile.
+ Profile* profile_;
imcheng 2016/08/31 05:39:49 Profile* const profile_;
takumif 2016/09/07 21:48:33 Done.
+
+ // The delegate that is responsible for showing and hiding the icon on the
+ // toolbar.
mark a. foltz 2016/09/02 22:19:09 Please document ownership & why delegate_ going to
takumif 2016/09/07 21:48:33 Done.
+ extensions::ComponentMigrationHelper::ComponentActionDelegate* delegate_;
imcheng 2016/08/31 05:39:49 ...ComponentActionDelegate* const delegate_;
mark a. foltz 2016/09/02 22:19:09 component_action_delegate_
takumif 2016/09/07 21:48:33 Done.
takumif 2016/09/07 21:48:33 Done.
+
+ std::unique_ptr<media_router::Issue> issue_;
+ bool has_local_display_route_;
+
+ base::ObserverList<Observer> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(MediaRouterActionController);
+};
+
+#endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_

Powered by Google App Engine
This is Rietveld 408576698