summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-24 05:46:57 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-24 05:46:57 +0000
commitd8ef715b6145fb3bd9cc70fd051c71b84bb7715b (patch)
tree3c05d3cf379723fccca5986f76017bc0a9a25ce6
parent240cc92d2f736c143258a6f62e39831e54b5e5d3 (diff)
downloadchromium_src-d8ef715b6145fb3bd9cc70fd051c71b84bb7715b.zip
chromium_src-d8ef715b6145fb3bd9cc70fd051c71b84bb7715b.tar.gz
chromium_src-d8ef715b6145fb3bd9cc70fd051c71b84bb7715b.tar.bz2
Revert 97662 - Initialize/Shutdown CrosLibrary explicitly to avoid singleton races during shutdown.
This caused Chrome on Chrome OS to use the fake network library. BUG=chromium-os:19511 TEST=chrome should not use the fake netowkr library -- BUG=chromium-os:18912 TEST=Ensure chrome shuts down cleanly after heavy usage. Include opening Other Wi-F > Advanced. Review URL: http://codereview.chromium.org/7672005 TBR=stevenjb@google.com Review URL: http://codereview.chromium.org/7718026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97999 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/chrome_main_posix.cc11
-rw-r--r--chrome/browser/chromeos/cros/cros_library.cc27
-rw-r--r--chrome/browser/chromeos/cros/cros_library.h17
-rw-r--r--chrome/browser/chromeos/cros/network_library.cc30
-rw-r--r--chrome/browser/chromeos/login/cryptohome_op_unittest.cc6
-rw-r--r--chrome/browser/chromeos/login/google_authenticator_unittest.cc4
-rw-r--r--chrome/browser/chromeos/login/online_attempt_unittest.cc3
-rw-r--r--chrome/browser/chromeos/login/parallel_authenticator_unittest.cc3
-rw-r--r--chrome/browser/chromeos/offline/offline_load_page_unittest.cc4
-rw-r--r--chrome/browser/chromeos/upgrade_detector_chromeos.cc5
-rw-r--r--chrome/browser/profiles/profile_manager_unittest.cc9
11 files changed, 20 insertions, 99 deletions
diff --git a/chrome/app/chrome_main_posix.cc b/chrome/app/chrome_main_posix.cc
index de44038..810c5c8 100644
--- a/chrome/app/chrome_main_posix.cc
+++ b/chrome/app/chrome_main_posix.cc
@@ -15,10 +15,6 @@
#include "chrome/app/breakpad_mac.h"
#endif
-#if defined(OS_CHROMEOS)
-#include "chrome/browser/chromeos/cros/cros_library.h"
-#endif
-
namespace {
// Setup signal-handling state: resanitize most signals, ignore SIGPIPE.
@@ -72,16 +68,9 @@ void LowLevelInit(void* instance) {
g_fds->Set(kCrashDumpSignal,
kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor);
#endif
-
-#if defined(OS_CHROMEOS)
- chromeos::CrosLibrary::Initialize();
-#endif
}
void LowLevelShutdown() {
-#if defined(OS_CHROMEOS)
- chromeos::CrosLibrary::Shutdown();
-#endif
#if defined(OS_MACOSX) && defined(GOOGLE_CHROME_BUILD)
// TODO(mark): See the TODO(mark) at InitCrashReporter.
DestructCrashReporter();
diff --git a/chrome/browser/chromeos/cros/cros_library.cc b/chrome/browser/chromeos/cros/cros_library.cc
index 33d13e3..b008792 100644
--- a/chrome/browser/chromeos/cros/cros_library.cc
+++ b/chrome/browser/chromeos/cros/cros_library.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "base/lazy_instance.h"
#include "chrome/browser/chromeos/cros/brightness_library.h"
#include "chrome/browser/chromeos/cros/burn_library.h"
#include "chrome/browser/chromeos/cros/cert_library.h"
@@ -29,9 +30,11 @@ void CrosLibrary::TestApi::Set##class_prefix##Library( \
library_->var_prefix##_lib_.SetImpl(library, own); \
}
+
namespace chromeos {
-static CrosLibrary* g_cros_library = NULL;
+static base::LazyInstance<CrosLibrary> g_cros_library(
+ base::LINKER_INITIALIZED);
CrosLibrary::CrosLibrary() : library_loader_(NULL),
own_library_loader_(false),
@@ -47,28 +50,8 @@ CrosLibrary::~CrosLibrary() {
}
// static
-void CrosLibrary::Initialize() {
- CHECK(!g_cros_library) <<
- "CrosLibrary::Initialize() called with non NULL library.";
- g_cros_library = new CrosLibrary();
-}
-
-// static
-bool CrosLibrary::Initialized() {
- return g_cros_library != NULL;
-}
-
-// static
-void CrosLibrary::Shutdown() {
- CHECK(g_cros_library) << "CrosLibrary::Shutdown() called with NULL library";
- delete g_cros_library;
- g_cros_library = NULL;
-}
-
-// static
CrosLibrary* CrosLibrary::Get() {
- CHECK(g_cros_library) << "CrosLibrary::Get() called before Initialize()";
- return g_cros_library;
+ return g_cros_library.Pointer();
}
DEFINE_GET_LIBRARY_METHOD(Brightness, brightness);
diff --git a/chrome/browser/chromeos/cros/cros_library.h b/chrome/browser/chromeos/cros/cros_library.h
index 2ddb568..331ec6f 100644
--- a/chrome/browser/chromeos/cros/cros_library.h
+++ b/chrome/browser/chromeos/cros/cros_library.h
@@ -73,17 +73,7 @@ class CrosLibrary {
CrosLibrary* library_;
};
- // Sets the global instance. Must be called before any calls to Get().
- static void Initialize();
-
- // Returns true if the global instance has been initialized.
- static bool Initialized();
-
- // Destroys the global instance. Must be called before AtExitManager is
- // destroyed to ensure clean shutdown.
- static void Shutdown();
-
- // Gets the global instance. Initialize() must be called first.
+ // This gets the CrosLibrary.
static CrosLibrary* Get();
BrightnessLibrary* GetBrightnessLibrary();
@@ -102,9 +92,6 @@ class CrosLibrary {
// Getter for Test API that gives access to internal members of this class.
TestApi* GetTestApi();
- // Returns true if the cros library was loaded (i.e. not a stub).
- bool LibraryLoaded() { return loaded_; }
-
// Ensures that the library is loaded, loading it if needed. If the library
// could not be loaded, returns false.
bool EnsureLoaded();
@@ -193,13 +180,11 @@ class CrosLibrary {
class ScopedStubCrosEnabler {
public:
ScopedStubCrosEnabler() {
- chromeos::CrosLibrary::Initialize();
chromeos::CrosLibrary::Get()->GetTestApi()->SetUseStubImpl();
}
~ScopedStubCrosEnabler() {
chromeos::CrosLibrary::Get()->GetTestApi()->ResetUseStubImpl();
- chromeos::CrosLibrary::Shutdown();
}
private:
diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc
index 9f39d24..a347ec7 100644
--- a/chrome/browser/chromeos/cros/network_library.cc
+++ b/chrome/browser/chromeos/cros/network_library.cc
@@ -119,7 +119,8 @@ static void WipeString(std::string* str) {
}
static bool EnsureCrosLoaded() {
- if (!CrosLibrary::Get()->LibraryLoaded()) {
+ if (!CrosLibrary::Get()->EnsureLoaded() ||
+ !CrosLibrary::Get()->GetNetworkLibrary()->IsCros()) {
return false;
} else {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI))
@@ -3098,8 +3099,6 @@ NetworkLibraryImplCros::~NetworkLibraryImplCros() {
}
void NetworkLibraryImplCros::Init() {
- CHECK(CrosLibrary::Get()->LibraryLoaded())
- << "libcros must be loaded before NetworkLibraryImplCros::Init()";
// First, get the currently available networks. This data is cached
// on the connman side, so the call should be quick.
VLOG(1) << "Requesting initial network manager info from libcros.";
@@ -4599,23 +4598,18 @@ void NetworkLibraryImplStub::SetIPConfig(const NetworkIPConfig& ipconfig) {
/////////////////////////////////////////////////////////////////////////////
-// In NetworkLibrary, rather than check each call to libcros (calls prefixed
-// here with explicit chromeos::), we check to see whether or not libcros was
-// actually loaded. If not, we return a stub implementation instead.
-// This is for UI and Browser tests that require more functionality than the
-// other CrosLibrary modules provide in their stub implementation.
-// TODO(stevenjb): Fix this to be consistent across all CrosLibrary modules.
-
// static
NetworkLibrary* NetworkLibrary::GetImpl(bool stub) {
- NetworkLibrary* impl;
- if (stub || !CrosLibrary::Get()->LibraryLoaded())
- impl = new NetworkLibraryImplStub();
- else
- impl = new NetworkLibraryImplCros();
- impl->Init();
-
- return impl;
+ // Use static global to avoid recursive GetImpl() call from EnsureCrosLoaded.
+ static NetworkLibrary* network_library = NULL;
+ if (network_library == NULL) {
+ if (stub || !CrosLibrary::Get()->EnsureLoaded())
+ network_library = new NetworkLibraryImplStub();
+ else
+ network_library = new NetworkLibraryImplCros();
+ network_library->Init();
+ }
+ return network_library;
}
/////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/chromeos/login/cryptohome_op_unittest.cc b/chrome/browser/chromeos/login/cryptohome_op_unittest.cc
index 3ea6908..3a9c205 100644
--- a/chrome/browser/chromeos/login/cryptohome_op_unittest.cc
+++ b/chrome/browser/chromeos/login/cryptohome_op_unittest.cc
@@ -131,12 +131,8 @@ class CryptohomeOpTest : public ::testing::Test {
TestAttemptState state_;
scoped_ptr<MockAuthAttemptStateResolver> resolver_;
scoped_refptr<CryptohomeOp> op_;
-
- // Initializes / shuts down a stub CrosLibrary.
- chromeos::ScopedStubCrosEnabler stub_cros_enabler_;
-
- // Provide a mock for testing cryptohome.
scoped_ptr<MockCryptohomeLibrary> mock_library_;
+
};
TEST_F(CryptohomeOpTest, MountSuccess) {
diff --git a/chrome/browser/chromeos/login/google_authenticator_unittest.cc b/chrome/browser/chromeos/login/google_authenticator_unittest.cc
index 49a3b2c..b3a9cae 100644
--- a/chrome/browser/chromeos/login/google_authenticator_unittest.cc
+++ b/chrome/browser/chromeos/login/google_authenticator_unittest.cc
@@ -163,10 +163,6 @@ class GoogleAuthenticatorTest : public TestingBrowserProcessTest {
std::string username_;
std::string password_;
GaiaAuthConsumer::ClientLoginResult result_;
-
- // Initializes / shuts down a stub CrosLibrary.
- chromeos::ScopedStubCrosEnabler stub_cros_enabler_;
-
// Mocks, destroyed by CrosLibrary class.
MockCryptohomeLibrary* mock_library_;
MockLibraryLoader* loader_;
diff --git a/chrome/browser/chromeos/login/online_attempt_unittest.cc b/chrome/browser/chromeos/login/online_attempt_unittest.cc
index a2f5989..b861b50 100644
--- a/chrome/browser/chromeos/login/online_attempt_unittest.cc
+++ b/chrome/browser/chromeos/login/online_attempt_unittest.cc
@@ -103,9 +103,6 @@ class OnlineAttemptTest : public TestingBrowserProcessTest {
TestAttemptState state_;
scoped_ptr<MockAuthAttemptStateResolver> resolver_;
scoped_refptr<OnlineAttempt> attempt_;
-
- // Initializes / shuts down a stub CrosLibrary.
- chromeos::ScopedStubCrosEnabler stub_cros_enabler_;
};
TEST_F(OnlineAttemptTest, LoginSuccess) {
diff --git a/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc b/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc
index 22e9b51..8954f8f 100644
--- a/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc
+++ b/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc
@@ -237,9 +237,6 @@ class ParallelAuthenticatorTest : public TestingBrowserProcessTest {
std::string hash_ascii_;
GaiaAuthConsumer::ClientLoginResult result_;
- // Initializes / shuts down a stub CrosLibrary.
- chromeos::ScopedStubCrosEnabler stub_cros_enabler_;
-
// Mocks, destroyed by CrosLibrary class.
MockCryptohomeLibrary* mock_library_;
MockLibraryLoader* loader_;
diff --git a/chrome/browser/chromeos/offline/offline_load_page_unittest.cc b/chrome/browser/chromeos/offline/offline_load_page_unittest.cc
index 7d52091..c9dce52 100644
--- a/chrome/browser/chromeos/offline/offline_load_page_unittest.cc
+++ b/chrome/browser/chromeos/offline/offline_load_page_unittest.cc
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/offline/offline_load_page.h"
#include "content/browser/browser_thread.h"
#include "content/browser/renderer_host/test_render_view_host.h"
@@ -85,9 +84,6 @@ class OfflineLoadPageTest : public RenderViewHostTestHarness,
UserResponse user_response_;
BrowserThread ui_thread_;
BrowserThread io_thread_;
-
- // Initializes / shuts down a stub CrosLibrary.
- chromeos::ScopedStubCrosEnabler stub_cros_enabler_;
};
diff --git a/chrome/browser/chromeos/upgrade_detector_chromeos.cc b/chrome/browser/chromeos/upgrade_detector_chromeos.cc
index ff96b3c..45ad77a 100644
--- a/chrome/browser/chromeos/upgrade_detector_chromeos.cc
+++ b/chrome/browser/chromeos/upgrade_detector_chromeos.cc
@@ -20,10 +20,7 @@ UpgradeDetectorChromeos::UpgradeDetectorChromeos() {
}
UpgradeDetectorChromeos::~UpgradeDetectorChromeos() {
- // Only remove observer if CrosLibrary has not already been shut down.
- // See: http://crosbug.com/19295.
- if (chromeos::CrosLibrary::Initialized())
- chromeos::CrosLibrary::Get()->GetUpdateLibrary()->RemoveObserver(this);
+ chromeos::CrosLibrary::Get()->GetUpdateLibrary()->RemoveObserver(this);
}
void UpgradeDetectorChromeos::UpdateStatusChanged(
diff --git a/chrome/browser/profiles/profile_manager_unittest.cc b/chrome/browser/profiles/profile_manager_unittest.cc
index 9e4bab6..ab0073a 100644
--- a/chrome/browser/profiles/profile_manager_unittest.cc
+++ b/chrome/browser/profiles/profile_manager_unittest.cc
@@ -10,7 +10,6 @@
#include "base/scoped_temp_dir.h"
#include "base/system_monitor/system_monitor.h"
#include "base/values.h"
-#include "build/build_config.h"
#include "chrome/browser/extensions/extension_event_router_forwarder.h"
#include "chrome/browser/io_thread.h"
#include "chrome/browser/prefs/browser_prefs.h"
@@ -28,10 +27,6 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
-#if defined(OS_CHROMEOS)
-#include "chrome/browser/chromeos/cros/cros_library.h"
-#endif
-
namespace {
// This global variable is used to check that value returned to different
// observers is the same.
@@ -85,10 +80,6 @@ class ProfileManagerTest : public TestingBrowserProcessTest {
scoped_ptr<base::SystemMonitor> system_monitor_dummy_;
-#if defined(OS_CHROMEOS)
- chromeos::ScopedStubCrosEnabler stub_cros_enabler_;
-#endif
-
// Also will test profile deletion.
scoped_ptr<ProfileManager> profile_manager_;
};