#include "chrome/browser/tracing/chrome_tracing_delegate.h"
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/json/values_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tracing/background_tracing_field_trial.h"
#include "chrome/browser/ui/browser_otr_state.h"
#include "chrome/common/pref_names.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/tracing/common/background_tracing_state_manager.h"
#include "components/tracing/common/background_tracing_utils.h"
#include "components/variations/active_field_trials.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/background_tracing_config.h"
#include "content/public/browser/browser_thread.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/tracing/public/cpp/tracing_features.h"
#if BUILDFLAG(IS_ANDROID)
#include "chrome/browser/ui/android/tab_model/tab_model.h"
#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
#else
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_pref_names.h"
#include "chromeos/dbus/constants/dbus_switches.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/lacros/crosapi_pref_observer.h"
#endif
namespace {
BackgroundTracingSetupMode;
BackgroundTracingState;
BackgroundTracingStateManager;
bool IsBackgroundTracingCommandLine() { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
class DevicePolicyObserver {
public:
DevicePolicyObserver()
: pref_observer_(
crosapi::mojom::PrefPath::kDeviceSystemWideTracingEnabled,
base::BindRepeating(&DevicePolicyObserver::OnPrefChanged,
base::Unretained(this))) {}
bool system_wide_tracing_enabled() const {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
return system_wide_tracing_enabled_;
}
static const DevicePolicyObserver& GetInstance() {
static base::NoDestructor<DevicePolicyObserver> instance;
return *instance;
}
private:
void OnPrefChanged(base::Value value) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
system_wide_tracing_enabled_ = value.GetBool();
}
~DevicePolicyObserver() = default;
CrosapiPrefObserver pref_observer_;
bool system_wide_tracing_enabled_ = false;
};
#endif
}
ChromeTracingDelegate::ChromeTracingDelegate()
: … { … }
ChromeTracingDelegate::~ChromeTracingDelegate() { … }
#if BUILDFLAG(IS_ANDROID)
void ChromeTracingDelegate::OnTabModelAdded() {
for (const TabModel* model : TabModelList::models()) {
if (model->GetProfile()->IsOffTheRecord())
incognito_launched_ = true;
}
}
void ChromeTracingDelegate::OnTabModelRemoved() {}
#else
void ChromeTracingDelegate::OnBrowserAdded(Browser* browser) { … }
#endif
bool ChromeTracingDelegate::IsActionAllowed(
BackgroundScenarioAction action,
bool requires_anonymized_data) const { … }
bool ChromeTracingDelegate::OnBackgroundTracingActive(
bool requires_anonymized_data) { … }
bool ChromeTracingDelegate::OnBackgroundTracingIdle(
bool requires_anonymized_data) { … }
bool ChromeTracingDelegate::ShouldSaveUnuploadedTrace() const { … }
bool ChromeTracingDelegate::IsSystemWideTracingEnabled() { … }