#include "chrome/browser/profiles/off_the_record_profile_impl.h"
#include <memory>
#include <utility>
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/task/sequenced_task_runner.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/accessibility/accessibility_labels_service.h"
#include "chrome/browser/background/background_contents_service_factory.h"
#include "chrome/browser/background_fetch/background_fetch_delegate_factory.h"
#include "chrome/browser/background_fetch/background_fetch_delegate_impl.h"
#include "chrome/browser/background_sync/background_sync_controller_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.h"
#include "chrome/browser/client_hints/client_hints_factory.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/dom_distiller/profile_utils.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/download/download_core_service.h"
#include "chrome/browser/download/download_core_service_factory.h"
#include "chrome/browser/file_system_access/chrome_file_system_access_permission_context.h"
#include "chrome/browser/file_system_access/file_system_access_permission_context_factory.h"
#include "chrome/browser/heavy_ad_intervention/heavy_ad_service_factory.h"
#include "chrome/browser/k_anonymity_service/k_anonymity_service_factory.h"
#include "chrome/browser/notifications/platform_notification_service_factory.h"
#include "chrome/browser/notifications/platform_notification_service_impl.h"
#include "chrome/browser/origin_trials/origin_trials_factory.h"
#include "chrome/browser/permissions/permission_manager_factory.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/prefs/pref_service_syncable_util.h"
#include "chrome/browser/profiles/keep_alive/profile_keep_alive_types.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/reduce_accept_language/reduce_accept_language_factory.h"
#include "chrome/browser/ssl/stateful_ssl_host_state_delegate_factory.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/transition_manager/full_browser_transition_manager.h"
#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
#include "chrome/browser/ui/zoom/chrome_zoom_level_otr_delegate.h"
#include "chrome/browser/webid/federated_identity_api_permission_context.h"
#include "chrome/browser/webid/federated_identity_api_permission_context_factory.h"
#include "chrome/browser/webid/federated_identity_auto_reauthn_permission_context.h"
#include "chrome/browser/webid/federated_identity_auto_reauthn_permission_context_factory.h"
#include "chrome/browser/webid/federated_identity_permission_context.h"
#include "chrome/browser/webid/federated_identity_permission_context_factory.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "components/background_sync/background_sync_controller_impl.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/heavy_ad_intervention/heavy_ad_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/core/simple_dependency_manager.h"
#include "components/keyed_service/core/simple_key_map.h"
#include "components/keyed_service/core/simple_keyed_service_factory.h"
#include "components/permissions/permission_manager.h"
#include "components/policy/core/common/policy_pref_names.h"
#include "components/prefs/json_pref_store.h"
#include "components/profile_metrics/browser_profile_type.h"
#include "components/security_interstitials/content/stateful_ssl_host_state_delegate.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "components/user_prefs/user_prefs.h"
#include "components/zoom/zoom_event_manager.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/render_process_host.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/url_data_source.h"
#include "content/public/browser/web_contents.h"
#include "extensions/buildflags/buildflags.h"
#include "media/capabilities/in_memory_video_decode_stats_db_impl.h"
#include "media/mojo/services/video_decode_perf_history.h"
#include "net/http/transport_security_state.h"
#include "ppapi/buildflags/buildflags.h"
#include "storage/browser/database/database_tracker.h"
#if BUILDFLAG(IS_ANDROID)
#include "components/prefs/scoped_user_pref_update.h"
#else
#include "chrome/browser/profiles/guest_profile_creation_logger.h"
#endif
#if BUILDFLAG(IS_CHROMEOS)
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/pref_names.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/preferences/preferences.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/startup/browser_params_proxy.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_special_storage_policy.h"
#include "components/guest_view/browser/guest_view_manager.h"
#include "extensions/browser/api/web_request/extension_web_request_event_router.h"
#include "extensions/browser/extension_pref_store.h"
#include "extensions/browser/extension_pref_value_map_factory.h"
#include "extensions/common/extension.h"
#endif
#if BUILDFLAG(ENABLE_PLUGINS)
#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
#include "chrome/browser/plugins/plugin_prefs.h"
#endif
BrowserThread;
DownloadManagerDelegate;
HostZoomMap;
namespace {
profile_metrics::BrowserProfileType ComputeOffTheRecordProfileType(
const Profile::OTRProfileID& otr_profile_id,
const Profile* parent_profile) { … }
}
OffTheRecordProfileImpl::OffTheRecordProfileImpl(
Profile* real_profile,
const OTRProfileID& otr_profile_id)
: … { … }
void OffTheRecordProfileImpl::Init() { … }
OffTheRecordProfileImpl::~OffTheRecordProfileImpl() { … }
void OffTheRecordProfileImpl::TrackZoomLevelsFromParent() { … }
std::string OffTheRecordProfileImpl::GetProfileUserName() const { … }
base::FilePath OffTheRecordProfileImpl::GetPath() { … }
base::FilePath OffTheRecordProfileImpl::GetPath() const { … }
base::Time OffTheRecordProfileImpl::GetCreationTime() const { … }
std::unique_ptr<content::ZoomLevelDelegate>
OffTheRecordProfileImpl::CreateZoomLevelDelegate(
const base::FilePath& partition_path) { … }
scoped_refptr<base::SequencedTaskRunner>
OffTheRecordProfileImpl::GetIOTaskRunner() { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
bool OffTheRecordProfileImpl::IsMainProfile() const {
return chromeos::BrowserParamsProxy::Get()->SessionType() ==
crosapi::mojom::SessionType::kGuestSession &&
profile_->IsMainProfile();
}
#endif
Profile* OffTheRecordProfileImpl::GetOffTheRecordProfile(
const OTRProfileID& otr_profile_id,
bool create_if_needed) { … }
std::vector<Profile*> OffTheRecordProfileImpl::GetAllOffTheRecordProfiles() { … }
void OffTheRecordProfileImpl::DestroyOffTheRecordProfile(
Profile* ) { … }
bool OffTheRecordProfileImpl::HasOffTheRecordProfile(
const OTRProfileID& otr_profile_id) { … }
bool OffTheRecordProfileImpl::HasAnyOffTheRecordProfile() { … }
Profile* OffTheRecordProfileImpl::GetOriginalProfile() { … }
const Profile* OffTheRecordProfileImpl::GetOriginalProfile() const { … }
ExtensionSpecialStoragePolicy*
OffTheRecordProfileImpl::GetExtensionSpecialStoragePolicy() { … }
bool OffTheRecordProfileImpl::IsChild() const { … }
bool OffTheRecordProfileImpl::AllowsBrowserWindows() const { … }
PrefService* OffTheRecordProfileImpl::GetPrefs() { … }
const PrefService* OffTheRecordProfileImpl::GetPrefs() const { … }
DownloadManagerDelegate* OffTheRecordProfileImpl::GetDownloadManagerDelegate() { … }
policy::SchemaRegistryService*
OffTheRecordProfileImpl::GetPolicySchemaRegistryService() { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
policy::UserCloudPolicyManagerAsh*
OffTheRecordProfileImpl::GetUserCloudPolicyManagerAsh() {
return GetOriginalProfile()->GetUserCloudPolicyManagerAsh();
}
#else
policy::UserCloudPolicyManager*
OffTheRecordProfileImpl::GetUserCloudPolicyManager() { … }
policy::ProfileCloudPolicyManager*
OffTheRecordProfileImpl::GetProfileCloudPolicyManager() { … }
#endif
policy::CloudPolicyManager* OffTheRecordProfileImpl::GetCloudPolicyManager() { … }
scoped_refptr<network::SharedURLLoaderFactory>
OffTheRecordProfileImpl::GetURLLoaderFactory() { … }
content::BrowserPluginGuestManager* OffTheRecordProfileImpl::GetGuestManager() { … }
storage::SpecialStoragePolicy*
OffTheRecordProfileImpl::GetSpecialStoragePolicy() { … }
content::PlatformNotificationService*
OffTheRecordProfileImpl::GetPlatformNotificationService() { … }
content::PushMessagingService*
OffTheRecordProfileImpl::GetPushMessagingService() { … }
content::StorageNotificationService*
OffTheRecordProfileImpl::GetStorageNotificationService() { … }
content::SSLHostStateDelegate*
OffTheRecordProfileImpl::GetSSLHostStateDelegate() { … }
content::PermissionControllerDelegate*
OffTheRecordProfileImpl::GetPermissionControllerDelegate() { … }
content::ClientHintsControllerDelegate*
OffTheRecordProfileImpl::GetClientHintsControllerDelegate() { … }
content::BackgroundFetchDelegate*
OffTheRecordProfileImpl::GetBackgroundFetchDelegate() { … }
content::BackgroundSyncController*
OffTheRecordProfileImpl::GetBackgroundSyncController() { … }
content::BrowsingDataRemoverDelegate*
OffTheRecordProfileImpl::GetBrowsingDataRemoverDelegate() { … }
content::ReduceAcceptLanguageControllerDelegate*
OffTheRecordProfileImpl::GetReduceAcceptLanguageControllerDelegate() { … }
std::unique_ptr<media::VideoDecodePerfHistory>
OffTheRecordProfileImpl::CreateVideoDecodePerfHistory() { … }
content::FileSystemAccessPermissionContext*
OffTheRecordProfileImpl::GetFileSystemAccessPermissionContext() { … }
bool OffTheRecordProfileImpl::IsSameOrParent(Profile* profile) { … }
base::Time OffTheRecordProfileImpl::GetStartTime() const { … }
ProfileKey* OffTheRecordProfileImpl::GetProfileKey() const { … }
policy::ProfilePolicyConnector*
OffTheRecordProfileImpl::GetProfilePolicyConnector() { … }
const policy::ProfilePolicyConnector*
OffTheRecordProfileImpl::GetProfilePolicyConnector() const { … }
base::FilePath OffTheRecordProfileImpl::last_selected_directory() { … }
void OffTheRecordProfileImpl::set_last_selected_directory(
const base::FilePath& path) { … }
bool OffTheRecordProfileImpl::WasCreatedByVersionOrLater(
const std::string& version) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
void OffTheRecordProfileImpl::ChangeAppLocale(const std::string& locale,
AppLocaleChangedVia) {}
void OffTheRecordProfileImpl::OnLogin() {}
void OffTheRecordProfileImpl::InitChromeOSPreferences() {
}
#endif
bool OffTheRecordProfileImpl::IsNewProfile() const { … }
GURL OffTheRecordProfileImpl::GetHomePage() { … }
void OffTheRecordProfileImpl::SetCreationTimeForTesting(
base::Time creation_time) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
class GuestSessionProfile : public OffTheRecordProfileImpl {
public:
explicit GuestSessionProfile(Profile* real_profile)
: OffTheRecordProfileImpl(real_profile, OTRProfileID::PrimaryID()) {
profile_metrics::SetBrowserProfileType(
this, profile_metrics::BrowserProfileType::kGuest);
}
void InitChromeOSPreferences() override {
chromeos_preferences_ = std::make_unique<ash::Preferences>();
chromeos_preferences_->Init(
this, user_manager::UserManager::Get()->GetActiveUser());
}
private:
std::unique_ptr<ash::Preferences> chromeos_preferences_;
};
#endif
std::unique_ptr<Profile> Profile::CreateOffTheRecordProfile(
Profile* parent,
const OTRProfileID& otr_profile_id) { … }
bool OffTheRecordProfileImpl::IsSignedIn() { … }
void OffTheRecordProfileImpl::OnParentZoomLevelChanged(
const HostZoomMap::ZoomLevelChange& change) { … }
void OffTheRecordProfileImpl::UpdateDefaultZoomLevel() { … }
void OffTheRecordProfileImpl::RecordPrimaryMainFrameNavigation() { … }
content::FederatedIdentityPermissionContextDelegate*
OffTheRecordProfileImpl::GetFederatedIdentityPermissionContext() { … }
content::FederatedIdentityApiPermissionContextDelegate*
OffTheRecordProfileImpl::GetFederatedIdentityApiPermissionContext() { … }
content::FederatedIdentityAutoReauthnPermissionContextDelegate*
OffTheRecordProfileImpl::GetFederatedIdentityAutoReauthnPermissionContext() { … }
content::KAnonymityServiceDelegate*
OffTheRecordProfileImpl::GetKAnonymityServiceDelegate() { … }