Chromium Code Reviews| 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::mojom::Issue::Severity severity( | |
| 151 const media_router::IssueInfo& issue) { | |
| 152 return EnumTraits< | |
|
dcheng
2016/12/12 01:45:36
If this is typemapped, it won't be necessary to ma
imcheng
2016/12/12 19:09:12
Done.
| |
| 153 media_router::mojom::Issue::Severity, | |
| 154 media_router::IssueInfo::Severity>::ToMojom(issue.severity); | |
| 155 } | |
| 156 | |
| 157 static bool is_blocking(const media_router::IssueInfo& issue) { | |
| 158 return issue.is_blocking; | |
| 159 } | |
| 160 | |
| 161 static std::string title(const media_router::IssueInfo& issue) { | |
| 162 return issue.title; | |
| 163 } | |
| 164 | |
| 165 static base::Optional<std::string> message( | |
| 166 const media_router::IssueInfo& issue) { | |
| 167 return issue.message.empty() ? base::Optional<std::string>() | |
| 168 : base::make_optional(issue.message); | |
| 169 } | |
| 170 | |
| 171 static media_router::mojom::Issue::ActionType default_action( | |
| 172 const media_router::IssueInfo& issue) { | |
| 173 return EnumTraits< | |
| 174 media_router::mojom::Issue::ActionType, | |
| 175 media_router::IssueInfo::Action>::ToMojom(issue.default_action); | |
| 176 } | |
| 177 | |
| 178 static base::Optional<std::vector<media_router::mojom::Issue::ActionType>> | |
| 179 secondary_actions(const media_router::IssueInfo& issue) { | |
| 180 if (issue.secondary_actions.empty()) | |
| 181 return base::Optional< | |
| 182 std::vector<media_router::mojom::Issue::ActionType>>(); | |
| 183 | |
| 184 std::vector<media_router::mojom::Issue::ActionType> mojo_action_types; | |
| 185 for (const auto& action : issue.secondary_actions) | |
| 186 mojo_action_types.push_back( | |
| 187 EnumTraits<media_router::mojom::Issue::ActionType, | |
| 188 media_router::IssueInfo::Action>::ToMojom(action)); | |
| 189 | |
| 190 return base::make_optional(std::move(mojo_action_types)); | |
| 191 } | |
| 192 | |
| 193 static int32_t help_page_id(const media_router::IssueInfo& issue) { | |
| 194 return issue.help_page_id; | |
| 195 } | |
| 196 }; | |
| 197 | |
| 69 } // namespace mojo | 198 } // namespace mojo |
| 70 | 199 |
| 71 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_STRUCT_TRAITS_H_ | 200 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_STRUCT_TRAITS_H_ |
| OLD | NEW |