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