diff options
author | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-08 20:53:06 +0000 |
---|---|---|
committer | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-08 20:53:06 +0000 |
commit | 08f3ac481ed50bf2975f2dfbd20aefd712450680 (patch) | |
tree | d8960a5e43c87b9a8b69a425f4aaf925405c4656 /chrome | |
parent | 06c3b84aa5849305e37034e4fce0573d59f48567 (diff) | |
download | chromium_src-08f3ac481ed50bf2975f2dfbd20aefd712450680.zip chromium_src-08f3ac481ed50bf2975f2dfbd20aefd712450680.tar.gz chromium_src-08f3ac481ed50bf2975f2dfbd20aefd712450680.tar.bz2 |
Use new libcros loading api to display better error messages.
Also remove all EnsureLoaded() methods except one.
Review URL: http://codereview.chromium.org/671004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40932 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
18 files changed, 45 insertions, 68 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 3651299..4e48382c 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -6738,9 +6738,6 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_INSTALLING_UPDATE" desc="Label shown on the updates installation screen"> Please wait while <ph name="PRODUCT_NAME">$1<ex>Chrome OS</ex></ph> installs an important update. </message> - <message name="IDS_LOGIN_DISABLED_NO_LIBCROS" desc="On the login screen, the text we put on the screen in the event that we cannot load the Chromium OS shared library and must therefore disable login."> - libcros.so cannot be loaded. Login disabled. - </message> <message name="IDS_NETWORK_SELECTION_TITLE" desc="Welcome title shown on network selection screen"> Welcome to <ph name="PRODUCT_NAME">$1<ex>Chrome OS</ex></ph> </message> diff --git a/chrome/browser/chromeos/cros/cros_library.cc b/chrome/browser/chromeos/cros/cros_library.cc index 57e00c0..e99ed18 100644 --- a/chrome/browser/chromeos/cros/cros_library.cc +++ b/chrome/browser/chromeos/cros/cros_library.cc @@ -18,19 +18,23 @@ namespace chromeos { bool CrosLibrary::loaded_ = false; // static +bool CrosLibrary::load_error_ = false; + +// static +std::string CrosLibrary::load_error_string_; + +// static bool CrosLibrary::EnsureLoaded() { - static bool initialized = false; - if (!initialized) { + if (!loaded_ && !load_error_) { FilePath path; if (PathService::Get(chrome::FILE_CHROMEOS_API, &path)) - loaded_ = LoadCros(path.value().c_str()); + loaded_ = LoadLibcros(path.value().c_str(), load_error_string_); if (!loaded_) { - char* error = dlerror(); - if (error) - LOG(ERROR) << "Problem loading chromeos shared object: " << error; + load_error_ = true; + LOG(ERROR) << "Problem loading chromeos shared object: " + << load_error_string_; } - initialized = true; } return loaded_; } diff --git a/chrome/browser/chromeos/cros/cros_library.h b/chrome/browser/chromeos/cros/cros_library.h index d2d962b..d4c0dc7 100644 --- a/chrome/browser/chromeos/cros/cros_library.h +++ b/chrome/browser/chromeos/cros/cros_library.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ #define CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ +#include <string> #include "base/basictypes.h" namespace chromeos { @@ -16,11 +17,21 @@ class CrosLibrary { // could not be loaded, returns false. static bool EnsureLoaded(); + // Returns an unlocalized string describing the last load error (if any). + static const std::string& load_error_string() { + return load_error_string_; + } + private: CrosLibrary() {} ~CrosLibrary() {} + // True if libcros was successfully loaded. static bool loaded_; + // True if the last load attempt had an error. + static bool load_error_; + // Contains the error string from the last load attempt. + static std::string load_error_string_; DISALLOW_COPY_AND_ASSIGN(CrosLibrary); }; diff --git a/chrome/browser/chromeos/cros/login_library.cc b/chrome/browser/chromeos/cros/login_library.cc index 8b02f03..ee07197 100644 --- a/chrome/browser/chromeos/cros/login_library.cc +++ b/chrome/browser/chromeos/cros/login_library.cc @@ -9,21 +9,12 @@ #include "chrome/browser/chromeos/cros/cros_library.h" namespace chromeos { -// static -bool LoginLibrary::tried_and_failed = false; // static LoginLibrary* LoginLibrary::Get() { return Singleton<LoginLibrary>::get(); } -// static -bool LoginLibrary::EnsureLoaded() { - if (!LoginLibrary::tried_and_failed) - LoginLibrary::tried_and_failed = !CrosLibrary::EnsureLoaded(); - return !LoginLibrary::tried_and_failed; -} - bool LoginLibrary::EmitLoginPromptReady() { return chromeos::EmitLoginPromptReady(); } diff --git a/chrome/browser/chromeos/cros/login_library.h b/chrome/browser/chromeos/cros/login_library.h index 653eb12..aea79be 100644 --- a/chrome/browser/chromeos/cros/login_library.h +++ b/chrome/browser/chromeos/cros/login_library.h @@ -24,10 +24,6 @@ class LoginLibrary { // This gets the singleton LoginLibrary. static LoginLibrary* Get(); - // Makes sure the library is loaded, loading it if necessary. Returns true if - // the library has been successfully loaded. - static bool EnsureLoaded(); - // Requests that the Upstart signal login-prompt-ready be emitted. bool EmitLoginPromptReady(); diff --git a/chrome/browser/chromeos/cros/mount_library.cc b/chrome/browser/chromeos/cros/mount_library.cc index beca30d..e7e3158 100644 --- a/chrome/browser/chromeos/cros/mount_library.cc +++ b/chrome/browser/chromeos/cros/mount_library.cc @@ -24,11 +24,6 @@ MountLibrary* MountLibrary::Get() { return Singleton<MountLibrary>::get(); } -// static -bool MountLibrary::EnsureLoaded() { - return CrosLibrary::EnsureLoaded(); -} - void MountLibrary::AddObserver(Observer* observer) { observers_.AddObserver(observer); } diff --git a/chrome/browser/chromeos/cros/mount_library.h b/chrome/browser/chromeos/cros/mount_library.h index 376c175..dccd06e 100644 --- a/chrome/browser/chromeos/cros/mount_library.h +++ b/chrome/browser/chromeos/cros/mount_library.h @@ -48,9 +48,6 @@ class MountLibrary { // This gets the singleton MountLibrary static MountLibrary* Get(); - // Returns true if the ChromeOS library was loaded. - static bool EnsureLoaded(); - void AddObserver(Observer* observer); void RemoveObserver(Observer* observer); diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc index afab041..6075332 100644 --- a/chrome/browser/chromeos/cros/network_library.cc +++ b/chrome/browser/chromeos/cros/network_library.cc @@ -49,11 +49,6 @@ NetworkLibrary* NetworkLibrary::Get() { return Singleton<NetworkLibrary>::get(); } -// static -bool NetworkLibrary::EnsureLoaded() { - return CrosLibrary::EnsureLoaded(); -} - //////////////////////////////////////////////////////////////////////////////// // NetworkLibrary, URLRequestJobTracker::JobObserver implementation: diff --git a/chrome/browser/chromeos/cros/network_library.h b/chrome/browser/chromeos/cros/network_library.h index 595b128..ab0ee2dc6 100644 --- a/chrome/browser/chromeos/cros/network_library.h +++ b/chrome/browser/chromeos/cros/network_library.h @@ -148,10 +148,6 @@ class NetworkLibrary : public URLRequestJobTracker::JobObserver { // This gets the singleton NetworkLibrary static NetworkLibrary* Get(); - // Makes sure the library is loaded, loading it if necessary. Returns true if - // the library has been successfully loaded. - static bool EnsureLoaded(); - // URLRequestJobTracker::JobObserver methods (called on the IO thread): virtual void OnJobAdded(URLRequestJob* job); virtual void OnJobRemoved(URLRequestJob* job); diff --git a/chrome/browser/chromeos/cros/power_library.cc b/chrome/browser/chromeos/cros/power_library.cc index ea7eaff..d055f3b 100644 --- a/chrome/browser/chromeos/cros/power_library.cc +++ b/chrome/browser/chromeos/cros/power_library.cc @@ -36,11 +36,6 @@ PowerLibrary* PowerLibrary::Get() { return Singleton<PowerLibrary>::get(); } -// static -bool PowerLibrary::EnsureLoaded() { - return CrosLibrary::EnsureLoaded(); -} - void PowerLibrary::AddObserver(Observer* observer) { observers_.AddObserver(observer); } diff --git a/chrome/browser/chromeos/cros/power_library.h b/chrome/browser/chromeos/cros/power_library.h index 4ee6b85..d362b64 100644 --- a/chrome/browser/chromeos/cros/power_library.h +++ b/chrome/browser/chromeos/cros/power_library.h @@ -25,10 +25,6 @@ class PowerLibrary { // This gets the singleton PowerLibrary static PowerLibrary* Get(); - // Makes sure the library is loaded, loading it if necessary. Returns true if - // the library has been successfully loaded. - static bool EnsureLoaded(); - void AddObserver(Observer* observer); void RemoveObserver(Observer* observer); diff --git a/chrome/browser/chromeos/cros/synaptics_library.cc b/chrome/browser/chromeos/cros/synaptics_library.cc index c98a9cd..3cf22c4 100644 --- a/chrome/browser/chromeos/cros/synaptics_library.cc +++ b/chrome/browser/chromeos/cros/synaptics_library.cc @@ -15,11 +15,6 @@ SynapticsLibrary* SynapticsLibrary::Get() { return Singleton<SynapticsLibrary>::get(); } -// static -bool SynapticsLibrary::EnsureLoaded() { - return CrosLibrary::EnsureLoaded(); -} - void SynapticsLibrary::SetBoolParameter(SynapticsParameter param, bool value) { SetParameter(param, value ? 1 : 0); } diff --git a/chrome/browser/chromeos/cros/synaptics_library.h b/chrome/browser/chromeos/cros/synaptics_library.h index 0a2db7e..c090606 100644 --- a/chrome/browser/chromeos/cros/synaptics_library.h +++ b/chrome/browser/chromeos/cros/synaptics_library.h @@ -19,10 +19,6 @@ class SynapticsLibrary { // This gets the singleton SynapticsLibrary. static SynapticsLibrary* Get(); - // Makes sure the library is loaded, loading it if necessary. Returns true if - // the library has been successfully loaded. - static bool EnsureLoaded(); - // Sets a boolean parameter. The actual call will be run on the FILE thread. void SetBoolParameter(SynapticsParameter param, bool value); diff --git a/chrome/browser/chromeos/login/login_manager_view.cc b/chrome/browser/chromeos/login/login_manager_view.cc index db57896..4a7ab00 100644 --- a/chrome/browser/chromeos/login/login_manager_view.cc +++ b/chrome/browser/chromeos/login/login_manager_view.cc @@ -20,6 +20,7 @@ #include "base/string_util.h" #include "chrome/browser/browser_init.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/login_library.h" #include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/external_cookie_handler.h" @@ -158,11 +159,12 @@ void LoginManagerView::Init() { // Controller to handle events from textfields username_field_->SetController(this); password_field_->SetController(this); - if (LoginLibrary::EnsureLoaded()) { + if (CrosLibrary::EnsureLoaded()) { loader_.GetVersion( &consumer_, NewCallback(this, &LoginManagerView::OnOSVersion)); } else if (!kStubOutLogin) { - ShowError(IDS_LOGIN_DISABLED_NO_LIBCROS); + error_label_->SetText( + ASCIIToWide(CrosLibrary::load_error_string())); username_field_->SetReadOnly(true); password_field_->SetReadOnly(true); } @@ -244,10 +246,17 @@ void LoginManagerView::Layout() { y += (setViewBounds(password_label_, x, y, max_width, false) + kLabelPad); y += (setViewBounds(password_field_, x, y, kTextfieldWidth, true) + kRowPad); y += (setViewBounds(sign_in_button_, x, y, max_width, false) + kRowPad); - y += (setViewBounds(error_label_, x, y, max_width, true) + kRowPad); int padding = BorderDefinition::kScreenBorder.shadow + BorderDefinition::kScreenBorder.corner_radius / 2; + + y += setViewBounds( + error_label_, + padding, + y, + width() - 2 * padding, + true); + setViewBounds( os_version_label_, padding, @@ -277,7 +286,7 @@ void LoginManagerView::OnLoginFailure() { NetworkLibrary* network = NetworkLibrary::Get(); // Check networking after trying to login in case user is // cached locally or the local admin account. - if (!network || !network->EnsureLoaded()) + if (!network || !CrosLibrary::EnsureLoaded()) ShowError(IDS_LOGIN_ERROR_NO_NETWORK_LIBRARY); else if (!network->Connected()) ShowError(IDS_LOGIN_ERROR_NETWORK_NOT_CONNECTED); @@ -315,7 +324,7 @@ void LoginManagerView::SetupSession(const std::string& username) { if (observer_) { observer_->OnExit(ScreenObserver::LOGIN_SIGN_IN_SELECTED); } - if (LoginLibrary::EnsureLoaded()) + if (CrosLibrary::EnsureLoaded()) LoginLibrary::Get()->StartSession(username, ""); } @@ -346,7 +355,7 @@ void LoginManagerView::ShowError(int error_id) { bool LoginManagerView::HandleKeystroke(views::Textfield* s, const views::Textfield::Keystroke& keystroke) { - if (!kStubOutLogin && !LoginLibrary::EnsureLoaded()) + if (!kStubOutLogin && !CrosLibrary::EnsureLoaded()) return false; if (keystroke.GetKeyboardCode() == base::VKEY_TAB) { diff --git a/chrome/browser/chromeos/login/wizard_window.cc b/chrome/browser/chromeos/login/wizard_window.cc index 759061f..ffd7cc1 100644 --- a/chrome/browser/chromeos/login/wizard_window.cc +++ b/chrome/browser/chromeos/login/wizard_window.cc @@ -9,6 +9,7 @@ #include <string> #include "base/process_util.h" +#include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/login_library.h" #include "chrome/browser/chromeos/login/wizard_controller.h" #include "chrome/browser/views/browser_dialogs.h" @@ -111,7 +112,7 @@ void ShowLoginWizard(const std::string& first_screen_name, const gfx::Size& size) { views::WindowGtk* window = WizardWindow::Create(first_screen_name, size); window->Show(); - if (chromeos::LoginLibrary::EnsureLoaded()) { + if (chromeos::CrosLibrary::EnsureLoaded()) { chromeos::LoginLibrary::Get()->EmitLoginPromptReady(); } } diff --git a/chrome/browser/chromeos/network_list.cc b/chrome/browser/chromeos/network_list.cc index cbef281..cd08d23 100644 --- a/chrome/browser/chromeos/network_list.cc +++ b/chrome/browser/chromeos/network_list.cc @@ -6,6 +6,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "chrome/browser/chromeos/cros/cros_library.h" #include "grit/generated_resources.h" namespace chromeos { @@ -58,7 +59,7 @@ void NetworkList::NetworkChanged(chromeos::NetworkLibrary* network_lib) { connected_network_ = NULL; connecting_network_ = NULL; networks_.clear(); - if (!network_lib || !network_lib->EnsureLoaded()) + if (!network_lib || !CrosLibrary::EnsureLoaded()) return; if (network_lib->ethernet_connected() || network_lib->ethernet_connecting()) { diff --git a/chrome/browser/chromeos/status/network_menu_button.cc b/chrome/browser/chromeos/status/network_menu_button.cc index 1f0d724..09d33fb 100644 --- a/chrome/browser/chromeos/status/network_menu_button.cc +++ b/chrome/browser/chromeos/status/network_menu_button.cc @@ -12,6 +12,7 @@ #include "app/resource_bundle.h" #include "base/string_util.h" #include "chrome/browser/chromeos/options/network_config_view.h" +#include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/status/status_area_host.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -295,7 +296,7 @@ void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) { void NetworkMenuButton::NetworkChanged(NetworkLibrary* cros) { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - if (cros->EnsureLoaded()) { + if (CrosLibrary::EnsureLoaded()) { if (cros->wifi_connecting() || cros->cellular_connecting()) { // Start the connecting animation if not running. if (!animation_connecting_.IsAnimating()) { diff --git a/chrome/browser/chromeos/status/power_menu_button.cc b/chrome/browser/chromeos/status/power_menu_button.cc index b277654..48615c1 100644 --- a/chrome/browser/chromeos/status/power_menu_button.cc +++ b/chrome/browser/chromeos/status/power_menu_button.cc @@ -8,6 +8,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/time.h" +#include "chrome/browser/chromeos/cros/cros_library.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -123,7 +124,7 @@ void PowerMenuButton::DrawPowerIcon(gfx::Canvas* canvas, SkBitmap icon) { void PowerMenuButton::UpdateIcon() { PowerLibrary* cros = PowerLibrary::Get(); int id = IDR_STATUSBAR_BATTERY_UNKNOWN; - if (PowerLibrary::EnsureLoaded()) { + if (CrosLibrary::EnsureLoaded()) { if (!cros->battery_is_present()) { id = IDR_STATUSBAR_BATTERY_MISSING; } else if (cros->line_power_on() && cros->battery_fully_charged()) { |