1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef INCLUDE_PERFETTO_TRACING_TRACING_POLICY_H_ 18 #define INCLUDE_PERFETTO_TRACING_TRACING_POLICY_H_ 19 20 #include <functional> 21 22 #include "perfetto/base/export.h" 23 #include "perfetto/tracing/backend_type.h" 24 25 namespace perfetto { 26 27 // Applies policy decisions, such as allowing or denying connections, when 28 // certain tracing SDK events occur. All methods are called on an internal 29 // perfetto thread. 30 class PERFETTO_EXPORT TracingPolicy { 31 public: 32 virtual ~TracingPolicy(); 33 34 // Called when the current process attempts to connect a new consumer to the 35 // backend of |backend_type| to check if the connection should be allowed. Its 36 // implementation should execute |result_callback| with the result of the 37 // check (synchronuosly or asynchronously on any thread). If the result is 38 // false, the consumer connection is aborted. Chrome uses this to restrict 39 // creating (system) tracing sessions based on an enterprise policy. 40 struct ShouldAllowConsumerSessionArgs { 41 BackendType backend_type; 42 std::function<void(bool /*allow*/)> result_callback; 43 }; 44 virtual void ShouldAllowConsumerSession( 45 const ShouldAllowConsumerSessionArgs&) = 0; 46 }; 47 48 } // namespace perfetto 49 50 #endif // INCLUDE_PERFETTO_TRACING_TRACING_POLICY_H_ 51