Commit e01b55ed authored by David Bienvenu's avatar David Bienvenu Committed by Commit Bot

Remove DISALLOW_COPY_AND_ASSIGN from Profile and sub-classes.

Also make more methods const and miscellaneous cleanup. No functional
changes.

Change-Id: I92004b1cdcdee52673eb71d52b6d54689d50d85b
Bug: 1010217
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2363072
Commit-Queue: David Bienvenu <davidbienvenu@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799334}
parent 3eb584cf
......@@ -97,7 +97,7 @@ void SessionStartupPref::SetStartupPref(PrefService* prefs,
}
// static
SessionStartupPref SessionStartupPref::GetStartupPref(Profile* profile) {
SessionStartupPref SessionStartupPref::GetStartupPref(const Profile* profile) {
DCHECK(profile);
// Guest sessions should not store any state, therefore they should never
......@@ -108,7 +108,8 @@ SessionStartupPref SessionStartupPref::GetStartupPref(Profile* profile) {
}
// static
SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) {
SessionStartupPref SessionStartupPref::GetStartupPref(
const PrefService* prefs) {
DCHECK(prefs);
SessionStartupPref pref(
......@@ -151,7 +152,7 @@ bool SessionStartupPref::TypeHasRecommendedValue(PrefService* prefs) {
}
// static
bool SessionStartupPref::TypeIsDefault(PrefService* prefs) {
bool SessionStartupPref::TypeIsDefault(const PrefService* prefs) {
DCHECK(prefs);
const PrefService::Preference* pref_restore =
prefs->FindPreference(prefs::kRestoreOnStartup);
......
......@@ -52,8 +52,8 @@ struct SessionStartupPref {
static void SetStartupPref(Profile* profile, const SessionStartupPref& pref);
static void SetStartupPref(PrefService* prefs,
const SessionStartupPref& pref);
static SessionStartupPref GetStartupPref(Profile* profile);
static SessionStartupPref GetStartupPref(PrefService* prefs);
static SessionStartupPref GetStartupPref(const Profile* profile);
static SessionStartupPref GetStartupPref(const PrefService* prefs);
// Whether the startup type and URLs are managed via mandatory policy.
static bool TypeIsManaged(PrefService* prefs);
......@@ -64,7 +64,7 @@ struct SessionStartupPref {
static bool TypeHasRecommendedValue(PrefService* prefs);
// Whether the startup type has not been overridden from its default.
static bool TypeIsDefault(PrefService* prefs);
static bool TypeIsDefault(const PrefService* prefs);
// Converts an integer pref value to a SessionStartupPref::Type.
static SessionStartupPref::Type PrefValueToType(int pref_value);
......
......@@ -560,7 +560,7 @@ bool OffTheRecordProfileImpl::WasCreatedByVersionOrLater(
return profile_->WasCreatedByVersionOrLater(version);
}
Profile::ExitType OffTheRecordProfileImpl::GetLastSessionExitType() {
Profile::ExitType OffTheRecordProfileImpl::GetLastSessionExitType() const {
return profile_->GetLastSessionExitType();
}
......
......@@ -7,8 +7,8 @@
#include <memory>
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/sequenced_task_runner.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
......@@ -39,6 +39,8 @@ class OffTheRecordProfileImpl : public Profile {
public:
OffTheRecordProfileImpl(Profile* real_profile,
const OTRProfileID& otr_profile_id);
OffTheRecordProfileImpl(const OffTheRecordProfileImpl&) = delete;
OffTheRecordProfileImpl& operator=(const OffTheRecordProfileImpl&) = delete;
~OffTheRecordProfileImpl() override;
void Init();
......@@ -83,7 +85,7 @@ class OffTheRecordProfileImpl : public Profile {
void set_last_selected_directory(const base::FilePath& path) override;
bool WasCreatedByVersionOrLater(const std::string& version) override;
void SetExitType(ExitType exit_type) override;
ExitType GetLastSessionExitType() override;
ExitType GetLastSessionExitType() const override;
#if defined(OS_CHROMEOS)
void ChangeAppLocale(const std::string& locale, AppLocaleChangedVia) override;
......@@ -167,8 +169,6 @@ class OffTheRecordProfileImpl : public Profile {
std::unique_ptr<ProfileKey> key_;
base::FilePath last_selected_directory_;
DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
};
#endif // CHROME_BROWSER_PROFILES_OFF_THE_RECORD_PROFILE_IMPL_H_
......@@ -181,12 +181,7 @@ JNI_OTRProfileID_CreateUniqueOTRProfileID(
}
#endif
Profile::Profile()
: restored_last_session_(false),
sent_destroyed_notification_(false),
accessibility_pause_level_(0),
is_guest_profile_(false),
is_system_profile_(false) {
Profile::Profile() {
#if DCHECK_IS_ON()
base::AutoLock lock(g_profile_instances_lock.Get());
g_profile_instances.Get().insert(this);
......@@ -359,12 +354,9 @@ void Profile::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
// chrome/browser/prefs/browser_prefs.cc.
}
std::string Profile::GetDebugName() {
std::string Profile::GetDebugName() const {
std::string name = GetPath().BaseName().MaybeAsASCII();
if (name.empty()) {
name = "UnknownProfile";
}
return name;
return name.empty() ? "UnknownProfile" : name;
}
bool Profile::IsRegularProfile() const {
......@@ -405,11 +397,11 @@ bool Profile::CanUseDiskWhenOffTheRecord() {
#endif
}
bool Profile::ShouldRestoreOldSessionCookies() {
bool Profile::ShouldRestoreOldSessionCookies() const {
return false;
}
bool Profile::ShouldPersistSessionCookies() {
bool Profile::ShouldPersistSessionCookies() const {
return false;
}
......@@ -424,7 +416,7 @@ void Profile::ConfigureNetworkContextParams(
cert_verifier_creation_params);
}
bool Profile::IsNewProfile() {
bool Profile::IsNewProfile() const {
#if !defined(OS_ANDROID)
// The profile is new if the preference files has just been created, except on
// first run, because the installer may create a preference file. See
......
......@@ -9,9 +9,9 @@
#include <memory>
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/observer_list.h"
#include "base/time/time.h"
......@@ -173,6 +173,8 @@ class Profile : public content::BrowserContext {
static const char kProfileKey[];
Profile();
Profile(const Profile&) = delete;
Profile& operator=(const Profile&) = delete;
~Profile() override;
// Profile prefs are registered as soon as the prefs are loaded for the first
......@@ -394,7 +396,7 @@ class Profile : public content::BrowserContext {
// more recent (or equal to) the one specified.
virtual bool WasCreatedByVersionOrLater(const std::string& version) = 0;
std::string GetDebugName();
std::string GetDebugName() const;
// IsRegularProfile() and IsIncognitoProfile() are mutually exclusive.
// IsSystemProfile() implies that IsRegularProfile() is true.
......@@ -440,12 +442,12 @@ class Profile : public content::BrowserContext {
virtual void SetExitType(ExitType exit_type) = 0;
// Returns how the last session was shutdown.
virtual ExitType GetLastSessionExitType() = 0;
virtual ExitType GetLastSessionExitType() const = 0;
// Returns whether session cookies are restored and saved. The value is
// ignored for in-memory profiles.
virtual bool ShouldRestoreOldSessionCookies();
virtual bool ShouldPersistSessionCookies();
virtual bool ShouldRestoreOldSessionCookies() const;
virtual bool ShouldPersistSessionCookies() const;
// Configures NetworkContextParams and CertVerifierCreationParams for the
// specified isolated app (or for the profile itself, if |relative_path| is
......@@ -476,7 +478,7 @@ class Profile : public content::BrowserContext {
// Returns whether the profile is new. A profile is new if the browser has
// not been shut down since the profile was created.
// This method is virtual in order to be overridden for tests.
virtual bool IsNewProfile();
virtual bool IsNewProfile() const;
// Send NOTIFICATION_PROFILE_DESTROYED for this Profile, if it has not
// already been sent. It is necessary because most Profiles are destroyed by
......@@ -518,28 +520,26 @@ class Profile : public content::BrowserContext {
void NotifyOffTheRecordProfileCreated(Profile* off_the_record);
private:
bool restored_last_session_;
bool restored_last_session_ = false;
// Used to prevent the notification that this Profile is destroyed from
// being sent twice.
bool sent_destroyed_notification_;
bool sent_destroyed_notification_ = false;
// Accessibility events will only be propagated when the pause
// level is zero. PauseAccessibilityEvents and ResumeAccessibilityEvents
// increment and decrement the level, respectively, rather than set it to
// true or false, so that calls can be nested.
int accessibility_pause_level_;
int accessibility_pause_level_ = 0;
bool is_guest_profile_;
bool is_guest_profile_ = false;
// A non-browsing profile not associated to a user. Sample use: User-Manager.
bool is_system_profile_;
bool is_system_profile_ = false;
base::ObserverList<ProfileObserver> observers_;
std::unique_ptr<variations::VariationsClient> chrome_variations_client_;
DISALLOW_COPY_AND_ASSIGN(Profile);
};
// The comparator for profile pointers as key in a map.
......
......@@ -1088,14 +1088,14 @@ void ProfileImpl::SetExitType(ExitType exit_type) {
}
}
Profile::ExitType ProfileImpl::GetLastSessionExitType() {
Profile::ExitType ProfileImpl::GetLastSessionExitType() const {
// last_session_exited_cleanly_ is set when the preferences are loaded. Force
// it to be set by asking for the prefs.
GetPrefs();
return last_session_exit_type_;
}
bool ProfileImpl::ShouldRestoreOldSessionCookies() {
bool ProfileImpl::ShouldRestoreOldSessionCookies() const {
#if defined(OS_ANDROID)
SessionStartupPref::Type startup_pref_type =
SessionStartupPref::GetDefaultStartupType();
......@@ -1109,7 +1109,7 @@ bool ProfileImpl::ShouldRestoreOldSessionCookies() {
startup_pref_type == SessionStartupPref::LAST;
}
bool ProfileImpl::ShouldPersistSessionCookies() {
bool ProfileImpl::ShouldPersistSessionCookies() const {
return true;
}
......
......@@ -7,12 +7,13 @@
#ifndef CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_
#define CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/optional.h"
#include "base/time/time.h"
......@@ -66,6 +67,8 @@ class ProfileImpl : public Profile {
// Value written to prefs when the exit type is EXIT_NORMAL. Public for tests.
static const char kPrefExitTypeNormal[];
ProfileImpl(const ProfileImpl&) = delete;
ProfileImpl& operator=(const ProfileImpl&) = delete;
~ProfileImpl() override;
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
......@@ -159,9 +162,9 @@ class ProfileImpl : public Profile {
GURL GetHomePage() override;
bool WasCreatedByVersionOrLater(const std::string& version) override;
void SetExitType(ExitType exit_type) override;
ExitType GetLastSessionExitType() override;
bool ShouldRestoreOldSessionCookies() override;
bool ShouldPersistSessionCookies() override;
ExitType GetLastSessionExitType() const override;
bool ShouldRestoreOldSessionCookies() const override;
bool ShouldPersistSessionCookies() const override;
#if defined(OS_CHROMEOS)
void ChangeAppLocale(const std::string& locale, AppLocaleChangedVia) override;
......@@ -327,8 +330,6 @@ class ProfileImpl : public Profile {
scoped_refptr<content::SharedCorsOriginAccessList>
shared_cors_origin_access_list_;
DISALLOW_COPY_AND_ASSIGN(ProfileImpl);
};
#endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_
......@@ -427,9 +427,9 @@ bool StartupBrowserCreator::WasRestarted() {
// static
SessionStartupPref StartupBrowserCreator::GetSessionStartupPref(
const base::CommandLine& command_line,
Profile* profile) {
const Profile* profile) {
DCHECK(profile);
PrefService* prefs = profile->GetPrefs();
const PrefService* prefs = profile->GetPrefs();
SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs);
// IsChromeFirstRun() looks for a sentinel file to determine whether the user
......
......@@ -88,7 +88,7 @@ class StartupBrowserCreator {
static SessionStartupPref GetSessionStartupPref(
const base::CommandLine& command_line,
Profile* profile);
const Profile* profile);
// For faking that no profiles have been launched yet.
static void ClearLaunchedProfilesForTesting();
......
......@@ -951,13 +951,13 @@ bool TestingProfile::IsGuestSession() const {
return guest_session_;
}
bool TestingProfile::IsNewProfile() {
bool TestingProfile::IsNewProfile() const {
if (is_new_profile_.has_value())
return is_new_profile_.value();
return Profile::IsNewProfile();
}
Profile::ExitType TestingProfile::GetLastSessionExitType() {
Profile::ExitType TestingProfile::GetLastSessionExitType() const {
return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED;
}
......
......@@ -5,6 +5,7 @@
#ifndef CHROME_TEST_BASE_TESTING_PROFILE_H_
#define CHROME_TEST_BASE_TESTING_PROFILE_H_
#include <map>
#include <memory>
#include <string>
#include <utility>
......@@ -89,6 +90,8 @@ class TestingProfile : public Profile {
class Builder {
public:
Builder();
Builder(const Builder&) = delete;
Builder& operator=(const Builder&) = delete;
~Builder();
// Sets a Delegate to be called back during profile init. This causes the
......@@ -180,8 +183,6 @@ class TestingProfile : public Profile {
TestingFactories testing_factories_;
std::string profile_name_;
base::Optional<bool> override_policy_connector_is_managed_;
DISALLOW_COPY_AND_ASSIGN(Builder);
};
// Multi-profile aware constructor that takes the path to a directory managed
......@@ -336,9 +337,9 @@ class TestingProfile : public Profile {
void set_last_selected_directory(const base::FilePath& path) override;
bool WasCreatedByVersionOrLater(const std::string& version) override;
bool IsGuestSession() const override;
bool IsNewProfile() override;
bool IsNewProfile() const override;
void SetExitType(ExitType exit_type) override {}
ExitType GetLastSessionExitType() override;
ExitType GetLastSessionExitType() const override;
void ConfigureNetworkContextParams(
bool in_memory,
const base::FilePath& relative_partition_path,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment