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

Unified Diff: base/trace_event/event_filter_registry.h

Issue 2499583003: [OBSOLETE] tracing: split trace event filter logic out of TraceLog (Closed)
Patch Set: . Created 4 years, 1 month 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: base/trace_event/event_filter_registry.h
diff --git a/base/trace_event/event_filter_registry.h b/base/trace_event/event_filter_registry.h
new file mode 100644
index 0000000000000000000000000000000000000000..161b0e9658225530c4260e1a28cf631cae6fff50
--- /dev/null
+++ b/base/trace_event/event_filter_registry.h
@@ -0,0 +1,59 @@
+// Copyright 2016 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.
+
+#ifndef BASE_TRACE_EVENT_EVENT_FILTER_REGISTRY_H_
+#define BASE_TRACE_EVENT_EVENT_FILTER_REGISTRY_H_
+
+#include <stddef.h>
+
+#include <memory>
+
+#include "base/base_export.h"
+#include "base/macros.h"
+
+namespace base {
+namespace trace_event {
+
+class TraceEventFilter;
+
+// Keeps track of all tracing filters. Tracing filters are long lived and once
+// registered are leaked forever. This guarnatees that the clients can hold onto
ssid 2016/11/16 10:19:44 The last time we discussed, Oystein was not happy
Primiano Tucci (use gerrit) 2016/11/16 16:56:21 Ah, I was not aware of the conversation. Honestly
+// the filter index for implementing efficient bitmap-based caching.
+class BASE_EXPORT EventFilterRegistry {
+ public:
+ // Registers a filter class, if not already registered. Returns the pointer
+ // to the filter instance. The caller must guarantee serialization.
+ template <typename FILTER_TYPE>
+ static FILTER_TYPE* RegisterFilterLocked() {
ssid 2016/11/16 10:19:44 Register feels like it should be called once, mayb
Primiano Tucci (use gerrit) 2016/11/16 16:56:22 Makes sense, will change this soon.
+ TraceEventFilter* filter = RegisterFilterInternal(FILTER_TYPE::kName, [] {
+ return std::unique_ptr<TraceEventFilter>(new FILTER_TYPE());
+ });
+ return reinterpret_cast<FILTER_TYPE*>(filter);
+ }
+
+ // Returns the filter at the given index. Crashes with a CHECK if
+ // |filter_index| is out of bound.
+ static TraceEventFilter* Get(int filter_index);
+
+ // Looks up the filter by name. Returns nullptr if not found.
+ static TraceEventFilter* GetByName(const char* filter_name);
+
+ // Returns the filter index from its name or -1 if not found. The returned
+ // index is guaranteed to be stable for the entire lifetime of the process.
+ static int GetIndexByName(const char* filter_name);
+
+ private:
+ using FilterFactoryFn = std::unique_ptr<TraceEventFilter> (*)();
+
+ static TraceEventFilter* RegisterFilterInternal(const char* name,
+ FilterFactoryFn);
+ EventFilterRegistry() = delete;
+
+ DISALLOW_COPY_AND_ASSIGN(EventFilterRegistry);
+};
+
+} // namespace trace_event
+} // namespace base
+
+#endif // BASE_TRACE_EVENT_EVENT_FILTER_REGISTRY_H_

Powered by Google App Engine
This is Rietveld 408576698