summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/browser_init.cc7
-rw-r--r--chrome/browser/browser_main.cc2
-rw-r--r--chrome/browser/chromeos/cros/cros_library.cc169
-rw-r--r--chrome/browser/chromeos/cros/cros_library.h96
-rw-r--r--chrome/browser/chromeos/cros/cros_library_loader.cc31
-rw-r--r--chrome/browser/chromeos/cros/cros_library_loader.h33
-rw-r--r--chrome/browser/chromeos/cros/cryptohome_library.cc14
-rw-r--r--chrome/browser/chromeos/cros/cryptohome_library.h36
-rw-r--r--chrome/browser/chromeos/cros/language_library.cc76
-rw-r--r--chrome/browser/chromeos/cros/language_library.h80
-rw-r--r--chrome/browser/chromeos/cros/login_library.cc11
-rw-r--r--chrome/browser/chromeos/cros/login_library.h38
-rw-r--r--chrome/browser/chromeos/cros/mock_cros_library.h26
-rw-r--r--chrome/browser/chromeos/cros/mock_cryptohome_library.h6
-rw-r--r--chrome/browser/chromeos/cros/mock_language_library.h36
-rw-r--r--chrome/browser/chromeos/cros/mock_library_loader.h24
-rw-r--r--chrome/browser/chromeos/cros/mock_login_library.h27
-rw-r--r--chrome/browser/chromeos/cros/mock_mount_library.h26
-rw-r--r--chrome/browser/chromeos/cros/mock_network_library.h66
-rw-r--r--chrome/browser/chromeos/cros/mock_power_library.h30
-rw-r--r--chrome/browser/chromeos/cros/mock_synaptics_library.h24
-rw-r--r--chrome/browser/chromeos/cros/mount_library.cc33
-rw-r--r--chrome/browser/chromeos/cros/mount_library.h29
-rw-r--r--chrome/browser/chromeos/cros/network_library.cc99
-rw-r--r--chrome/browser/chromeos/cros/network_library.h170
-rw-r--r--chrome/browser/chromeos/cros/power_library.cc47
-rw-r--r--chrome/browser/chromeos/cros/power_library.h56
-rw-r--r--chrome/browser/chromeos/cros/synaptics_library.cc15
-rw-r--r--chrome/browser/chromeos/cros/synaptics_library.h31
-rw-r--r--chrome/browser/chromeos/google_update_chromeos.cc2
-rw-r--r--chrome/browser/chromeos/login/existing_user_controller.cc4
-rw-r--r--chrome/browser/chromeos/login/google_authenticator.cc24
-rw-r--r--chrome/browser/chromeos/login/google_authenticator.h12
-rw-r--r--chrome/browser/chromeos/login/google_authenticator_unittest.cc65
-rw-r--r--chrome/browser/chromeos/login/login_manager_view.cc10
-rw-r--r--chrome/browser/chromeos/login/network_selection_view.cc11
-rw-r--r--chrome/browser/chromeos/login/utils.cc4
-rw-r--r--chrome/browser/chromeos/login/wizard_controller.cc7
-rw-r--r--chrome/browser/chromeos/network_list.cc2
-rw-r--r--chrome/browser/chromeos/options/internet_page_view.cc18
-rw-r--r--chrome/browser/chromeos/options/ip_config_view.cc3
-rw-r--r--chrome/browser/chromeos/options/language_config_view.cc21
-rw-r--r--chrome/browser/chromeos/options/language_hangul_config_view.cc13
-rw-r--r--chrome/browser/chromeos/options/network_config_view.cc7
-rw-r--r--chrome/browser/chromeos/preferences.cc16
-rw-r--r--chrome/browser/chromeos/status/language_menu_button.cc37
-rw-r--r--chrome/browser/chromeos/status/network_menu_button.cc20
-rw-r--r--chrome/browser/chromeos/status/power_menu_button.cc10
-rw-r--r--chrome/browser/chromeos/text_input/candidate_window.cc8
-rw-r--r--chrome/browser/chromeos/text_input/text_input.gyp2
-rw-r--r--chrome/browser/dom_ui/filebrowse_ui.cc10
-rw-r--r--chrome/browser/profile_manager.cc4
-rwxr-xr-xchrome/chrome_browser.gypi2
53 files changed, 1174 insertions, 476 deletions
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc
index f8f4735..34e61b3a 100644
--- a/chrome/browser/browser_init.cc
+++ b/chrome/browser/browser_init.cc
@@ -64,6 +64,7 @@
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/browser_notification_observers.h"
#include "chrome/browser/dom_ui/mediaplayer_ui.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/mount_library.h"
#include "chrome/browser/chromeos/cros/power_library.h"
#include "chrome/browser/chromeos/gview_request_interceptor.h"
@@ -403,7 +404,8 @@ bool BrowserInit::LaunchBrowser(
if (process_startup) {
// TODO(dhg): Try to make this just USBMountObserver::Get()->set_profile
// and have the constructor take care of everything else.
- chromeos::MountLibrary* lib = chromeos::MountLibrary::Get();
+ chromeos::MountLibrary* lib =
+ chromeos::CrosLibrary::Get()->GetMountLibrary();
chromeos::USBMountObserver* observe = chromeos::USBMountObserver::Get();
MediaPlayer* player = MediaPlayer::Get();
player->set_profile(profile);
@@ -416,7 +418,7 @@ bool BrowserInit::LaunchBrowser(
// in a global so that it isn't reported as a leak.
static chromeos::LowBatteryObserver* observer =
new chromeos::LowBatteryObserver(profile);
- chromeos::PowerLibrary::Get()->AddObserver(observer);
+ chromeos::CrosLibrary::Get()->GetPowerLibrary()->AddObserver(observer);
}
#endif
#if defined(OS_MACOSX)
@@ -931,6 +933,7 @@ bool BrowserInit::ProcessCmdLineImpl(const CommandLine& command_line,
}
bool silent_launch = false;
+
if (command_line.HasSwitch(switches::kAutomationClientChannelID)) {
std::string automation_channel_id = command_line.GetSwitchValueASCII(
switches::kAutomationClientChannelID);
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 3ac6224..48ecfbb 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -157,7 +157,7 @@ void HandleTestParameters(const CommandLine& command_line) {
// 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());
+ exit(!chromeos::CrosLibrary::Get()->EnsureLoaded());
#endif
}
diff --git a/chrome/browser/chromeos/cros/cros_library.cc b/chrome/browser/chromeos/cros/cros_library.cc
index e99ed18..3a06a54 100644
--- a/chrome/browser/chromeos/cros/cros_library.cc
+++ b/chrome/browser/chromeos/cros/cros_library.cc
@@ -4,39 +4,162 @@
#include "chrome/browser/chromeos/cros/cros_library.h"
-#include <dlfcn.h>
-
-#include "base/file_path.h"
-#include "base/logging.h"
-#include "base/path_service.h"
-#include "chrome/common/chrome_paths.h"
-#include "third_party/cros/chromeos_cros_api.h"
+#include "chrome/browser/chromeos/cros/cros_library_loader.h"
+#include "chrome/browser/chromeos/cros/cryptohome_library.h"
+#include "chrome/browser/chromeos/cros/language_library.h"
+#include "chrome/browser/chromeos/cros/login_library.h"
+#include "chrome/browser/chromeos/cros/mount_library.h"
+#include "chrome/browser/chromeos/cros/network_library.h"
+#include "chrome/browser/chromeos/cros/power_library.h"
+#include "chrome/browser/chromeos/cros/synaptics_library.h"
namespace chromeos {
-// static
-bool CrosLibrary::loaded_ = false;
+CrosLibrary::CrosLibrary() : library_loader_(NULL),
+ crypto_lib_(NULL),
+ language_lib_(NULL),
+ login_lib_(NULL),
+ mount_lib_(NULL),
+ network_lib_(NULL),
+ power_lib_(NULL),
+ synaptics_lib_(NULL),
+ loaded_(false),
+ load_error_(false),
+ test_api_(NULL) {
-// static
-bool CrosLibrary::load_error_ = false;
+}
-// static
-std::string CrosLibrary::load_error_string_;
+CrosLibrary::~CrosLibrary() {
+ if (library_loader_)
+ delete library_loader_;
+ if (crypto_lib_)
+ delete crypto_lib_;
+ if (language_lib_)
+ delete language_lib_;
+ if (login_lib_)
+ delete login_lib_;
+ if (mount_lib_)
+ delete mount_lib_;
+ if (network_lib_)
+ delete network_lib_;
+ if (power_lib_)
+ delete power_lib_;
+ if (synaptics_lib_)
+ delete synaptics_lib_;
+ if (test_api_)
+ delete test_api_;
+}
// static
+CrosLibrary* CrosLibrary::Get() {
+ return Singleton<CrosLibrary>::get();
+}
+
+CryptohomeLibrary* CrosLibrary::GetCryptohomeLibrary() {
+ if (!crypto_lib_)
+ crypto_lib_ = new CryptohomeLibraryImpl();
+ return crypto_lib_;
+}
+
+LanguageLibrary* CrosLibrary::GetLanguageLibrary() {
+ if (!language_lib_)
+ language_lib_ = new LanguageLibraryImpl();
+ return language_lib_;
+}
+
+LoginLibrary* CrosLibrary::GetLoginLibrary() {
+ if (!login_lib_)
+ login_lib_ = new LoginLibraryImpl();
+ return login_lib_;
+}
+
+MountLibrary* CrosLibrary::GetMountLibrary() {
+ if (!mount_lib_)
+ mount_lib_ = new MountLibraryImpl();
+ return mount_lib_;
+}
+
+NetworkLibrary* CrosLibrary::GetNetworkLibrary() {
+ if (!network_lib_)
+ network_lib_ = new NetworkLibraryImpl();
+ return network_lib_;
+}
+
+PowerLibrary* CrosLibrary::GetPowerLibrary() {
+ if (!power_lib_)
+ power_lib_ = new PowerLibraryImpl();
+ return power_lib_;
+}
+
+SynapticsLibrary* CrosLibrary::GetSynapticsLibrary() {
+ if (!synaptics_lib_)
+ synaptics_lib_ = new SynapticsLibraryImpl();
+ return synaptics_lib_;
+}
+
bool CrosLibrary::EnsureLoaded() {
if (!loaded_ && !load_error_) {
- FilePath path;
- if (PathService::Get(chrome::FILE_CHROMEOS_API, &path))
- loaded_ = LoadLibcros(path.value().c_str(), load_error_string_);
-
- if (!loaded_) {
- load_error_ = true;
- LOG(ERROR) << "Problem loading chromeos shared object: "
- << load_error_string_;
- }
+ if (!library_loader_)
+ library_loader_ = new CrosLibraryLoader();
+ loaded_ = library_loader_->Load(&load_error_string_);
+ load_error_ = !loaded_;
}
return loaded_;
}
-} // namespace chromeos
+CrosLibrary::TestApi* CrosLibrary::GetTestApi() {
+ if (!test_api_)
+ test_api_ = new TestApi(this);
+ return test_api_;
+}
+
+void CrosLibrary::TestApi::SetLibraryLoader(LibraryLoader* loader) {
+ if (library_->library_loader_)
+ delete library_->library_loader_;
+ library_->library_loader_ = loader;
+}
+
+void CrosLibrary::TestApi::SetCryptohomeLibrary(CryptohomeLibrary* library) {
+ if (library_->crypto_lib_)
+ delete library_->crypto_lib_;
+ library_->crypto_lib_ = library;
+}
+
+void CrosLibrary::TestApi::SetLanguageLibrary(LanguageLibrary* library) {
+ if (library_->language_lib_)
+ delete library_->language_lib_;
+ library_->language_lib_ = library;
+}
+
+void CrosLibrary::TestApi::SetLoginLibrary(LoginLibrary* library) {
+ if (library_->login_lib_)
+ delete library_->login_lib_;
+ library_->login_lib_ = library;
+}
+
+void CrosLibrary::TestApi::SetMountLibrary(MountLibrary* library) {
+ if (library_->mount_lib_)
+ delete library_->mount_lib_;
+ library_->mount_lib_ = library;
+}
+
+void CrosLibrary::TestApi::SetNetworkLibrary(NetworkLibrary* library) {
+ if (library_->network_lib_)
+ delete library_->network_lib_;
+ library_->network_lib_ = library;
+}
+
+void CrosLibrary::TestApi::SetPowerLibrary(PowerLibrary* library) {
+ if (library_->power_lib_)
+ delete library_->power_lib_;
+ library_->power_lib_ = library;
+}
+
+void CrosLibrary::TestApi::SetSynapticsLibrary(SynapticsLibrary* library) {
+ if (library_->synaptics_lib_)
+ delete library_->synaptics_lib_;
+ library_->synaptics_lib_ = library;
+}
+
+} // end namespace.
+
diff --git a/chrome/browser/chromeos/cros/cros_library.h b/chrome/browser/chromeos/cros/cros_library.h
index d4c0dc7..3bdfa50 100644
--- a/chrome/browser/chromeos/cros/cros_library.h
+++ b/chrome/browser/chromeos/cros/cros_library.h
@@ -7,31 +7,111 @@
#include <string>
#include "base/basictypes.h"
+#include "base/singleton.h"
namespace chromeos {
-// This class handles the loading of the ChromeOS shared library.
+class CryptohomeLibrary;
+class LanguageLibrary;
+class LibraryLoader;
+class LoginLibrary;
+class MountLibrary;
+class NetworkLibrary;
+class PowerLibrary;
+class SynapticsLibrary;
+
+// This class handles access to sub-parts of ChromeOS library. it provides
+// a level of indirection so individual libraries that it exposes can
+// be mocked for testing.
class CrosLibrary {
public:
+
+ // This class provides access to internal members of CrosLibrary class for
+ // purpose of testing (i.e. replacement of members' implementation with
+ // mock objects).
+ class TestApi {
+ public:
+ // Setter for LibraryLoader.
+ void SetLibraryLoader(LibraryLoader* loader);
+ // Setter for CryptohomeLibrary.
+ void SetCryptohomeLibrary(CryptohomeLibrary* library);
+ // Setter for LanguageLibrary
+ void SetLanguageLibrary(LanguageLibrary* library);
+ // Setter for LoginLibrary.
+ void SetLoginLibrary(LoginLibrary* library);
+ // Setter for MountLibrary.
+ void SetMountLibrary(MountLibrary* library);
+ // Setter for NetworkLibrary.
+ void SetNetworkLibrary(NetworkLibrary* library);
+ // Setter for PowerLibrary.
+ void SetPowerLibrary(PowerLibrary* library);
+ // Setter for SynapticsLibrary.
+ void SetSynapticsLibrary(SynapticsLibrary* library);
+
+ private:
+ friend class CrosLibrary;
+ explicit TestApi(CrosLibrary* library) : library_(library) {}
+ CrosLibrary* library_;
+ };
+
+ // This gets the CrosLibrary.
+ static CrosLibrary* Get();
+
+ // Getter for CryptohomeLibrary.
+ CryptohomeLibrary* GetCryptohomeLibrary();
+
+ // // Getter for LanguageLibrary
+ LanguageLibrary* GetLanguageLibrary();
+
+ // Getter for LoginLibrary.
+ LoginLibrary* GetLoginLibrary();
+
+ // Getter for MountLibrary
+ MountLibrary* GetMountLibrary();
+
+ // Getter for NetworkLibrary
+ NetworkLibrary* GetNetworkLibrary();
+
+ // Getter for PowerLibrary
+ PowerLibrary* GetPowerLibrary();
+
+ // This gets the singleton SynapticsLibrary.
+ SynapticsLibrary* GetSynapticsLibrary();
+
+ // Getter for Test API that gives access to internal members of this class.
+ TestApi* GetTestApi();
+
// Ensures that the library is loaded, loading it if needed. If the library
// could not be loaded, returns false.
- static bool EnsureLoaded();
+ bool EnsureLoaded();
// Returns an unlocalized string describing the last load error (if any).
- static const std::string& load_error_string() {
+ const std::string& load_error_string() {
return load_error_string_;
}
private:
- CrosLibrary() {}
- ~CrosLibrary() {}
+ friend struct DefaultSingletonTraits<chromeos::CrosLibrary>;
+ friend class CrosLibrary::TestApi;
+
+ CrosLibrary();
+ virtual ~CrosLibrary();
+ LibraryLoader* library_loader_;
+ CryptohomeLibrary* crypto_lib_;
+ LanguageLibrary* language_lib_;
+ LoginLibrary* login_lib_;
+ MountLibrary* mount_lib_;
+ NetworkLibrary* network_lib_;
+ PowerLibrary* power_lib_;
+ SynapticsLibrary* synaptics_lib_;
// True if libcros was successfully loaded.
- static bool loaded_;
+ bool loaded_;
// True if the last load attempt had an error.
- static bool load_error_;
+ bool load_error_;
// Contains the error string from the last load attempt.
- static std::string load_error_string_;
+ std::string load_error_string_;
+ TestApi* test_api_;
DISALLOW_COPY_AND_ASSIGN(CrosLibrary);
};
diff --git a/chrome/browser/chromeos/cros/cros_library_loader.cc b/chrome/browser/chromeos/cros/cros_library_loader.cc
new file mode 100644
index 0000000..d53d187
--- /dev/null
+++ b/chrome/browser/chromeos/cros/cros_library_loader.cc
@@ -0,0 +1,31 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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_loader.h"
+
+#include <dlfcn.h>
+
+#include "base/file_path.h"
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "chrome/common/chrome_paths.h"
+#include "third_party/cros/chromeos_cros_api.h"
+
+namespace chromeos {
+
+bool CrosLibraryLoader::Load(std::string* load_error_string) {
+ bool loaded = false;
+ FilePath path;
+ if (PathService::Get(chrome::FILE_CHROMEOS_API, &path))
+ loaded = LoadLibcros(path.value().c_str(), *load_error_string);
+
+ if (!loaded) {
+ LOG(ERROR) << "Problem loading chromeos shared object: "
+ << *load_error_string;
+ }
+ return loaded;
+}
+
+} // namespace chromeos
+
diff --git a/chrome/browser/chromeos/cros/cros_library_loader.h b/chrome/browser/chromeos/cros/cros_library_loader.h
new file mode 100644
index 0000000..c326ab6
--- /dev/null
+++ b/chrome/browser/chromeos/cros/cros_library_loader.h
@@ -0,0 +1,33 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_LOADER_H_
+#define CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_LOADER_H_
+
+#include <string>
+
+#include "chrome/browser/chromeos/cros/cros_library.h"
+
+namespace chromeos {
+
+// Library loads libcros library. It is abstracted behind this interface
+// so it can be mocked in tests.
+class LibraryLoader {
+ public:
+ virtual ~LibraryLoader() {}
+ virtual bool Load(std::string* load_error_string) = 0;
+};
+
+class CrosLibraryLoader : public LibraryLoader {
+ public:
+ CrosLibraryLoader() {}
+
+ // CrosLibrary::LibraryLoader overrides.
+ virtual bool Load(std::string* load_error_string);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_LOADER_H_
+
diff --git a/chrome/browser/chromeos/cros/cryptohome_library.cc b/chrome/browser/chromeos/cros/cryptohome_library.cc
index d74d4e0..19d5f65 100644
--- a/chrome/browser/chromeos/cros/cryptohome_library.cc
+++ b/chrome/browser/chromeos/cros/cryptohome_library.cc
@@ -8,22 +8,18 @@
#include "chrome/browser/chrome_thread.h"
namespace chromeos {
-// static
-CryptohomeLibrary* CryptohomeLibrary::Get() {
- return Singleton<CryptohomeLibrary>::get();
-}
-bool CryptohomeLibrary::CheckKey(const std::string& user_email,
- const std::string& passhash) {
+bool CryptohomeLibraryImpl::CheckKey(const std::string& user_email,
+ const std::string& passhash) {
return chromeos::CryptohomeCheckKey(user_email.c_str(), passhash.c_str());
}
-bool CryptohomeLibrary::Mount(const std::string& user_email,
- const std::string& passhash) {
+bool CryptohomeLibraryImpl::Mount(const std::string& user_email,
+ const std::string& passhash) {
return chromeos::CryptohomeMount(user_email.c_str(), passhash.c_str());
}
-bool CryptohomeLibrary::IsMounted() {
+bool CryptohomeLibraryImpl::IsMounted() {
return chromeos::CryptohomeIsMounted();
}
diff --git a/chrome/browser/chromeos/cros/cryptohome_library.h b/chrome/browser/chromeos/cros/cryptohome_library.h
index 7fab7e6..16c5a90 100644
--- a/chrome/browser/chromeos/cros/cryptohome_library.h
+++ b/chrome/browser/chromeos/cros/cryptohome_library.h
@@ -11,37 +11,45 @@
#include "third_party/cros/chromeos_cryptohome.h"
namespace chromeos {
-class MockCryptohomeLibrary;
-// This class handles the interaction with the ChromeOS cryptohome library APIs.
-// Users can get an instance of this library class like this:
-// CryptohomeLibrary::Get()
+// This interface defines the interaction with the ChromeOS cryptohome library
+// APIs.
class CryptohomeLibrary {
public:
- // This gets the singleton CryptohomeLibrary.
- static CryptohomeLibrary* Get();
+ virtual ~CryptohomeLibrary() {}
// Asks cryptohomed to try to find the cryptohome for |user_email| and then
// mount it using |passhash| to unlock the key.
virtual bool Mount(const std::string& user_email,
- const std::string& passhash);
+ const std::string& passhash) = 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,
+ const std::string& passhash) = 0;
+
+ // Asks cryptohomed if a drive is currently mounted.
+ virtual bool IsMounted() = 0;
+
+};
+
+// This class handles the interaction with the ChromeOS cryptohome library APIs.
+class CryptohomeLibraryImpl : public CryptohomeLibrary {
+ public:
+ CryptohomeLibraryImpl() {}
+ virtual ~CryptohomeLibraryImpl() {}
+
+ // CryptohomeLibrary overrides.
+ virtual bool Mount(const std::string& user_email,
+ const std::string& passhash);
+ virtual bool CheckKey(const std::string& user_email,
const std::string& passhash);
// Asks cryptohomed if a drive is currently mounted.
virtual bool IsMounted();
private:
- friend struct DefaultSingletonTraits<CryptohomeLibrary>;
- friend class MockCryptohomeLibrary;
-
- CryptohomeLibrary() {}
- ~CryptohomeLibrary() {}
-
- DISALLOW_COPY_AND_ASSIGN(CryptohomeLibrary);
+ DISALLOW_COPY_AND_ASSIGN(CryptohomeLibraryImpl);
};
} // namespace chromeos
diff --git a/chrome/browser/chromeos/cros/language_library.cc b/chrome/browser/chromeos/cros/language_library.cc
index 9ff93b9..ba6ac14 100644
--- a/chrome/browser/chromeos/cros/language_library.cc
+++ b/chrome/browser/chromeos/cros/language_library.cc
@@ -12,9 +12,9 @@
// Allows InvokeLater without adding refcounting. This class is a Singleton and
// won't be deleted until it's last InvokeLater is run.
template <>
-struct RunnableMethodTraits<chromeos::LanguageLibrary> {
- void RetainCallee(chromeos::LanguageLibrary* obj) {}
- void ReleaseCallee(chromeos::LanguageLibrary* obj) {}
+struct RunnableMethodTraits<chromeos::LanguageLibraryImpl> {
+ void RetainCallee(chromeos::LanguageLibraryImpl* obj) {}
+ void ReleaseCallee(chromeos::LanguageLibraryImpl* obj) {}
};
namespace {
@@ -41,32 +41,27 @@ bool FindAndUpdateProperty(const chromeos::ImeProperty& new_prop,
namespace chromeos {
-LanguageLibrary::LanguageLibrary() : language_status_connection_(NULL) {
+LanguageLibraryImpl::LanguageLibraryImpl() : language_status_connection_(NULL) {
}
-LanguageLibrary::~LanguageLibrary() {
- if (EnsureLoadedAndStarted()) {
+LanguageLibraryImpl::~LanguageLibraryImpl() {
+ if (language_status_connection_) {
chromeos::DisconnectLanguageStatus(language_status_connection_);
}
}
-LanguageLibrary::Observer::~Observer() {
-}
-
-// static
-LanguageLibrary* LanguageLibrary::Get() {
- return Singleton<LanguageLibrary>::get();
+LanguageLibraryImpl::Observer::~Observer() {
}
-void LanguageLibrary::AddObserver(Observer* observer) {
+void LanguageLibraryImpl::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
-void LanguageLibrary::RemoveObserver(Observer* observer) {
+void LanguageLibraryImpl::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
-chromeos::InputLanguageList* LanguageLibrary::GetActiveLanguages() {
+chromeos::InputLanguageList* LanguageLibraryImpl::GetActiveLanguages() {
chromeos::InputLanguageList* result = NULL;
if (EnsureLoadedAndStarted()) {
result = chromeos::GetActiveLanguages(language_status_connection_);
@@ -74,7 +69,7 @@ chromeos::InputLanguageList* LanguageLibrary::GetActiveLanguages() {
return result ? result : CreateFallbackInputLanguageList();
}
-chromeos::InputLanguageList* LanguageLibrary::GetSupportedLanguages() {
+chromeos::InputLanguageList* LanguageLibraryImpl::GetSupportedLanguages() {
chromeos::InputLanguageList* result = NULL;
if (EnsureLoadedAndStarted()) {
result = chromeos::GetSupportedLanguages(language_status_connection_);
@@ -82,14 +77,14 @@ chromeos::InputLanguageList* LanguageLibrary::GetSupportedLanguages() {
return result ? result : CreateFallbackInputLanguageList();
}
-void LanguageLibrary::ChangeLanguage(
+void LanguageLibraryImpl::ChangeLanguage(
LanguageCategory category, const std::string& id) {
if (EnsureLoadedAndStarted()) {
chromeos::ChangeLanguage(language_status_connection_, category, id.c_str());
}
}
-void LanguageLibrary::ActivateImeProperty(const std::string& key) {
+void LanguageLibraryImpl::ActivateImeProperty(const std::string& key) {
DCHECK(!key.empty());
if (EnsureLoadedAndStarted()) {
chromeos::ActivateImeProperty(
@@ -97,7 +92,7 @@ void LanguageLibrary::ActivateImeProperty(const std::string& key) {
}
}
-void LanguageLibrary::DeactivateImeProperty(const std::string& key) {
+void LanguageLibraryImpl::DeactivateImeProperty(const std::string& key) {
DCHECK(!key.empty());
if (EnsureLoadedAndStarted()) {
chromeos::DeactivateImeProperty(
@@ -105,7 +100,7 @@ void LanguageLibrary::DeactivateImeProperty(const std::string& key) {
}
}
-bool LanguageLibrary::ActivateLanguage(
+bool LanguageLibraryImpl::ActivateLanguage(
LanguageCategory category, const std::string& id) {
bool success = false;
if (EnsureLoadedAndStarted()) {
@@ -115,7 +110,7 @@ bool LanguageLibrary::ActivateLanguage(
return success;
}
-bool LanguageLibrary::DeactivateLanguage(
+bool LanguageLibraryImpl::DeactivateLanguage(
LanguageCategory category, const std::string& id) {
bool success = false;
if (EnsureLoadedAndStarted()) {
@@ -125,7 +120,7 @@ bool LanguageLibrary::DeactivateLanguage(
return success;
}
-bool LanguageLibrary::GetImeConfig(
+bool LanguageLibraryImpl::GetImeConfig(
const char* section, const char* config_name, ImeConfigValue* out_value) {
bool success = false;
if (EnsureLoadedAndStarted()) {
@@ -135,7 +130,7 @@ bool LanguageLibrary::GetImeConfig(
return success;
}
-bool LanguageLibrary::SetImeConfig(
+bool LanguageLibraryImpl::SetImeConfig(
const char* section, const char* config_name, const ImeConfigValue& value) {
bool success = false;
if (EnsureLoadedAndStarted()) {
@@ -146,27 +141,30 @@ bool LanguageLibrary::SetImeConfig(
}
// static
-void LanguageLibrary::LanguageChangedHandler(
+void LanguageLibraryImpl::LanguageChangedHandler(
void* object, const chromeos::InputLanguage& current_language) {
- LanguageLibrary* language_library = static_cast<LanguageLibrary*>(object);
+ LanguageLibraryImpl* language_library =
+ static_cast<LanguageLibraryImpl*>(object);
language_library->UpdateCurrentLanguage(current_language);
}
// static
-void LanguageLibrary::RegisterPropertiesHandler(
+void LanguageLibraryImpl::RegisterPropertiesHandler(
void* object, const ImePropertyList& prop_list) {
- LanguageLibrary* language_library = static_cast<LanguageLibrary*>(object);
+ LanguageLibraryImpl* language_library =
+ static_cast<LanguageLibraryImpl*>(object);
language_library->RegisterProperties(prop_list);
}
// static
-void LanguageLibrary::UpdatePropertyHandler(
+void LanguageLibraryImpl::UpdatePropertyHandler(
void* object, const ImePropertyList& prop_list) {
- LanguageLibrary* language_library = static_cast<LanguageLibrary*>(object);
+ LanguageLibraryImpl* language_library =
+ static_cast<LanguageLibraryImpl*>(object);
language_library->UpdateProperty(prop_list);
}
-bool LanguageLibrary::EnsureStarted() {
+bool LanguageLibraryImpl::EnsureStarted() {
if (language_status_connection_) {
if (chromeos::LanguageStatusConnectionIsAlive(
language_status_connection_)) {
@@ -184,11 +182,12 @@ bool LanguageLibrary::EnsureStarted() {
return language_status_connection_ != NULL;
}
-bool LanguageLibrary::EnsureLoadedAndStarted() {
- return CrosLibrary::EnsureLoaded() && EnsureStarted();
+bool LanguageLibraryImpl::EnsureLoadedAndStarted() {
+ return CrosLibrary::Get()->EnsureLoaded() &&
+ EnsureStarted();
}
-void LanguageLibrary::UpdateCurrentLanguage(
+void LanguageLibraryImpl::UpdateCurrentLanguage(
const chromeos::InputLanguage& current_language) {
// Make sure we run on UI thread.
if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
@@ -197,7 +196,8 @@ void LanguageLibrary::UpdateCurrentLanguage(
ChromeThread::UI, FROM_HERE,
// NewRunnableMethod() copies |current_language| by value.
NewRunnableMethod(
- this, &LanguageLibrary::UpdateCurrentLanguage, current_language));
+ this, &LanguageLibraryImpl::UpdateCurrentLanguage,
+ current_language));
return;
}
@@ -206,12 +206,12 @@ void LanguageLibrary::UpdateCurrentLanguage(
FOR_EACH_OBSERVER(Observer, observers_, LanguageChanged(this));
}
-void LanguageLibrary::RegisterProperties(const ImePropertyList& prop_list) {
+void LanguageLibraryImpl::RegisterProperties(const ImePropertyList& prop_list) {
if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
NewRunnableMethod(
- this, &LanguageLibrary::RegisterProperties, prop_list));
+ this, &LanguageLibraryImpl::RegisterProperties, prop_list));
return;
}
@@ -220,12 +220,12 @@ void LanguageLibrary::RegisterProperties(const ImePropertyList& prop_list) {
FOR_EACH_OBSERVER(Observer, observers_, ImePropertiesChanged(this));
}
-void LanguageLibrary::UpdateProperty(const ImePropertyList& prop_list) {
+void LanguageLibraryImpl::UpdateProperty(const ImePropertyList& prop_list) {
if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
NewRunnableMethod(
- this, &LanguageLibrary::UpdateProperty, prop_list));
+ this, &LanguageLibraryImpl::UpdateProperty, prop_list));
return;
}
diff --git a/chrome/browser/chromeos/cros/language_library.h b/chrome/browser/chromeos/cros/language_library.h
index bf2e242..0f44a6c 100644
--- a/chrome/browser/chromeos/cros/language_library.h
+++ b/chrome/browser/chromeos/cros/language_library.h
@@ -8,7 +8,6 @@
#include <string>
#include "base/observer_list.h"
-#include "base/singleton.h"
#include "base/time.h"
#include "third_party/cros/chromeos_language.h"
@@ -25,77 +24,106 @@ class LanguageLibrary {
virtual void LanguageChanged(LanguageLibrary* obj) = 0;
virtual void ImePropertiesChanged(LanguageLibrary* obj) = 0;
};
+ virtual ~LanguageLibrary() {}
- // This gets the singleton LanguageLibrary
- static LanguageLibrary* Get();
-
- void AddObserver(Observer* observer);
- void RemoveObserver(Observer* observer);
+ virtual void AddObserver(Observer* observer) = 0;
+ virtual void RemoveObserver(Observer* observer) = 0;
// Returns the list of IMEs and keyboard layouts we can select
// (i.e. active). If the cros library is not found or IBus/DBus daemon
// is not alive, this function returns a fallback language list (and
// never returns NULL).
- InputLanguageList* GetActiveLanguages();
+ virtual InputLanguageList* GetActiveLanguages() = 0;
// Returns the list of IMEs and keyboard layouts we support, including
// ones not active. If the cros library is not found or IBus/DBus
// daemon is not alive, this function returns a fallback language list
// (and never returns NULL).
- InputLanguageList* GetSupportedLanguages();
+ virtual InputLanguageList* GetSupportedLanguages() = 0;
// Changes the current IME engine to |id| and enable IME (when |category|
// is LANGUAGE_CATEGORY_IME). Changes the current XKB layout to |id| and
// disable IME (when |category| is LANGUAGE_CATEGORY_XKB). |id| is a unique
// identifier of a IME engine or XKB layout. Please check chromeos_language.h
// in src third_party/cros/ for details.
- void ChangeLanguage(LanguageCategory category, const std::string& id);
+ virtual void ChangeLanguage(LanguageCategory category,
+ const std::string& id) = 0;
// Activates an IME property identified by |key|. Examples of keys are:
// "InputMode.Katakana", "InputMode.HalfWidthKatakana", "TypingMode.Romaji",
// and "TypingMode.Kana."
- void ActivateImeProperty(const std::string& key);
+ virtual void ActivateImeProperty(const std::string& key) = 0;
// Deactivates an IME property identified by |key|.
- void DeactivateImeProperty(const std::string& key);
+ virtual void DeactivateImeProperty(const std::string& key) = 0;
// Activates the language specified by |category| and |id|. Returns true
// on success.
- bool ActivateLanguage(LanguageCategory category, const std::string& id);
+ virtual bool ActivateLanguage(LanguageCategory category,
+ const std::string& id) = 0;
// Dectivates the language specified by |category| and |id|. Returns
// true on success.
- bool DeactivateLanguage(LanguageCategory category, const std::string& id);
+ virtual bool DeactivateLanguage(LanguageCategory category,
+ const std::string& id) = 0;
// Get a configuration of ibus-daemon or IBus engines and stores it on
// |out_value|. Returns true if |out_value| is successfully updated.
// When you would like to retrieve 'panel/custom_font', |section| should
// be "panel", and |config_name| should be "custom_font".
- bool GetImeConfig(
- const char* section, const char* config_name, ImeConfigValue* out_value);
+ virtual bool GetImeConfig(
+ const char* section, const char* config_name,
+ ImeConfigValue* out_value) = 0;
// Updates a configuration of ibus-daemon or IBus engines with |value|.
// Returns true if the configuration is successfully updated.
// You can specify |section| and |config_name| arguments in the same way
// as GetImeConfig() above.
- bool SetImeConfig(const char* section,
- const char* config_name,
- const ImeConfigValue& value);
+ virtual bool SetImeConfig(const char* section,
+ const char* config_name,
+ const ImeConfigValue& value) = 0;
+
+ virtual const InputLanguage& current_language() const = 0;
+
+ virtual const ImePropertyList& current_ime_properties() const = 0;
+
+};
+
+// This class handles the interaction with the ChromeOS language library APIs.
+// Classes can add themselves as observers. Users can get an instance of this
+// library class like this: LanguageLibrary::Get()
+class LanguageLibraryImpl : public LanguageLibrary {
+ public:
+ LanguageLibraryImpl();
+ virtual ~LanguageLibraryImpl();
+
+ // LanguageLibrary overrides.
+ virtual void AddObserver(Observer* observer);
+ virtual void RemoveObserver(Observer* observer);
+ virtual InputLanguageList* GetActiveLanguages();
+ virtual InputLanguageList* GetSupportedLanguages();
+ virtual void ChangeLanguage(LanguageCategory category, const std::string& id);
+ virtual void ActivateImeProperty(const std::string& key);
+ virtual void DeactivateImeProperty(const std::string& key);
+ virtual bool ActivateLanguage(LanguageCategory category,
+ const std::string& id);
+ virtual bool DeactivateLanguage(LanguageCategory category,
+ const std::string& id);
+ virtual bool GetImeConfig(
+ const char* section, const char* config_name, ImeConfigValue* out_value);
+ virtual bool SetImeConfig(const char* section,
+ const char* config_name,
+ const ImeConfigValue& value);
- const InputLanguage& current_language() const {
+ virtual const InputLanguage& current_language() const {
return current_language_;
}
- const ImePropertyList& current_ime_properties() const {
+ virtual const ImePropertyList& current_ime_properties() const {
return current_ime_properties_;
}
private:
- friend struct DefaultSingletonTraits<LanguageLibrary>;
-
- LanguageLibrary();
- ~LanguageLibrary();
-
// This method is called when there's a change in language status.
static void LanguageChangedHandler(
void* object, const InputLanguage& current_language);
@@ -140,7 +168,7 @@ class LanguageLibrary {
// empty when no IME is used.
ImePropertyList current_ime_properties_;
- DISALLOW_COPY_AND_ASSIGN(LanguageLibrary);
+ DISALLOW_COPY_AND_ASSIGN(LanguageLibraryImpl);
};
} // namespace chromeos
diff --git a/chrome/browser/chromeos/cros/login_library.cc b/chrome/browser/chromeos/cros/login_library.cc
index ee07197..efd8536 100644
--- a/chrome/browser/chromeos/cros/login_library.cc
+++ b/chrome/browser/chromeos/cros/login_library.cc
@@ -10,22 +10,17 @@
namespace chromeos {
-// static
-LoginLibrary* LoginLibrary::Get() {
- return Singleton<LoginLibrary>::get();
-}
-
-bool LoginLibrary::EmitLoginPromptReady() {
+bool LoginLibraryImpl::EmitLoginPromptReady() {
return chromeos::EmitLoginPromptReady();
}
-bool LoginLibrary::StartSession(const std::string& user_email,
+bool LoginLibraryImpl::StartSession(const std::string& user_email,
const std::string& unique_id /* unused */) {
// only pass unique_id through once we use it for something.
return chromeos::StartSession(user_email.c_str(), "");
}
-bool LoginLibrary::StopSession(const std::string& unique_id /* unused */) {
+bool LoginLibraryImpl::StopSession(const std::string& unique_id /* unused */) {
// only pass unique_id through once we use it for something.
return chromeos::StopSession("");
}
diff --git a/chrome/browser/chromeos/cros/login_library.h b/chrome/browser/chromeos/cros/login_library.h
index aea79be..df1b9b4 100644
--- a/chrome/browser/chromeos/cros/login_library.h
+++ b/chrome/browser/chromeos/cros/login_library.h
@@ -12,41 +12,41 @@
namespace chromeos {
-// This class handles the interaction with the ChromeOS login library APIs.
-// Users can get an instance of this library class like this:
-// LoginLibrary::Get()
+// This interface defines the interaction with the ChromeOS login library APIs.
class LoginLibrary {
public:
- // If the libray fails to load the first time we check, we don't want to
- // keep trying to load the library. If it fails the first time, it fails.
- static bool tried_and_failed;
-
- // This gets the singleton LoginLibrary.
- static LoginLibrary* Get();
-
+ virtual ~LoginLibrary() {}
// Requests that the Upstart signal login-prompt-ready be emitted.
- bool EmitLoginPromptReady();
+ virtual bool EmitLoginPromptReady() = 0;
// Tells the session manager to start a logged-in session for the user
// |user_email|. |unique_id| is meant to be used when we have a non-human-
// readable unique identifier by which we distinguish users (to deal with
// potential email address changes over time).
- 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 */) = 0;
// Tells the session manager to terminate the current logged-in session.
// In the event that we ever support multiple simultaneous user sessions,
// This will tell the session manager to terminate the session for the user
// indicated by |unique_id|.
- bool StopSession(const std::string& unique_id /* unused */);
+ virtual bool StopSession(const std::string& unique_id /* unused */) = 0;
+};
- private:
- friend struct DefaultSingletonTraits<LoginLibrary>;
+// This class handles the interaction with the ChromeOS login library APIs.
+class LoginLibraryImpl : public LoginLibrary {
+ public:
+ LoginLibraryImpl() {}
+ virtual ~LoginLibraryImpl() {}
- LoginLibrary() {}
- ~LoginLibrary() {}
+ // LoginLibrary overrides.
+ virtual bool EmitLoginPromptReady();
+ virtual bool StartSession(const std::string& user_email,
+ const std::string& unique_id /* unused */);
+ virtual bool StopSession(const std::string& unique_id /* unused */);
- DISALLOW_COPY_AND_ASSIGN(LoginLibrary);
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LoginLibraryImpl);
};
} // namespace chromeos
diff --git a/chrome/browser/chromeos/cros/mock_cros_library.h b/chrome/browser/chromeos/cros/mock_cros_library.h
new file mode 100644
index 0000000..f66cc67
--- /dev/null
+++ b/chrome/browser/chromeos/cros/mock_cros_library.h
@@ -0,0 +1,26 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_CROS_MOCK_CROS_LIBRARY_H_
+#define CHROME_BROWSER_CHROMEOS_CROS_MOCK_CROS_LIBRARY_H_
+
+#include <string>
+
+#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+class MockCrosLibrary : public CrosLibrary {
+ public:
+ MockCrosLibrary() {}
+ virtual ~MockCrosLibrary() {}
+ MOCK_METHOD0(EnsureLoaded, bool(void));
+ MOCK_METHOD0(EnsureLoaded, const std::string&(void));
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_CROS_MOCK_CROS_LIBRARY_H_
+
diff --git a/chrome/browser/chromeos/cros/mock_cryptohome_library.h b/chrome/browser/chromeos/cros/mock_cryptohome_library.h
index 4ef8e8d..f13149b 100644
--- a/chrome/browser/chromeos/cros/mock_cryptohome_library.h
+++ b/chrome/browser/chromeos/cros/mock_cryptohome_library.h
@@ -5,10 +5,9 @@
#ifndef CHROME_BROWSER_CHROMEOS_CROS_MOCK_CRYPTOHOME_LIBRARY_H_
#define CHROME_BROWSER_CHROMEOS_CROS_MOCK_CRYPTOHOME_LIBRARY_H_
-#include "chrome/browser/chromeos/cros/cryptohome_library.h"
-
#include <string>
+#include "chrome/browser/chromeos/cros/cryptohome_library.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace chromeos {
@@ -16,11 +15,12 @@ namespace chromeos {
class MockCryptohomeLibrary : public CryptohomeLibrary {
public:
MockCryptohomeLibrary() {}
- ~MockCryptohomeLibrary() {}
+ virtual ~MockCryptohomeLibrary() {}
MOCK_METHOD2(Mount, bool(const std::string& user_email,
const std::string& passhash));
MOCK_METHOD2(CheckKey, bool(const std::string& user_email,
const std::string& passhash));
+ MOCK_METHOD0(IsMounted, bool(void));
};
} // namespace chromeos
diff --git a/chrome/browser/chromeos/cros/mock_language_library.h b/chrome/browser/chromeos/cros/mock_language_library.h
new file mode 100644
index 0000000..cd0419f
--- /dev/null
+++ b/chrome/browser/chromeos/cros/mock_language_library.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_CROS_MOCK_LANGUAGE_LIBRARY_H_
+#define CHROME_BROWSER_CHROMEOS_CROS_MOCK_LANGUAGE_LIBRARY_H_
+
+#include <string>
+
+#include "chrome/browser/chromeos/cros/language_library.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+class MockLanguageLibrary : public LanguageLibrary {
+ public:
+ MockLanguageLibrary() {}
+ virtual ~MockLanguageLibrary() {}
+ MOCK_METHOD0(GetActiveLanguages, InputLanguageList*(void));
+ MOCK_METHOD0(GetSupportedLanguages, InputLanguageList*(void));
+ MOCK_METHOD2(ChangeLanguage, void(LanguageCategory, const std::string&));
+ MOCK_METHOD1(ActivateImeProperty, void(const std::string&));
+ MOCK_METHOD1(DeactivateImeProperty, void(const std::string&));
+ MOCK_METHOD2(ActivateLanguage, bool(LanguageCategory, const std::string&));
+ MOCK_METHOD2(DeactivateLanguage, bool(LanguageCategory, const std::string&));
+ MOCK_METHOD3(GetImeConfig, bool(const char*, const char*, ImeConfigValue*));
+ MOCK_METHOD3(SetImeConfig, bool(const char*, const char*,
+ const ImeConfigValue&));
+ MOCK_CONST_METHOD0(current_language, const InputLanguage&(void));
+ MOCK_CONST_METHOD0(current_ime_properties, const ImePropertyList&(void));
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_CROS_MOCK_LANGUAGE_LIBRARY_H_
+
diff --git a/chrome/browser/chromeos/cros/mock_library_loader.h b/chrome/browser/chromeos/cros/mock_library_loader.h
new file mode 100644
index 0000000..5863a54
--- /dev/null
+++ b/chrome/browser/chromeos/cros/mock_library_loader.h
@@ -0,0 +1,24 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_CROS_MOCK_LIBRARY_LOADER_H_
+#define CHROME_BROWSER_CHROMEOS_CROS_MOCK_LIBRARY_LOADER_H_
+
+#include <string>
+
+#include "chrome/browser/chromeos/cros/cros_library_loader.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+// Mock for libcros library loader.
+class MockLibraryLoader : public LibraryLoader {
+ public:
+ MOCK_METHOD1(Load, bool(std::string*));
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_CROS_MOCK_LIBRARY_LOADER_H_
+
diff --git a/chrome/browser/chromeos/cros/mock_login_library.h b/chrome/browser/chromeos/cros/mock_login_library.h
new file mode 100644
index 0000000..a815ecf
--- /dev/null
+++ b/chrome/browser/chromeos/cros/mock_login_library.h
@@ -0,0 +1,27 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_CROS_MOCK_LOGIN_LIBRARY_H_
+#define CHROME_BROWSER_CHROMEOS_CROS_MOCK_LOGIN_LIBRARY_H_
+
+#include <string>
+
+#include "chrome/browser/chromeos/cros/login_library.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+class MockLoginLibrary : public LoginLibrary {
+ public:
+ MockLoginLibrary() {}
+ virtual ~MockLoginLibrary() {}
+ MOCK_METHOD0(EmitLoginPromptReady, bool(void));
+ MOCK_METHOD2(StartSession, bool(const std::string&, const std::string&));
+ MOCK_METHOD1(StartSession, bool(const std::string&));
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_CROS_MOCK_LOGIN_LIBRARY_H_
+
diff --git a/chrome/browser/chromeos/cros/mock_mount_library.h b/chrome/browser/chromeos/cros/mock_mount_library.h
new file mode 100644
index 0000000..743e76d
--- /dev/null
+++ b/chrome/browser/chromeos/cros/mock_mount_library.h
@@ -0,0 +1,26 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_CROS_MOCK_MOUNT_LIBRARY_H_
+#define CHROME_BROWSER_CHROMEOS_CROS_MOCK_MOUNT_LIBRARY_H_
+
+#include <string>
+
+#include "chrome/browser/chromeos/cros/mount_library.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+class MockMountLibrary : public MountLibrary {
+ public:
+ MockMountLibrary() {}
+ virtual ~MockMountLibrary() {}
+ MOCK_METHOD1(AddObserver, void(Observer*));
+ MOCK_METHOD1(RemoveObserver, void(Observer*));
+ MOCK_CONST_METHOD0(disks, const DiskVector&(void));
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_CROS_MOCK_MOUNT_LIBRARY_H_
diff --git a/chrome/browser/chromeos/cros/mock_network_library.h b/chrome/browser/chromeos/cros/mock_network_library.h
new file mode 100644
index 0000000..2090281
--- /dev/null
+++ b/chrome/browser/chromeos/cros/mock_network_library.h
@@ -0,0 +1,66 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_CROS_MOCK_NETWORK_LIBRARY_H_
+#define CHROME_BROWSER_CHROMEOS_CROS_MOCK_NETWORK_LIBRARY_H_
+
+#include <string>
+
+#include "chrome/browser/chromeos/cros/network_library.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+class MockNetworkLibrary : public NetworkLibrary {
+ public:
+ MockNetworkLibrary() {}
+ virtual ~MockNetworkLibrary() {}
+ MOCK_METHOD1(AddObserver, void(Observer*));
+ MOCK_METHOD1(RemoveObserver, void(Observer*));
+ MOCK_CONST_METHOD0(ethernet_network, const EthernetNetwork&(void));
+ MOCK_CONST_METHOD0(ethernet_connecting, bool(void));
+ MOCK_CONST_METHOD0(ethernet_connected, bool(void));
+ MOCK_CONST_METHOD0(wifi_ssid, const std::string&(void));
+ MOCK_CONST_METHOD0(wifi_connecting, bool(void));
+ MOCK_CONST_METHOD0(wifi_connected, bool(void));
+ MOCK_CONST_METHOD0(wifi_strength, int(void));
+
+ MOCK_CONST_METHOD0(cellular_name, const std::string&(void));
+ MOCK_CONST_METHOD0(cellular_connecting, bool(void));
+ MOCK_CONST_METHOD0(cellular_connected, bool(void));
+ MOCK_CONST_METHOD0(cellular_strength, int(void));
+
+ MOCK_CONST_METHOD0(Connected, bool(void));
+ MOCK_CONST_METHOD0(Connecting, bool(void));
+
+ MOCK_CONST_METHOD0(IPAddress, const std::string&(void));
+ MOCK_CONST_METHOD0(wifi_networks, const WifiNetworkVector&(void));
+ MOCK_CONST_METHOD0(cellular_networks, const CellularNetworkVector&(void));
+
+ MOCK_METHOD2(ConnectToWifiNetwork, void(WifiNetwork,
+ const string16&));
+ MOCK_METHOD2(ConnectToWifiNetwork, void(const string16&,
+ const string16&));
+ MOCK_METHOD1(ConnectToCellularNetwork, void(CellularNetwork));
+
+ MOCK_CONST_METHOD0(ethernet_available, bool(void));
+ MOCK_CONST_METHOD0(wifi_available, bool(void));
+ MOCK_CONST_METHOD0(cellular_available, bool(void));
+
+ MOCK_CONST_METHOD0(ethernet_enabled, bool(void));
+ MOCK_CONST_METHOD0(wifi_enabled, bool(void));
+ MOCK_CONST_METHOD0(cellular_enabled, bool(void));
+
+ MOCK_CONST_METHOD0(offline_mode, bool(void));
+
+ MOCK_METHOD1(EnableEthernetNetworkDevice, void(bool));
+ MOCK_METHOD1(EnableWifiNetworkDevice, void(bool));
+ MOCK_METHOD1(EnableCellularNetworkDevice, void(bool));
+ MOCK_METHOD1(EnableOfflineMode, void(bool));
+ MOCK_METHOD1(GetIPConfigs, NetworkIPConfigVector(const std::string&));
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_CROS_MOCK_NETWORK_LIBRARY_H_
diff --git a/chrome/browser/chromeos/cros/mock_power_library.h b/chrome/browser/chromeos/cros/mock_power_library.h
new file mode 100644
index 0000000..fb660f1
--- /dev/null
+++ b/chrome/browser/chromeos/cros/mock_power_library.h
@@ -0,0 +1,30 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_CROS_MOCK_POWER_LIBRARY_H_
+#define CHROME_BROWSER_CHROMEOS_CROS_MOCK_POWER_LIBRARY_H_
+
+#include "chrome/browser/chromeos/cros/power_library.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+class MockPowerLibrary : public PowerLibrary {
+ public:
+ MockPowerLibrary() {}
+ virtual ~MockPowerLibrary() {}
+ MOCK_METHOD1(AddObserver, void(Observer*));
+ MOCK_METHOD1(RemoveObserver, void(Observer*));
+
+ MOCK_CONST_METHOD1(line_power_on, bool(void));
+ MOCK_CONST_METHOD1(battery_fully_charged, bool(void));
+ MOCK_CONST_METHOD1(battery_percentage, double(void));
+ MOCK_CONST_METHOD1(battery_is_present, bool(void));
+ MOCK_CONST_METHOD1(battery_time_to_empty, base::TimeDelta(void));
+ MOCK_CONST_METHOD1(battery_time_to_full, base::TimeDelta(void));
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_CROS_MOCK_POWER_LIBRARY_H_
diff --git a/chrome/browser/chromeos/cros/mock_synaptics_library.h b/chrome/browser/chromeos/cros/mock_synaptics_library.h
new file mode 100644
index 0000000..be5efb0
--- /dev/null
+++ b/chrome/browser/chromeos/cros/mock_synaptics_library.h
@@ -0,0 +1,24 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_CROS_MOCK_SYNAPTICS_LIBRARY_H_
+#define CHROME_BROWSER_CHROMEOS_CROS_MOCK_SYNAPTICS_LIBRARY_H_
+
+#include "chrome/browser/chromeos/cros/synaptics_library.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+class MockSynapticsLibrary : public SynapticsLibrary {
+ public:
+ MockSynapticsLibrary() {}
+ virtual ~MockSynapticsLibrary() {}
+ MOCK_METHOD2(SetBoolParameter, void(SynapticsParameter, bool));
+ MOCK_METHOD2(SetRangeParameter, void(SynapticsParameter, int));
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_CROS_MOCK_SYNAPTICS_LIBRARY_H_
+
diff --git a/chrome/browser/chromeos/cros/mount_library.cc b/chrome/browser/chromeos/cros/mount_library.cc
index e7e3158..8126eaa 100644
--- a/chrome/browser/chromeos/cros/mount_library.cc
+++ b/chrome/browser/chromeos/cros/mount_library.cc
@@ -12,27 +12,22 @@
// Allows InvokeLater without adding refcounting. This class is a Singleton and
// won't be deleted until it's last InvokeLater is run.
template <>
-struct RunnableMethodTraits<chromeos::MountLibrary> {
- void RetainCallee(chromeos::MountLibrary* obj) {}
- void ReleaseCallee(chromeos::MountLibrary* obj) {}
+struct RunnableMethodTraits<chromeos::MountLibraryImpl> {
+ void RetainCallee(chromeos::MountLibraryImpl* obj) {}
+ void ReleaseCallee(chromeos::MountLibraryImpl* obj) {}
};
namespace chromeos {
-// static
-MountLibrary* MountLibrary::Get() {
- return Singleton<MountLibrary>::get();
-}
-
-void MountLibrary::AddObserver(Observer* observer) {
+void MountLibraryImpl::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
-void MountLibrary::RemoveObserver(Observer* observer) {
+void MountLibraryImpl::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
-void MountLibrary::ParseDisks(const MountStatus& status) {
+void MountLibraryImpl::ParseDisks(const MountStatus& status) {
disks_.clear();
for (int i = 0; i < status.size; i++) {
std::string path;
@@ -51,32 +46,32 @@ void MountLibrary::ParseDisks(const MountStatus& status) {
}
}
-MountLibrary::MountLibrary() {
- if (CrosLibrary::EnsureLoaded()) {
+MountLibraryImpl::MountLibraryImpl() : mount_status_connection_(NULL) {
+ if (CrosLibrary::Get()->EnsureLoaded()) {
Init();
} else {
LOG(ERROR) << "Cros Library has not been loaded";
}
}
-MountLibrary::~MountLibrary() {
- if (CrosLibrary::EnsureLoaded()) {
+MountLibraryImpl::~MountLibraryImpl() {
+ if (mount_status_connection_) {
DisconnectMountStatus(mount_status_connection_);
}
}
// static
-void MountLibrary::MountStatusChangedHandler(void* object,
+void MountLibraryImpl::MountStatusChangedHandler(void* object,
const MountStatus& status,
MountEventType evt,
const char* path) {
- MountLibrary* mount = static_cast<MountLibrary*>(object);
+ MountLibraryImpl* mount = static_cast<MountLibraryImpl*>(object);
std::string devicepath = path;
mount->ParseDisks(status);
mount->UpdateMountStatus(status, evt, devicepath);
}
-void MountLibrary::Init() {
+void MountLibraryImpl::Init() {
// Getting the monitor status so that the daemon starts up.
MountStatus* mount = RetrieveMountInformation();
FreeMountStatus(mount);
@@ -85,7 +80,7 @@ void MountLibrary::Init() {
&MountStatusChangedHandler, this);
}
-void MountLibrary::UpdateMountStatus(const MountStatus& status,
+void MountLibraryImpl::UpdateMountStatus(const MountStatus& status,
MountEventType evt,
const std::string& path) {
// Make sure we run on UI thread.
diff --git a/chrome/browser/chromeos/cros/mount_library.h b/chrome/browser/chromeos/cros/mount_library.h
index dccd06e..bbbc7cb 100644
--- a/chrome/browser/chromeos/cros/mount_library.h
+++ b/chrome/browser/chromeos/cros/mount_library.h
@@ -45,22 +45,29 @@ class MountLibrary {
const std::string& path) = 0;
};
- // This gets the singleton MountLibrary
- static MountLibrary* Get();
+ virtual ~MountLibrary() {}
+ virtual void AddObserver(Observer* observer) = 0;
+ virtual void RemoveObserver(Observer* observer) = 0;
+ virtual const DiskVector& disks() const = 0;
+};
+
- void AddObserver(Observer* observer);
- void RemoveObserver(Observer* observer);
+// This class handles the interaction with the ChromeOS mount library APIs.
+// Classes can add themselves as observers. Users can get an instance of this
+// library class like this: MountLibrary::Get().
+class MountLibraryImpl : public MountLibrary {
+ public:
+ MountLibraryImpl();
+ virtual ~MountLibraryImpl();
- const DiskVector& disks() const { return disks_; }
+ // MountLibrary overrides.
+ virtual void AddObserver(Observer* observer);
+ virtual void RemoveObserver(Observer* observer);
+ virtual const DiskVector& disks() const { return disks_; }
private:
- friend struct DefaultSingletonTraits<MountLibrary>;
-
void ParseDisks(const MountStatus& status);
- MountLibrary();
- ~MountLibrary();
-
// This method is called when there's a change in mount status.
// This method is called the UI Thread.
static void MountStatusChangedHandler(void* object,
@@ -87,7 +94,7 @@ class MountLibrary {
// The list of disks found.
DiskVector disks_;
- DISALLOW_COPY_AND_ASSIGN(MountLibrary);
+ DISALLOW_COPY_AND_ASSIGN(MountLibraryImpl);
};
} // namespace chromeos
diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc
index 2449bdd..54e013f 100644
--- a/chrome/browser/chromeos/cros/network_library.cc
+++ b/chrome/browser/chromeos/cros/network_library.cc
@@ -14,9 +14,9 @@
// Allows InvokeLater without adding refcounting. This class is a Singleton and
// won't be deleted until it's last InvokeLater is run.
template <>
-struct RunnableMethodTraits<chromeos::NetworkLibrary> {
- void RetainCallee(chromeos::NetworkLibrary* obj) {}
- void ReleaseCallee(chromeos::NetworkLibrary* obj) {}
+struct RunnableMethodTraits<chromeos::NetworkLibraryImpl> {
+ void RetainCallee(chromeos::NetworkLibraryImpl* obj) {}
+ void ReleaseCallee(chromeos::NetworkLibraryImpl* obj) {}
};
namespace chromeos {
@@ -25,82 +25,78 @@ namespace chromeos {
// NetworkLibrary
// static
-const int NetworkLibrary::kNetworkTrafficeTimerSecs = 1;
+const int NetworkLibraryImpl::kNetworkTrafficeTimerSecs = 1;
-NetworkLibrary::NetworkLibrary()
+NetworkLibraryImpl::NetworkLibraryImpl()
: traffic_type_(0),
+ network_status_connection_(NULL),
available_devices_(0),
enabled_devices_(0),
connected_devices_(0),
offline_mode_(false) {
- if (CrosLibrary::EnsureLoaded()) {
+ if (CrosLibrary::Get()->EnsureLoaded()) {
Init();
}
g_url_request_job_tracker.AddObserver(this);
}
-NetworkLibrary::~NetworkLibrary() {
- if (CrosLibrary::EnsureLoaded()) {
+NetworkLibraryImpl::~NetworkLibraryImpl() {
+ if (network_status_connection_) {
DisconnectMonitorNetwork(network_status_connection_);
}
g_url_request_job_tracker.RemoveObserver(this);
}
-// static
-NetworkLibrary* NetworkLibrary::Get() {
- return Singleton<NetworkLibrary>::get();
-}
-
////////////////////////////////////////////////////////////////////////////////
-// NetworkLibrary, URLRequestJobTracker::JobObserver implementation:
+// NetworkLibraryImpl, URLRequestJobTracker::JobObserver implementation:
-void NetworkLibrary::OnJobAdded(URLRequestJob* job) {
+void NetworkLibraryImpl::OnJobAdded(URLRequestJob* job) {
CheckNetworkTraffic(false);
}
-void NetworkLibrary::OnJobRemoved(URLRequestJob* job) {
+void NetworkLibraryImpl::OnJobRemoved(URLRequestJob* job) {
CheckNetworkTraffic(false);
}
-void NetworkLibrary::OnJobDone(URLRequestJob* job,
+void NetworkLibraryImpl::OnJobDone(URLRequestJob* job,
const URLRequestStatus& status) {
CheckNetworkTraffic(false);
}
-void NetworkLibrary::OnJobRedirect(URLRequestJob* job, const GURL& location,
+void NetworkLibraryImpl::OnJobRedirect(URLRequestJob* job, const GURL& location,
int status_code) {
CheckNetworkTraffic(false);
}
-void NetworkLibrary::OnBytesRead(URLRequestJob* job, int byte_count) {
+void NetworkLibraryImpl::OnBytesRead(URLRequestJob* job, int byte_count) {
CheckNetworkTraffic(true);
}
-void NetworkLibrary::AddObserver(Observer* observer) {
+void NetworkLibraryImpl::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
-void NetworkLibrary::RemoveObserver(Observer* observer) {
+void NetworkLibraryImpl::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
-void NetworkLibrary::RequestWifiScan() {
- if (CrosLibrary::EnsureLoaded()) {
+void NetworkLibraryImpl::RequestWifiScan() {
+ if (CrosLibrary::Get()->EnsureLoaded()) {
RequestScan(TYPE_WIFI);
}
}
-void NetworkLibrary::ConnectToWifiNetwork(WifiNetwork network,
+void NetworkLibraryImpl::ConnectToWifiNetwork(WifiNetwork network,
const string16& password) {
- if (CrosLibrary::EnsureLoaded()) {
+ if (CrosLibrary::Get()->EnsureLoaded()) {
ConnectToNetwork(network.service_path.c_str(),
password.empty() ? NULL : UTF16ToUTF8(password).c_str());
}
}
-void NetworkLibrary::ConnectToWifiNetwork(const string16& ssid,
+void NetworkLibraryImpl::ConnectToWifiNetwork(const string16& ssid,
const string16& password) {
- if (CrosLibrary::EnsureLoaded()) {
+ if (CrosLibrary::Get()->EnsureLoaded()) {
// First create a service from hidden network.
ServiceInfo* service = GetWifiService(UTF16ToUTF8(ssid).c_str(),
SECURITY_UNKNOWN);
@@ -117,26 +113,26 @@ void NetworkLibrary::ConnectToWifiNetwork(const string16& ssid,
}
}
-void NetworkLibrary::ConnectToCellularNetwork(CellularNetwork network) {
- if (CrosLibrary::EnsureLoaded()) {
+void NetworkLibraryImpl::ConnectToCellularNetwork(CellularNetwork network) {
+ if (CrosLibrary::Get()->EnsureLoaded()) {
ConnectToNetwork(network.service_path.c_str(), NULL);
}
}
-void NetworkLibrary::EnableEthernetNetworkDevice(bool enable) {
+void NetworkLibraryImpl::EnableEthernetNetworkDevice(bool enable) {
EnableNetworkDevice(TYPE_ETHERNET, enable);
}
-void NetworkLibrary::EnableWifiNetworkDevice(bool enable) {
+void NetworkLibraryImpl::EnableWifiNetworkDevice(bool enable) {
EnableNetworkDevice(TYPE_WIFI, enable);
}
-void NetworkLibrary::EnableCellularNetworkDevice(bool enable) {
+void NetworkLibraryImpl::EnableCellularNetworkDevice(bool enable) {
EnableNetworkDevice(TYPE_CELLULAR, enable);
}
-void NetworkLibrary::EnableOfflineMode(bool enable) {
- if (!CrosLibrary::EnsureLoaded())
+void NetworkLibraryImpl::EnableOfflineMode(bool enable) {
+ if (!CrosLibrary::Get()->EnsureLoaded())
return;
// If network device is already enabled/disabled, then don't do anything.
@@ -154,7 +150,7 @@ void NetworkLibrary::EnableOfflineMode(bool enable) {
}
}
-NetworkIPConfigVector NetworkLibrary::GetIPConfigs(
+NetworkIPConfigVector NetworkLibraryImpl::GetIPConfigs(
const std::string& device_path) {
NetworkIPConfigVector ipconfig_vector;
if (!device_path.empty()) {
@@ -176,8 +172,8 @@ NetworkIPConfigVector NetworkLibrary::GetIPConfigs(
}
// static
-void NetworkLibrary::NetworkStatusChangedHandler(void* object) {
- NetworkLibrary* network = static_cast<NetworkLibrary*>(object);
+void NetworkLibraryImpl::NetworkStatusChangedHandler(void* object) {
+ NetworkLibraryImpl* network = static_cast<NetworkLibraryImpl*>(object);
SystemInfo* system = GetSystemInfo();
if (system) {
network->UpdateNetworkStatus(system);
@@ -186,7 +182,7 @@ void NetworkLibrary::NetworkStatusChangedHandler(void* object) {
}
// static
-void NetworkLibrary::ParseSystem(SystemInfo* system,
+void NetworkLibraryImpl::ParseSystem(SystemInfo* system,
EthernetNetwork* ethernet,
WifiNetworkVector* wifi_networks,
CellularNetworkVector* cellular_networks) {
@@ -251,7 +247,7 @@ void NetworkLibrary::ParseSystem(SystemInfo* system,
}
}
-void NetworkLibrary::Init() {
+void NetworkLibraryImpl::Init() {
// First, get the currently available networks. This data is cached
// on the connman side, so the call should be quick.
SystemInfo* system = GetSystemInfo();
@@ -266,8 +262,9 @@ void NetworkLibrary::Init() {
this);
}
-void NetworkLibrary::EnableNetworkDevice(ConnectionType device, bool enable) {
- if (!CrosLibrary::EnsureLoaded())
+void NetworkLibraryImpl::EnableNetworkDevice(ConnectionType device,
+ bool enable) {
+ if (!CrosLibrary::Get()->EnsureLoaded())
return;
// If network device is already enabled/disabled, then don't do anything.
@@ -285,13 +282,13 @@ void NetworkLibrary::EnableNetworkDevice(ConnectionType device, bool enable) {
EnableNetworkDevice(device, enable);
}
-void NetworkLibrary::UpdateNetworkStatus(SystemInfo* system) {
+void NetworkLibraryImpl::UpdateNetworkStatus(SystemInfo* system) {
// Make sure we run on UI thread.
if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
NewRunnableMethod(this,
- &NetworkLibrary::UpdateNetworkStatus, system));
+ &NetworkLibraryImpl::UpdateNetworkStatus, system));
return;
}
@@ -326,7 +323,7 @@ void NetworkLibrary::UpdateNetworkStatus(SystemInfo* system) {
FOR_EACH_OBSERVER(Observer, observers_, NetworkChanged(this));
}
-void NetworkLibrary::CheckNetworkTraffic(bool download) {
+void NetworkLibraryImpl::CheckNetworkTraffic(bool download) {
// If we already have a pending upload and download notification, then
// shortcut and return.
if (traffic_type_ == (Observer::TRAFFIC_DOWNLOAD | Observer::TRAFFIC_UPLOAD))
@@ -351,32 +348,32 @@ void NetworkLibrary::CheckNetworkTraffic(bool download) {
// running, then start a new timer.
if (traffic_type_ && !timer_.IsRunning()) {
timer_.Start(base::TimeDelta::FromSeconds(kNetworkTrafficeTimerSecs), this,
- &NetworkLibrary::NetworkTrafficTimerFired);
+ &NetworkLibraryImpl::NetworkTrafficTimerFired);
}
}
-void NetworkLibrary:: NetworkTrafficTimerFired() {
+void NetworkLibraryImpl:: NetworkTrafficTimerFired() {
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
- NewRunnableMethod(this, &NetworkLibrary::NotifyNetworkTraffic,
+ NewRunnableMethod(this, &NetworkLibraryImpl::NotifyNetworkTraffic,
traffic_type_));
// Reset traffic type so that we don't send the same data next time.
traffic_type_ = 0;
}
-void NetworkLibrary::NotifyNetworkTraffic(int traffic_type) {
+void NetworkLibraryImpl::NotifyNetworkTraffic(int traffic_type) {
FOR_EACH_OBSERVER(Observer, observers_, NetworkTraffic(this, traffic_type));
}
-bool NetworkLibrary::Connected() const {
+bool NetworkLibraryImpl::Connected() const {
return ethernet_connected() || wifi_connected() || cellular_connected();
}
-bool NetworkLibrary::Connecting() const {
+bool NetworkLibraryImpl::Connecting() const {
return ethernet_connecting() || wifi_connecting() || cellular_connecting();
}
-const std::string& NetworkLibrary::IPAddress() const {
+const std::string& NetworkLibraryImpl::IPAddress() const {
// Returns highest priority IP address.
if (ethernet_connected())
return ethernet_.ip_address;
diff --git a/chrome/browser/chromeos/cros/network_library.h b/chrome/browser/chromeos/cros/network_library.h
index a4aaebe..8f5b244 100644
--- a/chrome/browser/chromeos/cros/network_library.h
+++ b/chrome/browser/chromeos/cros/network_library.h
@@ -126,10 +126,7 @@ struct NetworkIPConfig {
};
typedef std::vector<NetworkIPConfig> NetworkIPConfigVector;
-// This class handles the interaction with the ChromeOS network library APIs.
-// Classes can add themselves as observers. Users can get an instance of this
-// library class like this: NetworkLibrary::Get()
-class NetworkLibrary : public URLRequestJobTracker::JobObserver {
+class NetworkLibrary {
public:
class Observer {
public:
@@ -147,8 +144,88 @@ class NetworkLibrary : public URLRequestJobTracker::JobObserver {
virtual void NetworkTraffic(NetworkLibrary* obj, int traffic_type) = 0;
};
- // This gets the singleton NetworkLibrary
- static NetworkLibrary* Get();
+ virtual ~NetworkLibrary() {}
+ virtual void AddObserver(Observer* observer) = 0;
+ virtual void RemoveObserver(Observer* observer) = 0;
+
+ virtual const EthernetNetwork& ethernet_network() const = 0;
+ virtual bool ethernet_connecting() const = 0;
+ virtual bool ethernet_connected() const = 0;
+
+ virtual const std::string& wifi_ssid() const = 0;
+ virtual bool wifi_connecting() const = 0;
+ virtual bool wifi_connected() const = 0;
+ virtual int wifi_strength() const = 0;
+
+ virtual const std::string& cellular_name() const = 0;
+ virtual bool cellular_connecting() const = 0;
+ virtual bool cellular_connected() const = 0;
+ virtual int cellular_strength() const = 0;
+
+ // Return true if any network is currently connected.
+ virtual bool Connected() const = 0;
+
+ // Return true if any network is currently connecting.
+ virtual bool Connecting() const = 0;
+
+ // Returns the current IP address if connected. If not, returns empty string.
+ virtual const std::string& IPAddress() const = 0;
+
+ // Returns the current list of wifi networks.
+ virtual const WifiNetworkVector& wifi_networks() const = 0;
+
+ // Returns the current list of cellular networks.
+ virtual const CellularNetworkVector& cellular_networks() const = 0;
+
+ // Request a scan for new wifi networks.
+ virtual void RequestWifiScan() = 0;
+
+ // Connect to the specified wireless network with password.
+ virtual void ConnectToWifiNetwork(WifiNetwork network,
+ const string16& password) = 0;
+
+ // Connect to the specified wifi ssid with password.
+ virtual void ConnectToWifiNetwork(const string16& ssid,
+ const string16& password) = 0;
+
+ // Connect to the specified cellular network.
+ virtual void ConnectToCellularNetwork(CellularNetwork network) = 0;
+
+ virtual bool ethernet_available() const = 0;
+ virtual bool wifi_available() const = 0;
+ virtual bool cellular_available() const = 0;
+
+ virtual bool ethernet_enabled() const = 0;
+ virtual bool wifi_enabled() const = 0;
+ virtual bool cellular_enabled() const = 0;
+
+ virtual bool offline_mode() const = 0;
+
+ // Enables/disables the ethernet network device.
+ virtual void EnableEthernetNetworkDevice(bool enable) = 0;
+
+ // Enables/disables the wifi network device.
+ virtual void EnableWifiNetworkDevice(bool enable) = 0;
+
+ // Enables/disables the cellular network device.
+ virtual void EnableCellularNetworkDevice(bool enable) = 0;
+
+ // Enables/disables offline mode.
+ virtual void EnableOfflineMode(bool enable) = 0;
+
+ // Fetches IP configs for a given device_path
+ virtual NetworkIPConfigVector GetIPConfigs(
+ const std::string& device_path) = 0;
+};
+
+// This class handles the interaction with the ChromeOS network library APIs.
+// Classes can add themselves as observers. Users can get an instance of this
+// library class like this: NetworkLibrary::Get()
+class NetworkLibraryImpl : public NetworkLibrary,
+ public URLRequestJobTracker::JobObserver {
+ public:
+ NetworkLibraryImpl();
+ virtual ~NetworkLibraryImpl();
// URLRequestJobTracker::JobObserver methods (called on the IO thread):
virtual void OnJobAdded(URLRequestJob* job);
@@ -158,88 +235,89 @@ class NetworkLibrary : public URLRequestJobTracker::JobObserver {
int status_code);
virtual void OnBytesRead(URLRequestJob* job, int byte_count);
- void AddObserver(Observer* observer);
- void RemoveObserver(Observer* observer);
+ // NetworkLibrary overrides.
+ virtual void AddObserver(Observer* observer);
+ virtual void RemoveObserver(Observer* observer);
- const EthernetNetwork& ethernet_network() const { return ethernet_; }
- bool ethernet_connecting() const { return ethernet_.connecting; }
- bool ethernet_connected() const { return ethernet_.connected; }
+ virtual const EthernetNetwork& ethernet_network() const { return ethernet_; }
+ virtual bool ethernet_connecting() const { return ethernet_.connecting; }
+ virtual bool ethernet_connected() const { return ethernet_.connected; }
- const std::string& wifi_ssid() const { return wifi_.ssid; }
- bool wifi_connecting() const { return wifi_.connecting; }
- bool wifi_connected() const { return wifi_.connected; }
- int wifi_strength() const { return wifi_.strength; }
+ virtual const std::string& wifi_ssid() const { return wifi_.ssid; }
+ virtual bool wifi_connecting() const { return wifi_.connecting; }
+ virtual bool wifi_connected() const { return wifi_.connected; }
+ virtual int wifi_strength() const { return wifi_.strength; }
- const std::string& cellular_name() const { return cellular_.name; }
- bool cellular_connecting() const { return cellular_.connecting; }
- bool cellular_connected() const { return cellular_.connected; }
- int cellular_strength() const { return cellular_.strength; }
+ virtual const std::string& cellular_name() const { return cellular_.name; }
+ virtual bool cellular_connecting() const { return cellular_.connecting; }
+ virtual bool cellular_connected() const { return cellular_.connected; }
+ virtual int cellular_strength() const { return cellular_.strength; }
// Return true if any network is currently connected.
- bool Connected() const;
+ virtual bool Connected() const;
// Return true if any network is currently connecting.
- bool Connecting() const;
+ virtual bool Connecting() const;
// Returns the current IP address if connected. If not, returns empty string.
- const std::string& IPAddress() const;
+ virtual const std::string& IPAddress() const;
// Returns the current list of wifi networks.
- const WifiNetworkVector& wifi_networks() const { return wifi_networks_; }
+ virtual const WifiNetworkVector& wifi_networks() const {
+ return wifi_networks_;
+ }
// Returns the current list of cellular networks.
- const CellularNetworkVector& cellular_networks() const {
+ virtual const CellularNetworkVector& cellular_networks() const {
return cellular_networks_;
}
// Request a scan for new wifi networks.
- void RequestWifiScan();
+ virtual void RequestWifiScan();
// Connect to the specified wireless network with password.
- void ConnectToWifiNetwork(WifiNetwork network, const string16& password);
+ virtual void ConnectToWifiNetwork(WifiNetwork network,
+ const string16& password);
// Connect to the specified wifi ssid with password.
- void ConnectToWifiNetwork(const string16& ssid, const string16& password);
+ virtual void ConnectToWifiNetwork(const string16& ssid,
+ const string16& password);
// Connect to the specified cellular network.
- void ConnectToCellularNetwork(CellularNetwork network);
+ virtual void ConnectToCellularNetwork(CellularNetwork network);
- bool ethernet_available() const {
+ virtual bool ethernet_available() const {
return available_devices_ & (1 << TYPE_ETHERNET); }
- bool wifi_available() const {
+ virtual bool wifi_available() const {
return available_devices_ & (1 << TYPE_WIFI); }
- bool cellular_available() const {
+ virtual bool cellular_available() const {
return available_devices_ & (1 << TYPE_CELLULAR); }
- bool ethernet_enabled() const {
+ virtual bool ethernet_enabled() const {
return enabled_devices_ & (1 << TYPE_ETHERNET); }
- bool wifi_enabled() const {
+ virtual bool wifi_enabled() const {
return enabled_devices_ & (1 << TYPE_WIFI); }
- bool cellular_enabled() const {
+ virtual bool cellular_enabled() const {
return enabled_devices_ & (1 << TYPE_CELLULAR); }
- bool offline_mode() const { return offline_mode_; }
+ virtual bool offline_mode() const { return offline_mode_; }
// Enables/disables the ethernet network device.
- void EnableEthernetNetworkDevice(bool enable);
+ virtual void EnableEthernetNetworkDevice(bool enable);
// Enables/disables the wifi network device.
- void EnableWifiNetworkDevice(bool enable);
+ virtual void EnableWifiNetworkDevice(bool enable);
// Enables/disables the cellular network device.
- void EnableCellularNetworkDevice(bool enable);
+ virtual void EnableCellularNetworkDevice(bool enable);
// Enables/disables offline mode.
- void EnableOfflineMode(bool enable);
+ virtual void EnableOfflineMode(bool enable);
// Fetches IP configs for a given device_path
- NetworkIPConfigVector GetIPConfigs(const std::string& device_path);
+ virtual NetworkIPConfigVector GetIPConfigs(const std::string& device_path);
private:
- friend struct DefaultSingletonTraits<NetworkLibrary>;
-
- NetworkLibrary();
- ~NetworkLibrary();
// This method is called when there's a change in network status.
// This method is called on a background thread.
@@ -287,7 +365,7 @@ class NetworkLibrary : public URLRequestJobTracker::JobObserver {
// Timer for sending NetworkTraffic notification every
// kNetworkTrafficeTimerSecs seconds.
- base::OneShotTimer<NetworkLibrary> timer_;
+ base::OneShotTimer<NetworkLibraryImpl> timer_;
// The current traffic type that will be sent out for the next NetworkTraffic
// notification. This is a bitfield of TrafficTypeMasks.
@@ -322,7 +400,7 @@ class NetworkLibrary : public URLRequestJobTracker::JobObserver {
bool offline_mode_;
- DISALLOW_COPY_AND_ASSIGN(NetworkLibrary);
+ DISALLOW_COPY_AND_ASSIGN(NetworkLibraryImpl);
};
} // namespace chromeos
diff --git a/chrome/browser/chromeos/cros/power_library.cc b/chrome/browser/chromeos/cros/power_library.cc
index d055f3b..112f43c 100644
--- a/chrome/browser/chromeos/cros/power_library.cc
+++ b/chrome/browser/chromeos/cros/power_library.cc
@@ -12,80 +12,77 @@
// Allows InvokeLater without adding refcounting. This class is a Singleton and
// won't be deleted until it's last InvokeLater is run.
template <>
-struct RunnableMethodTraits<chromeos::PowerLibrary> {
- void RetainCallee(chromeos::PowerLibrary* obj) {}
- void ReleaseCallee(chromeos::PowerLibrary* obj) {}
+struct RunnableMethodTraits<chromeos::PowerLibraryImpl> {
+ void RetainCallee(chromeos::PowerLibraryImpl* obj) {}
+ void ReleaseCallee(chromeos::PowerLibraryImpl* obj) {}
};
namespace chromeos {
-PowerLibrary::PowerLibrary() : status_(chromeos::PowerStatus()) {
- if (CrosLibrary::EnsureLoaded()) {
+PowerLibraryImpl::PowerLibraryImpl()
+ : power_status_connection_(NULL),
+ status_(chromeos::PowerStatus()) {
+ if (CrosLibrary::Get()->EnsureLoaded()) {
Init();
}
}
-PowerLibrary::~PowerLibrary() {
- if (CrosLibrary::EnsureLoaded()) {
+PowerLibraryImpl::~PowerLibraryImpl() {
+ if (power_status_connection_) {
chromeos::DisconnectPowerStatus(power_status_connection_);
}
}
-// static
-PowerLibrary* PowerLibrary::Get() {
- return Singleton<PowerLibrary>::get();
-}
-
-void PowerLibrary::AddObserver(Observer* observer) {
+void PowerLibraryImpl::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
-void PowerLibrary::RemoveObserver(Observer* observer) {
+void PowerLibraryImpl::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
-bool PowerLibrary::line_power_on() const {
+bool PowerLibraryImpl::line_power_on() const {
return status_.line_power_on;
}
-bool PowerLibrary::battery_is_present() const {
+bool PowerLibraryImpl::battery_is_present() const {
return status_.battery_is_present;
}
-bool PowerLibrary::battery_fully_charged() const {
+bool PowerLibraryImpl::battery_fully_charged() const {
return status_.battery_state == chromeos::BATTERY_STATE_FULLY_CHARGED;
}
-double PowerLibrary::battery_percentage() const {
+double PowerLibraryImpl::battery_percentage() const {
return status_.battery_percentage;
}
-base::TimeDelta PowerLibrary::battery_time_to_empty() const {
+base::TimeDelta PowerLibraryImpl::battery_time_to_empty() const {
return base::TimeDelta::FromSeconds(status_.battery_time_to_empty);
}
-base::TimeDelta PowerLibrary::battery_time_to_full() const {
+base::TimeDelta PowerLibraryImpl::battery_time_to_full() const {
return base::TimeDelta::FromSeconds(status_.battery_time_to_full);
}
// static
-void PowerLibrary::PowerStatusChangedHandler(void* object,
+void PowerLibraryImpl::PowerStatusChangedHandler(void* object,
const chromeos::PowerStatus& status) {
- PowerLibrary* power = static_cast<PowerLibrary*>(object);
+ PowerLibraryImpl* power = static_cast<PowerLibraryImpl*>(object);
power->UpdatePowerStatus(status);
}
-void PowerLibrary::Init() {
+void PowerLibraryImpl::Init() {
power_status_connection_ = chromeos::MonitorPowerStatus(
&PowerStatusChangedHandler, this);
}
-void PowerLibrary::UpdatePowerStatus(const chromeos::PowerStatus& status) {
+void PowerLibraryImpl::UpdatePowerStatus(const chromeos::PowerStatus& status) {
// Make sure we run on UI thread.
if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
- NewRunnableMethod(this, &PowerLibrary::UpdatePowerStatus, status));
+ NewRunnableMethod(this, &PowerLibraryImpl::UpdatePowerStatus, status));
return;
}
diff --git a/chrome/browser/chromeos/cros/power_library.h b/chrome/browser/chromeos/cros/power_library.h
index d362b64..dcbab8c 100644
--- a/chrome/browser/chromeos/cros/power_library.h
+++ b/chrome/browser/chromeos/cros/power_library.h
@@ -12,7 +12,7 @@
namespace chromeos {
-// This class handles the interaction with the ChromeOS power library APIs.
+// This interface defines interaction with the ChromeOS power library APIs.
// Classes can add themselves as observers. Users can get an instance of this
// library class like this: PowerLibrary::Get()
class PowerLibrary {
@@ -21,36 +21,60 @@ class PowerLibrary {
public:
virtual void PowerChanged(PowerLibrary* obj) = 0;
};
+ virtual ~PowerLibrary() {}
+ virtual void AddObserver(Observer* observer) = 0;
+ virtual void RemoveObserver(Observer* observer) = 0;
+ // Whether or not the line power is connected.
+ virtual bool line_power_on() const = 0;
+
+ // Whether or not the battery is fully charged..
+ virtual bool battery_fully_charged() const = 0;
+
+ // The percentage (0-100) of remaining battery.
+ virtual double battery_percentage() const = 0;
- // This gets the singleton PowerLibrary
- static PowerLibrary* Get();
+ // Whether there is a battery present.
+ virtual bool battery_is_present() const = 0;
- void AddObserver(Observer* observer);
- void RemoveObserver(Observer* observer);
+ // The amount of time until battery is empty.
+ virtual base::TimeDelta battery_time_to_empty() const = 0;
+
+ // The amount of time until battery is full.
+ virtual base::TimeDelta battery_time_to_full() const = 0;
+};
+
+
+// This class handles the interaction with the ChromeOS power library APIs.
+// Classes can add themselves as observers. Users can get an instance of this
+// library class like this: PowerLibrary::Get()
+class PowerLibraryImpl : public PowerLibrary {
+ public:
+ PowerLibraryImpl();
+ virtual ~PowerLibraryImpl();
+
+ // PowerLibrary overrides.
+ virtual void AddObserver(Observer* observer);
+ virtual void RemoveObserver(Observer* observer);
// Whether or not the line power is connected.
- bool line_power_on() const;
+ virtual bool line_power_on() const;
// Whether or not the battery is fully charged..
- bool battery_fully_charged() const;
+ virtual bool battery_fully_charged() const;
// The percentage (0-100) of remaining battery.
- double battery_percentage() const;
+ virtual double battery_percentage() const;
// Whether there is a battery present.
- bool battery_is_present() const;
+ virtual bool battery_is_present() const;
// The amount of time until battery is empty.
- base::TimeDelta battery_time_to_empty() const;
+ virtual base::TimeDelta battery_time_to_empty() const;
// The amount of time until battery is full.
- base::TimeDelta battery_time_to_full() const;
+ virtual base::TimeDelta battery_time_to_full() const;
private:
- friend struct DefaultSingletonTraits<PowerLibrary>;
-
- PowerLibrary();
- ~PowerLibrary();
// This method is called when there's a change in power status.
// This method is called on a background thread.
@@ -73,7 +97,7 @@ class PowerLibrary {
// The latest power status.
chromeos::PowerStatus status_;
- DISALLOW_COPY_AND_ASSIGN(PowerLibrary);
+ DISALLOW_COPY_AND_ASSIGN(PowerLibraryImpl);
};
} // namespace chromeos
diff --git a/chrome/browser/chromeos/cros/synaptics_library.cc b/chrome/browser/chromeos/cros/synaptics_library.cc
index 3cf22c4..462be76 100644
--- a/chrome/browser/chromeos/cros/synaptics_library.cc
+++ b/chrome/browser/chromeos/cros/synaptics_library.cc
@@ -10,16 +10,13 @@
namespace chromeos {
-// static
-SynapticsLibrary* SynapticsLibrary::Get() {
- return Singleton<SynapticsLibrary>::get();
-}
-
-void SynapticsLibrary::SetBoolParameter(SynapticsParameter param, bool value) {
+void SynapticsLibraryImpl::SetBoolParameter(SynapticsParameter param,
+ bool value) {
SetParameter(param, value ? 1 : 0);
}
-void SynapticsLibrary::SetRangeParameter(SynapticsParameter param, int value) {
+void SynapticsLibraryImpl::SetRangeParameter(SynapticsParameter param,
+ int value) {
if (value < 1)
value = 1;
if (value > 10)
@@ -27,8 +24,8 @@ void SynapticsLibrary::SetRangeParameter(SynapticsParameter param, int value) {
SetParameter(param, value);
}
-void SynapticsLibrary::SetParameter(SynapticsParameter param, int value) {
- if (CrosLibrary::EnsureLoaded()) {
+void SynapticsLibraryImpl::SetParameter(SynapticsParameter param, int value) {
+ if (CrosLibrary::Get()->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/cros/synaptics_library.h b/chrome/browser/chromeos/cros/synaptics_library.h
index c090606..676e0f9 100644
--- a/chrome/browser/chromeos/cros/synaptics_library.h
+++ b/chrome/browser/chromeos/cros/synaptics_library.h
@@ -10,33 +10,42 @@
namespace chromeos {
-// This class handles the interaction with the ChromeOS synaptics library APIs.
+// This interface defines interaction with the ChromeOS synaptics library APIs.
// Users can get an instance of this library class like this:
// SynapticsLibrary::Get()
// For a list of SynapticsPrameters, see third_party/cros/chromeos_synaptics.h
class SynapticsLibrary {
public:
- // This gets the singleton SynapticsLibrary.
- static SynapticsLibrary* Get();
-
+ virtual ~SynapticsLibrary() {}
// Sets a boolean parameter. The actual call will be run on the FILE thread.
- void SetBoolParameter(SynapticsParameter param, bool value);
+ virtual void SetBoolParameter(SynapticsParameter param, bool value) = 0;
// Sets a range parameter. The actual call will be run on the FILE thread.
// Value should be between 1 and 10 inclusive.
- void SetRangeParameter(SynapticsParameter param, int value);
+ virtual void SetRangeParameter(SynapticsParameter param, int value) = 0;
+};
- private:
- friend struct DefaultSingletonTraits<SynapticsLibrary>;
- SynapticsLibrary() {}
- ~SynapticsLibrary() {}
+// This class handles the interaction with the ChromeOS synaptics library APIs.
+// Users can get an instance of this library class like this:
+// SynapticsLibrary::Get()
+// For a list of SynapticsPrameters, see third_party/cros/chromeos_synaptics.h
+class SynapticsLibraryImpl : public SynapticsLibrary {
+ public:
+ SynapticsLibraryImpl() {}
+ virtual ~SynapticsLibraryImpl() {}
+
+ // SynapticsLibrary overrides.
+ virtual void SetBoolParameter(SynapticsParameter param, bool value);
+ virtual void SetRangeParameter(SynapticsParameter param, int value);
+
+ private:
// This helper methods calls into the libcros library to set the parameter.
// This call is run on the FILE thread.
void SetParameter(SynapticsParameter param, int value);
- DISALLOW_COPY_AND_ASSIGN(SynapticsLibrary);
+ DISALLOW_COPY_AND_ASSIGN(SynapticsLibraryImpl);
};
} // namespace chromeos
diff --git a/chrome/browser/chromeos/google_update_chromeos.cc b/chrome/browser/chromeos/google_update_chromeos.cc
index 2aab04a..7cf32cb 100644
--- a/chrome/browser/chromeos/google_update_chromeos.cc
+++ b/chrome/browser/chromeos/google_update_chromeos.cc
@@ -22,7 +22,7 @@ using views::Window;
GoogleUpdate::GoogleUpdate()
: listener_(NULL) {
- chromeos::CrosLibrary::EnsureLoaded();
+ chromeos::CrosLibrary::Get()->EnsureLoaded();
}
GoogleUpdate::~GoogleUpdate() {
diff --git a/chrome/browser/chromeos/login/existing_user_controller.cc b/chrome/browser/chromeos/login/existing_user_controller.cc
index e8df4bc..763e30d 100644
--- a/chrome/browser/chromeos/login/existing_user_controller.cc
+++ b/chrome/browser/chromeos/login/existing_user_controller.cc
@@ -74,8 +74,8 @@ void ExistingUserController::Init() {
WmMessageListener::instance()->AddObserver(this);
- if (CrosLibrary::EnsureLoaded())
- LoginLibrary::Get()->EmitLoginPromptReady();
+ if (CrosLibrary::Get()->EnsureLoaded())
+ CrosLibrary::Get()->GetLoginLibrary()->EmitLoginPromptReady();
}
ExistingUserController::~ExistingUserController() {
diff --git a/chrome/browser/chromeos/login/google_authenticator.cc b/chrome/browser/chromeos/login/google_authenticator.cc
index f14ba97..409d382 100644
--- a/chrome/browser/chromeos/login/google_authenticator.cc
+++ b/chrome/browser/chromeos/login/google_authenticator.cc
@@ -47,6 +47,7 @@ const char GoogleAuthenticator::kCookiePersistence[] = "true";
const char GoogleAuthenticator::kAccountType[] = "HOSTED_OR_GOOGLE";
const char GoogleAuthenticator::kSource[] = "chromeos";
const int GoogleAuthenticator::kHttpSuccess = 200;
+const int kPassHashLen = 32;
// Chromium OS system salt stored here
const char GoogleAuthenticator::kSystemSalt[] = "/home/.shadow/salt";
@@ -102,7 +103,6 @@ void GoogleAuthenticator::OnURLFetchComplete(const URLFetcher* source,
ChromeThread::UI, FROM_HERE,
NewRunnableFunction(GoogleAuthenticator::OnLoginSuccess,
consumer_,
- library_,
username_,
ascii_hash_,
cookies));
@@ -114,7 +114,6 @@ void GoogleAuthenticator::OnURLFetchComplete(const URLFetcher* source,
ChromeThread::UI, FROM_HERE,
NewRunnableFunction(GoogleAuthenticator::CheckOffline,
consumer_,
- library_,
username_,
ascii_hash_,
status));
@@ -136,11 +135,11 @@ void GoogleAuthenticator::OnURLFetchComplete(const URLFetcher* source,
// static
void GoogleAuthenticator::OnLoginSuccess(LoginStatusConsumer* consumer,
- CryptohomeLibrary* library,
const std::string& username,
const std::string& passhash,
const ResponseCookies& cookies) {
- if (library->Mount(username.c_str(), passhash.c_str()))
+ if (CrosLibrary::Get()->GetCryptohomeLibrary()->Mount(username.c_str(),
+ passhash.c_str()))
consumer->OnLoginSuccess(username, cookies);
else
GoogleAuthenticator::OnLoginFailure(consumer, "Could not mount cryptohome");
@@ -148,16 +147,15 @@ void GoogleAuthenticator::OnLoginSuccess(LoginStatusConsumer* consumer,
// static
void GoogleAuthenticator::CheckOffline(LoginStatusConsumer* consumer,
- CryptohomeLibrary* library,
const std::string& username,
const std::string& passhash,
const URLRequestStatus& status) {
- if (library->CheckKey(username.c_str(), passhash.c_str())) {
+ if (CrosLibrary::Get()->GetCryptohomeLibrary()->CheckKey(username.c_str(),
+ passhash.c_str())) {
// The fetch didn't succeed, but offline login did.
LOG(INFO) << "Offline login successful!";
ResponseCookies cookies;
GoogleAuthenticator::OnLoginSuccess(consumer,
- library,
username,
passhash,
cookies);
@@ -196,12 +194,12 @@ std::string GoogleAuthenticator::SaltAsAscii() {
FilePath salt_path(kSystemSalt);
LoadSystemSalt(salt_path);
unsigned int salt_len = system_salt_.size();
- char ascii_salt[2 * salt_len];
+ char ascii_salt[2 * salt_len + 1];
if (GoogleAuthenticator::BinaryToHex(system_salt_,
salt_len,
ascii_salt,
sizeof(ascii_salt))) {
- return std::string(ascii_salt, sizeof(ascii_salt));
+ return std::string(ascii_salt, sizeof(ascii_salt) - 1);
} else {
return std::string();
}
@@ -211,8 +209,8 @@ void GoogleAuthenticator::StoreHashedPassword(const std::string& password) {
// Get salt, ascii encode, update sha with that, then update with ascii
// of password, then end.
std::string ascii_salt = SaltAsAscii();
- unsigned char passhash_buf[32];
- char ascii_buf[32];
+ unsigned char passhash_buf[kPassHashLen];
+ char ascii_buf[kPassHashLen + 1];
// Hash salt and password
SHA256Context ctx;
@@ -234,7 +232,7 @@ void GoogleAuthenticator::StoreHashedPassword(const std::string& password) {
passhash.size() / 2, // only want top half, at least for now.
ascii_buf,
sizeof(ascii_buf));
- ascii_hash_.assign(ascii_buf, sizeof(ascii_buf));
+ ascii_hash_.assign(ascii_buf, sizeof(ascii_buf) - 1);
}
// static
@@ -246,6 +244,6 @@ bool GoogleAuthenticator::BinaryToHex(const std::vector<unsigned char>& binary,
return false;
memset(hex_string, 0, len);
for (uint i = 0, j = 0; i < binary_len; i++, j+=2)
- sprintf(hex_string + j, "%02x", binary[i]);
+ snprintf(hex_string + j, len - j, "%02x", binary[i]);
return true;
}
diff --git a/chrome/browser/chromeos/login/google_authenticator.h b/chrome/browser/chromeos/login/google_authenticator.h
index f8b6e10..f00ae8d 100644
--- a/chrome/browser/chromeos/login/google_authenticator.h
+++ b/chrome/browser/chromeos/login/google_authenticator.h
@@ -26,17 +26,15 @@ class GoogleAuthenticator : public Authenticator,
public URLFetcher::Delegate {
public:
GoogleAuthenticator(LoginStatusConsumer* consumer,
- chromeos::CryptohomeLibrary* library,
AuthResponseHandler* cl_handler,
AuthResponseHandler* i_handler)
: Authenticator(consumer),
- library_(library),
fetcher_(NULL),
getter_(NULL),
client_login_handler_(cl_handler),
issue_handler_(i_handler) {
- if (!library && chromeos::CrosLibrary::EnsureLoaded())
- library_ = chromeos::CryptohomeLibrary::Get();
+ CHECK(chromeos::CrosLibrary::Get()->EnsureLoaded());
+ library_ = chromeos::CrosLibrary::Get()->GetCryptohomeLibrary();
}
explicit GoogleAuthenticator(LoginStatusConsumer* consumer)
@@ -45,8 +43,8 @@ class GoogleAuthenticator : public Authenticator,
getter_(NULL),
client_login_handler_(NULL),
issue_handler_(NULL) {
- CHECK(chromeos::CrosLibrary::EnsureLoaded());
- library_ = chromeos::CryptohomeLibrary::Get();
+ CHECK(chromeos::CrosLibrary::Get()->EnsureLoaded());
+ library_ = chromeos::CrosLibrary::Get()->GetCryptohomeLibrary();
}
virtual ~GoogleAuthenticator() {}
@@ -81,12 +79,10 @@ class GoogleAuthenticator : public Authenticator,
// to the subclasses specifically, and I want to allow mocked out
// LoginStatusConsumers to be used here as well.
static void OnLoginSuccess(LoginStatusConsumer* consumer,
- chromeos::CryptohomeLibrary* library,
const std::string& username,
const std::string& passhash,
const ResponseCookies& cookies);
static void CheckOffline(LoginStatusConsumer* consumer,
- chromeos::CryptohomeLibrary* library,
const std::string& username,
const std::string& passhash,
const URLRequestStatus& status);
diff --git a/chrome/browser/chromeos/login/google_authenticator_unittest.cc b/chrome/browser/chromeos/login/google_authenticator_unittest.cc
index 570463f..89cddc6 100644
--- a/chrome/browser/chromeos/login/google_authenticator_unittest.cc
+++ b/chrome/browser/chromeos/login/google_authenticator_unittest.cc
@@ -13,6 +13,7 @@
#include "base/message_loop.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/chromeos/cros/mock_cryptohome_library.h"
+#include "chrome/browser/chromeos/cros/mock_library_loader.h"
#include "chrome/browser/chromeos/login/mock_auth_response_handler.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/net/url_fetcher.h"
@@ -22,6 +23,7 @@
#include "testing/gmock/include/gmock/gmock.h"
namespace chromeos {
+using ::testing::AnyNumber;
using ::testing::InvokeWithoutArgs;
using ::testing::Return;
using ::testing::_;
@@ -47,10 +49,33 @@ class GoogleAuthenticatorTest : public ::testing::Test {
}
~GoogleAuthenticatorTest() {}
+ virtual void SetUp() {
+ chromeos::CrosLibrary::TestApi* test_api =
+ chromeos::CrosLibrary::Get()->GetTestApi();
+
+ loader_ = new MockLibraryLoader();
+ ON_CALL(*loader_, Load(_))
+ .WillByDefault(Return(true));
+ EXPECT_CALL(*loader_, Load(_))
+ .Times(AnyNumber());
+
+ test_api->SetLibraryLoader(loader_);
+
+ mock_library_ = new MockCryptohomeLibrary();
+ test_api->SetCryptohomeLibrary(mock_library_);
+}
+
+ // Tears down the test fixture.
+ virtual void TearDown() {
+ }
+
unsigned char fake_hash_[32];
std::string hash_ascii_;
std::string username_;
ResponseCookies cookies_;
+ // Mocks, destroyed by CrosLibrary class.
+ MockCryptohomeLibrary* mock_library_;
+ MockLibraryLoader* loader_;
};
TEST_F(GoogleAuthenticatorTest, SaltToAsciiTest) {
@@ -60,8 +85,7 @@ TEST_F(GoogleAuthenticatorTest, SaltToAsciiTest) {
fake_salt[7] = 10 << 4;
std::vector<unsigned char> salt_v(fake_salt, fake_salt + sizeof(fake_salt));
- MockCryptohomeLibrary library;
- GoogleAuthenticator auth(NULL, &library, NULL, NULL);
+ GoogleAuthenticator auth(NULL, NULL, NULL);
auth.set_system_salt(salt_v);
EXPECT_EQ("0a010000000000a0", auth.SaltAsAscii());
@@ -91,24 +115,24 @@ TEST_F(GoogleAuthenticatorTest, OnLoginSuccessTest) {
MockConsumer consumer;
EXPECT_CALL(consumer, OnLoginSuccess(username_, _));
- MockCryptohomeLibrary library;
- EXPECT_CALL(library, Mount(username_, hash_ascii_))
+ EXPECT_CALL(*mock_library_, Mount(username_, hash_ascii_))
.WillOnce(Return(true));
- GoogleAuthenticator auth(&consumer, &library, NULL, NULL);
- auth.OnLoginSuccess(&consumer, &library, username_, hash_ascii_, cookies_);
+ GoogleAuthenticator auth(&consumer, NULL, NULL);
+ auth.OnLoginSuccess(&consumer, username_, hash_ascii_,
+ cookies_);
}
TEST_F(GoogleAuthenticatorTest, MountFailureTest) {
MockConsumer consumer;
EXPECT_CALL(consumer, OnLoginFailure(_));
- MockCryptohomeLibrary library;
- EXPECT_CALL(library, Mount(username_, hash_ascii_))
+ EXPECT_CALL(*mock_library_, Mount(username_, hash_ascii_))
.WillOnce(Return(false));
- GoogleAuthenticator auth(&consumer, &library, NULL, NULL);
- auth.OnLoginSuccess(&consumer, &library, username_, hash_ascii_, cookies_);
+ GoogleAuthenticator auth(&consumer, NULL, NULL);
+ auth.OnLoginSuccess(&consumer, username_, hash_ascii_,
+ cookies_);
}
static void Quit() { MessageLoop::current()->Quit(); }
@@ -125,11 +149,10 @@ TEST_F(GoogleAuthenticatorTest, LoginNetFailureTest) {
MockConsumer consumer;
EXPECT_CALL(consumer, OnLoginFailure(data))
.WillOnce(InvokeWithoutArgs(Quit));
- MockCryptohomeLibrary library;
- EXPECT_CALL(library, CheckKey(username_, hash_ascii_))
+ EXPECT_CALL(*mock_library_, CheckKey(username_, hash_ascii_))
.WillOnce(Return(false));
- GoogleAuthenticator auth(&consumer, &library, NULL, NULL);
+ GoogleAuthenticator auth(&consumer, NULL, NULL);
auth.set_password_hash(hash_ascii_);
auth.set_username(username_);
auth.OnURLFetchComplete(NULL, source, status, 0, cookies_, data);
@@ -148,9 +171,8 @@ TEST_F(GoogleAuthenticatorTest, LoginDeniedTest) {
MockConsumer consumer;
EXPECT_CALL(consumer, OnLoginFailure(data))
.WillOnce(InvokeWithoutArgs(Quit));
- MockCryptohomeLibrary library;
- GoogleAuthenticator auth(&consumer, &library, NULL, NULL);
+ GoogleAuthenticator auth(&consumer, NULL, NULL);
auth.OnURLFetchComplete(NULL, source, status, 403, cookies_, data);
MessageLoop::current()->Run(); // So tasks can be posted.
}
@@ -168,13 +190,12 @@ TEST_F(GoogleAuthenticatorTest, OfflineLoginTest) {
MockConsumer consumer;
EXPECT_CALL(consumer, OnLoginSuccess(username_, cookies_))
.WillOnce(InvokeWithoutArgs(Quit));
- MockCryptohomeLibrary library;
- EXPECT_CALL(library, CheckKey(username_, hash_ascii_))
+ EXPECT_CALL(*mock_library_, CheckKey(username_, hash_ascii_))
.WillOnce(Return(true));
- EXPECT_CALL(library, Mount(username_, hash_ascii_))
+ EXPECT_CALL(*mock_library_, Mount(username_, hash_ascii_))
.WillOnce(Return(true));
- GoogleAuthenticator auth(&consumer, &library, NULL, NULL);
+ GoogleAuthenticator auth(&consumer, NULL, NULL);
auth.set_password_hash(hash_ascii_);
auth.set_username(username_);
auth.OnURLFetchComplete(NULL, source, status, 0, cookies_, data);
@@ -193,13 +214,11 @@ TEST_F(GoogleAuthenticatorTest, ClientLoginPassIssueAuthTokenFailTest) {
MockConsumer consumer;
EXPECT_CALL(consumer, OnLoginFailure(data))
.WillOnce(InvokeWithoutArgs(Quit));
- MockCryptohomeLibrary library;
MockAuthResponseHandler* cl_handler = new MockAuthResponseHandler;
EXPECT_CALL(*cl_handler, CanHandle(cl_source))
.WillOnce(Return(true));
GoogleAuthenticator auth(&consumer,
- &library,
cl_handler, // takes ownership.
new IssueResponseHandler(NULL));
auth.set_password_hash(hash_ascii_);
@@ -230,12 +249,10 @@ TEST_F(GoogleAuthenticatorTest, OnlineLoginTest) {
MockConsumer consumer;
EXPECT_CALL(consumer, OnLoginSuccess(username_, cookies_))
.WillOnce(InvokeWithoutArgs(Quit));
- MockCryptohomeLibrary library;
- EXPECT_CALL(library, Mount(username_, hash_ascii_))
+ EXPECT_CALL(*mock_library_, Mount(username_, hash_ascii_))
.WillOnce(Return(true));
GoogleAuthenticator auth(&consumer,
- &library,
new ClientLoginResponseHandler(NULL),
new IssueResponseHandler(NULL));
auth.set_password_hash(hash_ascii_);
diff --git a/chrome/browser/chromeos/login/login_manager_view.cc b/chrome/browser/chromeos/login/login_manager_view.cc
index 179c9ad..fe5b17f 100644
--- a/chrome/browser/chromeos/login/login_manager_view.cc
+++ b/chrome/browser/chromeos/login/login_manager_view.cc
@@ -157,12 +157,12 @@ void LoginManagerView::Init() {
// Controller to handle events from textfields
username_field_->SetController(this);
password_field_->SetController(this);
- if (CrosLibrary::EnsureLoaded()) {
+ if (CrosLibrary::Get()->EnsureLoaded()) {
loader_.GetVersion(
&consumer_, NewCallback(this, &LoginManagerView::OnOSVersion));
} else if (!kStubOutLogin) {
error_label_->SetText(
- ASCIIToWide(CrosLibrary::load_error_string()));
+ ASCIIToWide(CrosLibrary::Get()->load_error_string()));
username_field_->SetReadOnly(true);
password_field_->SetReadOnly(true);
}
@@ -316,7 +316,7 @@ void LoginManagerView::ButtonPressed(
void LoginManagerView::OnLoginFailure(const std::string error) {
LOG(INFO) << "LoginManagerView: OnLoginFailure() " << error;
- NetworkLibrary* network = NetworkLibrary::Get();
+ NetworkLibrary* network = CrosLibrary::Get()->GetNetworkLibrary();
// Send notification of failure
AuthenticationNotificationDetails details(false);
@@ -326,7 +326,7 @@ void LoginManagerView::OnLoginFailure(const std::string error) {
// Check networking after trying to login in case user is
// cached locally or the local admin account.
- if (!network || !CrosLibrary::EnsureLoaded())
+ if (!network || !CrosLibrary::Get()->EnsureLoaded())
ShowError(IDS_LOGIN_ERROR_NO_NETWORK_LIBRARY);
else if (!network->Connected())
ShowError(IDS_LOGIN_ERROR_NETWORK_NOT_CONNECTED);
@@ -353,7 +353,7 @@ void LoginManagerView::ShowError(int error_id) {
bool LoginManagerView::HandleKeystroke(views::Textfield* s,
const views::Textfield::Keystroke& keystroke) {
- if (!kStubOutLogin && !CrosLibrary::EnsureLoaded())
+ if (!kStubOutLogin && !CrosLibrary::Get()->EnsureLoaded())
return false;
if (keystroke.GetKeyboardCode() == base::VKEY_TAB) {
diff --git a/chrome/browser/chromeos/login/network_selection_view.cc b/chrome/browser/chromeos/login/network_selection_view.cc
index ebbda45..d6b936e 100644
--- a/chrome/browser/chromeos/login/network_selection_view.cc
+++ b/chrome/browser/chromeos/login/network_selection_view.cc
@@ -13,6 +13,7 @@
#include "app/resource_bundle.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/login/screen_observer.h"
#include "chrome/browser/pref_service.h"
#include "chrome/common/pref_names.h"
@@ -145,7 +146,7 @@ void NetworkSelectionView::UpdateLocalizedStrings() {
void NetworkSelectionView::Refresh() {
ChangeNetworkNotification(true);
- NetworkChanged(chromeos::NetworkLibrary::Get());
+ NetworkChanged(chromeos::CrosLibrary::Get()->GetNetworkLibrary());
}
////////////////////////////////////////////////////////////////////////////////
@@ -247,12 +248,12 @@ void NetworkSelectionView::ItemChanged(views::Combobox* sender,
OpenPasswordDialog(network->wifi_network);
return;
} else {
- NetworkLibrary::Get()->ConnectToWifiNetwork(
+ CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork(
network->wifi_network, string16());
}
} else if (NetworkList::NETWORK_CELLULAR ==
network->network_type) {
- NetworkLibrary::Get()->ConnectToCellularNetwork(
+ CrosLibrary::Get()->GetNetworkLibrary()->ConnectToCellularNetwork(
network->cellular_network);
}
}
@@ -380,9 +381,9 @@ void NetworkSelectionView::ShowConnectingStatus(bool connecting,
void NetworkSelectionView::ChangeNetworkNotification(bool subscribe) {
network_notification_ = subscribe;
if (subscribe)
- chromeos::NetworkLibrary::Get()->AddObserver(this);
+ chromeos::CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this);
else
- chromeos::NetworkLibrary::Get()->RemoveObserver(this);
+ chromeos::CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this);
}
void NetworkSelectionView::UpdateConnectingNetworkLabel() {
diff --git a/chrome/browser/chromeos/login/utils.cc b/chrome/browser/chromeos/login/utils.cc
index d94252e..0421f2b 100644
--- a/chrome/browser/chromeos/login/utils.cc
+++ b/chrome/browser/chromeos/login/utils.cc
@@ -34,8 +34,8 @@ void CompleteLogin(const std::string& username,
std::vector<std::string> cookies) {
LOG(INFO) << "LoginManagerView: OnLoginSuccess()";
- if (CrosLibrary::EnsureLoaded())
- LoginLibrary::Get()->StartSession(username, "");
+ if (CrosLibrary::Get()->EnsureLoaded())
+ CrosLibrary::Get()->GetLoginLibrary()->StartSession(username, "");
UserManager::Get()->UserLoggedIn(username);
diff --git a/chrome/browser/chromeos/login/wizard_controller.cc b/chrome/browser/chromeos/login/wizard_controller.cc
index 6a00335..69ce58c 100644
--- a/chrome/browser/chromeos/login/wizard_controller.cc
+++ b/chrome/browser/chromeos/login/wizard_controller.cc
@@ -410,7 +410,8 @@ void ShowLoginWizard(const std::string& first_screen_name,
const gfx::Size& size) {
gfx::Rect screen_bounds(CalculateScreenBounds(size));
- if (first_screen_name.empty() && chromeos::CrosLibrary::EnsureLoaded() &&
+ if (first_screen_name.empty() &&
+ chromeos::CrosLibrary::Get()->EnsureLoaded() &&
CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableLoginImages)) {
std::vector<chromeos::UserManager::User> users =
@@ -426,8 +427,8 @@ void ShowLoginWizard(const std::string& first_screen_name,
controller->ShowBackground(screen_bounds);
controller->Init(first_screen_name, screen_bounds, true);
controller->Show();
- if (chromeos::CrosLibrary::EnsureLoaded())
- chromeos::LoginLibrary::Get()->EmitLoginPromptReady();
+ if (chromeos::CrosLibrary::Get()->EnsureLoaded())
+ chromeos::CrosLibrary::Get()->GetLoginLibrary()->EmitLoginPromptReady();
}
} // namespace browser
diff --git a/chrome/browser/chromeos/network_list.cc b/chrome/browser/chromeos/network_list.cc
index ea70674..9c2b90d 100644
--- a/chrome/browser/chromeos/network_list.cc
+++ b/chrome/browser/chromeos/network_list.cc
@@ -81,7 +81,7 @@ void NetworkList::NetworkChanged(chromeos::NetworkLibrary* network_lib) {
networks_.clear();
// Index of the last added network item.
int index = 0;
- if (!network_lib || !CrosLibrary::EnsureLoaded())
+ if (!network_lib || !CrosLibrary::Get()->EnsureLoaded())
return;
if (network_lib->ethernet_connected() || network_lib->ethernet_connecting()) {
diff --git a/chrome/browser/chromeos/options/internet_page_view.cc b/chrome/browser/chromeos/options/internet_page_view.cc
index 2b021ba..2912d3d 100644
--- a/chrome/browser/chromeos/options/internet_page_view.cc
+++ b/chrome/browser/chromeos/options/internet_page_view.cc
@@ -7,6 +7,7 @@
#include <string>
#include "app/combobox_model.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/network_library.h"
#include "chrome/browser/chromeos/options/network_config_view.h"
#include "chrome/browser/chromeos/status/network_menu_button.h"
@@ -52,7 +53,8 @@ class NetworkSection : public SettingsPageSection,
class WifiNetworkComboModel : public ComboboxModel {
public:
WifiNetworkComboModel() {
- wifi_networks_ = NetworkLibrary::Get()->wifi_networks();
+ wifi_networks_ =
+ CrosLibrary::Get()->GetNetworkLibrary()->wifi_networks();
}
virtual int GetItemCount() {
@@ -124,11 +126,11 @@ NetworkSection::NetworkSection(Profile* profile)
: SettingsPageSection(profile, IDS_OPTIONS_SETTINGS_SECTION_TITLE_NETWORK),
wifi_ssid_combobox_(NULL),
last_selected_wifi_ssid_index_(0) {
- NetworkLibrary::Get()->AddObserver(this);
+ CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this);
}
NetworkSection::~NetworkSection() {
- NetworkLibrary::Get()->RemoveObserver(this);
+ CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this);
}
void NetworkSection::ItemChanged(views::Combobox* sender,
@@ -161,8 +163,9 @@ void NetworkSection::ItemChanged(views::Combobox* sender,
window->Show();
view->SetLoginTextfieldFocus();
} else {
- NetworkLibrary::Get()->ConnectToWifiNetwork(activated_wifi_network_,
- string16());
+ CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork(
+ activated_wifi_network_,
+ string16());
}
}
@@ -170,7 +173,8 @@ void NetworkSection::ButtonPressed(views::Button* sender,
const views::Event& event) {
if (sender == ethernet_options_button_) {
NetworkConfigView* view =
- new NetworkConfigView(NetworkLibrary::Get()->ethernet_network());
+ new NetworkConfigView(
+ CrosLibrary::Get()->GetNetworkLibrary()->ethernet_network());
views::Window* window = views::Window::CreateChromeWindow(
NULL, gfx::Rect(), view);
window->SetIsAlwaysOnTop(true);
@@ -349,7 +353,7 @@ void NetworkSection::InitContents(GridLayout* layout) {
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
// Call NetworkChanged to set initial values.
- NetworkChanged(NetworkLibrary::Get());
+ NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary());
}
void NetworkSection::SelectWifi(const std::string& wifi_ssid) {
diff --git a/chrome/browser/chromeos/options/ip_config_view.cc b/chrome/browser/chromeos/options/ip_config_view.cc
index 29ac02b..9fb1520 100644
--- a/chrome/browser/chromeos/options/ip_config_view.cc
+++ b/chrome/browser/chromeos/options/ip_config_view.cc
@@ -6,6 +6,7 @@
#include "app/l10n_util.h"
#include "base/string_util.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
@@ -30,7 +31,7 @@ IPConfigView::IPConfigView(const std::string& device_path)
void IPConfigView::RefreshData() {
NetworkIPConfigVector ipconfigs =
- NetworkLibrary::Get()->GetIPConfigs(device_path_);
+ CrosLibrary::Get()->GetNetworkLibrary()->GetIPConfigs(device_path_);
for (NetworkIPConfigVector::const_iterator it = ipconfigs.begin();
it != ipconfigs.end(); ++it) {
const NetworkIPConfig& ipconfig = *it;
diff --git a/chrome/browser/chromeos/options/language_config_view.cc b/chrome/browser/chromeos/options/language_config_view.cc
index cd0e280..4c14ede 100644
--- a/chrome/browser/chromeos/options/language_config_view.cc
+++ b/chrome/browser/chromeos/options/language_config_view.cc
@@ -11,6 +11,7 @@
#include "app/l10n_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/language_library.h"
#include "chrome/browser/chromeos/options/language_hangul_config_view.h"
#include "chrome/browser/language_combobox_model.h"
@@ -88,7 +89,7 @@ class AddLanguageView : public views::View,
LanguageComboboxModel* CreateLanguageComboboxModel() {
// GetSupportedLanguages() never return NULL.
scoped_ptr<InputLanguageList> supported_language_list(
- LanguageLibrary::Get()->GetSupportedLanguages());
+ CrosLibrary::Get()->GetLanguageLibrary()->GetSupportedLanguages());
std::set<std::string> language_set;
for (size_t i = 0; i < supported_language_list->size(); ++i) {
@@ -209,7 +210,7 @@ views::View* LanguageConfigView::CreatePerLanguageConfigView(
// TODO(satorux): Implement ways to activate/deactivate individual input
// methods. For instance a language can have multiple input methods.
scoped_ptr<InputLanguageList> supported_language_list(
- LanguageLibrary::Get()->GetSupportedLanguages());
+ CrosLibrary::Get()->GetLanguageLibrary()->GetSupportedLanguages());
for (size_t i = 0; i < supported_language_list->size(); ++i) {
const InputLanguage& language = supported_language_list->at(i);
@@ -315,7 +316,7 @@ void LanguageConfigView::Init() {
void LanguageConfigView::InitPreferredLanguageCodes() {
scoped_ptr<InputLanguageList> active_language_list(
- LanguageLibrary::Get()->GetActiveLanguages());
+ CrosLibrary::Get()->GetLanguageLibrary()->GetActiveLanguages());
for (size_t i = 0; i < active_language_list->size(); ++i) {
const InputLanguage& language = active_language_list->at(i);
@@ -395,12 +396,12 @@ void LanguageConfigView::OnAddLanguage(const std::string& language_code) {
// Activate the first input language associated with the language.
scoped_ptr<InputLanguageList> supported_language_list(
- LanguageLibrary::Get()->GetSupportedLanguages());
+ CrosLibrary::Get()->GetLanguageLibrary()->GetSupportedLanguages());
for (size_t i = 0; i < supported_language_list->size(); ++i) {
const InputLanguage& language = supported_language_list->at(i);
if (language.language_code == language_code) {
- LanguageLibrary::Get()->ActivateLanguage(language.category,
- language.id);
+ CrosLibrary::Get()->GetLanguageLibrary()->ActivateLanguage(
+ language.category, language.id);
break;
}
}
@@ -410,17 +411,17 @@ void LanguageConfigView::OnAddLanguage(const std::string& language_code) {
void LanguageConfigView::DeactivateInputLanguagesFor(
const std::string& language_code) {
scoped_ptr<InputLanguageList> active_language_list(
- LanguageLibrary::Get()->GetActiveLanguages());
+ CrosLibrary::Get()->GetLanguageLibrary()->GetActiveLanguages());
for (size_t i = 0; i < active_language_list->size(); ++i) {
const InputLanguage& language = active_language_list->at(i);
if (language.language_code == language_code) {
- LanguageLibrary::Get()->DeactivateLanguage(language.category,
- language.id);
+ CrosLibrary::Get()->GetLanguageLibrary()->DeactivateLanguage(
+ language.category, language.id);
}
}
// Switch back to the US English.
- LanguageLibrary::Get()->ChangeLanguage(
+ CrosLibrary::Get()->GetLanguageLibrary()->ChangeLanguage(
chromeos::LANGUAGE_CATEGORY_XKB, "USA");
}
diff --git a/chrome/browser/chromeos/options/language_hangul_config_view.cc b/chrome/browser/chromeos/options/language_hangul_config_view.cc
index a4167c0..a97cb08 100644
--- a/chrome/browser/chromeos/options/language_hangul_config_view.cc
+++ b/chrome/browser/chromeos/options/language_hangul_config_view.cc
@@ -6,6 +6,7 @@
#include "app/combobox_model.h"
#include "app/l10n_util.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/language_library.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
@@ -76,10 +77,10 @@ class HangulKeyboardComboboxModel : public ComboboxModel {
DISALLOW_COPY_AND_ASSIGN(HangulKeyboardComboboxModel);
};
-LanguageHangulConfigView::LanguageHangulConfigView() :
- contents_(NULL),
- hangul_keyboard_combobox_(NULL),
- hangul_keyboard_combobox_model_(new HangulKeyboardComboboxModel) {
+LanguageHangulConfigView::LanguageHangulConfigView()
+ : contents_(NULL),
+ hangul_keyboard_combobox_(NULL),
+ hangul_keyboard_combobox_model_(new HangulKeyboardComboboxModel) {
}
LanguageHangulConfigView::~LanguageHangulConfigView() {
@@ -91,7 +92,7 @@ void LanguageHangulConfigView::ItemChanged(
config.type = ImeConfigValue::kValueTypeString;
config.string_value =
hangul_keyboard_combobox_model_->GetItemIDAt(new_index);
- LanguageLibrary::Get()->SetImeConfig(
+ CrosLibrary::Get()->GetLanguageLibrary()->SetImeConfig(
kHangulSection, kHangulKeyboardConfigName, config);
UpdateHangulKeyboardCombobox();
@@ -158,7 +159,7 @@ void LanguageHangulConfigView::Init() {
void LanguageHangulConfigView::UpdateHangulKeyboardCombobox() {
DCHECK(hangul_keyboard_combobox_);
ImeConfigValue config;
- if (LanguageLibrary::Get()->GetImeConfig(
+ if (CrosLibrary::Get()->GetLanguageLibrary()->GetImeConfig(
kHangulSection, kHangulKeyboardConfigName, &config)) {
const int index
= hangul_keyboard_combobox_model_->GetIndexFromID(config.string_value);
diff --git a/chrome/browser/chromeos/options/network_config_view.cc b/chrome/browser/chromeos/options/network_config_view.cc
index 783ea80..27dfd7d 100644
--- a/chrome/browser/chromeos/options/network_config_view.cc
+++ b/chrome/browser/chromeos/options/network_config_view.cc
@@ -6,6 +6,7 @@
#include "app/l10n_util.h"
#include "base/string_util.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/options/ip_config_view.h"
#include "chrome/browser/chromeos/options/wifi_config_view.h"
#include "grit/chromium_strings.h"
@@ -74,10 +75,10 @@ bool NetworkConfigView::Cancel() {
bool NetworkConfigView::Accept() {
if (flags_ & FLAG_LOGIN_ONLY) {
if (flags_ & FLAG_OTHER_NETWORK) {
- NetworkLibrary::Get()->ConnectToWifiNetwork(wificonfig_view_->GetSSID(),
- wificonfig_view_->GetPassphrase());
+ CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork(
+ wificonfig_view_->GetSSID(), wificonfig_view_->GetPassphrase());
} else {
- NetworkLibrary::Get()->ConnectToWifiNetwork(wifi_,
+ CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork(wifi_,
wificonfig_view_->GetPassphrase());
}
} else {
diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc
index 6bb2a70..61b414c 100644
--- a/chrome/browser/chromeos/preferences.cc
+++ b/chrome/browser/chromeos/preferences.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/preferences.h"
#include "base/string_util.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/synaptics_library.h"
#include "chrome/browser/pref_member.h"
#include "chrome/browser/pref_service.h"
@@ -45,18 +46,21 @@ void Preferences::NotifyPrefChanged(const std::wstring* pref_name) {
if (!pref_name || *pref_name == prefs::kTimeZone)
SetTimeZone(timezone_.GetValue());
if (!pref_name || *pref_name == prefs::kTapToClickEnabled)
- SynapticsLibrary::Get()->SetBoolParameter(PARAM_BOOL_TAP_TO_CLICK,
+ CrosLibrary::Get()->GetSynapticsLibrary()->SetBoolParameter(
+ PARAM_BOOL_TAP_TO_CLICK,
tap_to_click_enabled_.GetValue());
if (!pref_name || *pref_name == prefs::kVertEdgeScrollEnabled)
- SynapticsLibrary::Get()->SetBoolParameter(
+ CrosLibrary::Get()->GetSynapticsLibrary()->SetBoolParameter(
PARAM_BOOL_VERTICAL_EDGE_SCROLLING,
vert_edge_scroll_enabled_.GetValue());
if (!pref_name || *pref_name == prefs::kTouchpadSpeedFactor)
- SynapticsLibrary::Get()->SetRangeParameter(PARAM_RANGE_SPEED_SENSITIVITY,
- speed_factor_.GetValue());
+ CrosLibrary::Get()->GetSynapticsLibrary()->SetRangeParameter(
+ PARAM_RANGE_SPEED_SENSITIVITY,
+ speed_factor_.GetValue());
if (!pref_name || *pref_name == prefs::kTouchpadSensitivity)
- SynapticsLibrary::Get()->SetRangeParameter(PARAM_RANGE_TOUCH_SENSITIVITY,
- sensitivity_.GetValue());
+ CrosLibrary::Get()->GetSynapticsLibrary()->SetRangeParameter(
+ PARAM_RANGE_TOUCH_SENSITIVITY,
+ sensitivity_.GetValue());
}
void Preferences::SetTimeZone(const std::wstring& id) {
diff --git a/chrome/browser/chromeos/status/language_menu_button.cc b/chrome/browser/chromeos/status/language_menu_button.cc
index 2541bdd..b7d70f1 100644
--- a/chrome/browser/chromeos/status/language_menu_button.cc
+++ b/chrome/browser/chromeos/status/language_menu_button.cc
@@ -11,6 +11,7 @@
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/status/language_menu_l10n_util.h"
#include "chrome/browser/chromeos/status/status_area_host.h"
#include "grit/generated_resources.h"
@@ -123,7 +124,8 @@ namespace chromeos {
LanguageMenuButton::LanguageMenuButton(StatusAreaHost* host)
: MenuButton(NULL, std::wstring(), this, false),
- language_list_(LanguageLibrary::Get()->GetActiveLanguages()),
+ language_list_(CrosLibrary::Get()->GetLanguageLibrary()->
+ GetActiveLanguages()),
model_(NULL),
// Be aware that the constructor of |language_menu_| calls GetItemCount()
// in this class. Therefore, GetItemCount() have to return 0 when
@@ -138,11 +140,11 @@ LanguageMenuButton::LanguageMenuButton(StatusAreaHost* host)
// Display the default XKB name (usually "US").
const std::wstring name = FormatInputLanguage(language_list_->at(0), false);
UpdateIcon(name);
- LanguageLibrary::Get()->AddObserver(this);
+ CrosLibrary::Get()->GetLanguageLibrary()->AddObserver(this);
}
LanguageMenuButton::~LanguageMenuButton() {
- LanguageLibrary::Get()->RemoveObserver(this);
+ CrosLibrary::Get()->GetLanguageLibrary()->RemoveObserver(this);
}
////////////////////////////////////////////////////////////////////////////////
@@ -169,12 +171,13 @@ bool LanguageMenuButton::IsItemCheckedAt(int index) const {
if (IndexIsInLanguageList(index)) {
const InputLanguage& language = language_list_->at(index);
- return language == LanguageLibrary::Get()->current_language();
+ return language == CrosLibrary::Get()->GetLanguageLibrary()->
+ current_language();
}
if (GetPropertyIndex(index, &index)) {
const ImePropertyList& property_list
- = LanguageLibrary::Get()->current_ime_properties();
+ = CrosLibrary::Get()->GetLanguageLibrary()->current_ime_properties();
return property_list.at(index).is_selection_item_checked;
}
@@ -191,7 +194,7 @@ int LanguageMenuButton::GetGroupIdAt(int index) const {
if (GetPropertyIndex(index, &index)) {
const ImePropertyList& property_list
- = LanguageLibrary::Get()->current_ime_properties();
+ = CrosLibrary::Get()->GetLanguageLibrary()->current_ime_properties();
return property_list.at(index).selection_item_id;
}
@@ -248,7 +251,7 @@ menus::MenuModel::ItemType LanguageMenuButton::GetTypeAt(int index) const {
if (GetPropertyIndex(index, &index)) {
const ImePropertyList& property_list
- = LanguageLibrary::Get()->current_ime_properties();
+ = CrosLibrary::Get()->GetLanguageLibrary()->current_ime_properties();
if (property_list.at(index).is_selection_item) {
return menus::MenuModel::TYPE_RADIO;
}
@@ -271,7 +274,7 @@ string16 LanguageMenuButton::GetLabelAt(int index) const {
name = FormatInputLanguage(language_list_->at(index), true);
} else if (GetPropertyIndex(index, &index)) {
const ImePropertyList& property_list
- = LanguageLibrary::Get()->current_ime_properties();
+ = CrosLibrary::Get()->GetLanguageLibrary()->current_ime_properties();
return LanguageMenuL10nUtil::GetStringUTF16(
property_list.at(index).label);
}
@@ -291,14 +294,15 @@ void LanguageMenuButton::ActivatedAt(int index) {
if (IndexIsInLanguageList(index)) {
// Inter-IME switching or IME-XKB switching.
const InputLanguage& language = language_list_->at(index);
- LanguageLibrary::Get()->ChangeLanguage(language.category, language.id);
+ CrosLibrary::Get()->GetLanguageLibrary()->ChangeLanguage(language.category,
+ language.id);
return;
}
if (GetPropertyIndex(index, &index)) {
// Intra-IME switching (e.g. Japanese-Hiragana to Japanese-Katakana).
const ImePropertyList& property_list
- = LanguageLibrary::Get()->current_ime_properties();
+ = CrosLibrary::Get()->GetLanguageLibrary()->current_ime_properties();
const std::string key = property_list.at(index).key;
if (property_list.at(index).is_selection_item) {
// Radio button is clicked.
@@ -306,16 +310,16 @@ void LanguageMenuButton::ActivatedAt(int index) {
// First, deactivate all other properties in the same radio group.
for (int i = 0; i < static_cast<int>(property_list.size()); ++i) {
if (i != index && id == property_list.at(i).selection_item_id) {
- LanguageLibrary::Get()->DeactivateImeProperty(
+ CrosLibrary::Get()->GetLanguageLibrary()->DeactivateImeProperty(
property_list.at(i).key);
}
}
// Then, activate the property clicked.
- LanguageLibrary::Get()->ActivateImeProperty(key);
+ CrosLibrary::Get()->GetLanguageLibrary()->ActivateImeProperty(key);
} else {
// Command button like "Switch to half punctuation mode" is clicked.
// We can always use "Deactivate" for command buttons.
- LanguageLibrary::Get()->DeactivateImeProperty(key);
+ CrosLibrary::Get()->GetLanguageLibrary()->DeactivateImeProperty(key);
}
return;
}
@@ -328,7 +332,8 @@ void LanguageMenuButton::ActivatedAt(int index) {
// LanguageMenuButton, views::ViewMenuDelegate implementation:
void LanguageMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
- language_list_.reset(LanguageLibrary::Get()->GetActiveLanguages());
+ language_list_.reset(CrosLibrary::Get()->GetLanguageLibrary()->
+ GetActiveLanguages());
RebuildModel();
language_menu_.Rebuild();
language_menu_.UpdateStates();
@@ -379,9 +384,9 @@ void LanguageMenuButton::RebuildModel() {
}
const ImePropertyList& property_list
- = LanguageLibrary::Get()->current_ime_properties();
+ = CrosLibrary::Get()->GetLanguageLibrary()->current_ime_properties();
const InputLanguage& current_language
- = LanguageLibrary::Get()->current_language();
+ = CrosLibrary::Get()->GetLanguageLibrary()->current_language();
if ((!property_list.empty()) &&
(current_language.category == chromeos::LANGUAGE_CATEGORY_IME)) {
if (need_separator)
diff --git a/chrome/browser/chromeos/status/network_menu_button.cc b/chrome/browser/chromeos/status/network_menu_button.cc
index 3d487fb..e7f10e7 100644
--- a/chrome/browser/chromeos/status/network_menu_button.cc
+++ b/chrome/browser/chromeos/status/network_menu_button.cc
@@ -9,8 +9,8 @@
#include "app/l10n_util.h"
#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/options/network_config_view.h"
#include "chrome/browser/chromeos/status/status_area_host.h"
#include "gfx/canvas.h"
#include "gfx/skbitmap_operations.h"
@@ -35,12 +35,12 @@ NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host)
ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)) {
animation_connecting_.SetThrobDuration(kThrobDuration);
animation_connecting_.SetTweenType(SlideAnimation::NONE);
- NetworkChanged(NetworkLibrary::Get());
- NetworkLibrary::Get()->AddObserver(this);
+ NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary());
+ CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this);
}
NetworkMenuButton::~NetworkMenuButton() {
- NetworkLibrary::Get()->RemoveObserver(this);
+ CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this);
}
////////////////////////////////////////////////////////////////////////////////
@@ -86,7 +86,7 @@ void NetworkMenuButton::ActivatedAt(int index) {
if (refreshing_menu_)
return;
- NetworkLibrary* cros = NetworkLibrary::Get();
+ NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
int flags = menu_items_[index].flags;
if (flags & FLAG_OPTIONS) {
host_->OpenButtonOptions(this);
@@ -184,7 +184,7 @@ void NetworkMenuButton::AnimationProgressed(const Animation* animation) {
void NetworkMenuButton::DrawPressed(gfx::Canvas* canvas) {
// If ethernet connected and not current connecting, then show ethernet
// pressed icon. Otherwise, show the bars pressed icon.
- if (NetworkLibrary::Get()->ethernet_connected() &&
+ if (CrosLibrary::Get()->GetNetworkLibrary()->ethernet_connected() &&
!animation_connecting_.IsAnimating())
canvas->DrawBitmapInt(IconForDisplay(
*ResourceBundle::GetSharedInstance().
@@ -212,7 +212,7 @@ void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) {
canvas->DrawBitmapInt(icon(), 0, 0);
// If wifi, we draw the wifi signal bars.
- NetworkLibrary* cros = NetworkLibrary::Get();
+ NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
if (cros->wifi_connecting() ||
(!cros->ethernet_connected() && cros->wifi_connected())) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
@@ -296,7 +296,7 @@ void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) {
void NetworkMenuButton::NetworkChanged(NetworkLibrary* cros) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- if (CrosLibrary::EnsureLoaded()) {
+ if (CrosLibrary::Get()->EnsureLoaded()) {
if (cros->wifi_connecting() || cros->cellular_connecting()) {
// Start the connecting animation if not running.
if (!animation_connecting_.IsAnimating()) {
@@ -395,7 +395,7 @@ SkBitmap NetworkMenuButton::IconForDisplay(SkBitmap icon, SkBitmap badge) {
void NetworkMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
refreshing_menu_ = true;
- NetworkLibrary::Get()->RequestWifiScan();
+ CrosLibrary::Get()->GetNetworkLibrary()->RequestWifiScan();
InitMenuItems();
network_menu_.Rebuild();
network_menu_.UpdateStates();
@@ -406,7 +406,7 @@ void NetworkMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
void NetworkMenuButton::InitMenuItems() {
menu_items_.clear();
// Populate our MenuItems with the current list of wifi networks.
- NetworkLibrary* cros = NetworkLibrary::Get();
+ NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
// Ethernet
diff --git a/chrome/browser/chromeos/status/power_menu_button.cc b/chrome/browser/chromeos/status/power_menu_button.cc
index 2a4c221..26f43c1 100644
--- a/chrome/browser/chromeos/status/power_menu_button.cc
+++ b/chrome/browser/chromeos/status/power_menu_button.cc
@@ -24,11 +24,11 @@ PowerMenuButton::PowerMenuButton()
: StatusAreaButton(this),
ALLOW_THIS_IN_INITIALIZER_LIST(power_menu_(this)) {
UpdateIcon();
- PowerLibrary::Get()->AddObserver(this);
+ CrosLibrary::Get()->GetPowerLibrary()->AddObserver(this);
}
PowerMenuButton::~PowerMenuButton() {
- PowerLibrary::Get()->RemoveObserver(this);
+ CrosLibrary::Get()->GetPowerLibrary()->RemoveObserver(this);
}
////////////////////////////////////////////////////////////////////////////////
@@ -43,7 +43,7 @@ menus::MenuModel::ItemType PowerMenuButton::GetTypeAt(int index) const {
}
string16 PowerMenuButton::GetLabelAt(int index) const {
- PowerLibrary* cros = PowerLibrary::Get();
+ PowerLibrary* cros = CrosLibrary::Get()->GetPowerLibrary();
// The first item shows the percentage of battery left.
if (index == 0) {
// If fully charged, always show 100% even if internal number is a bit less.
@@ -122,9 +122,9 @@ void PowerMenuButton::DrawPowerIcon(gfx::Canvas* canvas, SkBitmap icon) {
}
void PowerMenuButton::UpdateIcon() {
- PowerLibrary* cros = PowerLibrary::Get();
+ PowerLibrary* cros = CrosLibrary::Get()->GetPowerLibrary();
int id = IDR_STATUSBAR_BATTERY_UNKNOWN;
- if (CrosLibrary::EnsureLoaded()) {
+ if (CrosLibrary::Get()->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/text_input/candidate_window.cc b/chrome/browser/chromeos/text_input/candidate_window.cc
index f075207..b86d2b9 100644
--- a/chrome/browser/chromeos/text_input/candidate_window.cc
+++ b/chrome/browser/chromeos/text_input/candidate_window.cc
@@ -19,7 +19,7 @@
#include "base/process_util.h"
#include "base/scoped_ptr.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/browser/chromeos/cros/cros_library_loader.h"
#include "chrome/common/chrome_paths.h"
#include "gfx/canvas.h"
#include "gfx/font.h"
@@ -948,8 +948,10 @@ int main(int argc, char** argv) {
// Load libcros.
chrome::RegisterPathProvider(); // for libcros.so.
- CHECK(chromeos::CrosLibrary::EnsureLoaded())
- << "Failed to load libcros";
+ chromeos::CrosLibraryLoader lib_loader;
+ std::string error_string;
+ CHECK(lib_loader.Load(&error_string))
+ << "Failed to load libcros, " << error_string;
// Create the main message loop.
MessageLoop main_message_loop(MessageLoop::TYPE_UI);
diff --git a/chrome/browser/chromeos/text_input/text_input.gyp b/chrome/browser/chromeos/text_input/text_input.gyp
index ee2ab4d..cecd9d7 100644
--- a/chrome/browser/chromeos/text_input/text_input.gyp
+++ b/chrome/browser/chromeos/text_input/text_input.gyp
@@ -22,7 +22,7 @@
'sources': [
'candidate_window.cc',
# For loading libcros.
- '../cros/cros_library.cc',
+ '../cros/cros_library_loader.cc',
],
},
],
diff --git a/chrome/browser/dom_ui/filebrowse_ui.cc b/chrome/browser/dom_ui/filebrowse_ui.cc
index 100124e..c1e69c7 100644
--- a/chrome/browser/dom_ui/filebrowse_ui.cc
+++ b/chrome/browser/dom_ui/filebrowse_ui.cc
@@ -43,6 +43,7 @@
#include "grit/locale_settings.h"
#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/mount_library.h"
#endif
@@ -307,14 +308,16 @@ FilebrowseHandler::FilebrowseHandler()
download_manager_(NULL) {
lister_ = NULL;
#if defined(OS_CHROMEOS)
- chromeos::MountLibrary* lib = chromeos::MountLibrary::Get();
+ chromeos::MountLibrary* lib =
+ chromeos::CrosLibrary::Get()->GetMountLibrary();
lib->AddObserver(this);
#endif
}
FilebrowseHandler::~FilebrowseHandler() {
#if defined(OS_CHROMEOS)
- chromeos::MountLibrary* lib = chromeos::MountLibrary::Get();
+ chromeos::MountLibrary* lib =
+ chromeos::CrosLibrary::Get()->GetMountLibrary();
lib->RemoveObserver(this);
#endif
if (lister_.get()) {
@@ -437,7 +440,8 @@ void FilebrowseHandler::HandleGetRoots(const Value* value) {
DictionaryValue info_value;
// TODO(dhg): add other entries, make this more general
#if defined(OS_CHROMEOS)
- chromeos::MountLibrary* lib = chromeos::MountLibrary::Get();
+ chromeos::MountLibrary* lib =
+ chromeos::CrosLibrary::Get()->GetMountLibrary();
const chromeos::MountLibrary::DiskVector& disks = lib->disks();
for (size_t i = 0; i < disks.size(); ++i) {
diff --git a/chrome/browser/profile_manager.cc b/chrome/browser/profile_manager.cc
index 6699c7a..38283891 100644
--- a/chrome/browser/profile_manager.cc
+++ b/chrome/browser/profile_manager.cc
@@ -227,12 +227,12 @@ void ProfileManager::Observe(
const NotificationDetails& details) {
#if defined(OS_CHROMEOS)
if (type == NotificationType::LOGIN_USER_CHANGED) {
- CHECK(chromeos::CrosLibrary::EnsureLoaded());
+ CHECK(chromeos::CrosLibrary::Get()->EnsureLoaded());
// If we don't have a mounted profile directory we're in trouble.
// TODO(davemoore) Once we have better api this check should ensure that
// our profile directory is the one that's mounted, and that it's mounted
// as the current user.
- CHECK(chromeos::CryptohomeLibrary::Get()->IsMounted());
+ CHECK(chromeos::CrosLibrary::Get()->GetCryptohomeLibrary()->IsMounted());
logged_in_ = true;
}
#endif
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index ec32bc3..935162d 100755
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -324,6 +324,8 @@
'browser/chromeos/compact_navigation_bar.h',
'browser/chromeos/cros/cros_library.cc',
'browser/chromeos/cros/cros_library.h',
+ 'browser/chromeos/cros/cros_library_loader.cc',
+ 'browser/chromeos/cros/cros_library_loader.h',
'browser/chromeos/cros/cryptohome_library.cc',
'browser/chromeos/cros/cryptohome_library.h',
'browser/chromeos/cros/language_library.cc',