From 9bade09ac71236e99865278def63b5212b7cf6b6 Mon Sep 17 00:00:00 2001 From: "brettw@chromium.org" Date: Fri, 13 Nov 2009 17:04:42 +0000 Subject: Write a test for loading libcros.so on startup of Chrome. You just pass the --test-load-libcros on the command line. The browser will exit immediately and the error code (and error messages) will indicate success or failure. I also renamed loaded() static functions related to loading this library. These are not simple getters since they will actually load the library if its not loaded yet. I renamed it to EnsureLoaded. TEST=This is a test BUG=none Review URL: http://codereview.chromium.org/387014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31911 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/browser_main.cc | 13 +++++++++++-- chrome/browser/chromeos/cros_library.cc | 2 +- chrome/browser/chromeos/cros_library.h | 7 +++---- chrome/browser/chromeos/network_library.cc | 12 ++++++------ chrome/browser/chromeos/network_library.h | 5 +++-- chrome/browser/chromeos/network_menu_button.cc | 2 +- chrome/browser/chromeos/power_library.cc | 8 ++++---- chrome/browser/chromeos/power_library.h | 5 +++-- chrome/browser/chromeos/power_menu_button.cc | 2 +- chrome/browser/chromeos/synaptics_library.cc | 6 +++--- chrome/browser/chromeos/synaptics_library.h | 5 +++-- chrome/common/chrome_switches.cc | 12 +++++++----- chrome/common/chrome_switches.h | 8 +++----- 13 files changed, 49 insertions(+), 38 deletions(-) diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 78e35dc..dc82b1fd 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -122,6 +122,7 @@ #endif #if defined(OS_CHROMEOS) +#include "chrome/browser/chromeos/cros_library.h" #include "chrome/browser/chromeos/external_cookie_handler.h" #endif @@ -129,7 +130,7 @@ namespace { // This function provides some ways to test crash and assertion handling // behavior of the program. -void HandleErrorTestParameters(const CommandLine& command_line) { +void HandleTestParameters(const CommandLine& command_line) { // This parameter causes an assertion. if (command_line.HasSwitch(switches::kBrowserAssertTest)) { DCHECK(false); @@ -140,6 +141,14 @@ void HandleErrorTestParameters(const CommandLine& command_line) { int* bad_pointer = NULL; *bad_pointer = 0; } + +#if defined(OS_CHROMEOS) + // Test loading libcros and exit. We return 0 if the library could be loaded, + // and 1 if it can't be. This is for validation that the library is installed + // and versioned properly for Chrome to find. + if (command_line.HasSwitch(switches::kTestLoadLibcros)) + exit(!chromeos::CrosLibrary::EnsureLoaded()); +#endif } void RunUIMessageLoop(BrowserProcess* browser_process) { @@ -844,7 +853,7 @@ int BrowserMain(const MainFunctionParams& parameters) { } #endif - HandleErrorTestParameters(parsed_command_line); + HandleTestParameters(parsed_command_line); Platform::RecordBreakpadStatusUMA(metrics); // Start up the extensions service. This should happen before Start(). profile->InitExtensions(); diff --git a/chrome/browser/chromeos/cros_library.cc b/chrome/browser/chromeos/cros_library.cc index 40d5e4e..6b342e0 100644 --- a/chrome/browser/chromeos/cros_library.cc +++ b/chrome/browser/chromeos/cros_library.cc @@ -18,7 +18,7 @@ namespace chromeos { bool CrosLibrary::loaded_ = false; // static -bool CrosLibrary::loaded() { +bool CrosLibrary::EnsureLoaded() { static bool initialized = false; if (!initialized) { FilePath path; diff --git a/chrome/browser/chromeos/cros_library.h b/chrome/browser/chromeos/cros_library.h index 2894f9a5..0872e74 100644 --- a/chrome/browser/chromeos/cros_library.h +++ b/chrome/browser/chromeos/cros_library.h @@ -12,10 +12,9 @@ namespace chromeos { // This class handles the loading of the ChromeOS shared library. class CrosLibrary { public: - // Returns true if the ChromeOS library was loaded. - // If this is the first time this method is called, - // we will attempt to load the ChromeOS shared library. - static bool loaded(); + // Ensures that the library is loaded, loading it if needed. If the library + // could not be loaded, returns false. + static bool EnsureLoaded(); private: CrosLibrary() {} diff --git a/chrome/browser/chromeos/network_library.cc b/chrome/browser/chromeos/network_library.cc index 13e216d..b1068b5 100644 --- a/chrome/browser/chromeos/network_library.cc +++ b/chrome/browser/chromeos/network_library.cc @@ -30,14 +30,14 @@ const int NetworkLibrary::kNetworkTrafficeTimerSecs = 1; NetworkLibrary::NetworkLibrary() : traffic_type_(0), network_devices_(0) { - if (CrosLibrary::loaded()) { + if (CrosLibrary::EnsureLoaded()) { Init(); } g_url_request_job_tracker.AddObserver(this); } NetworkLibrary::~NetworkLibrary() { - if (CrosLibrary::loaded()) { + if (CrosLibrary::EnsureLoaded()) { chromeos::DisconnectNetworkStatus(network_status_connection_); } g_url_request_job_tracker.RemoveObserver(this); @@ -49,8 +49,8 @@ NetworkLibrary* NetworkLibrary::Get() { } // static -bool NetworkLibrary::loaded() { - return CrosLibrary::loaded(); +bool NetworkLibrary::EnsureLoaded() { + return CrosLibrary::EnsureLoaded(); } //////////////////////////////////////////////////////////////////////////////// @@ -102,7 +102,7 @@ static const char* GetEncryptionString(chromeos::EncryptionType encryption) { void NetworkLibrary::ConnectToWifiNetwork(WifiNetwork network, const string16& password) { - if (CrosLibrary::loaded()) { + if (CrosLibrary::EnsureLoaded()) { // This call kicks off a request to connect to this network, the results of // which we'll hear about through the monitoring we've set up in Init(); chromeos::ConnectToWifiNetwork( @@ -182,7 +182,7 @@ void NetworkLibrary::Init() { void NetworkLibrary::EnableNetworkDevice(chromeos::ConnectionType device, bool enable) { - if (!CrosLibrary::loaded()) + if (!CrosLibrary::EnsureLoaded()) return; // If network device is already enabled/disabled, then don't do anything. diff --git a/chrome/browser/chromeos/network_library.h b/chrome/browser/chromeos/network_library.h index baee22b..b313ced 100644 --- a/chrome/browser/chromeos/network_library.h +++ b/chrome/browser/chromeos/network_library.h @@ -85,8 +85,9 @@ class NetworkLibrary : public URLRequestJobTracker::JobObserver { // This gets the singleton NetworkLibrary static NetworkLibrary* Get(); - // Returns true if the ChromeOS library was loaded. - static bool loaded(); + // 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); diff --git a/chrome/browser/chromeos/network_menu_button.cc b/chrome/browser/chromeos/network_menu_button.cc index 2a197d8..6fbbd6a 100644 --- a/chrome/browser/chromeos/network_menu_button.cc +++ b/chrome/browser/chromeos/network_menu_button.cc @@ -261,7 +261,7 @@ void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) { void NetworkMenuButton::NetworkChanged(NetworkLibrary* cros) { int id = IDR_STATUSBAR_WARNING; - if (cros->loaded()) { + if (cros->EnsureLoaded()) { id = IDR_STATUSBAR_NETWORK_DISCONNECTED; if (cros->wifi_connecting()) { // Start the connecting animation if not running. diff --git a/chrome/browser/chromeos/power_library.cc b/chrome/browser/chromeos/power_library.cc index 6689d9b..9f7a71a 100644 --- a/chrome/browser/chromeos/power_library.cc +++ b/chrome/browser/chromeos/power_library.cc @@ -20,13 +20,13 @@ struct RunnableMethodTraits { namespace chromeos { PowerLibrary::PowerLibrary() : status_(chromeos::PowerStatus()) { - if (CrosLibrary::loaded()) { + if (CrosLibrary::EnsureLoaded()) { Init(); } } PowerLibrary::~PowerLibrary() { - if (CrosLibrary::loaded()) { + if (CrosLibrary::EnsureLoaded()) { chromeos::DisconnectPowerStatus(power_status_connection_); } } @@ -37,8 +37,8 @@ PowerLibrary* PowerLibrary::Get() { } // static -bool PowerLibrary::loaded() { - return CrosLibrary::loaded(); +bool PowerLibrary::EnsureLoaded() { + return CrosLibrary::EnsureLoaded(); } void PowerLibrary::AddObserver(Observer* observer) { diff --git a/chrome/browser/chromeos/power_library.h b/chrome/browser/chromeos/power_library.h index a44149f..cf32108 100644 --- a/chrome/browser/chromeos/power_library.h +++ b/chrome/browser/chromeos/power_library.h @@ -25,8 +25,9 @@ class PowerLibrary { // This gets the singleton PowerLibrary static PowerLibrary* Get(); - // Returns true if the ChromeOS library was loaded. - static bool loaded(); + // 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/power_menu_button.cc b/chrome/browser/chromeos/power_menu_button.cc index 7947529..fb2677f 100644 --- a/chrome/browser/chromeos/power_menu_button.cc +++ b/chrome/browser/chromeos/power_menu_button.cc @@ -102,7 +102,7 @@ void PowerMenuButton::PowerChanged(PowerLibrary* obj) { void PowerMenuButton::UpdateIcon() { PowerLibrary* cros = PowerLibrary::Get(); int id = IDR_STATUSBAR_BATTERY_UNKNOWN; - if (PowerLibrary::loaded()) { + if (PowerLibrary::EnsureLoaded()) { if (!cros->battery_is_present()) { id = IDR_STATUSBAR_BATTERY_MISSING; } else if (cros->line_power_on() && cros->battery_fully_charged()) { diff --git a/chrome/browser/chromeos/synaptics_library.cc b/chrome/browser/chromeos/synaptics_library.cc index c849c33..f68b3ea 100644 --- a/chrome/browser/chromeos/synaptics_library.cc +++ b/chrome/browser/chromeos/synaptics_library.cc @@ -16,8 +16,8 @@ SynapticsLibrary* SynapticsLibrary::Get() { } // static -bool SynapticsLibrary::loaded() { - return CrosLibrary::loaded(); +bool SynapticsLibrary::EnsureLoaded() { + return CrosLibrary::EnsureLoaded(); } void SynapticsLibrary::SetBoolParameter(SynapticsParameter param, bool value) { @@ -33,7 +33,7 @@ void SynapticsLibrary::SetRangeParameter(SynapticsParameter param, int value) { } void SynapticsLibrary::SetParameter(SynapticsParameter param, int value) { - if (CrosLibrary::loaded()) { + if (CrosLibrary::EnsureLoaded()) { // This calls SetSynapticsParameter in the cros library which is // potentially time consuming. So we run this on the FILE thread. ChromeThread::PostTask( diff --git a/chrome/browser/chromeos/synaptics_library.h b/chrome/browser/chromeos/synaptics_library.h index af15a49..c55be97 100644 --- a/chrome/browser/chromeos/synaptics_library.h +++ b/chrome/browser/chromeos/synaptics_library.h @@ -19,8 +19,9 @@ class SynapticsLibrary { // This gets the singleton SynapticsLibrary. static SynapticsLibrary* Get(); - // Returns true if the ChromeOS library was loaded. - static bool loaded(); + // 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/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 072f02e..d4230bc 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -310,11 +310,6 @@ const char kInternalNaCl[] = "internal-nacl"; // Specifies the flags passed to JS engine const char kJavaScriptFlags[] = "js-flags"; -#if !defined(OS_MACOSX) -// Enable Kiosk mode. -const char kKioskMode[] = "kiosk"; -#endif - // Load an extension from the specified directory. const char kLoadExtension[] = "load-extension"; @@ -658,6 +653,10 @@ const char kCookiePipe[] = "cookie-pipe"; // Enable the redirection of viewable document requests to the Google // Document Viewer. const char kEnableGView[] = "enable-gview"; + +// Attempts to load libcros and validate it, then exits. A nonzero return code +// means the library could not be loaded correctly. +const char kTestLoadLibcros[] = "test-load-libcros"; #endif #if defined(OS_LINUX) @@ -688,6 +687,9 @@ const char kNoProcessSingletonDialog[] = "no-process-singleton-dialog"; // Cause the OS X sandbox write to syslog every time an access to a resource // is denied by the sandbox. const char kEnableSandboxLogging[] = "enable-sandbox-logging"; +#else +// Enable Kiosk mode. +const char kKioskMode[] = "kiosk"; #endif #ifndef NDEBUG diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index ff8ac12..d778e3d 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -98,11 +98,6 @@ extern const char kInProcessPlugins[]; extern const char kIncognito[]; extern const char kInternalNaCl[]; extern const char kJavaScriptFlags[]; - -#if !defined(OS_MACOSX) -extern const char kKioskMode[]; -#endif - extern const char kLoadExtension[]; extern const char kLoadPlugin[]; extern const char kLogFilterPrefix[]; @@ -191,6 +186,7 @@ extern const char kZygoteProcess[]; #if defined(OS_CHROMEOS) extern const char kCookiePipe[]; extern const char kEnableGView[]; +extern const char kTestLoadLibcros[]; #endif #if defined(OS_LINUX) @@ -204,6 +200,8 @@ extern const char kNoProcessSingletonDialog[]; #if defined(OS_MACOSX) extern const char kEnableSandboxLogging[]; +#else +extern const char kKioskMode[]; #endif #ifndef NDEBUG -- cgit v1.1