diff options
author | stevenjb@google.com <stevenjb@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-20 00:41:05 +0000 |
---|---|---|
committer | stevenjb@google.com <stevenjb@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-20 00:41:05 +0000 |
commit | 8ec2c7e81ab2e1f5bcfa93e3655263d5e27d90cf (patch) | |
tree | 3b78be545fd8a0990676991459712c40d24c598f /chrome | |
parent | 505d5b07b369d684c811f1347c65a6e098b2ec88 (diff) | |
download | chromium_src-8ec2c7e81ab2e1f5bcfa93e3655263d5e27d90cf.zip chromium_src-8ec2c7e81ab2e1f5bcfa93e3655263d5e27d90cf.tar.gz chromium_src-8ec2c7e81ab2e1f5bcfa93e3655263d5e27d90cf.tar.bz2 |
Use stub impl when libcros fails to load
Previous behavior would either:
a. Successfully load libcros. CrosLibrary::EnsureLoaded() returns true. Calls to libcros succeed.
b. Fail to load libcros. CrosLibrary::EnsureLoaded() returns false. Login is blocked. Calls to libcros fail (crash) if not protected and login is skipped for debugging.
c. Load a stub implementation if --stub-cros is specified. CrosLibrary::EnsureLoaded() returns true. Calls to libcros fail (crash).
Problems with this behavior:
1. CrosLibrary::EnsureLoaded() would be used incorrectly to protect calls to libcros outside of CrosLibrary non-stub implementations.
2. CrosLibrary non-stub implementations would still be called if libcros failed to load, so all calls to libcros in the non-stub implementations needed to be protected.
New behavior:
a. Successfully load libcros. CrosLibrary::libcros_loaded() returns true. Calls to libcros succeed.
b. Fail to load libcros. CrosLibrary::libcros_loaded() returns false. Stub implementation is used instead. load_error_string() specifies an error and login is blocked.
c. Load a stub implementation if --stub-cros is specified. CrosLibrary::libcros_loaded() returns false. Stub implementation is used.
BUG=chromium-os:20350
TEST=Test chrome for chromeos on linux and chromeos, with and without --stub-cros
Review URL: http://codereview.chromium.org/7891021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101876 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
19 files changed, 270 insertions, 297 deletions
diff --git a/chrome/browser/chromeos/cros/brightness_library.cc b/chrome/browser/chromeos/cros/brightness_library.cc index 2255320..fdf0c50 100644 --- a/chrome/browser/chromeos/cros/brightness_library.cc +++ b/chrome/browser/chromeos/cros/brightness_library.cc @@ -28,11 +28,10 @@ class BrightnessLibraryImpl : public BrightnessLibrary { // Begin BrightnessLibrary implementation. virtual void Init() OVERRIDE { - if (CrosLibrary::Get()->EnsureLoaded()) { - CHECK(!brightness_connection_) << "Already intialized"; - brightness_connection_ = - chromeos::MonitorBrightnessV2(&BrightnessChangedHandler, this); - } + DCHECK(CrosLibrary::Get()->libcros_loaded()); + CHECK(!brightness_connection_) << "Already intialized"; + brightness_connection_ = + chromeos::MonitorBrightnessV2(&BrightnessChangedHandler, this); } virtual void AddObserver(Observer* observer) OVERRIDE { @@ -44,13 +43,11 @@ class BrightnessLibraryImpl : public BrightnessLibrary { } virtual void DecreaseScreenBrightness(bool allow_off) OVERRIDE { - if (chromeos::DecreaseScreenBrightness) - chromeos::DecreaseScreenBrightness(allow_off); + chromeos::DecreaseScreenBrightness(allow_off); } virtual void IncreaseScreenBrightness() OVERRIDE { - if (chromeos::IncreaseScreenBrightness) - chromeos::IncreaseScreenBrightness(); + chromeos::IncreaseScreenBrightness(); } // End BrightnessLibrary implementation. diff --git a/chrome/browser/chromeos/cros/burn_library.cc b/chrome/browser/chromeos/cros/burn_library.cc index e45863c..62406e7 100644 --- a/chrome/browser/chromeos/cros/burn_library.cc +++ b/chrome/browser/chromeos/cros/burn_library.cc @@ -88,11 +88,6 @@ BurnLibraryImpl::BurnLibraryImpl() : unzipping_(false), cancelled_(false), burning_(false), block_burn_signals_(false) { - if (CrosLibrary::Get()->EnsureLoaded()) { - Init(); - } else { - LOG(ERROR) << "Cros Library has not been loaded"; - } } BurnLibraryImpl::~BurnLibraryImpl() { @@ -102,7 +97,9 @@ BurnLibraryImpl::~BurnLibraryImpl() { } void BurnLibraryImpl::Init() { - burn_status_connection_ = MonitorBurnStatus(&BurnStatusChangedHandler, this); + DCHECK(CrosLibrary::Get()->libcros_loaded()); + burn_status_connection_ = + chromeos::MonitorBurnStatus(&BurnStatusChangedHandler, this); } void BurnLibraryImpl::AddObserver(Observer* observer) { @@ -254,6 +251,7 @@ class BurnLibraryStubImpl : public BurnLibrary { virtual ~BurnLibraryStubImpl() {} // BurnLibrary overrides. + virtual void Init() OVERRIDE {} virtual void AddObserver(Observer* observer) OVERRIDE {} virtual void RemoveObserver(Observer* observer) OVERRIDE {} virtual void DoBurn(const FilePath& source_path, @@ -268,10 +266,13 @@ class BurnLibraryStubImpl : public BurnLibrary { // static BurnLibrary* BurnLibrary::GetImpl(bool stub) { + BurnLibrary* impl; if (stub) - return new BurnLibraryStubImpl(); + impl = new BurnLibraryStubImpl(); else - return new BurnLibraryImpl(); + impl = new BurnLibraryImpl(); + impl->Init(); + return impl; } } // namespace chromeos @@ -279,4 +280,3 @@ BurnLibrary* BurnLibrary::GetImpl(bool stub) { // Allows InvokeLater without adding refcounting. This class is a Singleton and // won't be deleted until it's last InvokeLater is run. DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::BurnLibraryImpl); - diff --git a/chrome/browser/chromeos/cros/burn_library.h b/chrome/browser/chromeos/cros/burn_library.h index 8130f84..838a63f 100644 --- a/chrome/browser/chromeos/cros/burn_library.h +++ b/chrome/browser/chromeos/cros/burn_library.h @@ -67,6 +67,8 @@ class BurnLibrary { virtual ~BurnLibrary() {} + virtual void Init() = 0; + virtual void AddObserver(Observer* observer) = 0; virtual void RemoveObserver(Observer* observer) = 0; // Example values: diff --git a/chrome/browser/chromeos/cros/cros_library.cc b/chrome/browser/chromeos/cros/cros_library.cc index a3a748d..9e4596f 100644 --- a/chrome/browser/chromeos/cros/cros_library.cc +++ b/chrome/browser/chromeos/cros/cros_library.cc @@ -18,9 +18,12 @@ #include "chrome/browser/chromeos/cros/update_library.h" #include "third_party/cros/chromeos_cros_api.h" +// Pass !libcros_loaded_ to GetDefaultImpl instead of use_stub_impl_ so that +// we load the stub impl regardless of whether use_stub was specified or the +// library failed to load. #define DEFINE_GET_LIBRARY_METHOD(class_prefix, var_prefix) \ class_prefix##Library* CrosLibrary::Get##class_prefix##Library() { \ - return var_prefix##_lib_.GetDefaultImpl(use_stub_impl_); \ + return var_prefix##_lib_.GetDefaultImpl(!libcros_loaded_); \ } #define DEFINE_SET_LIBRARY_METHOD(class_prefix, var_prefix) \ @@ -57,10 +60,12 @@ void CrosLibrary::Initialize(bool use_stub) { } // Attempt to load libcros here, so that we can log, show warnings, and // set load_error_string_ immediately. - if (g_cros_library->LoadLibcros()) + if (g_cros_library->LoadLibcros()) { VLOG(1) << "CrosLibrary Initialized, version = " << kCrosAPIVersion; - else - LOG(WARNING) << "CrosLibrary failed to Initialize."; + } else { + LOG(WARNING) << "CrosLibrary failed to Initialize." + << " Will use stub implementations."; + } } // static diff --git a/chrome/browser/chromeos/cros/cryptohome_library.cc b/chrome/browser/chromeos/cros/cryptohome_library.cc index 29c62c9..98cf83d 100644 --- a/chrome/browser/chromeos/cros/cryptohome_library.cc +++ b/chrome/browser/chromeos/cros/cryptohome_library.cc @@ -20,37 +20,40 @@ namespace chromeos { // This class handles the interaction with the ChromeOS cryptohome library APIs. class CryptohomeLibraryImpl : public CryptohomeLibrary { public: - CryptohomeLibraryImpl() { - if (CrosLibrary::Get()->EnsureLoaded()) - Init(); - } + CryptohomeLibraryImpl() {} virtual ~CryptohomeLibraryImpl() {} - bool CheckKey(const std::string& user_email, const std::string& passhash) { + virtual void Init() OVERRIDE { + DCHECK(CrosLibrary::Get()->libcros_loaded()); + cryptohome_connection_ = chromeos::CryptohomeMonitorSession(&Handler, this); + } + + virtual bool CheckKey( + const std::string& user_email, const std::string& passhash) OVERRIDE { return chromeos::CryptohomeCheckKey(user_email.c_str(), passhash.c_str()); } - bool AsyncCheckKey(const std::string& user_email, - const std::string& passhash, - Delegate* d) { + virtual bool AsyncCheckKey(const std::string& user_email, + const std::string& passhash, + Delegate* d) OVERRIDE { return CacheCallback( chromeos::CryptohomeAsyncCheckKey(user_email.c_str(), passhash.c_str()), d, "Couldn't initiate async check of user's key."); } - bool MigrateKey(const std::string& user_email, - const std::string& old_hash, - const std::string& new_hash) { + virtual bool MigrateKey(const std::string& user_email, + const std::string& old_hash, + const std::string& new_hash) OVERRIDE { return chromeos::CryptohomeMigrateKey(user_email.c_str(), old_hash.c_str(), new_hash.c_str()); } - bool AsyncMigrateKey(const std::string& user_email, + virtual bool AsyncMigrateKey(const std::string& user_email, const std::string& old_hash, const std::string& new_hash, - Delegate* d) { + Delegate* d) OVERRIDE { return CacheCallback( chromeos::CryptohomeAsyncMigrateKey(user_email.c_str(), old_hash.c_str(), @@ -59,18 +62,18 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary { "Couldn't initiate aync migration of user's key"); } - bool Mount(const std::string& user_email, - const std::string& passhash, - int* error_code) { + virtual bool Mount(const std::string& user_email, + const std::string& passhash, + int* error_code) OVERRIDE { return chromeos::CryptohomeMountAllowFail(user_email.c_str(), passhash.c_str(), error_code); } - bool AsyncMount(const std::string& user_email, - const std::string& passhash, - const bool create_if_missing, - Delegate* d) { + virtual bool AsyncMount(const std::string& user_email, + const std::string& passhash, + const bool create_if_missing, + Delegate* d) OVERRIDE { return CacheCallback( chromeos::CryptohomeAsyncMountSafe(user_email.c_str(), passhash.c_str(), @@ -81,36 +84,37 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary { "Couldn't initiate async mount of cryptohome."); } - bool MountForBwsi(int* error_code) { + virtual bool MountForBwsi(int* error_code) OVERRIDE { return chromeos::CryptohomeMountGuest(error_code); } - bool AsyncMountForBwsi(Delegate* d) { + virtual bool AsyncMountForBwsi(Delegate* d) OVERRIDE { return CacheCallback(chromeos::CryptohomeAsyncMountGuest(), d, "Couldn't initiate async mount of cryptohome."); } - bool Unmount() { + virtual bool Unmount() OVERRIDE { return chromeos::CryptohomeUnmount(); } - bool Remove(const std::string& user_email) { + virtual bool Remove(const std::string& user_email) OVERRIDE { return chromeos::CryptohomeRemove(user_email.c_str()); } - bool AsyncRemove(const std::string& user_email, Delegate* d) { + virtual bool AsyncRemove( + const std::string& user_email, Delegate* d) OVERRIDE { return CacheCallback( chromeos::CryptohomeAsyncRemove(user_email.c_str()), d, "Couldn't initiate async removal of cryptohome."); } - bool IsMounted() { + virtual bool IsMounted() OVERRIDE { return chromeos::CryptohomeIsMounted(); } - CryptohomeBlob GetSystemSalt() { + virtual CryptohomeBlob GetSystemSalt() OVERRIDE { CryptohomeBlob system_salt; char* salt_buf; int salt_len; @@ -127,37 +131,38 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary { return system_salt; } - bool AsyncDoAutomaticFreeDiskSpaceControl(Delegate* d) { + virtual bool AsyncDoAutomaticFreeDiskSpaceControl(Delegate* d) OVERRIDE { return CacheCallback( chromeos::CryptohomeAsyncDoAutomaticFreeDiskSpaceControl(), d, "Couldn't do automatic free disk space control."); } - bool AsyncSetOwnerUser(const std::string& username, Delegate* d) { + virtual bool AsyncSetOwnerUser( + const std::string& username, Delegate* d) OVERRIDE { return CacheCallback( chromeos::CryptohomeAsyncSetOwnerUser(username.c_str()), d, "Couldn't do set owner user in Cryptohomed."); } - bool TpmIsReady() { + virtual bool TpmIsReady() OVERRIDE { return chromeos::CryptohomeTpmIsReady(); } - bool TpmIsEnabled() { + virtual bool TpmIsEnabled() OVERRIDE { return chromeos::CryptohomeTpmIsEnabled(); } - bool TpmIsOwned() { + virtual bool TpmIsOwned() OVERRIDE { return chromeos::CryptohomeTpmIsOwned(); } - bool TpmIsBeingOwned() { + virtual bool TpmIsBeingOwned() OVERRIDE { return chromeos::CryptohomeTpmIsBeingOwned(); } - bool TpmGetPassword(std::string* password) { + virtual bool TpmGetPassword(std::string* password) OVERRIDE { char *password_buf; bool result = chromeos::CryptohomeTpmGetPasswordSafe(&password_buf); *password = password_buf; @@ -165,15 +170,16 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary { return result; } - void TpmCanAttemptOwnership() { + virtual void TpmCanAttemptOwnership() OVERRIDE { chromeos::CryptohomeTpmCanAttemptOwnership(); } - void TpmClearStoredPassword() { + virtual void TpmClearStoredPassword() OVERRIDE { chromeos::CryptohomeTpmClearStoredPassword(); } - bool InstallAttributesGet(const std::string& name, std::string* value) { + virtual bool InstallAttributesGet( + const std::string& name, std::string* value) OVERRIDE { char* local_value; bool done = chromeos::CryptohomeInstallAttributesGet(name.c_str(), &local_value); @@ -184,40 +190,42 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary { return done; } - bool InstallAttributesSet(const std::string& name, const std::string& value) { + virtual bool InstallAttributesSet( + const std::string& name, const std::string& value) OVERRIDE { return chromeos::CryptohomeInstallAttributesSet(name.c_str(), value.c_str()); } - int InstallAttributesCount() { + virtual int InstallAttributesCount() OVERRIDE { return chromeos::CryptohomeInstallAttributesCount(); } - bool InstallAttributesFinalize() { + virtual bool InstallAttributesFinalize() OVERRIDE { return chromeos::CryptohomeInstallAttributesFinalize(); } - bool InstallAttributesIsReady() { + virtual bool InstallAttributesIsReady() OVERRIDE { return chromeos::CryptohomeInstallAttributesIsReady(); } - bool InstallAttributesIsSecure() { + virtual bool InstallAttributesIsSecure() OVERRIDE { return chromeos::CryptohomeInstallAttributesIsSecure(); } - bool InstallAttributesIsInvalid() { + virtual bool InstallAttributesIsInvalid() OVERRIDE { return chromeos::CryptohomeInstallAttributesIsInvalid(); } - bool InstallAttributesIsFirstInstall() { + virtual bool InstallAttributesIsFirstInstall() OVERRIDE { return chromeos::CryptohomeInstallAttributesIsFirstInstall(); } - void Pkcs11GetTpmTokenInfo(std::string* label, std::string* user_pin) { + virtual void Pkcs11GetTpmTokenInfo( + std::string* label, std::string* user_pin) OVERRIDE { chromeos::CryptohomePkcs11GetTpmTokenInfo(label, user_pin); } - bool Pkcs11IsTpmTokenReady() { + virtual bool Pkcs11IsTpmTokenReady() OVERRIDE { return chromeos::CryptohomePkcs11IsTpmTokenReady(); } @@ -229,10 +237,6 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary { library->Dispatch(event); } - void Init() { - cryptohome_connection_ = chromeos::CryptohomeMonitorSession(&Handler, this); - } - void Dispatch(const chromeos::CryptohomeAsyncCallStatus& event) { const CallbackMap::iterator callback = callback_map_.find(event.async_id); if (callback == callback_map_.end()) { @@ -268,38 +272,41 @@ class CryptohomeLibraryStubImpl : public CryptohomeLibrary { : locked_(false) {} virtual ~CryptohomeLibraryStubImpl() {} - bool CheckKey(const std::string& user_email, const std::string& passhash) { + virtual void Init() OVERRIDE {} + + virtual bool CheckKey( + const std::string& user_email, const std::string& passhash) OVERRIDE { return true; } - bool AsyncCheckKey(const std::string& user_email, - const std::string& passhash, - Delegate* callback) { + virtual bool AsyncCheckKey(const std::string& user_email, + const std::string& passhash, + Delegate* callback) OVERRIDE { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, NewRunnableFunction(&DoStubCallback, callback)); return true; } - bool MigrateKey(const std::string& user_email, - const std::string& old_hash, - const std::string& new_hash) { + virtual bool MigrateKey(const std::string& user_email, + const std::string& old_hash, + const std::string& new_hash) OVERRIDE { return true; } - bool AsyncMigrateKey(const std::string& user_email, - const std::string& old_hash, - const std::string& new_hash, - Delegate* callback) { + virtual bool AsyncMigrateKey(const std::string& user_email, + const std::string& old_hash, + const std::string& new_hash, + Delegate* callback) OVERRIDE { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, NewRunnableFunction(&DoStubCallback, callback)); return true; } - bool Mount(const std::string& user_email, - const std::string& passhash, - int* error_code) { + virtual bool Mount(const std::string& user_email, + const std::string& passhash, + int* error_code) OVERRIDE { // For testing password change. if (user_email == CommandLine::ForCurrentProcess()->GetSwitchValueASCII( @@ -311,47 +318,48 @@ class CryptohomeLibraryStubImpl : public CryptohomeLibrary { return true; } - bool AsyncMount(const std::string& user_email, - const std::string& passhash, - const bool create_if_missing, - Delegate* callback) { + virtual bool AsyncMount(const std::string& user_email, + const std::string& passhash, + const bool create_if_missing, + Delegate* callback) OVERRIDE { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, NewRunnableFunction(&DoStubCallback, callback)); return true; } - bool MountForBwsi(int* error_code) { + virtual bool MountForBwsi(int* error_code) OVERRIDE { return true; } - bool AsyncMountForBwsi(Delegate* callback) { + virtual bool AsyncMountForBwsi(Delegate* callback) OVERRIDE { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, NewRunnableFunction(&DoStubCallback, callback)); return true; } - bool Unmount() { + virtual bool Unmount() OVERRIDE { return true; } - bool Remove(const std::string& user_email) { + virtual bool Remove(const std::string& user_email) OVERRIDE { return true; } - bool AsyncRemove(const std::string& user_email, Delegate* callback) { + virtual bool AsyncRemove( + const std::string& user_email, Delegate* callback) OVERRIDE { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, NewRunnableFunction(&DoStubCallback, callback)); return true; } - bool IsMounted() { + virtual bool IsMounted() OVERRIDE { return true; } - CryptohomeBlob GetSystemSalt() { + virtual CryptohomeBlob GetSystemSalt() OVERRIDE { CryptohomeBlob salt = CryptohomeBlob(); for (size_t i = 0; i < strlen(kStubSystemSalt); i++) salt.push_back(static_cast<unsigned char>(kStubSystemSalt[i])); @@ -359,14 +367,16 @@ class CryptohomeLibraryStubImpl : public CryptohomeLibrary { return salt; } - bool AsyncDoAutomaticFreeDiskSpaceControl(Delegate* callback) { + virtual bool AsyncDoAutomaticFreeDiskSpaceControl( + Delegate* callback) OVERRIDE { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, NewRunnableFunction(&DoStubCallback, callback)); return true; } - bool AsyncSetOwnerUser(const std::string& username, Delegate* callback) { + virtual bool AsyncSetOwnerUser( + const std::string& username, Delegate* callback) OVERRIDE { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, NewRunnableFunction(&DoStubCallback, callback)); @@ -374,33 +384,34 @@ class CryptohomeLibraryStubImpl : public CryptohomeLibrary { } // Tpm begin ready after 20-th call. - bool TpmIsReady() { + virtual bool TpmIsReady() OVERRIDE { static int counter = 0; return ++counter > 20; } - bool TpmIsEnabled() { + virtual bool TpmIsEnabled() OVERRIDE { return true; } - bool TpmIsOwned() { + virtual bool TpmIsOwned() OVERRIDE { return true; } - bool TpmIsBeingOwned() { + virtual bool TpmIsBeingOwned() OVERRIDE { return true; } - bool TpmGetPassword(std::string* password) { + virtual bool TpmGetPassword(std::string* password) OVERRIDE { *password = "Stub-TPM-password"; return true; } - void TpmCanAttemptOwnership() {} + virtual void TpmCanAttemptOwnership() OVERRIDE {} - void TpmClearStoredPassword() {} + virtual void TpmClearStoredPassword() OVERRIDE {} - bool InstallAttributesGet(const std::string& name, std::string* value) { + virtual bool InstallAttributesGet( + const std::string& name, std::string* value) OVERRIDE { if (install_attrs_.find(name) != install_attrs_.end()) { *value = install_attrs_[name]; return true; @@ -408,43 +419,44 @@ class CryptohomeLibraryStubImpl : public CryptohomeLibrary { return false; } - bool InstallAttributesSet(const std::string& name, const std::string& value) { + virtual bool InstallAttributesSet( + const std::string& name, const std::string& value) OVERRIDE { install_attrs_[name] = value; return true; } - int InstallAttributesCount() { + virtual int InstallAttributesCount() OVERRIDE { return install_attrs_.size(); } - bool InstallAttributesFinalize() { + virtual bool InstallAttributesFinalize() OVERRIDE { locked_ = true; return true; } - bool InstallAttributesIsReady() { + virtual bool InstallAttributesIsReady() OVERRIDE { return true; } - bool InstallAttributesIsSecure() { + virtual bool InstallAttributesIsSecure() OVERRIDE { return false; } - bool InstallAttributesIsInvalid() { + virtual bool InstallAttributesIsInvalid() OVERRIDE { return false; } - bool InstallAttributesIsFirstInstall() { + virtual bool InstallAttributesIsFirstInstall() OVERRIDE { return !locked_; } - void Pkcs11GetTpmTokenInfo(std::string* label, - std::string* user_pin) { + virtual void Pkcs11GetTpmTokenInfo(std::string* label, + std::string* user_pin) OVERRIDE { *label = "Stub TPM Token"; *user_pin = "012345"; } - bool Pkcs11IsTpmTokenReady() { return true; } + virtual bool Pkcs11IsTpmTokenReady() OVERRIDE { return true; } private: static void DoStubCallback(Delegate* callback) { @@ -462,10 +474,13 @@ CryptohomeLibrary::~CryptohomeLibrary() {} // static CryptohomeLibrary* CryptohomeLibrary::GetImpl(bool stub) { + CryptohomeLibrary* impl; if (stub) - return new CryptohomeLibraryStubImpl(); + impl = new CryptohomeLibraryStubImpl(); else - return new CryptohomeLibraryImpl(); + impl = new CryptohomeLibraryImpl(); + impl->Init(); + return impl; } } // namespace chromeos diff --git a/chrome/browser/chromeos/cros/cryptohome_library.h b/chrome/browser/chromeos/cros/cryptohome_library.h index e126e1a..547d2ab 100644 --- a/chrome/browser/chromeos/cros/cryptohome_library.h +++ b/chrome/browser/chromeos/cros/cryptohome_library.h @@ -28,6 +28,8 @@ class CryptohomeLibrary { CryptohomeLibrary(); virtual ~CryptohomeLibrary(); + virtual void Init() = 0; + // Asks cryptohomed to try to find the cryptohome for |user_email| and then // use |passhash| to unlock the key. virtual bool CheckKey(const std::string& user_email, diff --git a/chrome/browser/chromeos/cros/login_library.cc b/chrome/browser/chromeos/cros/login_library.cc index 4bd2f13..1e5d7c0 100644 --- a/chrome/browser/chromeos/cros/login_library.cc +++ b/chrome/browser/chromeos/cros/login_library.cc @@ -25,8 +25,6 @@ LoginLibrary::~LoginLibrary() {} class LoginLibraryImpl : public LoginLibrary { public: LoginLibraryImpl() : job_restart_request_(NULL) { - CHECK(CrosLibrary::Get() && CrosLibrary::Get()->libcros_loaded()); - Init(); } virtual ~LoginLibraryImpl() { @@ -36,44 +34,52 @@ class LoginLibraryImpl : public LoginLibrary { } } - void EmitLoginPromptReady() { + virtual void Init() OVERRIDE { + DCHECK(CrosLibrary::Get()->libcros_loaded()); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + session_connection_ = chromeos::MonitorSession(&Handler, this); + } + + virtual void EmitLoginPromptReady() OVERRIDE { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); chromeos::EmitLoginPromptReady(); } - void RequestRetrievePolicy(RetrievePolicyCallback callback, void* delegate) { + virtual void RequestRetrievePolicy( + RetrievePolicyCallback callback, void* delegate) OVERRIDE { DCHECK(callback) << "must provide a callback to RequestRetrievePolicy()"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); chromeos::RetrievePolicy(callback, delegate); } - void RequestStorePolicy(const std::string& policy, - StorePolicyCallback callback, - void* delegate) { + virtual void RequestStorePolicy(const std::string& policy, + StorePolicyCallback callback, + void* delegate) OVERRIDE { DCHECK(callback) << "must provide a callback to StorePolicy()"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); chromeos::StorePolicy(policy.c_str(), policy.length(), callback, delegate); } - bool StartSession(const std::string& user_email, - const std::string& unique_id /* unused */) { + virtual bool StartSession( + const std::string& user_email, + const std::string& unique_id /* unused */) OVERRIDE { // only pass unique_id through once we use it for something. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); return chromeos::StartSession(user_email.c_str(), ""); } - bool StopSession(const std::string& unique_id /* unused */) { + virtual bool StopSession(const std::string& unique_id /* unused */) OVERRIDE { // only pass unique_id through once we use it for something. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); return chromeos::StopSession(""); } - bool RestartEntd() { + virtual bool RestartEntd() OVERRIDE { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); return chromeos::RestartEntd(); } - bool RestartJob(int pid, const std::string& command_line) { + virtual bool RestartJob(int pid, const std::string& command_line) OVERRIDE { if (job_restart_request_) { NOTREACHED(); return false; @@ -172,11 +178,6 @@ class LoginLibraryImpl : public LoginLibrary { } } - void Init() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - session_connection_ = chromeos::MonitorSession(&Handler, this); - } - void CompleteSetOwnerKey(bool value) { VLOG(1) << "Owner key generation: " << (value ? "success" : "fail"); int result = @@ -221,20 +222,30 @@ class LoginLibraryStubImpl : public LoginLibrary { LoginLibraryStubImpl() {} virtual ~LoginLibraryStubImpl() {} - void EmitLoginPromptReady() { } - void RequestRetrievePolicy(RetrievePolicyCallback callback, void* delegate) { + virtual void Init() OVERRIDE {} + + virtual void EmitLoginPromptReady() OVERRIDE {} + virtual void RequestRetrievePolicy( + RetrievePolicyCallback callback, void* delegate) OVERRIDE { callback(delegate, "", 0); } - void RequestStorePolicy(const std::string& policy, - StorePolicyCallback callback, - void* delegate) { + virtual void RequestStorePolicy(const std::string& policy, + StorePolicyCallback callback, + void* delegate) OVERRIDE { callback(delegate, true); } - bool StartSession(const std::string& user_email, - const std::string& unique_id /* unused */) { return true; } - bool StopSession(const std::string& unique_id /* unused */) { return true; } - bool RestartJob(int pid, const std::string& command_line) { return true; } - bool RestartEntd() { return true; } + virtual bool StartSession( + const std::string& user_email, + const std::string& unique_id /* unused */) OVERRIDE { + return true; + } + virtual bool StopSession(const std::string& unique_id /* unused */) OVERRIDE { + return true; + } + virtual bool RestartJob(int pid, const std::string& command_line) OVERRIDE { + return true; + } + virtual bool RestartEntd() OVERRIDE { return true; } private: DISALLOW_COPY_AND_ASSIGN(LoginLibraryStubImpl); @@ -242,13 +253,13 @@ class LoginLibraryStubImpl : public LoginLibrary { // static LoginLibrary* LoginLibrary::GetImpl(bool stub) { + LoginLibrary* impl; if (stub) - return new LoginLibraryStubImpl(); + impl = new LoginLibraryStubImpl(); else - return new LoginLibraryImpl(); + impl = new LoginLibraryImpl(); + impl->Init(); + return impl; } } // namespace chromeos - -// Needed for NewRunnableMethod() call above. -DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::LoginLibraryImpl); diff --git a/chrome/browser/chromeos/cros/login_library.h b/chrome/browser/chromeos/cros/login_library.h index d2f0538..f8c94c0 100644 --- a/chrome/browser/chromeos/cros/login_library.h +++ b/chrome/browser/chromeos/cros/login_library.h @@ -17,6 +17,9 @@ namespace chromeos { class LoginLibrary { public: virtual ~LoginLibrary(); + + virtual void Init() = 0; + // Requests that the Upstart signal login-prompt-ready be emitted. virtual void EmitLoginPromptReady() = 0; diff --git a/chrome/browser/chromeos/cros/mock_cryptohome_library.h b/chrome/browser/chromeos/cros/mock_cryptohome_library.h index f792fc3..b80a9a7 100644 --- a/chrome/browser/chromeos/cros/mock_cryptohome_library.h +++ b/chrome/browser/chromeos/cros/mock_cryptohome_library.h @@ -24,6 +24,7 @@ class MockCryptohomeLibrary : public CryptohomeLibrary { void SetUp(bool outcome, int code); + MOCK_METHOD0(Init, void(void)); MOCK_METHOD2(CheckKey, bool(const std::string& user_email, const std::string& passhash)); MOCK_METHOD3(AsyncCheckKey, bool(const std::string& user_email, diff --git a/chrome/browser/chromeos/cros/mock_login_library.h b/chrome/browser/chromeos/cros/mock_login_library.h index bd65aca..1e7650d 100644 --- a/chrome/browser/chromeos/cros/mock_login_library.h +++ b/chrome/browser/chromeos/cros/mock_login_library.h @@ -18,6 +18,7 @@ class MockLoginLibrary : public LoginLibrary { MockLoginLibrary(); virtual ~MockLoginLibrary(); + MOCK_METHOD0(Init, void(void)); MOCK_METHOD0(EmitLoginPromptReady, void(void)); MOCK_METHOD2(RequestRetrievePolicy, void(RetrievePolicyCallback, void*)); MOCK_METHOD3(RequestStorePolicy, void(const std::string&, diff --git a/chrome/browser/chromeos/cros/mock_mount_library.h b/chrome/browser/chromeos/cros/mock_mount_library.h index 020849f..793bff9 100644 --- a/chrome/browser/chromeos/cros/mock_mount_library.h +++ b/chrome/browser/chromeos/cros/mock_mount_library.h @@ -22,6 +22,7 @@ class MockMountLibrary : public MountLibrary { MockMountLibrary(); virtual ~MockMountLibrary(); + MOCK_METHOD0(Init, void(void)); MOCK_METHOD1(AddObserver, void(MountLibrary::Observer*)); MOCK_METHOD1(RemoveObserver, void(MountLibrary::Observer*)); MOCK_CONST_METHOD0(disks, const MountLibrary::DiskMap&(void)); diff --git a/chrome/browser/chromeos/cros/mount_library.cc b/chrome/browser/chromeos/cros/mount_library.cc index 32086ca..7d256c0 100644 --- a/chrome/browser/chromeos/cros/mount_library.cc +++ b/chrome/browser/chromeos/cros/mount_library.cc @@ -101,43 +101,45 @@ class MountLibcrosProxyImpl : public MountLibcrosProxy { const MountPathOptions& options, MountCompletedMonitor callback, void* object) OVERRIDE { - MountSourcePath(source_path, type, options, callback, object); + chromeos::MountSourcePath(source_path, type, options, callback, object); } virtual void CallUnmountPath(const char* path, UnmountRequestCallback callback, void* object) OVERRIDE { - UnmountMountPoint(path, callback, object); + chromeos::UnmountMountPoint(path, callback, object); } virtual void CallRequestMountInfo(RequestMountInfoCallback callback, void* object) OVERRIDE { - RequestMountInfo(callback, object); + chromeos::RequestMountInfo(callback, object); } virtual void CallFormatDevice(const char* file_path, const char* filesystem, FormatRequestCallback callback, void* object) OVERRIDE { - FormatDevice(file_path, filesystem, callback, object); + chromeos::FormatDevice(file_path, filesystem, callback, object); } virtual void CallGetDiskProperties(const char* device_path, GetDiskPropertiesCallback callback, void* object) OVERRIDE { - GetDiskProperties(device_path, callback, object); + chromeos::GetDiskProperties(device_path, callback, object); } - virtual MountEventConnection MonitorCrosDisks(MountEventMonitor monitor, + virtual MountEventConnection MonitorCrosDisks( + MountEventMonitor monitor, MountCompletedMonitor mount_completed_monitor, void* object) OVERRIDE { - return MonitorAllMountEvents(monitor, mount_completed_monitor, object); + return chromeos::MonitorAllMountEvents( + monitor, mount_completed_monitor, object); } - virtual void DisconnectCrosDisksMonitorIfSet(MountEventConnection conn) - OVERRIDE { + virtual void DisconnectCrosDisksMonitorIfSet( + MountEventConnection conn) OVERRIDE { if (conn) - DisconnectMountEventMonitor(conn); + chromeos::DisconnectMountEventMonitor(conn); } }; @@ -163,10 +165,6 @@ class MountLibraryImpl : public MountLibrary { public: MountLibraryImpl() : libcros_proxy_(new MountLibcrosProxyImpl()), mount_status_connection_(NULL) { - if (CrosLibrary::Get()->EnsureLoaded()) - Init(); - else - LOG(ERROR) << kLibraryNotLoaded; } virtual ~MountLibraryImpl() { @@ -175,6 +173,13 @@ class MountLibraryImpl : public MountLibrary { } // MountLibrary overrides. + virtual void Init() OVERRIDE { + DCHECK(CrosLibrary::Get()->libcros_loaded()); + // Getting the monitor status so that the daemon starts up. + mount_status_connection_ = libcros_proxy_->MonitorCrosDisks( + &MonitorMountEventsHandler, &MountCompletedHandler, this); + } + virtual void AddObserver(Observer* observer) OVERRIDE { observers_.AddObserver(observer); } @@ -187,40 +192,18 @@ class MountLibraryImpl : public MountLibrary { MountType type, const MountPathOptions& options) OVERRIDE { CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!CrosLibrary::Get()->EnsureLoaded()) { - OnMountCompleted(MOUNT_ERROR_LIBRARY_NOT_LOADED, - MountPointInfo(source_path, - NULL, - type, - MOUNT_CONDITION_NONE)); - return; - } libcros_proxy_->CallMountPath(source_path, type, options, &MountCompletedHandler, this); } virtual void UnmountPath(const char* mount_path) OVERRIDE { CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!CrosLibrary::Get()->EnsureLoaded()) { - OnUnmountPath(mount_path, - MOUNT_METHOD_ERROR_LOCAL, - kLibraryNotLoaded); - return; - } - libcros_proxy_->CallUnmountPath(mount_path, &UnmountMountPointCallback, this); } virtual void FormatUnmountedDevice(const char* file_path) OVERRIDE { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!CrosLibrary::Get()->EnsureLoaded()) { - OnFormatDevice(file_path, - false, - MOUNT_METHOD_ERROR_LOCAL, - kLibraryNotLoaded); - return; - } for (MountLibrary::DiskMap::iterator it = disks_.begin(); it != disks_.end(); ++it) { if (it->second->file_path().compare(file_path) == 0 && @@ -274,30 +257,25 @@ class MountLibraryImpl : public MountLibrary { const char* error_message = NULL; std::vector<const char*> devices_to_unmount; - if (!CrosLibrary::Get()->EnsureLoaded()) { - success = false; - error_message = kLibraryNotLoaded; - } else { - // Get list of all devices to unmount. - int device_path_len = strlen(device_path); - for (DiskMap::iterator it = disks_.begin(); it != disks_.end(); ++it) { - if (!it->second->mount_path().empty() && - strncmp(device_path, it->second->device_path().c_str(), - device_path_len) == 0) { - devices_to_unmount.push_back(it->second->mount_path().c_str()); - } + // Get list of all devices to unmount. + int device_path_len = strlen(device_path); + for (DiskMap::iterator it = disks_.begin(); it != disks_.end(); ++it) { + if (!it->second->mount_path().empty() && + strncmp(device_path, it->second->device_path().c_str(), + device_path_len) == 0) { + devices_to_unmount.push_back(it->second->mount_path().c_str()); } + } - // We should detect at least original device. - if (devices_to_unmount.size() == 0) { - if (disks_.find(device_path) == disks_.end()) { - success = false; - error_message = kDeviceNotFound; - } else { - // Nothing to unmount. - callback(user_data, true); - return; - } + // We should detect at least original device. + if (devices_to_unmount.size() == 0) { + if (disks_.find(device_path) == disks_.end()) { + success = false; + error_message = kDeviceNotFound; + } else { + // Nothing to unmount. + callback(user_data, true); + return; } } @@ -322,13 +300,6 @@ class MountLibraryImpl : public MountLibrary { virtual void RequestMountInfoRefresh() OVERRIDE { CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!CrosLibrary::Get()->EnsureLoaded()) { - OnRequestMountInfo(NULL, - 0, - MOUNT_METHOD_ERROR_LOCAL, - kLibraryNotLoaded); - return; - } libcros_proxy_->CallRequestMountInfo(RequestMountInfoCallback, this); } @@ -722,12 +693,6 @@ class MountLibraryImpl : public MountLibrary { FireDeviceStatusUpdate(type, std::string(device_path)); } - void Init() { - // Getting the monitor status so that the daemon starts up. - mount_status_connection_ = libcros_proxy_->MonitorCrosDisks( - &MonitorMountEventsHandler, &MountCompletedHandler, this); - } - void FireDiskStatusUpdate(MountLibraryEventType evt, const Disk* disk) { // Make sure we run on UI thread. @@ -813,6 +778,7 @@ class MountLibraryStubImpl : public MountLibrary { virtual ~MountLibraryStubImpl() {} // MountLibrary overrides. + virtual void Init() OVERRIDE {} virtual void AddObserver(Observer* observer) OVERRIDE {} virtual void RemoveObserver(Observer* observer) OVERRIDE {} virtual const DiskMap& disks() const OVERRIDE { return disks_; } @@ -838,15 +804,13 @@ class MountLibraryStubImpl : public MountLibrary { // static MountLibrary* MountLibrary::GetImpl(bool stub) { + MountLibrary* impl; if (stub) - return new MountLibraryStubImpl(); + impl = new MountLibraryStubImpl(); else - return new MountLibraryImpl(); + impl = new MountLibraryImpl(); + impl->Init(); + return impl; } } // namespace chromeos - -// Allows InvokeLater without adding refcounting. This class is a Singleton and -// won't be deleted until it's last InvokeLater is run. -DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl); - diff --git a/chrome/browser/chromeos/cros/mount_library.h b/chrome/browser/chromeos/cros/mount_library.h index e0a3dd3..4f99389 100644 --- a/chrome/browser/chromeos/cros/mount_library.h +++ b/chrome/browser/chromeos/cros/mount_library.h @@ -177,6 +177,7 @@ class MountLibrary { }; virtual ~MountLibrary() {} + virtual void Init() = 0; virtual void AddObserver(Observer* observer) = 0; virtual void RemoveObserver(Observer* observer) = 0; virtual const DiskMap& disks() const = 0; diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc index a9ab183..eb7516f 100644 --- a/chrome/browser/chromeos/cros/network_library.cc +++ b/chrome/browser/chromeos/cros/network_library.cc @@ -4940,18 +4940,11 @@ void NetworkLibraryImplStub::SetIPConfig(const NetworkIPConfig& ipconfig) { // static NetworkLibrary* NetworkLibrary::GetImpl(bool stub) { NetworkLibrary* impl; - // If CrosLibrary failed to load, use the stub implementation, since the - // cros implementation would crash on any libcros call. - if (!stub && !CrosLibrary::Get()->libcros_loaded()) { - LOG(WARNING) << "NetworkLibrary: falling back to stub impl."; - stub = true; - } if (stub) impl = new NetworkLibraryImplStub(); else impl = new NetworkLibraryImplCros(); impl->Init(); - return impl; } diff --git a/chrome/browser/chromeos/cros/power_library.cc b/chrome/browser/chromeos/cros/power_library.cc index b4e0d9f..6ebb11d 100644 --- a/chrome/browser/chromeos/cros/power_library.cc +++ b/chrome/browser/chromeos/cros/power_library.cc @@ -38,12 +38,11 @@ class PowerLibraryImpl : public PowerLibrary { // Begin PowerLibrary implementation. virtual void Init() OVERRIDE { - if (CrosLibrary::Get()->EnsureLoaded()) { - power_status_connection_ = - chromeos::MonitorPowerStatus(&PowerStatusChangedHandler, this); - resume_status_connection_ = - chromeos::MonitorResume(&SystemResumedHandler, this); - } + DCHECK(CrosLibrary::Get()->libcros_loaded()); + power_status_connection_ = + chromeos::MonitorPowerStatus(&PowerStatusChangedHandler, this); + resume_status_connection_ = + chromeos::MonitorResume(&SystemResumedHandler, this); } virtual void AddObserver(Observer* observer) OVERRIDE { @@ -85,9 +84,6 @@ class PowerLibraryImpl : public PowerLibrary { } virtual void EnableScreenLock(bool enable) OVERRIDE { - if (!CrosLibrary::Get()->EnsureLoaded()) - return; - // Make sure we run on FILE thread becuase chromeos::EnableScreenLock // would write power manager config file to disk. if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { @@ -101,13 +97,11 @@ class PowerLibraryImpl : public PowerLibrary { } virtual void RequestRestart() OVERRIDE { - if (CrosLibrary::Get()->EnsureLoaded()) - chromeos::RequestRestart(); + chromeos::RequestRestart(); } virtual void RequestShutdown() OVERRIDE { - if (CrosLibrary::Get()->EnsureLoaded()) - chromeos::RequestShutdown(); + chromeos::RequestShutdown(); } virtual void RequestStatusUpdate() OVERRIDE { diff --git a/chrome/browser/chromeos/cros/screen_lock_library.cc b/chrome/browser/chromeos/cros/screen_lock_library.cc index fa6cbb8..53f8034 100644 --- a/chrome/browser/chromeos/cros/screen_lock_library.cc +++ b/chrome/browser/chromeos/cros/screen_lock_library.cc @@ -28,10 +28,9 @@ class ScreenLockLibraryImpl : public ScreenLockLibrary { // Begin ScreenLockLibrary implementation. virtual void Init() OVERRIDE { - if (CrosLibrary::Get()->EnsureLoaded()) { - screen_lock_connection_ = - chromeos::MonitorScreenLock(&ScreenLockedHandler, this); - } + DCHECK(CrosLibrary::Get()->libcros_loaded()); + screen_lock_connection_ = + chromeos::MonitorScreenLock(&ScreenLockedHandler, this); } virtual void AddObserver(Observer* observer) OVERRIDE { diff --git a/chrome/browser/chromeos/cros/speech_synthesis_library.cc b/chrome/browser/chromeos/cros/speech_synthesis_library.cc index 9dc797e..1102f94 100644 --- a/chrome/browser/chromeos/cros/speech_synthesis_library.cc +++ b/chrome/browser/chromeos/cros/speech_synthesis_library.cc @@ -66,10 +66,12 @@ class SpeechSynthesisLibraryStubImpl : public SpeechSynthesisLibrary { // static SpeechSynthesisLibrary* SpeechSynthesisLibrary::GetImpl(bool stub) { + SpeechSynthesisLibrary* impl; if (stub) - return new SpeechSynthesisLibraryStubImpl(); + impl = new SpeechSynthesisLibraryStubImpl(); else - return new SpeechSynthesisLibraryImpl(); + impl = new SpeechSynthesisLibraryImpl(); + return impl; } } // namespace chromeos diff --git a/chrome/browser/chromeos/cros/update_library.cc b/chrome/browser/chromeos/cros/update_library.cc index 1466b0e..3e8ce71 100644 --- a/chrome/browser/chromeos/cros/update_library.cc +++ b/chrome/browser/chromeos/cros/update_library.cc @@ -27,13 +27,12 @@ class UpdateLibraryImpl : public UpdateLibrary { // Begin UpdateLibrary implementation. virtual void Init() OVERRIDE { - if (CrosLibrary::Get()->EnsureLoaded()) { - CHECK(!status_connection_) << "Already initialized"; - status_connection_ = - chromeos::MonitorUpdateStatus(&UpdateStatusHandler, this); - // Asynchronously load the initial state. - chromeos::RequestUpdateStatus(&UpdateStatusHandler, this); - } + DCHECK(CrosLibrary::Get()->libcros_loaded()); + CHECK(!status_connection_) << "Already initialized"; + status_connection_ = + chromeos::MonitorUpdateStatus(&UpdateStatusHandler, this); + // Asynchronously load the initial state. + chromeos::RequestUpdateStatus(&UpdateStatusHandler, this); } virtual void AddObserver(Observer* observer) OVERRIDE { @@ -50,26 +49,20 @@ class UpdateLibraryImpl : public UpdateLibrary { virtual void RequestUpdateCheck(chromeos::UpdateCallback callback, void* user_data) OVERRIDE { - if (CrosLibrary::Get()->EnsureLoaded()) - chromeos::RequestUpdateCheck(callback, user_data); + chromeos::RequestUpdateCheck(callback, user_data); } virtual bool RebootAfterUpdate() OVERRIDE { - if (!CrosLibrary::Get()->EnsureLoaded()) - return false; - return RebootIfUpdated(); } virtual void SetReleaseTrack(const std::string& track) OVERRIDE { - if (CrosLibrary::Get()->EnsureLoaded()) - chromeos::SetUpdateTrack(track); + chromeos::SetUpdateTrack(track); } virtual void GetReleaseTrack(chromeos::UpdateTrackCallback callback, void* user_data) OVERRIDE { - if (CrosLibrary::Get()->EnsureLoaded()) - chromeos::RequestUpdateTrack(callback, user_data); + chromeos::RequestUpdateTrack(callback, user_data); } // End UpdateLibrary implementation. diff --git a/chrome/browser/chromeos/status/power_menu_button.cc b/chrome/browser/chromeos/status/power_menu_button.cc index 87eef9dd..0fc7354 100644 --- a/chrome/browser/chromeos/status/power_menu_button.cc +++ b/chrome/browser/chromeos/status/power_menu_button.cc @@ -161,9 +161,7 @@ class PowerMenuButton::StatusView : public View { SkBitmap image; bool draw_percentage_text = false; - if (!CrosLibrary::Get()->EnsureLoaded()) { - image = GetUnknownImage(LARGE); - } else if (!menu_button_->battery_is_present_) { + if (!menu_button_->battery_is_present_) { image = GetMissingImage(LARGE); } else { image = GetImage( @@ -317,8 +315,7 @@ void PowerMenuButton::OnLocaleChanged() { void PowerMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { // Explicitly query the power status. - if (CrosLibrary::Get()->EnsureLoaded()) - CrosLibrary::Get()->GetPowerLibrary()->RequestStatusUpdate(); + CrosLibrary::Get()->GetPowerLibrary()->RequestStatusUpdate(); views::MenuItemView* menu = new views::MenuItemView(this); // MenuRunner takes ownership of |menu|. @@ -358,31 +355,23 @@ void PowerMenuButton::PowerChanged(PowerLibrary* obj) { void PowerMenuButton::UpdateIconAndLabelInfo() { PowerLibrary* cros = CrosLibrary::Get()->GetPowerLibrary(); - if (!cros) - return; - - bool cros_loaded = CrosLibrary::Get()->EnsureLoaded(); - if (cros_loaded) { - battery_is_present_ = cros->battery_is_present(); - line_power_on_ = cros->line_power_on(); - // If fully charged, always show 100% even if internal number is a bit less. - if (cros->battery_fully_charged()) { - // We always call cros->battery_percentage() for test predictability. - cros->battery_percentage(); - battery_percentage_ = 100.0; - } else { - battery_percentage_ = cros->battery_percentage(); - } + battery_is_present_ = cros->battery_is_present(); + line_power_on_ = cros->line_power_on(); - UpdateBatteryTime(&battery_time_to_full_, cros->battery_time_to_full()); - UpdateBatteryTime(&battery_time_to_empty_, cros->battery_time_to_empty()); + // If fully charged, always show 100% even if internal number is a bit less. + if (cros->battery_fully_charged()) { + // We always call cros->battery_percentage() for test predictability. + cros->battery_percentage(); + battery_percentage_ = 100.0; + } else { + battery_percentage_ = cros->battery_percentage(); } - if (!cros_loaded) { - battery_index_ = -1; - SetIcon(GetUnknownImage(SMALL)); - } else if (!battery_is_present_) { + UpdateBatteryTime(&battery_time_to_full_, cros->battery_time_to_full()); + UpdateBatteryTime(&battery_time_to_empty_, cros->battery_time_to_empty()); + + if (!battery_is_present_) { battery_index_ = -1; SetIcon(GetMissingImage(SMALL)); } else { |