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

Unified Diff: services/resource_coordinator/public/cpp/coordination_unit_struct_traits.cc

Issue 2798713002: Global Resource Coordinator: Basic service internals (Closed)
Patch Set: Wrap EventType directly in resource_coordinator namespace when using helper Created 3 years, 8 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: services/resource_coordinator/public/cpp/coordination_unit_struct_traits.cc
diff --git a/services/resource_coordinator/public/cpp/coordination_unit_struct_traits.cc b/services/resource_coordinator/public/cpp/coordination_unit_struct_traits.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0a1d2359270ef2849f6bb829590cc59d11f5beb4
--- /dev/null
+++ b/services/resource_coordinator/public/cpp/coordination_unit_struct_traits.cc
@@ -0,0 +1,71 @@
+// 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 "services/resource_coordinator/public/cpp/coordination_unit_struct_traits.h"
+
+namespace mojo {
+
+// static
+resource_coordinator::mojom::CoordinationUnitType
+EnumTraits<resource_coordinator::mojom::CoordinationUnitType,
+ resource_coordinator::CoordinationUnitType>::
+ ToMojom(resource_coordinator::CoordinationUnitType type) {
+ switch (type) {
+ case resource_coordinator::CoordinationUnitType::INVALID_TYPE:
+ return resource_coordinator::mojom::CoordinationUnitType::INVALID_TYPE;
+ case resource_coordinator::CoordinationUnitType::WEBCONTENTS:
+ return resource_coordinator::mojom::CoordinationUnitType::WEBCONTENTS;
+ case resource_coordinator::CoordinationUnitType::FRAME:
+ return resource_coordinator::mojom::CoordinationUnitType::FRAME;
+ case resource_coordinator::CoordinationUnitType::NAVIGATION:
+ return resource_coordinator::mojom::CoordinationUnitType::NAVIGATION;
+ case resource_coordinator::CoordinationUnitType::PROCESS:
+ return resource_coordinator::mojom::CoordinationUnitType::PROCESS;
+ default:
+ CHECK(false) << "Invalid type: " << static_cast<uint8_t>(type);
dcheng 2017/04/18 05:40:46 NOTREACHED() is more appropriate here.
oystein (OOO til 10th of July) 2017/04/18 20:55:33 Done.
+ // This should not be reached. Just return a random value.
+ return resource_coordinator::mojom::CoordinationUnitType::INVALID_TYPE;
+ }
+}
+
+// static
+bool EnumTraits<resource_coordinator::mojom::CoordinationUnitType,
+ resource_coordinator::CoordinationUnitType>::
+ FromMojom(resource_coordinator::mojom::CoordinationUnitType input,
+ resource_coordinator::CoordinationUnitType* out) {
+ switch (input) {
+ case resource_coordinator::mojom::CoordinationUnitType::INVALID_TYPE:
+ *out = resource_coordinator::CoordinationUnitType::INVALID_TYPE;
+ break;
+ case resource_coordinator::mojom::CoordinationUnitType::WEBCONTENTS:
+ *out = resource_coordinator::CoordinationUnitType::WEBCONTENTS;
+ break;
+ case resource_coordinator::mojom::CoordinationUnitType::FRAME:
+ *out = resource_coordinator::CoordinationUnitType::FRAME;
+ break;
+ case resource_coordinator::mojom::CoordinationUnitType::NAVIGATION:
+ *out = resource_coordinator::CoordinationUnitType::NAVIGATION;
+ break;
+ case resource_coordinator::mojom::CoordinationUnitType::PROCESS:
+ *out = resource_coordinator::CoordinationUnitType::PROCESS;
+ break;
+ default:
+ NOTREACHED() << "Invalid type: " << static_cast<uint8_t>(input);
+ return false;
+ }
+ return true;
+}
+
+// static
+bool StructTraits<resource_coordinator::mojom::CoordinationUnitIDDataView,
+ resource_coordinator::CoordinationUnitID>::
+ Read(resource_coordinator::mojom::CoordinationUnitIDDataView input,
+ resource_coordinator::CoordinationUnitID* out) {
+ out->id = input.id();
+ if (!input.ReadType(&out->type))
+ return false;
+ return true;
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698