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