chromium/chrome/browser/profiles/profile.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/profiles/profile.h"

#include <string>

#include "base/check_deref.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/observer_list.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "base/trace_event/typed_macros.h"
#include "base/tracing/protos/chrome_track_event.pbzero.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_constants.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "chrome/browser/profiles/profile_selections.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/language/core/browser/pref_names.h"
#include "components/live_caption/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/profile_metrics/browser_profile_type.h"
#include "components/search_engines/search_engine_choice/search_engine_choice_utils.h"
#include "components/search_engines/search_engines_pref_names.h"
#include "components/variations/variations.mojom.h"
#include "components/variations/variations_client.h"
#include "components/variations/variations_ids_provider.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/host_zoom_map.h"
#include "content/public/browser/shared_cors_origin_access_list.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "extensions/buildflags/buildflags.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "chromeos/constants/pref_names.h"
#endif

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_switches.h"
#include "base/command_line.h"
#endif

#if BUILDFLAG(IS_ANDROID)
#include "base/android/jni_string.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/android/jni_headers/OTRProfileID_jni.h"
#endif

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/browser/extension_pref_store.h"              // nogncheck
#include "extensions/browser/extension_pref_value_map_factory.h"  // nogncheck
#include "extensions/browser/pref_names.h"                        // nogncheck
#endif

#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chrome/common/chrome_constants.h"
#include "chromeos/startup/browser_params_proxy.h"
#endif

#if DCHECK_IS_ON()

#include <set>
#include "base/check_op.h"
#include "base/lazy_instance.h"
#include "base/synchronization/lock.h"

namespace {

base::LazyInstance<base::Lock>::Leaky g_profile_instances_lock =;
base::LazyInstance<std::set<content::BrowserContext*>>::Leaky
    g_profile_instances =;

}  // namespace

#endif  // DCHECK_IS_ON()

namespace {

const char kDevToolsOTRProfileIDPrefix[] =;
const char kMediaRouterOTRProfileIDPrefix[] =;
const char kTestOTRProfileIDPrefix[] =;

#if BUILDFLAG(IS_CHROMEOS)
const char kCaptivePortalOTRProfileIDPrefix[] = "CaptivePortal::Signin";
#endif

ChromeTrackEvent;

}  // namespace

Profile::OTRProfileID::OTRProfileID(const std::string& profile_id)
    :{}

bool Profile::OTRProfileID::AllowsBrowserWindows() const {}

#if BUILDFLAG(IS_CHROMEOS)
bool Profile::OTRProfileID::IsCaptivePortal() const {
  return base::StartsWith(profile_id_, kCaptivePortalOTRProfileIDPrefix,
                          base::CompareCase::SENSITIVE);
}
#endif

// static
const Profile::OTRProfileID Profile::OTRProfileID::PrimaryID() {}

// static
Profile::OTRProfileID Profile::OTRProfileID::CreateUnique(
    const std::string& profile_id_prefix) {}

// static
Profile::OTRProfileID Profile::OTRProfileID::CreateUniqueForDevTools() {}

// static
Profile::OTRProfileID Profile::OTRProfileID::CreateUniqueForMediaRouter() {}

#if BUILDFLAG(IS_CHROMEOS)
// static
Profile::OTRProfileID Profile::OTRProfileID::CreateUniqueForCaptivePortal() {
  return CreateUnique(kCaptivePortalOTRProfileIDPrefix);
}
#endif

// static
Profile::OTRProfileID Profile::OTRProfileID::CreateUniqueForTesting() {}

const std::string& Profile::OTRProfileID::ToString() const {}

std::ostream& operator<<(std::ostream& out,
                         const Profile::OTRProfileID& profile_id) {}

#if BUILDFLAG(IS_ANDROID)
base::android::ScopedJavaLocalRef<jobject>
Profile::OTRProfileID::ConvertToJavaOTRProfileID(JNIEnv* env) const {
  return Java_OTRProfileID_Constructor(
      env, base::android::ConvertUTF8ToJavaString(env, profile_id_));
}

// static
Profile::OTRProfileID Profile::OTRProfileID::ConvertFromJavaOTRProfileID(
    JNIEnv* env,
    const base::android::JavaRef<jobject>& j_otr_profile_id) {
  return OTRProfileID(base::android::ConvertJavaStringToUTF8(
      env, Java_OTRProfileID_getProfileID(env, j_otr_profile_id)));
}

// static
base::android::ScopedJavaLocalRef<jobject>
JNI_OTRProfileID_CreateUniqueOTRProfileID(
    JNIEnv* env,
    const base::android::JavaParamRef<jstring>& j_profile_id_prefix) {
  Profile::OTRProfileID profile_id = Profile::OTRProfileID::CreateUnique(
      base::android::ConvertJavaStringToUTF8(env, j_profile_id_prefix));
  return profile_id.ConvertToJavaOTRProfileID(env);
}

// static
base::android::ScopedJavaLocalRef<jobject> JNI_OTRProfileID_GetPrimaryID(
    JNIEnv* env) {
  return Profile::OTRProfileID::PrimaryID().ConvertToJavaOTRProfileID(env);
}

// static
Profile::OTRProfileID Profile::OTRProfileID::Deserialize(
    const std::string& value) {
  JNIEnv* env = base::android::AttachCurrentThread();
  base::android::ScopedJavaLocalRef<jstring> j_value =
      base::android::ConvertUTF8ToJavaString(env, value);
  base::android::ScopedJavaLocalRef<jobject> j_otr_profile_id =
      Java_OTRProfileID_deserializeWithoutVerify(env, j_value);
  return ConvertFromJavaOTRProfileID(env, j_otr_profile_id);
}

std::string Profile::OTRProfileID::Serialize() const {
  JNIEnv* env = base::android::AttachCurrentThread();
  return base::android::ConvertJavaStringToUTF8(
      env, Java_OTRProfileID_serialize(env, ConvertToJavaOTRProfileID(env)));
}
#endif  // BUILDFLAG(IS_ANDROID)

Profile::Profile(const OTRProfileID* otr_profile_id)
    :{}

Profile::~Profile() {}

// static
Profile* Profile::FromBrowserContext(content::BrowserContext* browser_context) {}

// static
Profile* Profile::FromWebUI(content::WebUI* web_ui) {}

void Profile::AddObserver(ProfileObserver* observer) {}

void Profile::RemoveObserver(ProfileObserver* observer) {}

base::FilePath Profile::GetBaseName() const {}

std::string Profile::GetDebugName() const {}

TestingProfile* Profile::AsTestingProfile() {}

ChromeZoomLevelPrefs* Profile::GetZoomLevelPrefs() {}

Profile::Delegate::~Delegate() {}

// static
const char Profile::kProfileKey[] =;

// static
void Profile::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {}

bool Profile::IsRegularProfile() const {}

bool Profile::IsIncognitoProfile() const {}

bool Profile::IsGuestSession() const {}

PrefService* Profile::GetReadOnlyOffTheRecordPrefs() {}

bool Profile::IsSystemProfile() const {}

#if BUILDFLAG(IS_CHROMEOS_LACROS)
// static
bool Profile::IsMainProfilePath(base::FilePath profile_path) {
  // The main profile is the one with the "Default" path.
  return profile_path.BaseName().value() == chrome::kInitialProfile;
}
#endif  // BUILDFLAG(IS_CHROMEOS_LACROS)

bool Profile::IsPrimaryOTRProfile() const {}

bool Profile::CanUseDiskWhenOffTheRecord() {}

bool Profile::ShouldRestoreOldSessionCookies() {}

bool Profile::ShouldPersistSessionCookies() const {}

void Profile::MaybeSendDestroyedNotification() {}

// static
PrefStore* Profile::CreateExtensionPrefStore(Profile* profile,
                                             bool incognito_pref_store) {}

bool ProfileCompare::operator()(Profile* a, Profile* b) const {}

double Profile::GetDefaultZoomLevelForProfile() {}

void Profile::Wipe() {}

void Profile::NotifyOffTheRecordProfileCreated(Profile* off_the_record) {}

void Profile::NotifyProfileInitializationComplete() {}

Profile* Profile::GetPrimaryOTRProfile(bool create_if_needed) {}

const Profile::OTRProfileID& Profile::GetOTRProfileID() const {}

bool Profile::HasPrimaryOTRProfile() {}

class Profile::ChromeVariationsClient : public variations::VariationsClient {};

bool Profile::IsOffTheRecord() {}

variations::VariationsClient* Profile::GetVariationsClient() {}

base::WeakPtr<const Profile> Profile::GetWeakPtr() const {}

base::WeakPtr<Profile> Profile::GetWeakPtr() {}