Index: services/blamer/public/cpp/blame_classes.h |
diff --git a/services/blamer/public/cpp/blame_classes.h b/services/blamer/public/cpp/blame_classes.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4ae1be8d5c89d40e7ad76b4cc4d525508c1a1ade |
--- /dev/null |
+++ b/services/blamer/public/cpp/blame_classes.h |
@@ -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. |
+ |
+// Defines all known classes of nodes for attribution, as well as descriptions |
+// of their equivalence classes and possible relationships. |
+ |
+#ifndef SERVICES_BLAMER_PUBLIC_CPP_BLAME_CLASSES_H_ |
+#define SERVICES_BLAMER_PUBLIC_CPP_BLAME_CLASSES_H_ |
+ |
+#include "base/hash.h" |
+ |
+namespace blamer { |
+ |
+// An enumeration of all known classes. New ones should strictly be added to |
+// the end. Retired classes should be marked as deprecated, and their slots |
+// should not be reused. This ensures that IDs are stable across Chrome |
+// versions. |
+enum class BlameClassId : uint32_t { |
+ // This is reserved and used as a sentinel value. |
+ UNDEFINED = 0, |
+ |
+ V8_ISOLATE, |
+ CONTENT_WEBVIEW, |
+ CONTENT_FRAME_TREE_NODE, |
+ CONTENT_RENDER_FRAME, |
+ BLINK_LOCAL_FRAME, |
+ BLINK_REMOTE_FRAME, |
+ // New classes should be added here. |
+ |
+ // This should always be last. |
+ MAX |
+}; |
+ |
+// TODO(chrisha): Build "class descriptions", which allow the class to be |
+// introspected at runtime. This could include valid parent types, valid child |
+// types, valid equivalent class types, etc. This should be present in all |
+// process types. |
+ |
+// Templated class for generating IDs given an instance of an object. Each |
+// process is expected to have defined one of these for any blame classes that |
+// occur in the context of that process. It should satisfy the following |
+// interface: |
+// |
+// // Generate an ID for the given object type. Two equivalent objects in |
+// // distinct processes should generate the same ID. |
+// static uint32_t GenerateId(const ObjectType& object); |
+// |
+// By default the implementation of GenerateId will make a call to the following |
+// function: |
+// |
+// static void SerializeObject(const ObjectType& object, |
+// std::vector<uint8_t>* buffer); |
+// |
+// Specializations of this class may choose to implement SerializeObject, or |
+// to override GenerateId directly. |
+template<typename ObjectType> |
+class BlameClassIdGenerator { |
+ public: |
+ // Generate an ID for the given object type. Does so by hashing the results of |
+ // SerializeObject(). |
+ static uint32_t GenerateId(const ObjectType& object) { |
+ std::vector<uint8_t> buffer; |
+ SerializeObject(object, &buffer); |
+ return base::SuperFastHash(buffer.data(), buffer.size()); |
+ } |
+}; |
+ |
+} // namespace blamer |
+ |
+#endif // SERVICES_BLAMER_PUBLIC_CPP_BLAME_CLASSES_H_ |