Commit 67461c86 authored by mark a. foltz's avatar mark a. foltz Committed by Commit Bot

[Presentation API] Remove content::PresentationConnectionCloseReason.

We'd like to remove redundant enums from content/ and chrome/ related
to the Presentation API, and the associated typemapping code.

Eventually we will eliminate all the Presentation API typemaps from content/.

This change eliminates one enum from content, others will follow.

Bug: 817903
Change-Id: I944f114886bee6a10348f33a4355262f3feb5901
Reviewed-on: https://chromium-review.googlesource.com/1003772Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarDerek Cheng <imcheng@chromium.org>
Commit-Queue: mark a. foltz <mfoltz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550659}
parent 1d26eda6
...@@ -142,7 +142,7 @@ void MediaRouterAndroid::DetachRoute(const MediaRoute::Id& route_id) { ...@@ -142,7 +142,7 @@ void MediaRouterAndroid::DetachRoute(const MediaRoute::Id& route_id) {
bridge_->DetachRoute(route_id); bridge_->DetachRoute(route_id);
RemoveRoute(route_id); RemoveRoute(route_id);
NotifyPresentationConnectionClose( NotifyPresentationConnectionClose(
route_id, content::PRESENTATION_CONNECTION_CLOSE_REASON_CLOSED, route_id, blink::mojom::PresentationConnectionCloseReason::CLOSED,
"Remove route"); "Remove route");
} }
...@@ -278,7 +278,7 @@ void MediaRouterAndroid::OnRouteClosedWithError(const MediaRoute::Id& route_id, ...@@ -278,7 +278,7 @@ void MediaRouterAndroid::OnRouteClosedWithError(const MediaRoute::Id& route_id,
RemoveRoute(route_id); RemoveRoute(route_id);
NotifyPresentationConnectionClose( NotifyPresentationConnectionClose(
route_id, route_id,
content::PRESENTATION_CONNECTION_CLOSE_REASON_CONNECTION_ERROR, blink::mojom::PresentationConnectionCloseReason::CONNECTION_ERROR,
message); message);
} }
......
...@@ -71,7 +71,7 @@ TEST_F(MediaRouterAndroidTest, DetachRoute) { ...@@ -71,7 +71,7 @@ TEST_F(MediaRouterAndroidTest, DetachRoute) {
content::PresentationConnectionStateChangeInfo change_info_closed( content::PresentationConnectionStateChangeInfo change_info_closed(
content::PRESENTATION_CONNECTION_STATE_CLOSED); content::PRESENTATION_CONNECTION_STATE_CLOSED);
change_info_closed.close_reason = change_info_closed.close_reason =
content::PRESENTATION_CONNECTION_CLOSE_REASON_CLOSED; blink::mojom::PresentationConnectionCloseReason::CLOSED;
change_info_closed.message = "Remove route"; change_info_closed.message = "Remove route";
EXPECT_CALL(callback, Run(StateChangeInfoEquals(change_info_closed))); EXPECT_CALL(callback, Run(StateChangeInfoEquals(change_info_closed)));
......
...@@ -118,7 +118,7 @@ void MediaRouterBase::NotifyPresentationConnectionStateChange( ...@@ -118,7 +118,7 @@ void MediaRouterBase::NotifyPresentationConnectionStateChange(
void MediaRouterBase::NotifyPresentationConnectionClose( void MediaRouterBase::NotifyPresentationConnectionClose(
const MediaRoute::Id& route_id, const MediaRoute::Id& route_id,
content::PresentationConnectionCloseReason reason, blink::mojom::PresentationConnectionCloseReason reason,
const std::string& message) { const std::string& message) {
auto it = presentation_connection_state_callbacks_.find(route_id); auto it = presentation_connection_state_callbacks_.find(route_id);
if (it == presentation_connection_state_callbacks_.end()) if (it == presentation_connection_state_callbacks_.end())
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "chrome/browser/media/router/media_routes_observer.h" #include "chrome/browser/media/router/media_routes_observer.h"
#include "chrome/common/media_router/media_route.h" #include "chrome/common/media_router/media_route.h"
#include "content/public/browser/media_controller.h" #include "content/public/browser/media_controller.h"
#include "third_party/blink/public/platform/modules/presentation/presentation.mojom.h"
namespace media_router { namespace media_router {
...@@ -63,7 +64,7 @@ class MediaRouterBase : public MediaRouter { ...@@ -63,7 +64,7 @@ class MediaRouterBase : public MediaRouter {
content::PresentationConnectionState state); content::PresentationConnectionState state);
void NotifyPresentationConnectionClose( void NotifyPresentationConnectionClose(
const MediaRoute::Id& route_id, const MediaRoute::Id& route_id,
content::PresentationConnectionCloseReason reason, blink::mojom::PresentationConnectionCloseReason reason,
const std::string& message); const std::string& message);
// Returns true when there is at least one MediaRoute that can be returned by // Returns true when there is at least one MediaRoute that can be returned by
......
...@@ -86,7 +86,7 @@ TEST_F(MediaRouterBaseTest, NotifyCallbacks) { ...@@ -86,7 +86,7 @@ TEST_F(MediaRouterBaseTest, NotifyCallbacks) {
content::PresentationConnectionStateChangeInfo change_info_closed( content::PresentationConnectionStateChangeInfo change_info_closed(
content::PRESENTATION_CONNECTION_STATE_CLOSED); content::PRESENTATION_CONNECTION_STATE_CLOSED);
change_info_closed.close_reason = change_info_closed.close_reason =
content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; blink::mojom::PresentationConnectionCloseReason::WENT_AWAY;
change_info_closed.message = "Test message"; change_info_closed.message = "Test message";
EXPECT_CALL(callback1, Run(StateChangeInfoEquals(change_info_connected))); EXPECT_CALL(callback1, Run(StateChangeInfoEquals(change_info_connected)));
......
...@@ -50,6 +50,27 @@ void RunRouteRequestCallbacks( ...@@ -50,6 +50,27 @@ void RunRouteRequestCallbacks(
std::move(callback).Run(*result); std::move(callback).Run(*result);
} }
// TODO(crbug.com/831416): Delete temporary code once we can use
// presentation.mojom types here.
blink::mojom::PresentationConnectionCloseReason
PresentationConnectionCloseReasonToBlink(
media_router::mojom::MediaRouter::PresentationConnectionCloseReason
reason) {
switch (reason) {
case media_router::mojom::MediaRouter::PresentationConnectionCloseReason::
CONNECTION_ERROR:
return blink::mojom::PresentationConnectionCloseReason::CONNECTION_ERROR;
case media_router::mojom::MediaRouter::PresentationConnectionCloseReason::
CLOSED:
return blink::mojom::PresentationConnectionCloseReason::CLOSED;
case media_router::mojom::MediaRouter::PresentationConnectionCloseReason::
WENT_AWAY:
return blink::mojom::PresentationConnectionCloseReason::WENT_AWAY;
}
NOTREACHED() << "Unknown PresentationConnectionCloseReason " << reason;
return blink::mojom::PresentationConnectionCloseReason::CONNECTION_ERROR;
}
} // namespace } // namespace
using SinkAvailability = mojom::MediaRouter::SinkAvailability; using SinkAvailability = mojom::MediaRouter::SinkAvailability;
...@@ -817,9 +838,10 @@ void MediaRouterMojoImpl::OnPresentationConnectionStateChanged( ...@@ -817,9 +838,10 @@ void MediaRouterMojoImpl::OnPresentationConnectionStateChanged(
void MediaRouterMojoImpl::OnPresentationConnectionClosed( void MediaRouterMojoImpl::OnPresentationConnectionClosed(
const std::string& route_id, const std::string& route_id,
content::PresentationConnectionCloseReason reason, media_router::mojom::MediaRouter::PresentationConnectionCloseReason reason,
const std::string& message) { const std::string& message) {
NotifyPresentationConnectionClose(route_id, reason, message); NotifyPresentationConnectionClose(
route_id, PresentationConnectionCloseReasonToBlink(reason), message);
} }
void MediaRouterMojoImpl::OnTerminateRouteResult( void MediaRouterMojoImpl::OnTerminateRouteResult(
......
...@@ -345,7 +345,8 @@ class MediaRouterMojoImpl : public MediaRouterBase, ...@@ -345,7 +345,8 @@ class MediaRouterMojoImpl : public MediaRouterBase,
content::PresentationConnectionState state) override; content::PresentationConnectionState state) override;
void OnPresentationConnectionClosed( void OnPresentationConnectionClosed(
const std::string& route_id, const std::string& route_id,
content::PresentationConnectionCloseReason reason, media_router::mojom::MediaRouter::PresentationConnectionCloseReason
reason,
const std::string& message) override; const std::string& message) override;
void OnRouteMessagesReceived( void OnRouteMessagesReceived(
const std::string& route_id, const std::string& route_id,
......
...@@ -942,13 +942,15 @@ TEST_F(MediaRouterMojoImplTest, PresentationConnectionStateChangedCallback) { ...@@ -942,13 +942,15 @@ TEST_F(MediaRouterMojoImplTest, PresentationConnectionStateChangedCallback) {
content::PresentationConnectionStateChangeInfo closed_info( content::PresentationConnectionStateChangeInfo closed_info(
content::PRESENTATION_CONNECTION_STATE_CLOSED); content::PRESENTATION_CONNECTION_STATE_CLOSED);
closed_info.close_reason = closed_info.close_reason =
content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; blink::mojom::PresentationConnectionCloseReason::WENT_AWAY;
closed_info.message = "Foo"; closed_info.message = "Foo";
EXPECT_CALL(callback, Run(StateChangeInfoEquals(closed_info))) EXPECT_CALL(callback, Run(StateChangeInfoEquals(closed_info)))
.WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
router()->OnPresentationConnectionClosed( router()->OnPresentationConnectionClosed(
route_id, content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY, route_id,
media_router::mojom::MediaRouter::PresentationConnectionCloseReason::
WENT_AWAY,
"Foo"); "Foo");
run_loop.Run(); run_loop.Run();
EXPECT_TRUE(Mock::VerifyAndClearExpectations(&callback)); EXPECT_TRUE(Mock::VerifyAndClearExpectations(&callback));
......
...@@ -44,10 +44,12 @@ class MockMojoMediaRouter : public MockMediaRouter, public mojom::MediaRouter { ...@@ -44,10 +44,12 @@ class MockMojoMediaRouter : public MockMediaRouter, public mojom::MediaRouter {
MOCK_METHOD2(OnPresentationConnectionStateChanged, MOCK_METHOD2(OnPresentationConnectionStateChanged,
void(const std::string& route_id, void(const std::string& route_id,
content::PresentationConnectionState state)); content::PresentationConnectionState state));
MOCK_METHOD3(OnPresentationConnectionClosed, MOCK_METHOD3(
void(const std::string& route_id, OnPresentationConnectionClosed,
content::PresentationConnectionCloseReason reason, void(const std::string& route_id,
const std::string& message)); media_router::mojom::MediaRouter::PresentationConnectionCloseReason
reason,
const std::string& message));
MOCK_METHOD2(OnRouteMessagesReceived, MOCK_METHOD2(OnRouteMessagesReceived,
void(const std::string& route_id, void(const std::string& route_id,
const std::vector<content::PresentationConnectionMessage>& const std::vector<content::PresentationConnectionMessage>&
......
...@@ -466,7 +466,7 @@ interface MediaRouter { ...@@ -466,7 +466,7 @@ interface MediaRouter {
AVAILABLE AVAILABLE
}; };
// Keep in sync with content/public/common/presentation_info.h. // TODO(crbug.com/831416): Remove and use presentation.mojom type instead.
enum PresentationConnectionState { enum PresentationConnectionState {
CONNECTING, CONNECTING,
CONNECTED, CONNECTED,
...@@ -474,7 +474,7 @@ interface MediaRouter { ...@@ -474,7 +474,7 @@ interface MediaRouter {
TERMINATED TERMINATED
}; };
// Keep in sync with content/public/common/presentation_info.h. // TODO(crbug.com/831416): Remove and use presentation.mojom type instead.
enum PresentationConnectionCloseReason { enum PresentationConnectionCloseReason {
CONNECTION_ERROR, CONNECTION_ERROR,
CLOSED, CLOSED,
......
...@@ -34,7 +34,6 @@ type_mappings = [ ...@@ -34,7 +34,6 @@ type_mappings = [
"media_router.mojom.Issue.Severity=media_router::IssueInfo::Severity", "media_router.mojom.Issue.Severity=media_router::IssueInfo::Severity",
"media_router.mojom.MediaRoute=media_router::MediaRoute", "media_router.mojom.MediaRoute=media_router::MediaRoute",
"media_router.mojom.MediaRouteProvider.Id=media_router::MediaRouteProviderId", "media_router.mojom.MediaRouteProvider.Id=media_router::MediaRouteProviderId",
"media_router.mojom.MediaRouter.PresentationConnectionCloseReason=content::PresentationConnectionCloseReason",
"media_router.mojom.MediaRouter.PresentationConnectionState=content::PresentationConnectionState", "media_router.mojom.MediaRouter.PresentationConnectionState=content::PresentationConnectionState",
"media_router.mojom.MediaSink=media_router::MediaSinkInternal", "media_router.mojom.MediaSink=media_router::MediaSinkInternal",
"media_router.mojom.RouteMessage=content::PresentationConnectionMessage", "media_router.mojom.RouteMessage=content::PresentationConnectionMessage",
......
...@@ -498,52 +498,6 @@ struct EnumTraits<media_router::mojom::MediaRouter::PresentationConnectionState, ...@@ -498,52 +498,6 @@ struct EnumTraits<media_router::mojom::MediaRouter::PresentationConnectionState,
} }
}; };
// PresentationConnectionCloseReason
template <>
struct EnumTraits<
media_router::mojom::MediaRouter::PresentationConnectionCloseReason,
content::PresentationConnectionCloseReason> {
static media_router::mojom::MediaRouter::PresentationConnectionCloseReason
ToMojom(content::PresentationConnectionCloseReason reason) {
switch (reason) {
case content::PRESENTATION_CONNECTION_CLOSE_REASON_CONNECTION_ERROR:
return media_router::mojom::MediaRouter::
PresentationConnectionCloseReason::CONNECTION_ERROR;
case content::PRESENTATION_CONNECTION_CLOSE_REASON_CLOSED:
return media_router::mojom::MediaRouter::
PresentationConnectionCloseReason::CLOSED;
case content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY:
return media_router::mojom::MediaRouter::
PresentationConnectionCloseReason::WENT_AWAY;
}
NOTREACHED() << "Unknown PresentationConnectionCloseReason "
<< static_cast<int>(reason);
return media_router::mojom::MediaRouter::PresentationConnectionCloseReason::
CONNECTION_ERROR;
}
static bool FromMojom(
media_router::mojom::MediaRouter::PresentationConnectionCloseReason input,
content::PresentationConnectionCloseReason* state) {
switch (input) {
case media_router::mojom::MediaRouter::PresentationConnectionCloseReason::
CONNECTION_ERROR:
*state = content::PRESENTATION_CONNECTION_CLOSE_REASON_CONNECTION_ERROR;
return true;
case media_router::mojom::MediaRouter::PresentationConnectionCloseReason::
CLOSED:
*state = content::PRESENTATION_CONNECTION_CLOSE_REASON_CLOSED;
return true;
case media_router::mojom::MediaRouter::PresentationConnectionCloseReason::
WENT_AWAY:
*state = content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY;
return true;
}
return false;
}
};
// RouteRequestResultCode // RouteRequestResultCode
template <> template <>
......
...@@ -241,7 +241,7 @@ class MockPresentationController : public blink::mojom::PresentationController { ...@@ -241,7 +241,7 @@ class MockPresentationController : public blink::mojom::PresentationController {
PresentationConnectionState new_state)); PresentationConnectionState new_state));
MOCK_METHOD3(OnConnectionClosed, MOCK_METHOD3(OnConnectionClosed,
void(const PresentationInfo& connection, void(const PresentationInfo& connection,
PresentationConnectionCloseReason reason, blink::mojom::PresentationConnectionCloseReason reason,
const std::string& message)); const std::string& message));
// PresentationConnectionMessage is move-only. // PresentationConnectionMessage is move-only.
void OnConnectionMessagesReceived( void OnConnectionMessagesReceived(
...@@ -483,13 +483,15 @@ TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { ...@@ -483,13 +483,15 @@ TEST_F(PresentationServiceImplTest, ListenForConnectionClose) {
PresentationInfo presentation_connection(presentation_url1_, kPresentationId); PresentationInfo presentation_connection(presentation_url1_, kPresentationId);
PresentationConnectionStateChangeInfo closed_info( PresentationConnectionStateChangeInfo closed_info(
PRESENTATION_CONNECTION_STATE_CLOSED); PRESENTATION_CONNECTION_STATE_CLOSED);
closed_info.close_reason = PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; closed_info.close_reason =
blink::mojom::PresentationConnectionCloseReason::WENT_AWAY;
closed_info.message = "Foo"; closed_info.message = "Foo";
EXPECT_CALL(mock_controller_, EXPECT_CALL(
OnConnectionClosed(InfoEquals(presentation_connection), mock_controller_,
PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY, OnConnectionClosed(
"Foo")); InfoEquals(presentation_connection),
blink::mojom::PresentationConnectionCloseReason::WENT_AWAY, "Foo"));
state_changed_cb.Run(closed_info); state_changed_cb.Run(closed_info);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
......
...@@ -13,7 +13,6 @@ deps = [ ...@@ -13,7 +13,6 @@ deps = [
"//url", "//url",
] ]
type_mappings = [ type_mappings = [
"blink.mojom.PresentationConnectionCloseReason=content::PresentationConnectionCloseReason",
"blink.mojom.PresentationConnectionMessage=content::PresentationConnectionMessage[move_only]", "blink.mojom.PresentationConnectionMessage=content::PresentationConnectionMessage[move_only]",
"blink.mojom.PresentationConnectionState=content::PresentationConnectionState", "blink.mojom.PresentationConnectionState=content::PresentationConnectionState",
"blink.mojom.PresentationError=content::PresentationError", "blink.mojom.PresentationError=content::PresentationError",
......
...@@ -104,43 +104,6 @@ struct EnumTraits<blink::mojom::PresentationConnectionState, ...@@ -104,43 +104,6 @@ struct EnumTraits<blink::mojom::PresentationConnectionState,
} }
}; };
template <>
struct EnumTraits<blink::mojom::PresentationConnectionCloseReason,
content::PresentationConnectionCloseReason> {
static blink::mojom::PresentationConnectionCloseReason ToMojom(
content::PresentationConnectionCloseReason input) {
switch (input) {
case content::PRESENTATION_CONNECTION_CLOSE_REASON_CONNECTION_ERROR:
return blink::mojom::PresentationConnectionCloseReason::
CONNECTION_ERROR;
case content::PRESENTATION_CONNECTION_CLOSE_REASON_CLOSED:
return blink::mojom::PresentationConnectionCloseReason::CLOSED;
case content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY:
return blink::mojom::PresentationConnectionCloseReason::WENT_AWAY;
}
NOTREACHED() << "Unknown content::PresentationConnectionCloseReason "
<< static_cast<int>(input);
return blink::mojom::PresentationConnectionCloseReason::CONNECTION_ERROR;
}
static bool FromMojom(blink::mojom::PresentationConnectionCloseReason input,
content::PresentationConnectionCloseReason* output) {
switch (input) {
case blink::mojom::PresentationConnectionCloseReason::CONNECTION_ERROR:
*output =
content::PRESENTATION_CONNECTION_CLOSE_REASON_CONNECTION_ERROR;
return true;
case blink::mojom::PresentationConnectionCloseReason::CLOSED:
*output = content::PRESENTATION_CONNECTION_CLOSE_REASON_CLOSED;
return true;
case blink::mojom::PresentationConnectionCloseReason::WENT_AWAY:
*output = content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY;
return true;
}
return false;
}
};
template <> template <>
struct StructTraits<blink::mojom::PresentationInfoDataView, struct StructTraits<blink::mojom::PresentationInfoDataView,
content::PresentationInfo> { content::PresentationInfo> {
......
...@@ -33,13 +33,15 @@ struct PresentationConnectionStateChangeInfo { ...@@ -33,13 +33,15 @@ struct PresentationConnectionStateChangeInfo {
explicit PresentationConnectionStateChangeInfo( explicit PresentationConnectionStateChangeInfo(
PresentationConnectionState state) PresentationConnectionState state)
: state(state), : state(state),
close_reason(PRESENTATION_CONNECTION_CLOSE_REASON_CONNECTION_ERROR) {} close_reason(
blink::mojom::PresentationConnectionCloseReason::CONNECTION_ERROR) {
}
~PresentationConnectionStateChangeInfo() = default; ~PresentationConnectionStateChangeInfo() = default;
PresentationConnectionState state; PresentationConnectionState state;
// |close_reason| and |messsage| are only used for state change to CLOSED. // |close_reason| and |messsage| are only used for state change to CLOSED.
PresentationConnectionCloseReason close_reason; blink::mojom::PresentationConnectionCloseReason close_reason;
std::string message; std::string message;
}; };
......
...@@ -19,14 +19,6 @@ enum PresentationConnectionState { ...@@ -19,14 +19,6 @@ enum PresentationConnectionState {
PRESENTATION_CONNECTION_STATE_TERMINATED PRESENTATION_CONNECTION_STATE_TERMINATED
}; };
// TODO(imcheng): Use WENT_AWAY for 1-UA mode when it is implemented
// (crbug.com/513859).
enum PresentationConnectionCloseReason {
PRESENTATION_CONNECTION_CLOSE_REASON_CONNECTION_ERROR,
PRESENTATION_CONNECTION_CLOSE_REASON_CLOSED,
PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY
};
// Represents a presentation that has been established via either // Represents a presentation that has been established via either
// browser actions or Presentation API. // browser actions or Presentation API.
struct CONTENT_EXPORT PresentationInfo { struct CONTENT_EXPORT PresentationInfo {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment