Commit 7fe93106 authored by stevenjb@chromium.org's avatar stevenjb@chromium.org

Make CrosSettings and DeviceSettingsService non Lazy instances

BUG=222681
For BrowserProcessImpl change:
TBR=sky@chromium.org

Review URL: https://codereview.chromium.org/14200028

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194656 0039d316-1c4b-4281-b951-d872f2087c98
parent 09a8d917
...@@ -116,6 +116,7 @@ ...@@ -116,6 +116,7 @@
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/memory/oom_priority_manager.h" #include "chrome/browser/chromeos/memory/oom_priority_manager.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
#if defined(ENABLE_PLUGIN_INSTALLATION) #if defined(ENABLE_PLUGIN_INSTALLATION)
...@@ -204,6 +205,11 @@ BrowserProcessImpl::~BrowserProcessImpl() { ...@@ -204,6 +205,11 @@ BrowserProcessImpl::~BrowserProcessImpl() {
tracked_objects::ThreadData::EnsureCleanupWasCalled(4); tracked_objects::ThreadData::EnsureCleanupWasCalled(4);
g_browser_process = NULL; g_browser_process = NULL;
#if defined(OS_CHROMEOS)
// Initialized in PreCreateThreards()
chromeos::CrosSettings::Shutdown();
#endif
} }
void BrowserProcessImpl::StartTearDown() { void BrowserProcessImpl::StartTearDown() {
...@@ -852,6 +858,9 @@ void BrowserProcessImpl::CreateLocalState() { ...@@ -852,6 +858,9 @@ void BrowserProcessImpl::CreateLocalState() {
} }
void BrowserProcessImpl::PreCreateThreads() { void BrowserProcessImpl::PreCreateThreads() {
#if defined(OS_CHROMEOS)
chromeos::CrosSettings::Initialize();
#endif
io_thread_.reset(new IOThread(local_state(), policy_service(), net_log_.get(), io_thread_.reset(new IOThread(local_state(), policy_service(), net_log_.get(),
extension_event_router_forwarder_.get())); extension_event_router_forwarder_.get()));
} }
......
...@@ -326,8 +326,10 @@ class DBusServices { ...@@ -326,8 +326,10 @@ class DBusServices {
} }
// Initialize the device settings service so that we'll take actions per // Initialize the device settings service so that we'll take actions per
// signals sent from the session manager. // signals sent from the session manager. This needs to happen before
DeviceSettingsService::Get()->Initialize( // g_browser_process initializes BrowserPolicyConnector.
DeviceSettingsService::Initialize();
DeviceSettingsService::Get()->SetSessionManager(
DBusThreadManager::Get()->GetSessionManagerClient(), DBusThreadManager::Get()->GetSessionManagerClient(),
OwnerKeyUtil::Create()); OwnerKeyUtil::Create());
chromeos::ConnectivityStateHelper::Initialize(); chromeos::ConnectivityStateHelper::Initialize();
...@@ -738,8 +740,10 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() { ...@@ -738,8 +740,10 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() {
if (NetworkPortalDetector::IsEnabledInCommandLine() && detector) if (NetworkPortalDetector::IsEnabledInCommandLine() && detector)
detector->Shutdown(); detector->Shutdown();
// Tell DeviceSettingsService to stop talking to session_manager. // Tell DeviceSettingsService to stop talking to session_manager. Do not
DeviceSettingsService::Get()->Shutdown(); // shutdown DeviceSettingsService yet, it might still be accessed by
// BrowserPolicyConnector (owned by g_browser_process).
DeviceSettingsService::Get()->UnsetSessionManager();
// We should remove observers attached to D-Bus clients before // We should remove observers attached to D-Bus clients before
// DBusThreadManager is shut down. // DBusThreadManager is shut down.
...@@ -793,6 +797,12 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() { ...@@ -793,6 +797,12 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() {
ChromeBrowserMainPartsLinux::PostMainMessageLoopRun(); ChromeBrowserMainPartsLinux::PostMainMessageLoopRun();
} }
void ChromeBrowserMainPartsChromeos::PostDestroyThreads() {
ChromeBrowserMainPartsLinux::PostDestroyThreads();
// Destroy DeviceSettingsService after g_browser_process.
DeviceSettingsService::Shutdown();
}
void ChromeBrowserMainPartsChromeos::SetupPlatformFieldTrials() { void ChromeBrowserMainPartsChromeos::SetupPlatformFieldTrials() {
SetupZramFieldTrial(); SetupZramFieldTrial();
} }
......
...@@ -66,6 +66,7 @@ class ChromeBrowserMainPartsChromeos : public ChromeBrowserMainPartsLinux { ...@@ -66,6 +66,7 @@ class ChromeBrowserMainPartsChromeos : public ChromeBrowserMainPartsLinux {
virtual void PostBrowserStart() OVERRIDE; virtual void PostBrowserStart() OVERRIDE;
virtual void PostMainMessageLoopRun() OVERRIDE; virtual void PostMainMessageLoopRun() OVERRIDE;
virtual void PostDestroyThreads() OVERRIDE;
virtual void SetupPlatformFieldTrials() OVERRIDE; virtual void SetupPlatformFieldTrials() OVERRIDE;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/message_loop.h" #include "base/message_loop.h"
#include "chrome/browser/chromeos/drive/drive_test_util.h" #include "chrome/browser/chromeos/drive/drive_test_util.h"
#include "chrome/browser/chromeos/drive/mock_drive_file_system.h" #include "chrome/browser/chromeos/drive/mock_drive_file_system.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/google_apis/dummy_drive_service.h" #include "chrome/browser/google_apis/dummy_drive_service.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
...@@ -45,6 +46,8 @@ class DriveSystemServiceTest : public testing::Test { ...@@ -45,6 +46,8 @@ class DriveSystemServiceTest : public testing::Test {
content::TestBrowserThread ui_thread_; content::TestBrowserThread ui_thread_;
scoped_ptr<TestingProfile> profile_; scoped_ptr<TestingProfile> profile_;
chromeos::ScopedTestCrosSettings test_cros_settings_;
MockDriveFileSystem* file_system_; MockDriveFileSystem* file_system_;
DriveSystemService* system_service_; DriveSystemService* system_service_;
}; };
......
...@@ -73,6 +73,8 @@ class KioskModeSettingsTest : public testing::Test { ...@@ -73,6 +73,8 @@ class KioskModeSettingsTest : public testing::Test {
content::TestBrowserThread ui_thread_; content::TestBrowserThread ui_thread_;
content::TestBrowserThread file_thread_; content::TestBrowserThread file_thread_;
ScopedTestCrosSettings test_cros_settings_;
CrosSettingsProvider* device_settings_provider_; CrosSettingsProvider* device_settings_provider_;
StubCrosSettingsProvider stub_settings_provider_; StubCrosSettingsProvider stub_settings_provider_;
}; };
......
...@@ -118,11 +118,17 @@ class ExistingUserControllerAutoLoginTest : public ::testing::Test { ...@@ -118,11 +118,17 @@ class ExistingUserControllerAutoLoginTest : public ::testing::Test {
MockLoginDisplay* mock_login_display_; MockLoginDisplay* mock_login_display_;
scoped_ptr<MockLoginDisplayHost> mock_login_display_host_; scoped_ptr<MockLoginDisplayHost> mock_login_display_host_;
scoped_ptr<ExistingUserController> existing_user_controller_;
MessageLoop message_loop_; MessageLoop message_loop_;
content::TestBrowserThread ui_thread_; content::TestBrowserThread ui_thread_;
ScopedTestingLocalState local_state_; ScopedTestingLocalState local_state_;
// Required by ExistingUserController:
ScopedDeviceSettingsTestHelper device_settings_test_helper_; ScopedDeviceSettingsTestHelper device_settings_test_helper_;
ScopedTestCrosSettings test_cros_settings_;
// |existing_user_controller_| must be destroyed before
// |device_settings_test_helper_|.
scoped_ptr<ExistingUserController> existing_user_controller_;
}; };
TEST_F(ExistingUserControllerAutoLoginTest, StartAutoLoginTimer) { TEST_F(ExistingUserControllerAutoLoginTest, StartAutoLoginTimer) {
......
...@@ -26,7 +26,10 @@ ...@@ -26,7 +26,10 @@
#include "chrome/browser/chromeos/net/connectivity_state_helper.h" #include "chrome/browser/chromeos/net/connectivity_state_helper.h"
#include "chrome/browser/chromeos/net/mock_connectivity_state_helper.h" #include "chrome/browser/chromeos/net/mock_connectivity_state_helper.h"
#include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chrome/browser/chromeos/settings/device_settings_test_helper.h" #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
#include "chrome/browser/chromeos/settings/mock_owner_key_util.h"
#include "chrome/browser/io_thread.h" #include "chrome/browser/io_thread.h"
#include "chrome/browser/net/predictor.h" #include "chrome/browser/net/predictor.h"
#include "chrome/browser/policy/browser_policy_connector.h" #include "chrome/browser/policy/browser_policy_connector.h"
...@@ -290,6 +293,8 @@ class LoginUtilsTest : public testing::Test, ...@@ -290,6 +293,8 @@ class LoginUtilsTest : public testing::Test,
cryptohome_client_ = mock_dbus_thread_manager_.mock_cryptohome_client(); cryptohome_client_ = mock_dbus_thread_manager_.mock_cryptohome_client();
EXPECT_CALL(*cryptohome_client_, IsMounted(_)); EXPECT_CALL(*cryptohome_client_, IsMounted(_));
test_cros_settings_.reset(new ScopedTestCrosSettings);
browser_process_->SetProfileManager( browser_process_->SetProfileManager(
new ProfileManagerWithoutInit(scoped_temp_dir_.path())); new ProfileManagerWithoutInit(scoped_temp_dir_.path()));
connector_ = browser_process_->browser_policy_connector(); connector_ = browser_process_->browser_policy_connector();
...@@ -419,7 +424,10 @@ class LoginUtilsTest : public testing::Test, ...@@ -419,7 +424,10 @@ class LoginUtilsTest : public testing::Test,
} }
void PrepareProfile(const std::string& username) { void PrepareProfile(const std::string& username) {
ScopedDeviceSettingsTestHelper device_settings_test_helper; DeviceSettingsTestHelper device_settings_test_helper;
DeviceSettingsService::Get()->SetSessionManager(
&device_settings_test_helper, new MockOwnerKeyUtil());
MockSessionManagerClient* session_manager_client = MockSessionManagerClient* session_manager_client =
mock_dbus_thread_manager_.mock_session_manager_client(); mock_dbus_thread_manager_.mock_session_manager_client();
EXPECT_CALL(*session_manager_client, StartSession(_)); EXPECT_CALL(*session_manager_client, StartSession(_));
...@@ -447,6 +455,8 @@ class LoginUtilsTest : public testing::Test, ...@@ -447,6 +455,8 @@ class LoginUtilsTest : public testing::Test,
std::string(), kUsingOAuth, kHasCookies, this); std::string(), kUsingOAuth, kHasCookies, this);
device_settings_test_helper.Flush(); device_settings_test_helper.Flush();
RunUntilIdle(); RunUntilIdle();
DeviceSettingsService::Get()->UnsetSessionManager();
} }
net::TestURLFetcher* PrepareOAuthFetcher(const std::string& expected_url) { net::TestURLFetcher* PrepareOAuthFetcher(const std::string& expected_url) {
...@@ -529,6 +539,10 @@ class LoginUtilsTest : public testing::Test, ...@@ -529,6 +539,10 @@ class LoginUtilsTest : public testing::Test,
policy::BrowserPolicyConnector* connector_; policy::BrowserPolicyConnector* connector_;
MockCryptohomeLibrary* cryptohome_; MockCryptohomeLibrary* cryptohome_;
MockCryptohomeClient* cryptohome_client_; MockCryptohomeClient* cryptohome_client_;
// Initialized after |mock_dbus_thread_manager_| and |cryptohome_| are set up.
scoped_ptr<ScopedTestCrosSettings> test_cros_settings_;
Profile* prepared_profile_; Profile* prepared_profile_;
base::Closure rlz_initialized_cb_; base::Closure rlz_initialized_cb_;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/login/merge_session_load_page.h" #include "chrome/browser/chromeos/login/merge_session_load_page.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "content/public/browser/interstitial_page.h" #include "content/public/browser/interstitial_page.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
...@@ -74,8 +75,8 @@ class MergeSessionLoadPageTest : public ChromeRenderViewHostTestHarness { ...@@ -74,8 +75,8 @@ class MergeSessionLoadPageTest : public ChromeRenderViewHostTestHarness {
content::TestBrowserThread file_user_blocking_thread_; content::TestBrowserThread file_user_blocking_thread_;
content::TestBrowserThread io_thread_; content::TestBrowserThread io_thread_;
// Initializes / shuts down a stub CrosLibrary.
chromeos::ScopedStubCrosEnabler stub_cros_enabler_; chromeos::ScopedStubCrosEnabler stub_cros_enabler_;
chromeos::ScopedTestCrosSettings test_cros_settings_;
DISALLOW_COPY_AND_ASSIGN(MergeSessionLoadPageTest); DISALLOW_COPY_AND_ASSIGN(MergeSessionLoadPageTest);
}; };
......
...@@ -218,10 +218,9 @@ class ParallelAuthenticatorTest : public testing::Test { ...@@ -218,10 +218,9 @@ class ParallelAuthenticatorTest : public testing::Test {
std::string username_hash_; std::string username_hash_;
std::string hash_ascii_; std::string hash_ascii_;
ScopedDeviceSettingsTestHelper device_settings_test_helper_;
// Initializes / shuts down a stub CrosLibrary.
ScopedStubCrosEnabler stub_cros_enabler_; ScopedStubCrosEnabler stub_cros_enabler_;
ScopedDeviceSettingsTestHelper device_settings_test_helper_;
ScopedTestCrosSettings test_cros_settings_;
// Mocks, destroyed by CrosLibrary class. // Mocks, destroyed by CrosLibrary class.
MockCertLibrary* mock_cert_library_; MockCertLibrary* mock_cert_library_;
...@@ -333,8 +332,7 @@ TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededFailedMount) { ...@@ -333,8 +332,7 @@ TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededFailedMount) {
LoginFailure failure = LoginFailure(LoginFailure::OWNER_REQUIRED); LoginFailure failure = LoginFailure(LoginFailure::OWNER_REQUIRED);
ExpectLoginFailure(failure); ExpectLoginFailure(failure);
MockDBusThreadManager* mock_dbus_thread_manager = MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager;
new MockDBusThreadManager;
EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus())
.WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL)));
DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
......
...@@ -927,7 +927,7 @@ void UserManagerImpl::NotifyLocalStateChanged() { ...@@ -927,7 +927,7 @@ void UserManagerImpl::NotifyLocalStateChanged() {
void UserManagerImpl::EnsureUsersLoaded() { void UserManagerImpl::EnsureUsersLoaded() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!g_browser_process) if (!g_browser_process || !g_browser_process->local_state())
return; return;
if (users_loaded_) if (users_loaded_)
......
...@@ -84,7 +84,7 @@ class UserManagerTest : public testing::Test { ...@@ -84,7 +84,7 @@ class UserManagerTest : public testing::Test {
UserManager::Set(old_user_manager_); UserManager::Set(old_user_manager_);
// Shut down the DeviceSettingsService. // Shut down the DeviceSettingsService.
DeviceSettingsService::Get()->Shutdown(); DeviceSettingsService::Get()->UnsetSessionManager();
// Shut down the remaining UserManager instances. // Shut down the remaining UserManager instances.
if (user_manager_impl) if (user_manager_impl)
...@@ -146,8 +146,8 @@ class UserManagerTest : public testing::Test { ...@@ -146,8 +146,8 @@ class UserManagerTest : public testing::Test {
StubCrosSettingsProvider stub_settings_provider_; StubCrosSettingsProvider stub_settings_provider_;
scoped_ptr<TestingPrefServiceSimple> local_state_; scoped_ptr<TestingPrefServiceSimple> local_state_;
// Initializes / shuts down a stub CrosLibrary. ScopedStubCrosEnabler stub_cros_enabler_;
chromeos::ScopedStubCrosEnabler stub_cros_enabler_; ScopedTestCrosSettings test_cros_settings_;
scoped_ptr<UserManagerImpl> user_manager_impl; scoped_ptr<UserManagerImpl> user_manager_impl;
UserManager* old_user_manager_; UserManager* old_user_manager_;
......
...@@ -104,6 +104,11 @@ void DeviceCloudPolicyManagerChromeOS::CancelEnrollment() { ...@@ -104,6 +104,11 @@ void DeviceCloudPolicyManagerChromeOS::CancelEnrollment() {
} }
} }
void DeviceCloudPolicyManagerChromeOS::Shutdown() {
CloudPolicyManager::Shutdown();
device_status_provider_.reset();
}
void DeviceCloudPolicyManagerChromeOS::OnStoreLoaded(CloudPolicyStore* store) { void DeviceCloudPolicyManagerChromeOS::OnStoreLoaded(CloudPolicyStore* store) {
CloudPolicyManager::OnStoreLoaded(store); CloudPolicyManager::OnStoreLoaded(store);
......
...@@ -56,6 +56,9 @@ class DeviceCloudPolicyManagerChromeOS : public CloudPolicyManager { ...@@ -56,6 +56,9 @@ class DeviceCloudPolicyManagerChromeOS : public CloudPolicyManager {
// Cancels a pending enrollment operation, if any. // Cancels a pending enrollment operation, if any.
void CancelEnrollment(); void CancelEnrollment();
// CloudPolicyManager:
virtual void Shutdown() OVERRIDE;
// CloudPolicyStore::Observer: // CloudPolicyStore::Observer:
virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE;
......
...@@ -233,11 +233,12 @@ class DeviceStatusCollectorTest : public testing::Test { ...@@ -233,11 +233,12 @@ class DeviceStatusCollectorTest : public testing::Test {
TestingPrefServiceSimple prefs_; TestingPrefServiceSimple prefs_;
chromeos::system::MockStatisticsProvider statistics_provider_; chromeos::system::MockStatisticsProvider statistics_provider_;
scoped_ptr<TestingDeviceStatusCollector> status_collector_; chromeos::ScopedTestCrosSettings test_cros_settings_;
em::DeviceStatusReportRequest status_;
chromeos::CrosSettings* cros_settings_; chromeos::CrosSettings* cros_settings_;
chromeos::CrosSettingsProvider* device_settings_provider_; chromeos::CrosSettingsProvider* device_settings_provider_;
chromeos::StubCrosSettingsProvider stub_settings_provider_; chromeos::StubCrosSettingsProvider stub_settings_provider_;
em::DeviceStatusReportRequest status_;
scoped_ptr<TestingDeviceStatusCollector> status_collector_;
}; };
TEST_F(DeviceStatusCollectorTest, AllIdle) { TEST_F(DeviceStatusCollectorTest, AllIdle) {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/string_util.h" #include "base/string_util.h"
#include "base/stringprintf.h" #include "base/stringprintf.h"
#include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
...@@ -329,6 +330,7 @@ class ProxyConfigServiceImplTestBase : public TESTBASE { ...@@ -329,6 +330,7 @@ class ProxyConfigServiceImplTestBase : public TESTBASE {
// Default stub state has ethernet as the active connected network and // Default stub state has ethernet as the active connected network and
// PROFILE_SHARED as profile type, which this unittest expects. // PROFILE_SHARED as profile type, which this unittest expects.
ScopedStubCrosEnabler stub_cros_enabler_; ScopedStubCrosEnabler stub_cros_enabler_;
ScopedTestCrosSettings test_cros_settings_;
content::TestBrowserThread ui_thread_; content::TestBrowserThread ui_thread_;
content::TestBrowserThread io_thread_; content::TestBrowserThread io_thread_;
}; };
......
...@@ -6,10 +6,11 @@ ...@@ -6,10 +6,11 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/lazy_instance.h" #include "base/logging.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/settings/device_settings_provider.h" #include "chrome/browser/chromeos/settings/device_settings_provider.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h" #include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chrome/browser/chromeos/settings/kiosk_app_local_settings.h" #include "chrome/browser/chromeos/settings/kiosk_app_local_settings.h"
...@@ -24,12 +25,30 @@ ...@@ -24,12 +25,30 @@
namespace chromeos { namespace chromeos {
static base::LazyInstance<CrosSettings> g_cros_settings = static CrosSettings* g_cros_settings = NULL;
LAZY_INSTANCE_INITIALIZER;
// static
void CrosSettings::Initialize() {
CHECK(!g_cros_settings);
g_cros_settings = new CrosSettings();
}
// static
bool CrosSettings::IsInitialized() {
return g_cros_settings;
}
// static
void CrosSettings::Shutdown() {
CHECK(g_cros_settings);
delete g_cros_settings;
g_cros_settings = NULL;
}
// static
CrosSettings* CrosSettings::Get() { CrosSettings* CrosSettings::Get() {
// TODO(xiyaun): Use real stuff when underlying libcros is ready. CHECK(g_cros_settings);
return g_cros_settings.Pointer(); return g_cros_settings;
} }
bool CrosSettings::IsCrosSettings(const std::string& path) { bool CrosSettings::IsCrosSettings(const std::string& path) {
...@@ -310,4 +329,21 @@ void CrosSettings::FireObservers(const std::string& path) { ...@@ -310,4 +329,21 @@ void CrosSettings::FireObservers(const std::string& path) {
} }
} }
ScopedTestCrosSettings::ScopedTestCrosSettings()
: initialized_device_settings_service_(false) {
if (!DeviceSettingsService::IsInitialized()) {
DeviceSettingsService::Initialize();
initialized_device_settings_service_ = true;
}
CrosSettings::Initialize();
}
ScopedTestCrosSettings::~ScopedTestCrosSettings() {
// UserManager holds a CrosSettings*, so ensure that it is destroyed.
UserManager::Set(NULL);
CrosSettings::Shutdown();
if (initialized_device_settings_service_)
DeviceSettingsService::Shutdown();
}
} // namespace chromeos } // namespace chromeos
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
namespace base { namespace base {
template <typename T> struct DefaultLazyInstanceTraits;
class ListValue; class ListValue;
class Value; class Value;
} }
...@@ -27,7 +26,10 @@ namespace chromeos { ...@@ -27,7 +26,10 @@ namespace chromeos {
// This class manages per-device/global settings. // This class manages per-device/global settings.
class CrosSettings : public base::NonThreadSafe { class CrosSettings : public base::NonThreadSafe {
public: public:
// Class factory. // Manage singleton instance.
static void Initialize();
static bool IsInitialized();
static void Shutdown();
static CrosSettings* Get(); static CrosSettings* Get();
// Helper function to test if the given |path| is a valid cros setting. // Helper function to test if the given |path| is a valid cros setting.
...@@ -92,12 +94,10 @@ class CrosSettings : public base::NonThreadSafe { ...@@ -92,12 +94,10 @@ class CrosSettings : public base::NonThreadSafe {
CrosSettingsProvider* GetProvider(const std::string& path) const; CrosSettingsProvider* GetProvider(const std::string& path) const;
private: private:
friend struct base::DefaultLazyInstanceTraits<CrosSettings>;
friend class CrosSettingsTest; friend class CrosSettingsTest;
// Public for testing.
CrosSettings(); CrosSettings();
~CrosSettings(); virtual ~CrosSettings();
// Fires system setting change notification. // Fires system setting change notification.
void FireObservers(const std::string& path); void FireObservers(const std::string& path);
...@@ -116,6 +116,20 @@ class CrosSettings : public base::NonThreadSafe { ...@@ -116,6 +116,20 @@ class CrosSettings : public base::NonThreadSafe {
DISALLOW_COPY_AND_ASSIGN(CrosSettings); DISALLOW_COPY_AND_ASSIGN(CrosSettings);
}; };
// Helper class for unit tests. Initializes DeviceSettingsService if it has
// not already been initialized (e.g. by ScopedDeviceSettingsTestHelper)
// and initializes CrosSettings.
class ScopedTestCrosSettings {
public:
ScopedTestCrosSettings();
~ScopedTestCrosSettings();
private:
bool initialized_device_settings_service_;
DISALLOW_COPY_AND_ASSIGN(ScopedTestCrosSettings);
};
} // namespace chromeos } // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_ #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_
...@@ -683,6 +683,8 @@ void DeviceSettingsProvider::ApplyMetricsSetting(bool use_file, ...@@ -683,6 +683,8 @@ void DeviceSettingsProvider::ApplyMetricsSetting(bool use_file,
} }
void DeviceSettingsProvider::ApplyRoamingSetting(bool new_value) { void DeviceSettingsProvider::ApplyRoamingSetting(bool new_value) {
if (!CrosLibrary::Get())
return; // May not be initialized in tests.
NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
const NetworkDevice* cellular = cros->FindCellularDevice(); const NetworkDevice* cellular = cros->FindCellularDevice();
if (cellular) { if (cellular) {
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/file_util.h" #include "base/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/stl_util.h" #include "base/stl_util.h"
...@@ -37,9 +36,6 @@ int kMaxLoadRetries = (1000 * 60 * 10) / kLoadRetryDelayMs; ...@@ -37,9 +36,6 @@ int kMaxLoadRetries = (1000 * 60 * 10) / kLoadRetryDelayMs;
namespace chromeos { namespace chromeos {
static base::LazyInstance<DeviceSettingsService> g_device_settings_service =
LAZY_INSTANCE_INITIALIZER;
OwnerKey::OwnerKey(scoped_ptr<std::vector<uint8> > public_key, OwnerKey::OwnerKey(scoped_ptr<std::vector<uint8> > public_key,
scoped_ptr<crypto::RSAPrivateKey> private_key) scoped_ptr<crypto::RSAPrivateKey> private_key)
: public_key_(public_key.Pass()), : public_key_(public_key.Pass()),
...@@ -49,22 +45,44 @@ OwnerKey::~OwnerKey() {} ...@@ -49,22 +45,44 @@ OwnerKey::~OwnerKey() {}
DeviceSettingsService::Observer::~Observer() {} DeviceSettingsService::Observer::~Observer() {}
static DeviceSettingsService* g_device_settings_service = NULL;
// static
void DeviceSettingsService::Initialize() {
CHECK(!g_device_settings_service);
g_device_settings_service = new DeviceSettingsService();
}
// static
bool DeviceSettingsService::IsInitialized() {
return g_device_settings_service;
}
// static
void DeviceSettingsService::Shutdown() {
CHECK(g_device_settings_service);
delete g_device_settings_service;
g_device_settings_service = NULL;
}
// static
DeviceSettingsService* DeviceSettingsService::Get() {
CHECK(g_device_settings_service);
return g_device_settings_service;
}
DeviceSettingsService::DeviceSettingsService() DeviceSettingsService::DeviceSettingsService()
: session_manager_client_(NULL), : session_manager_client_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
store_status_(STORE_SUCCESS), store_status_(STORE_SUCCESS),
load_retries_left_(kMaxLoadRetries) {} load_retries_left_(kMaxLoadRetries) {
}
DeviceSettingsService::~DeviceSettingsService() { DeviceSettingsService::~DeviceSettingsService() {
DCHECK(pending_operations_.empty()); DCHECK(pending_operations_.empty());
} }
// static void DeviceSettingsService::SetSessionManager(
DeviceSettingsService* DeviceSettingsService::Get() {
return g_device_settings_service.Pointer();
}
void DeviceSettingsService::Initialize(
SessionManagerClient* session_manager_client, SessionManagerClient* session_manager_client,
scoped_refptr<OwnerKeyUtil> owner_key_util) { scoped_refptr<OwnerKeyUtil> owner_key_util) {
DCHECK(session_manager_client); DCHECK(session_manager_client);
...@@ -80,7 +98,7 @@ void DeviceSettingsService::Initialize( ...@@ -80,7 +98,7 @@ void DeviceSettingsService::Initialize(
StartNextOperation(); StartNextOperation();
} }
void DeviceSettingsService::Shutdown() { void DeviceSettingsService::UnsetSessionManager() {
STLDeleteContainerPointers(pending_operations_.begin(), STLDeleteContainerPointers(pending_operations_.begin(),
pending_operations_.end()); pending_operations_.end());
pending_operations_.clear(); pending_operations_.clear();
......
...@@ -17,10 +17,6 @@ ...@@ -17,10 +17,6 @@
#include "chrome/browser/policy/cloud/cloud_policy_validator.h" #include "chrome/browser/policy/cloud/cloud_policy_validator.h"
#include "chromeos/dbus/session_manager_client.h" #include "chromeos/dbus/session_manager_client.h"
namespace base {
template <typename T> struct DefaultLazyInstanceTraits;
}
namespace crypto { namespace crypto {
class RSAPrivateKey; class RSAPrivateKey;
} }
...@@ -110,21 +106,24 @@ class DeviceSettingsService : public SessionManagerClient::Observer { ...@@ -110,21 +106,24 @@ class DeviceSettingsService : public SessionManagerClient::Observer {
virtual void DeviceSettingsUpdated() = 0; virtual void DeviceSettingsUpdated() = 0;
}; };
// Manage singleton instance.
static void Initialize();
static bool IsInitialized();
static void Shutdown();
static DeviceSettingsService* Get();
// Creates a device settings service instance. This is meant for unit tests, // Creates a device settings service instance. This is meant for unit tests,
// production code uses the singleton returned by Get() below. // production code uses the singleton returned by Get() above.
DeviceSettingsService(); DeviceSettingsService();
~DeviceSettingsService(); virtual ~DeviceSettingsService();
// Returns the singleton instance.
static DeviceSettingsService* Get();
// To be called on startup once threads are initialized and DBus is ready. // To be called on startup once threads are initialized and DBus is ready.
void Initialize(SessionManagerClient* session_manager_client, void SetSessionManager(SessionManagerClient* session_manager_client,
scoped_refptr<OwnerKeyUtil> owner_key_util); scoped_refptr<OwnerKeyUtil> owner_key_util);
// Prevents the service from making further calls to session_manager_client // Prevents the service from making further calls to session_manager_client
// and stops any pending operations. // and stops any pending operations.
void Shutdown(); void UnsetSessionManager();
// Returns the currently active device settings. Returns NULL if the device // Returns the currently active device settings. Returns NULL if the device
// settings have not been retrieved from session_manager yet. // settings have not been retrieved from session_manager yet.
......
...@@ -167,14 +167,16 @@ DeviceSettingsTestHelper::PolicyState::PolicyState() ...@@ -167,14 +167,16 @@ DeviceSettingsTestHelper::PolicyState::PolicyState()
DeviceSettingsTestHelper::PolicyState::~PolicyState() {} DeviceSettingsTestHelper::PolicyState::~PolicyState() {}
ScopedDeviceSettingsTestHelper::ScopedDeviceSettingsTestHelper() { ScopedDeviceSettingsTestHelper::ScopedDeviceSettingsTestHelper() {
DeviceSettingsService::Get()->Initialize(this, new MockOwnerKeyUtil()); DeviceSettingsService::Initialize();
DeviceSettingsService::Get()->SetSessionManager(this, new MockOwnerKeyUtil());
DeviceSettingsService::Get()->Load(); DeviceSettingsService::Get()->Load();
Flush(); Flush();
} }
ScopedDeviceSettingsTestHelper::~ScopedDeviceSettingsTestHelper() { ScopedDeviceSettingsTestHelper::~ScopedDeviceSettingsTestHelper() {
Flush(); Flush();
DeviceSettingsService::Get()->Shutdown(); DeviceSettingsService::Get()->UnsetSessionManager();
DeviceSettingsService::Shutdown();
} }
DeviceSettingsTestBase::DeviceSettingsTestBase() DeviceSettingsTestBase::DeviceSettingsTestBase()
...@@ -193,13 +195,13 @@ void DeviceSettingsTestBase::SetUp() { ...@@ -193,13 +195,13 @@ void DeviceSettingsTestBase::SetUp() {
owner_key_util_->SetPublicKeyFromPrivateKey(device_policy_.signing_key()); owner_key_util_->SetPublicKeyFromPrivateKey(device_policy_.signing_key());
device_policy_.Build(); device_policy_.Build();
device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
device_settings_service_.Initialize(&device_settings_test_helper_, device_settings_service_.SetSessionManager(&device_settings_test_helper_,
owner_key_util_); owner_key_util_);
} }
void DeviceSettingsTestBase::TearDown() { void DeviceSettingsTestBase::TearDown() {
FlushDeviceSettings(); FlushDeviceSettings();
device_settings_service_.Shutdown(); device_settings_service_.UnsetSessionManager();
} }
void DeviceSettingsTestBase::FlushDeviceSettings() { void DeviceSettingsTestBase::FlushDeviceSettings() {
......
...@@ -167,6 +167,8 @@ class DeviceSettingsTestBase : public testing::Test { ...@@ -167,6 +167,8 @@ class DeviceSettingsTestBase : public testing::Test {
DeviceSettingsTestHelper device_settings_test_helper_; DeviceSettingsTestHelper device_settings_test_helper_;
scoped_refptr<MockOwnerKeyUtil> owner_key_util_; scoped_refptr<MockOwnerKeyUtil> owner_key_util_;
// Local DeviceSettingsService instance for tests. Avoid using in combination
// with the global instance (DeviceSettingsService::Get()).
DeviceSettingsService device_settings_service_; DeviceSettingsService device_settings_service_;
private: private:
......
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/settings/cros_settings.h"
#endif
class TestingProfile; class TestingProfile;
namespace extensions { namespace extensions {
...@@ -72,6 +76,10 @@ class ExtensionServiceTestBase : public extensions::ExtensionTest { ...@@ -72,6 +76,10 @@ class ExtensionServiceTestBase : public extensions::ExtensionTest {
content::TestBrowserThread file_thread_; content::TestBrowserThread file_thread_;
content::TestBrowserThread file_user_blocking_thread_; content::TestBrowserThread file_user_blocking_thread_;
content::TestBrowserThread io_thread_; content::TestBrowserThread io_thread_;
#if defined(OS_CHROMEOS)
// ExtensionService depends on UserManager which depends on CrosSettings.
chromeos::ScopedTestCrosSettings test_cros_settings_;
#endif
}; };
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_UNITTEST_H_ #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_UNITTEST_H_
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
#include "ui/base/win/scoped_ole_initializer.h" #include "ui/base/win/scoped_ole_initializer.h"
#endif #endif
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/settings/cros_settings.h"
#endif
class ExtensionService; class ExtensionService;
class TestingProfile; class TestingProfile;
...@@ -60,6 +64,11 @@ class TestExtensionEnvironment { ...@@ -60,6 +64,11 @@ class TestExtensionEnvironment {
// likely to be indicated by memory leaks in which the object was // likely to be indicated by memory leaks in which the object was
// expected to be freed by a DeleteSoon() call. // expected to be freed by a DeleteSoon() call.
#if defined(OS_CHROMEOS)
// ExtensionService depends on UserManager which depends on CrosSettings.
chromeos::ScopedTestCrosSettings test_cros_settings_;
#endif
#if defined(OS_WIN) #if defined(OS_WIN)
ui::ScopedOleInitializer ole_initializer_; ui::ScopedOleInitializer ole_initializer_;
#endif #endif
......
...@@ -26,6 +26,10 @@ ...@@ -26,6 +26,10 @@
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/settings/cros_settings.h"
#endif
using content::BrowserThread; using content::BrowserThread;
namespace extensions { namespace extensions {
...@@ -33,6 +37,13 @@ namespace extensions { ...@@ -33,6 +37,13 @@ namespace extensions {
TestExtensionSystem::TestExtensionSystem(Profile* profile) TestExtensionSystem::TestExtensionSystem(Profile* profile)
: profile_(profile), : profile_(profile),
info_map_(new ExtensionInfoMap()) { info_map_(new ExtensionInfoMap()) {
#if defined OS_CHROMEOS
// TestExtensionSystem may or may not be created within
// TestExtensionEnvironment, so only create a ScopedTestCrosSettings instance
// if none has been created.
if (!chromeos::CrosSettings::IsInitialized())
test_cros_settings_.reset(new chromeos::ScopedTestCrosSettings);
#endif
} }
TestExtensionSystem::~TestExtensionSystem() { TestExtensionSystem::~TestExtensionSystem() {
......
...@@ -15,6 +15,12 @@ class FilePath; ...@@ -15,6 +15,12 @@ class FilePath;
class Time; class Time;
} }
#if defined(OS_CHROMEOS)
namespace chromeos {
class ScopedTestCrosSettings;
}
#endif
namespace extensions { namespace extensions {
// Test ExtensionSystem, for use with TestingProfile. // Test ExtensionSystem, for use with TestingProfile.
...@@ -87,6 +93,10 @@ class TestExtensionSystem : public ExtensionSystem { ...@@ -87,6 +93,10 @@ class TestExtensionSystem : public ExtensionSystem {
scoped_ptr<AlarmManager> alarm_manager_; scoped_ptr<AlarmManager> alarm_manager_;
scoped_refptr<ExtensionInfoMap> info_map_; scoped_refptr<ExtensionInfoMap> info_map_;
scoped_ptr<ApiResourceManager<Socket> > socket_manager_; scoped_ptr<ApiResourceManager<Socket> > socket_manager_;
#if defined OS_CHROMEOS
// ExtensionService depends on UserManager which depends on CrosSettings.
scoped_ptr<chromeos::ScopedTestCrosSettings> test_cros_settings_;
#endif
}; };
} // namespace extensions } // namespace extensions
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/extensions/event_router_forwarder.h" #include "chrome/browser/extensions/event_router_forwarder.h"
#include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/history_service_factory.h"
...@@ -124,6 +125,7 @@ class ProfileManagerTest : public testing::Test { ...@@ -124,6 +125,7 @@ class ProfileManagerTest : public testing::Test {
// before io_thread_ which requires CrosLibrary to be initialized to construct // before io_thread_ which requires CrosLibrary to be initialized to construct
// its data member pref_proxy_config_tracker_ on ChromeOS. // its data member pref_proxy_config_tracker_ on ChromeOS.
chromeos::ScopedStubCrosEnabler stub_cros_enabler_; chromeos::ScopedStubCrosEnabler stub_cros_enabler_;
chromeos::ScopedTestCrosSettings test_cros_settings_;
#endif #endif
// The path to temporary directory used to contain the test operations. // The path to temporary directory used to contain the test operations.
......
...@@ -24,10 +24,6 @@ ...@@ -24,10 +24,6 @@
#include "chrome/browser/thumbnails/render_widget_snapshot_taker.h" #include "chrome/browser/thumbnails/render_widget_snapshot_taker.h"
#endif #endif
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#endif
#if defined(ENABLE_CONFIGURATION_POLICY) #if defined(ENABLE_CONFIGURATION_POLICY)
#include "chrome/browser/policy/browser_policy_connector.h" #include "chrome/browser/policy/browser_policy_connector.h"
#else #else
...@@ -380,13 +376,6 @@ void TestingBrowserProcess::SetBrowserPolicyConnector( ...@@ -380,13 +376,6 @@ void TestingBrowserProcess::SetBrowserPolicyConnector(
#if defined(ENABLE_CONFIGURATION_POLICY) #if defined(ENABLE_CONFIGURATION_POLICY)
if (browser_policy_connector_) { if (browser_policy_connector_) {
browser_policy_connector_->Shutdown(); browser_policy_connector_->Shutdown();
#if defined(OS_CHROMEOS)
if (!connector) {
// If the connector was created then it accessed this global singleton.
// It must also be Shutdown() for a clean teardown.
chromeos::DeviceSettingsService::Get()->Shutdown();
}
#endif
} }
browser_policy_connector_.reset(connector); browser_policy_connector_.reset(connector);
#else #else
......
...@@ -521,8 +521,9 @@ void DBusThreadManager::Shutdown() { ...@@ -521,8 +521,9 @@ void DBusThreadManager::Shutdown() {
// If we called InitializeForTesting, this may get called more than once. // If we called InitializeForTesting, this may get called more than once.
// Ensure that we only shutdown DBusThreadManager once. // Ensure that we only shutdown DBusThreadManager once.
CHECK(g_dbus_thread_manager || g_dbus_thread_manager_set_for_testing); CHECK(g_dbus_thread_manager || g_dbus_thread_manager_set_for_testing);
delete g_dbus_thread_manager; DBusThreadManager* dbus_thread_manager = g_dbus_thread_manager;
g_dbus_thread_manager = NULL; g_dbus_thread_manager = NULL;
delete dbus_thread_manager;
VLOG(1) << "DBusThreadManager Shutdown completed"; VLOG(1) << "DBusThreadManager Shutdown completed";
} }
...@@ -532,6 +533,17 @@ DBusThreadManager::DBusThreadManager() { ...@@ -532,6 +533,17 @@ DBusThreadManager::DBusThreadManager() {
DBusThreadManager::~DBusThreadManager() { DBusThreadManager::~DBusThreadManager() {
dbus::statistics::Shutdown(); dbus::statistics::Shutdown();
if (g_dbus_thread_manager == NULL)
return; // Called form Shutdown() or local test instance.
// There should never be both a global instance and a local instance.
CHECK(this == g_dbus_thread_manager);
if (g_dbus_thread_manager_set_for_testing) {
g_dbus_thread_manager = NULL;
g_dbus_thread_manager_set_for_testing = false;
VLOG(1) << "DBusThreadManager destroyed";
} else {
LOG(FATAL) << "~DBusThreadManager() called outside of Shutdown()";
}
} }
// static // static
......
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