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

Unified Diff: content/common/push_messaging_param_traits.cc

Issue 2690203003: Convert push_messaging IPC msgs into mojo interfaces (Closed)
Patch Set: format push_messaging.mojom, less than 80 col Created 3 years, 10 months 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: content/common/push_messaging_param_traits.cc
diff --git a/content/common/push_messaging_param_traits.cc b/content/common/push_messaging_param_traits.cc
new file mode 100644
index 0000000000000000000000000000000000000000..aa1d30efe8298f04eab14ffe73521f8b839a903f
--- /dev/null
+++ b/content/common/push_messaging_param_traits.cc
@@ -0,0 +1,131 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/push_messaging_param_traits.h"
+
+namespace mojo {
+
+static_assert(content::PushRegistrationStatus::PUSH_REGISTRATION_STATUS_LAST ==
+ static_cast<content::PushRegistrationStatus>(
+ content::mojom::PushRegistrationStatus::LAST),
+ "PushRegistrationStatus enums must match");
+
+static_assert(blink::WebPushError::ErrorType::ErrorTypeLast ==
+ static_cast<blink::WebPushError::ErrorType>(
+ content::mojom::PushErrorType::LAST),
+ "PushErrorType enums must match");
+
+static_assert(
+ content::PushGetRegistrationStatus::PUSH_GETREGISTRATION_STATUS_LAST ==
+ static_cast<content::PushGetRegistrationStatus>(
+ content::mojom::PushGetRegistrationStatus::LAST),
+ "PushGetRegistrationStatus enums must match");
+
+static_assert(blink::WebPushPermissionStatus::WebPushPermissionStatusLast ==
+ static_cast<blink::WebPushPermissionStatus>(
+ content::mojom::PushPermissionStatus::LAST),
+ "PushPermissionStatus enums must match");
+
+// static
+bool StructTraits<content::mojom::PushSubscriptionOptionsDataView,
+ content::PushSubscriptionOptions>::
+ Read(content::mojom::PushSubscriptionOptionsDataView data,
+ content::PushSubscriptionOptions* out) {
+ out->user_visible_only = data.user_visible_only();
+ if (!data.ReadSenderInfo(&out->sender_info))
+ return false;
+
+ return true;
+}
+
+// static
+content::mojom::PushRegistrationStatus EnumTraits<
+ content::mojom::PushRegistrationStatus,
+ content::PushRegistrationStatus>::ToMojom(content::PushRegistrationStatus
+ input) {
+ CHECK(input >= content::PushRegistrationStatus::
Tom Sepez 2017/02/17 19:27:37 Which process calls this (and will be terminated i
Peter Beverloo 2017/02/17 19:40:43 Good point. These probably should be if-statements
ke.he 2017/02/18 01:59:57 Done.
+ PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE &&
+ input <=
+ content::PushRegistrationStatus::PUSH_REGISTRATION_STATUS_LAST);
+ return static_cast<content::mojom::PushRegistrationStatus>(input);
Tom Sepez 2017/02/17 19:27:37 Typically, there's a switch statement here explici
Peter Beverloo 2017/02/17 19:40:43 Unless you feel strongly, I highly prefer this ove
+}
+
+// static
+bool EnumTraits<content::mojom::PushRegistrationStatus,
+ content::PushRegistrationStatus>::
+ FromMojom(content::mojom::PushRegistrationStatus input,
+ content::PushRegistrationStatus* output) {
+ CHECK(input >=
+ content::mojom::PushRegistrationStatus::SUCCESS_FROM_PUSH_SERVICE &&
+ input <= content::mojom::PushRegistrationStatus::LAST);
+ *output = static_cast<content::PushRegistrationStatus>(input);
+ return true;
+}
+
+// static
+content::mojom::PushErrorType
+EnumTraits<content::mojom::PushErrorType, blink::WebPushError::ErrorType>::
+ ToMojom(blink::WebPushError::ErrorType input) {
+ CHECK(input >= blink::WebPushError::ErrorType::ErrorTypeAbort &&
+ input <= blink::WebPushError::ErrorType::ErrorTypeInvalidState);
+ return static_cast<content::mojom::PushErrorType>(input);
+}
+
+// static
+bool EnumTraits<content::mojom::PushErrorType, blink::WebPushError::ErrorType>::
+ FromMojom(content::mojom::PushErrorType input,
+ blink::WebPushError::ErrorType* output) {
+ CHECK(input >= content::mojom::PushErrorType::ABORT &&
+ input <= content::mojom::PushErrorType::INVALID_STATE);
+ *output = static_cast<blink::WebPushError::ErrorType>(input);
+ return true;
+}
+
+// static
+content::mojom::PushGetRegistrationStatus
+EnumTraits<content::mojom::PushGetRegistrationStatus,
+ content::PushGetRegistrationStatus>::
+ ToMojom(content::PushGetRegistrationStatus input) {
+ CHECK(
+ input >= content::PushGetRegistrationStatus::
+ PUSH_GETREGISTRATION_STATUS_SUCCESS &&
+ input <=
+ content::PushGetRegistrationStatus::PUSH_GETREGISTRATION_STATUS_LAST);
+ return static_cast<content::mojom::PushGetRegistrationStatus>(input);
+}
+
+// static
+bool EnumTraits<content::mojom::PushGetRegistrationStatus,
+ content::PushGetRegistrationStatus>::
+ FromMojom(content::mojom::PushGetRegistrationStatus input,
+ content::PushGetRegistrationStatus* output) {
+ CHECK(input >= content::mojom::PushGetRegistrationStatus::SUCCESS &&
+ input <= content::mojom::PushGetRegistrationStatus::LAST);
+ *output = static_cast<content::PushGetRegistrationStatus>(input);
+ return true;
+}
+
+// static
+content::mojom::PushPermissionStatus EnumTraits<
+ content::mojom::PushPermissionStatus,
+ blink::WebPushPermissionStatus>::ToMojom(blink::WebPushPermissionStatus
+ input) {
+ CHECK(input >=
+ blink::WebPushPermissionStatus::WebPushPermissionStatusGranted &&
+ input <= blink::WebPushPermissionStatus::WebPushPermissionStatusLast);
+ return static_cast<content::mojom::PushPermissionStatus>(input);
+}
+
+// static
+bool EnumTraits<content::mojom::PushPermissionStatus,
+ blink::WebPushPermissionStatus>::
+ FromMojom(content::mojom::PushPermissionStatus input,
+ blink::WebPushPermissionStatus* output) {
+ CHECK(input >= content::mojom::PushPermissionStatus::GRANTED &&
+ input <= content::mojom::PushPermissionStatus::LAST);
+ *output = static_cast<blink::WebPushPermissionStatus>(input);
+ return true;
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698