| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_STRUCT_TRAITS_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_STRUCT_TRAITS_H_ |
| 6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_STRUCT_TRAITS_H_ | 6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_STRUCT_TRAITS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "chrome/browser/media/router/issue.h" |
| 10 #include "chrome/browser/media/router/mojo/media_router.mojom.h" | 11 #include "chrome/browser/media/router/mojo/media_router.mojom.h" |
| 11 #include "mojo/common/common_custom_types_struct_traits.h" | 12 #include "mojo/common/common_custom_types_struct_traits.h" |
| 12 | 13 |
| 13 namespace mojo { | 14 namespace mojo { |
| 14 | 15 |
| 15 template <> | 16 template <> |
| 17 struct EnumTraits<media_router::mojom::Issue::ActionType, |
| 18 media_router::IssueInfo::Action> { |
| 19 static media_router::mojom::Issue::ActionType ToMojom( |
| 20 media_router::IssueInfo::Action action) { |
| 21 switch (action) { |
| 22 case media_router::IssueInfo::Action::DISMISS: |
| 23 return media_router::mojom::Issue::ActionType::DISMISS; |
| 24 case media_router::IssueInfo::Action::LEARN_MORE: |
| 25 return media_router::mojom::Issue::ActionType::LEARN_MORE; |
| 26 } |
| 27 NOTREACHED() << "Unknown issue action type " << static_cast<int>(action); |
| 28 return media_router::mojom::Issue::ActionType::DISMISS; |
| 29 } |
| 30 |
| 31 static bool FromMojom(media_router::mojom::Issue::ActionType input, |
| 32 media_router::IssueInfo::Action* output) { |
| 33 switch (input) { |
| 34 case media_router::mojom::Issue::ActionType::DISMISS: |
| 35 *output = media_router::IssueInfo::Action::DISMISS; |
| 36 return true; |
| 37 case media_router::mojom::Issue::ActionType::LEARN_MORE: |
| 38 *output = media_router::IssueInfo::Action::LEARN_MORE; |
| 39 return true; |
| 40 } |
| 41 return false; |
| 42 } |
| 43 }; |
| 44 |
| 45 template <> |
| 46 struct EnumTraits<media_router::mojom::Issue::Severity, |
| 47 media_router::IssueInfo::Severity> { |
| 48 static media_router::mojom::Issue::Severity ToMojom( |
| 49 media_router::IssueInfo::Severity severity) { |
| 50 switch (severity) { |
| 51 case media_router::IssueInfo::Severity::FATAL: |
| 52 return media_router::mojom::Issue::Severity::FATAL; |
| 53 case media_router::IssueInfo::Severity::WARNING: |
| 54 return media_router::mojom::Issue::Severity::WARNING; |
| 55 case media_router::IssueInfo::Severity::NOTIFICATION: |
| 56 return media_router::mojom::Issue::Severity::NOTIFICATION; |
| 57 } |
| 58 NOTREACHED() << "Unknown issue severity " << static_cast<int>(severity); |
| 59 return media_router::mojom::Issue::Severity::WARNING; |
| 60 } |
| 61 |
| 62 static bool FromMojom(media_router::mojom::Issue::Severity input, |
| 63 media_router::IssueInfo::Severity* output) { |
| 64 switch (input) { |
| 65 case media_router::mojom::Issue::Severity::FATAL: |
| 66 *output = media_router::IssueInfo::Severity::FATAL; |
| 67 return true; |
| 68 case media_router::mojom::Issue::Severity::WARNING: |
| 69 *output = media_router::IssueInfo::Severity::WARNING; |
| 70 return true; |
| 71 case media_router::mojom::Issue::Severity::NOTIFICATION: |
| 72 *output = media_router::IssueInfo::Severity::NOTIFICATION; |
| 73 return true; |
| 74 } |
| 75 return false; |
| 76 } |
| 77 }; |
| 78 |
| 79 template <> |
| 16 struct StructTraits<media_router::mojom::RouteMessageDataView, | 80 struct StructTraits<media_router::mojom::RouteMessageDataView, |
| 17 media_router::RouteMessage> { | 81 media_router::RouteMessage> { |
| 18 static media_router::mojom::RouteMessage::Type type( | 82 static media_router::mojom::RouteMessage::Type type( |
| 19 const media_router::RouteMessage& msg) { | 83 const media_router::RouteMessage& msg) { |
| 20 switch (msg.type) { | 84 switch (msg.type) { |
| 21 case media_router::RouteMessage::TEXT: | 85 case media_router::RouteMessage::TEXT: |
| 22 return media_router::mojom::RouteMessage::Type::TEXT; | 86 return media_router::mojom::RouteMessage::Type::TEXT; |
| 23 case media_router::RouteMessage::BINARY: | 87 case media_router::RouteMessage::BINARY: |
| 24 return media_router::mojom::RouteMessage::Type::BINARY; | 88 return media_router::mojom::RouteMessage::Type::BINARY; |
| 25 } | 89 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 out->binary = std::move(binary); | 123 out->binary = std::move(binary); |
| 60 break; | 124 break; |
| 61 } | 125 } |
| 62 default: | 126 default: |
| 63 return false; | 127 return false; |
| 64 } | 128 } |
| 65 return true; | 129 return true; |
| 66 } | 130 } |
| 67 }; | 131 }; |
| 68 | 132 |
| 133 template <> |
| 134 struct StructTraits<media_router::mojom::IssueDataView, |
| 135 media_router::IssueInfo> { |
| 136 static bool Read(media_router::mojom::IssueDataView data, |
| 137 media_router::IssueInfo* out); |
| 138 |
| 139 static base::Optional<std::string> route_id( |
| 140 const media_router::IssueInfo& issue) { |
| 141 return issue.route_id.empty() ? base::Optional<std::string>() |
| 142 : base::make_optional(issue.route_id); |
| 143 } |
| 144 |
| 145 static media_router::IssueInfo::Severity severity( |
| 146 const media_router::IssueInfo& issue) { |
| 147 return issue.severity; |
| 148 } |
| 149 |
| 150 static bool is_blocking(const media_router::IssueInfo& issue) { |
| 151 return issue.is_blocking; |
| 152 } |
| 153 |
| 154 static std::string title(const media_router::IssueInfo& issue) { |
| 155 return issue.title; |
| 156 } |
| 157 |
| 158 static base::Optional<std::string> message( |
| 159 const media_router::IssueInfo& issue) { |
| 160 return issue.message.empty() ? base::Optional<std::string>() |
| 161 : base::make_optional(issue.message); |
| 162 } |
| 163 |
| 164 static media_router::IssueInfo::Action default_action( |
| 165 const media_router::IssueInfo& issue) { |
| 166 return issue.default_action; |
| 167 } |
| 168 |
| 169 static base::Optional<std::vector<media_router::IssueInfo::Action>> |
| 170 secondary_actions(const media_router::IssueInfo& issue) { |
| 171 return issue.secondary_actions; |
| 172 } |
| 173 |
| 174 static int32_t help_page_id(const media_router::IssueInfo& issue) { |
| 175 return issue.help_page_id; |
| 176 } |
| 177 }; |
| 178 |
| 69 } // namespace mojo | 179 } // namespace mojo |
| 70 | 180 |
| 71 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_STRUCT_TRAITS_H_ | 181 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_STRUCT_TRAITS_H_ |
| OLD | NEW |