OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/media/router/media_router_base.h" | 5 #include "chrome/browser/media/router/media_router_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/guid.h" | 8 #include "base/guid.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #if !defined(OS_ANDROID) | |
14 #include "chrome/browser/ui/toolbar/media_router_action_controller.h" | |
15 #endif | |
13 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
14 | 17 |
15 namespace media_router { | 18 namespace media_router { |
16 | 19 |
17 // A MediaRoutesObserver that maintains state about the current set of media | 20 // A MediaRoutesObserver that maintains state about the current set of media |
18 // routes. | 21 // routes. |
19 class MediaRouterBase::InternalMediaRoutesObserver | 22 class MediaRouterBase::InternalMediaRoutesObserver |
20 : public MediaRoutesObserver { | 23 : public MediaRoutesObserver { |
21 public: | 24 public: |
22 explicit InternalMediaRoutesObserver(MediaRouter* router) | 25 explicit InternalMediaRoutesObserver(MediaRouter* router) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 } | 68 } |
66 | 69 |
67 return callbacks->Add(callback); | 70 return callbacks->Add(callback); |
68 } | 71 } |
69 | 72 |
70 void MediaRouterBase::OnIncognitoProfileShutdown() { | 73 void MediaRouterBase::OnIncognitoProfileShutdown() { |
71 for (const auto& route_id : internal_routes_observer_->incognito_route_ids) | 74 for (const auto& route_id : internal_routes_observer_->incognito_route_ids) |
72 TerminateRoute(route_id); | 75 TerminateRoute(route_id); |
73 } | 76 } |
74 | 77 |
75 MediaRouterBase::MediaRouterBase() : initialized_(false) {} | 78 #if !defined(OS_ANDROID) |
79 MediaRouterActionController* MediaRouterBase::GetActionController() { | |
80 return action_controller_.get(); | |
81 } | |
82 #endif | |
83 | |
84 MediaRouterBase::MediaRouterBase(Profile* profile) | |
85 : initialized_(false), | |
86 profile_(profile) {} | |
76 | 87 |
77 // static | 88 // static |
78 std::string MediaRouterBase::CreatePresentationId() { | 89 std::string MediaRouterBase::CreatePresentationId() { |
79 return "mr_" + base::GenerateGUID(); | 90 return "mr_" + base::GenerateGUID(); |
80 } | 91 } |
81 | 92 |
82 void MediaRouterBase::NotifyPresentationConnectionStateChange( | 93 void MediaRouterBase::NotifyPresentationConnectionStateChange( |
83 const MediaRoute::Id& route_id, | 94 const MediaRoute::Id& route_id, |
84 content::PresentationConnectionState state) { | 95 content::PresentationConnectionState state) { |
85 auto* callbacks = presentation_connection_state_callbacks_.get(route_id); | 96 auto* callbacks = presentation_connection_state_callbacks_.get(route_id); |
(...skipping 17 matching lines...) Expand all Loading... | |
103 info.message = message; | 114 info.message = message; |
104 callbacks->Notify(info); | 115 callbacks->Notify(info); |
105 } | 116 } |
106 | 117 |
107 bool MediaRouterBase::HasJoinableRoute() const { | 118 bool MediaRouterBase::HasJoinableRoute() const { |
108 return internal_routes_observer_->has_route; | 119 return internal_routes_observer_->has_route; |
109 } | 120 } |
110 | 121 |
111 void MediaRouterBase::Initialize() { | 122 void MediaRouterBase::Initialize() { |
112 DCHECK(!initialized_); | 123 DCHECK(!initialized_); |
113 // The observer calls virtual methods on MediaRouter; it must be created | 124 // |internal_routes_observer_| and |action_controller_| call virtual methods |
114 // outside of the ctor | 125 // on MediaRouter; they must be created outside of the ctor. |
115 internal_routes_observer_.reset(new InternalMediaRoutesObserver(this)); | 126 internal_routes_observer_.reset(new InternalMediaRoutesObserver(this)); |
127 #if !defined(OS_ANDROID) | |
128 // TODO(takumif): Actually instantiate MediaRouterActionController here to | |
129 // enable ephemeral toolbar icon. | |
130 action_controller_.reset(); | |
mark a. foltz
2016/09/02 22:19:09
Can this TODO be done now?
takumif
2016/09/07 21:48:32
We need to change MRAction to use MRActionControll
| |
131 #endif | |
132 | |
116 initialized_ = true; | 133 initialized_ = true; |
117 } | 134 } |
118 | 135 |
119 void MediaRouterBase::OnPresentationConnectionStateCallbackRemoved( | 136 void MediaRouterBase::OnPresentationConnectionStateCallbackRemoved( |
120 const MediaRoute::Id& route_id) { | 137 const MediaRoute::Id& route_id) { |
121 auto* callbacks = presentation_connection_state_callbacks_.get(route_id); | 138 auto* callbacks = presentation_connection_state_callbacks_.get(route_id); |
122 if (callbacks && callbacks->empty()) | 139 if (callbacks && callbacks->empty()) |
123 presentation_connection_state_callbacks_.erase(route_id); | 140 presentation_connection_state_callbacks_.erase(route_id); |
124 } | 141 } |
125 | 142 |
126 void MediaRouterBase::Shutdown() { | 143 void MediaRouterBase::Shutdown() { |
127 // The observer calls virtual methods on MediaRouter; it must be destroyed | 144 // |internal_routes_observer_| and |action_controller_| call virtual methods |
128 // outside of the dtor | 145 // on MediaRouter; they must be destroyed outside of the dtor. |
129 internal_routes_observer_.reset(); | 146 internal_routes_observer_.reset(); |
147 #if !defined(OS_ANDROID) | |
148 action_controller_.reset(); | |
149 #endif | |
130 } | 150 } |
131 | 151 |
132 } // namespace media_router | 152 } // namespace media_router |
OLD | NEW |