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

Unified Diff: chrome/browser/media/router/media_router_base.cc

Issue 2463843003: [Presentation API] Media Router: queue PresentationConnectionStateChanged events fired before callb… (Closed)
Patch Set: Created 4 years, 1 month 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/media/router/media_router_base.cc
diff --git a/chrome/browser/media/router/media_router_base.cc b/chrome/browser/media/router/media_router_base.cc
index 60f85c88b331990f8b00d668b2b9a904895a6fce..a65f812e09f28df199b7acfcdce573fcb6d02b51 100644
--- a/chrome/browser/media/router/media_router_base.cc
+++ b/chrome/browser/media/router/media_router_base.cc
@@ -64,7 +64,13 @@ MediaRouterBase::AddPresentationConnectionStateChangedCallback(
base::WrapUnique(callbacks));
}
- return callbacks->Add(callback);
+ auto subscription = callbacks->Add(callback);
+ auto queued_state_change = queued_state_changes_.find(route_id);
+ if (queued_state_change != queued_state_changes_.end()) {
+ callbacks->Notify(queued_state_change->second);
+ queued_state_changes_.erase(queued_state_change);
+ }
+ return subscription;
}
void MediaRouterBase::OnIncognitoProfileShutdown() {
@@ -85,26 +91,36 @@ void MediaRouterBase::NotifyPresentationConnectionStateChange(
// We should call NotifyPresentationConnectionClose() for the CLOSED state.
DCHECK_NE(state, content::PRESENTATION_CONNECTION_STATE_CLOSED);
- auto* callbacks = presentation_connection_state_callbacks_.get(route_id);
- if (!callbacks)
- return;
-
- callbacks->Notify(content::PresentationConnectionStateChangeInfo(state));
+ content::PresentationConnectionStateChangeInfo info(state);
+ NotifyPresentationConnectionStateChange(route_id, info);
}
void MediaRouterBase::NotifyPresentationConnectionClose(
const MediaRoute::Id& route_id,
content::PresentationConnectionCloseReason reason,
const std::string& message) {
- auto* callbacks = presentation_connection_state_callbacks_.get(route_id);
- if (!callbacks)
- return;
-
content::PresentationConnectionStateChangeInfo info(
content::PRESENTATION_CONNECTION_STATE_CLOSED);
info.close_reason = reason;
info.message = message;
- callbacks->Notify(info);
+ NotifyPresentationConnectionStateChange(route_id, info);
+}
+
+void MediaRouterBase::NotifyPresentationConnectionStateChange(
+ const MediaRoute::Id& route_id,
+ const content::PresentationConnectionStateChangeInfo& info) {
+ auto* callbacks = presentation_connection_state_callbacks_.get(route_id);
+
+ if (callbacks) {
+ callbacks->Notify(info);
+ return;
+ }
+
+ auto queued_state_change = queued_state_changes_.find(route_id);
+ if (queued_state_change == queued_state_changes_.end())
+ queued_state_changes_.insert(std::make_pair(route_id, info));
imcheng 2016/11/01 20:09:19 If we never added a state change callback, would t
+ else
+ queued_state_change->second = info;
}
bool MediaRouterBase::HasJoinableRoute() const {
« no previous file with comments | « chrome/browser/media/router/media_router_base.h ('k') | chrome/browser/media/router/media_router_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698