Commit 55486659 authored by Glen Robertson's avatar Glen Robertson Committed by Chromium LUCI CQ

Use modern default member initialization in testing_profile

As recommended by clang-tidy on crrev.com/c/2626814

Change-Id: Id895aa84ac23f7c1435da869047b38ed84d4e648
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2631816
Commit-Queue: Greg Thompson <grt@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Auto-Submit: Glen Robertson <glenrob@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844448}
parent b55c4fa5
...@@ -67,9 +67,7 @@ ...@@ -67,9 +67,7 @@
#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/history/core/browser/history_service.h" #include "components/history/core/browser/history_service.h"
#include "components/history/core/test/history_service_test_util.h" #include "components/history/core/test/history_service_test_util.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/core/refcounted_keyed_service.h" #include "components/keyed_service/core/refcounted_keyed_service.h"
#include "components/keyed_service/core/simple_dependency_manager.h"
#include "components/keyed_service/core/simple_factory_key.h" #include "components/keyed_service/core/simple_factory_key.h"
#include "components/keyed_service/core/simple_key_map.h" #include "components/keyed_service/core/simple_key_map.h"
#include "components/leveldb_proto/public/proto_database_provider.h" #include "components/leveldb_proto/public/proto_database_provider.h"
...@@ -152,9 +150,6 @@ using testing::Return; ...@@ -152,9 +150,6 @@ using testing::Return;
namespace { namespace {
// Default profile name
const char kTestingProfile[] = "testing_profile";
void TestProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type, void TestProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type,
sql::InitStatus status, sql::InitStatus status,
const std::string& diagnostics) { const std::string& diagnostics) {
...@@ -179,6 +174,9 @@ std::unique_ptr<KeyedService> BuildPersonalDataManagerInstanceFor( ...@@ -179,6 +174,9 @@ std::unique_ptr<KeyedService> BuildPersonalDataManagerInstanceFor(
} // namespace } // namespace
// static
const char TestingProfile::kDefaultProfileUserName[] = "testing_profile";
// static // static
#if BUILDFLAG(IS_CHROMEOS_ASH) #if BUILDFLAG(IS_CHROMEOS_ASH)
// Must be kept in sync with // Must be kept in sync with
...@@ -216,22 +214,7 @@ TestingProfile::TestingProfile(const base::FilePath& path) ...@@ -216,22 +214,7 @@ TestingProfile::TestingProfile(const base::FilePath& path)
: TestingProfile(path, nullptr) {} : TestingProfile(path, nullptr) {}
TestingProfile::TestingProfile(const base::FilePath& path, Delegate* delegate) TestingProfile::TestingProfile(const base::FilePath& path, Delegate* delegate)
: start_time_(Time::Now()), : profile_path_(path), delegate_(delegate) {
testing_prefs_(nullptr),
original_profile_(nullptr),
guest_session_(false),
allows_browser_windows_(true),
is_new_profile_(false),
last_session_exited_cleanly_(true),
profile_path_(path),
simple_dependency_manager_(SimpleDependencyManager::GetInstance()),
browser_context_dependency_manager_(
BrowserContextDependencyManager::GetInstance()),
resource_context_(nullptr),
delegate_(delegate),
profile_name_(kTestingProfile),
override_policy_connector_is_managed_(base::nullopt),
otr_profile_id_(base::nullopt) {
if (profile_path_.empty()) { if (profile_path_.empty()) {
profile_path_ = base::CreateUniqueTempDirectoryScopedToTest(); profile_path_ = base::CreateUniqueTempDirectoryScopedToTest();
} }
...@@ -267,23 +250,16 @@ TestingProfile::TestingProfile( ...@@ -267,23 +250,16 @@ TestingProfile::TestingProfile(
const std::string& profile_name, const std::string& profile_name,
base::Optional<bool> override_policy_connector_is_managed, base::Optional<bool> override_policy_connector_is_managed,
base::Optional<OTRProfileID> otr_profile_id) base::Optional<OTRProfileID> otr_profile_id)
: start_time_(Time::Now()), : prefs_(std::move(prefs)),
prefs_(std::move(prefs)),
testing_prefs_(nullptr),
original_profile_(parent), original_profile_(parent),
guest_session_(guest_session), guest_session_(guest_session),
allows_browser_windows_(allows_browser_windows), allows_browser_windows_(allows_browser_windows),
is_new_profile_(is_new_profile), is_new_profile_(is_new_profile),
supervised_user_id_(supervised_user_id), supervised_user_id_(supervised_user_id),
last_session_exited_cleanly_(true),
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
extension_special_storage_policy_(extension_policy), extension_special_storage_policy_(extension_policy),
#endif #endif
profile_path_(path), profile_path_(path),
simple_dependency_manager_(SimpleDependencyManager::GetInstance()),
browser_context_dependency_manager_(
BrowserContextDependencyManager::GetInstance()),
resource_context_(nullptr),
user_cloud_policy_manager_(std::move(policy_manager)), user_cloud_policy_manager_(std::move(policy_manager)),
delegate_(delegate), delegate_(delegate),
profile_name_(profile_name), profile_name_(profile_name),
...@@ -1022,16 +998,9 @@ Profile::ExitType TestingProfile::GetLastSessionExitType() const { ...@@ -1022,16 +998,9 @@ Profile::ExitType TestingProfile::GetLastSessionExitType() const {
return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED; return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED;
} }
TestingProfile::Builder::Builder() TestingProfile::Builder::Builder() = default;
: build_called_(false),
delegate_(nullptr),
guest_session_(false),
allows_browser_windows_(true),
is_new_profile_(false),
profile_name_(kTestingProfile) {}
TestingProfile::Builder::~Builder() { TestingProfile::Builder::~Builder() = default;
}
void TestingProfile::Builder::SetPath(const base::FilePath& path) { void TestingProfile::Builder::SetPath(const base::FilePath& path) {
path_ = path; path_ = path;
...@@ -1113,7 +1082,7 @@ std::unique_ptr<TestingProfile> TestingProfile::Builder::Build() { ...@@ -1113,7 +1082,7 @@ std::unique_ptr<TestingProfile> TestingProfile::Builder::Build() {
DCHECK(!build_called_); DCHECK(!build_called_);
build_called_ = true; build_called_ = true;
return std::unique_ptr<TestingProfile>(new TestingProfile( return std::make_unique<TestingProfile>(
path_, delegate_, path_, delegate_,
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
extension_policy_, extension_policy_,
...@@ -1122,7 +1091,7 @@ std::unique_ptr<TestingProfile> TestingProfile::Builder::Build() { ...@@ -1122,7 +1091,7 @@ std::unique_ptr<TestingProfile> TestingProfile::Builder::Build() {
allows_browser_windows_, is_new_profile_, supervised_user_id_, allows_browser_windows_, is_new_profile_, supervised_user_id_,
std::move(user_cloud_policy_manager_), std::move(policy_service_), std::move(user_cloud_policy_manager_), std::move(policy_service_),
std::move(testing_factories_), profile_name_, std::move(testing_factories_), profile_name_,
override_policy_connector_is_managed_, base::Optional<OTRProfileID>())); override_policy_connector_is_managed_, base::Optional<OTRProfileID>());
} }
TestingProfile* TestingProfile::Builder::BuildOffTheRecord( TestingProfile* TestingProfile::Builder::BuildOffTheRecord(
......
...@@ -15,12 +15,15 @@ ...@@ -15,12 +15,15 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "build/chromeos_buildflags.h" #include "build/chromeos_buildflags.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/buildflags.h" #include "chrome/common/buildflags.h"
#include "components/domain_reliability/clear_mode.h" #include "components/domain_reliability/clear_mode.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h" #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "components/keyed_service/core/simple_dependency_manager.h"
#include "components/keyed_service/core/simple_factory_key.h" #include "components/keyed_service/core/simple_factory_key.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "extensions/buildflags/buildflags.h" #include "extensions/buildflags/buildflags.h"
...@@ -34,8 +37,6 @@ ...@@ -34,8 +37,6 @@
#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
#endif #endif
class BrowserContextDependencyManager;
class SimpleDependencyManager;
class ExtensionSpecialStoragePolicy; class ExtensionSpecialStoragePolicy;
class HostContentSettingsMap; class HostContentSettingsMap;
class TestingPrefStore; class TestingPrefStore;
...@@ -74,6 +75,8 @@ class TestingPrefServiceSyncable; ...@@ -74,6 +75,8 @@ class TestingPrefServiceSyncable;
class TestingProfile : public Profile { class TestingProfile : public Profile {
public: public:
static const char kDefaultProfileUserName[];
// Profile directory name for the test user. This is "Default" on most // Profile directory name for the test user. This is "Default" on most
// platforms but must be different on ChromeOS because a logged-in user cannot // platforms but must be different on ChromeOS because a logged-in user cannot
// use "Default" as profile directory. // use "Default" as profile directory.
...@@ -185,7 +188,7 @@ class TestingProfile : public Profile { ...@@ -185,7 +188,7 @@ class TestingProfile : public Profile {
private: private:
// If true, Build() has already been called. // If true, Build() has already been called.
bool build_called_; bool build_called_ = false;
// Various staging variables where values are held until Build() is invoked. // Various staging variables where values are held until Build() is invoked.
std::unique_ptr<sync_preferences::PrefServiceSyncable> pref_service_; std::unique_ptr<sync_preferences::PrefServiceSyncable> pref_service_;
...@@ -193,10 +196,10 @@ class TestingProfile : public Profile { ...@@ -193,10 +196,10 @@ class TestingProfile : public Profile {
scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy_; scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy_;
#endif #endif
base::FilePath path_; base::FilePath path_;
Delegate* delegate_; Delegate* delegate_ = nullptr;
bool guest_session_; bool guest_session_ = false;
bool allows_browser_windows_; bool allows_browser_windows_ = true;
bool is_new_profile_; bool is_new_profile_ = false;
std::string supervised_user_id_; std::string supervised_user_id_;
#if BUILDFLAG(IS_CHROMEOS_ASH) #if BUILDFLAG(IS_CHROMEOS_ASH)
std::unique_ptr<policy::UserCloudPolicyManagerChromeOS> std::unique_ptr<policy::UserCloudPolicyManagerChromeOS>
...@@ -206,7 +209,7 @@ class TestingProfile : public Profile { ...@@ -206,7 +209,7 @@ class TestingProfile : public Profile {
#endif #endif
std::unique_ptr<policy::PolicyService> policy_service_; std::unique_ptr<policy::PolicyService> policy_service_;
TestingFactories testing_factories_; TestingFactories testing_factories_;
std::string profile_name_; std::string profile_name_{kDefaultProfileUserName};
base::Optional<bool> override_policy_connector_is_managed_; base::Optional<bool> override_policy_connector_is_managed_;
}; };
...@@ -411,7 +414,7 @@ class TestingProfile : public Profile { ...@@ -411,7 +414,7 @@ class TestingProfile : public Profile {
ProfileDestructionCallback profile_destruction_callback_; ProfileDestructionCallback profile_destruction_callback_;
protected: protected:
base::Time start_time_; base::Time start_time_{base::Time::Now()};
// The key to index KeyedService instances created by // The key to index KeyedService instances created by
// SimpleKeyedServiceFactory. // SimpleKeyedServiceFactory.
...@@ -419,7 +422,7 @@ class TestingProfile : public Profile { ...@@ -419,7 +422,7 @@ class TestingProfile : public Profile {
std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs_; std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs_;
// ref only for right type, lifecycle is managed by prefs_ // ref only for right type, lifecycle is managed by prefs_
sync_preferences::TestingPrefServiceSyncable* testing_prefs_; sync_preferences::TestingPrefServiceSyncable* testing_prefs_ = nullptr;
// Profile implementation. // Profile implementation.
bool IsSignedIn() override; bool IsSignedIn() override;
...@@ -451,18 +454,18 @@ class TestingProfile : public Profile { ...@@ -451,18 +454,18 @@ class TestingProfile : public Profile {
extensions_cookie_store_; extensions_cookie_store_;
std::map<OTRProfileID, std::unique_ptr<Profile>> otr_profiles_; std::map<OTRProfileID, std::unique_ptr<Profile>> otr_profiles_;
TestingProfile* original_profile_; TestingProfile* original_profile_ = nullptr;
bool guest_session_; bool guest_session_ = false;
bool allows_browser_windows_; bool allows_browser_windows_ = true;
bool is_new_profile_; bool is_new_profile_ = false;
std::string supervised_user_id_; std::string supervised_user_id_;
// Did the last session exit cleanly? Default is true. // Whether the last session exited cleanly.
bool last_session_exited_cleanly_; bool last_session_exited_cleanly_ = true;
scoped_refptr<HostContentSettingsMap> host_content_settings_map_; scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
...@@ -482,12 +485,14 @@ class TestingProfile : public Profile { ...@@ -482,12 +485,14 @@ class TestingProfile : public Profile {
// We keep a weak pointer to the dependency manager we want to notify on our // We keep a weak pointer to the dependency manager we want to notify on our
// death. Defaults to the Singleton implementation but overridable for // death. Defaults to the Singleton implementation but overridable for
// testing. // testing.
SimpleDependencyManager* simple_dependency_manager_; SimpleDependencyManager* simple_dependency_manager_{
BrowserContextDependencyManager* browser_context_dependency_manager_; SimpleDependencyManager::GetInstance()};
BrowserContextDependencyManager* browser_context_dependency_manager_{
BrowserContextDependencyManager::GetInstance()};
// Owned, but must be deleted on the IO thread so not placing in a // Owned, but must be deleted on the IO thread so not placing in a
// std::unique_ptr<>. // std::unique_ptr<>.
content::MockResourceContext* resource_context_; content::MockResourceContext* resource_context_ = nullptr;
std::unique_ptr<policy::SchemaRegistryService> schema_registry_service_; std::unique_ptr<policy::SchemaRegistryService> schema_registry_service_;
#if BUILDFLAG(IS_CHROMEOS_ASH) #if BUILDFLAG(IS_CHROMEOS_ASH)
...@@ -499,9 +504,9 @@ class TestingProfile : public Profile { ...@@ -499,9 +504,9 @@ class TestingProfile : public Profile {
std::unique_ptr<policy::ProfilePolicyConnector> profile_policy_connector_; std::unique_ptr<policy::ProfilePolicyConnector> profile_policy_connector_;
// Weak pointer to a delegate for indicating that a profile was created. // Weak pointer to a delegate for indicating that a profile was created.
Delegate* delegate_; Delegate* delegate_ = nullptr;
std::string profile_name_; std::string profile_name_{kDefaultProfileUserName};
base::Optional<bool> override_policy_connector_is_managed_; base::Optional<bool> override_policy_connector_is_managed_;
base::Optional<OTRProfileID> otr_profile_id_; base::Optional<OTRProfileID> otr_profile_id_;
......
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