summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/cros
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/chromeos/cros')
-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
27 files changed, 993 insertions, 336 deletions
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