| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ | 6 #define CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/singleton.h" | 11 #include "base/singleton.h" |
| 12 | |
| 13 namespace chromeos { | 12 namespace chromeos { |
| 14 | 13 |
| 15 class CryptohomeLibrary; | 14 class CryptohomeLibrary; |
| 16 class KeyboardLibrary; | 15 class KeyboardLibrary; |
| 17 class InputMethodLibrary; | 16 class InputMethodLibrary; |
| 18 class LibraryLoader; | 17 class LibraryLoader; |
| 19 class LoginLibrary; | 18 class LoginLibrary; |
| 20 class MountLibrary; | 19 class MountLibrary; |
| 21 class NetworkLibrary; | 20 class NetworkLibrary; |
| 22 class PowerLibrary; | 21 class PowerLibrary; |
| 23 class ScreenLockLibrary; | 22 class ScreenLockLibrary; |
| 24 class SpeechSynthesisLibrary; | 23 class SpeechSynthesisLibrary; |
| 25 class SynapticsLibrary; | 24 class SynapticsLibrary; |
| 26 class SyslogsLibrary; | 25 class SyslogsLibrary; |
| 27 class SystemLibrary; | 26 class SystemLibrary; |
| 28 class UpdateLibrary; | 27 class UpdateLibrary; |
| 29 | 28 |
| 30 // This class handles access to sub-parts of ChromeOS library. it provides | 29 // This class handles access to sub-parts of ChromeOS library. it provides |
| 31 // a level of indirection so individual libraries that it exposes can | 30 // a level of indirection so individual libraries that it exposes can |
| 32 // be mocked for testing. | 31 // be mocked for testing. |
| 33 class CrosLibrary { | 32 class CrosLibrary { |
| 34 public: | 33 public: |
| 35 | |
| 36 // This class provides access to internal members of CrosLibrary class for | 34 // This class provides access to internal members of CrosLibrary class for |
| 37 // purpose of testing (i.e. replacement of members' implementation with | 35 // purpose of testing (i.e. replacement of members' implementation with |
| 38 // mock objects). | 36 // mock objects). |
| 39 class TestApi { | 37 class TestApi { |
| 40 public: | 38 public: |
| 39 // Use the stub implementations of the library. This is mainly for |
| 40 // running the chromeos build of chrome on the desktop. |
| 41 void SetUseStubImpl(); |
| 41 // Passing true for own for these setters will cause them to be deleted | 42 // Passing true for own for these setters will cause them to be deleted |
| 42 // when the CrosLibrary is deleted (or other mocks are set). | 43 // when the CrosLibrary is deleted (or other mocks are set). |
| 43 // Setter for LibraryLoader. | 44 // Setter for LibraryLoader. |
| 44 void SetLibraryLoader(LibraryLoader* loader, bool own); | 45 void SetLibraryLoader(LibraryLoader* loader, bool own); |
| 45 // Setter for CryptohomeLibrary. | 46 // Setter for CryptohomeLibrary. |
| 46 void SetCryptohomeLibrary(CryptohomeLibrary* library, bool own); | 47 void SetCryptohomeLibrary(CryptohomeLibrary* library, bool own); |
| 47 // Setter for KeyboardLibrary | 48 // Setter for KeyboardLibrary |
| 48 void SetKeyboardLibrary(KeyboardLibrary* library, bool own); | 49 void SetKeyboardLibrary(KeyboardLibrary* library, bool own); |
| 49 // Setter for InputMethodLibrary | 50 // Setter for InputMethodLibrary |
| 50 void SetInputMethodLibrary(InputMethodLibrary* library, bool own); | 51 void SetInputMethodLibrary(InputMethodLibrary* library, bool own); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } | 131 } |
| 131 | 132 |
| 132 private: | 133 private: |
| 133 friend struct DefaultSingletonTraits<chromeos::CrosLibrary>; | 134 friend struct DefaultSingletonTraits<chromeos::CrosLibrary>; |
| 134 friend class CrosLibrary::TestApi; | 135 friend class CrosLibrary::TestApi; |
| 135 | 136 |
| 136 CrosLibrary(); | 137 CrosLibrary(); |
| 137 virtual ~CrosLibrary(); | 138 virtual ~CrosLibrary(); |
| 138 | 139 |
| 139 LibraryLoader* library_loader_; | 140 LibraryLoader* library_loader_; |
| 140 CryptohomeLibrary* crypto_lib_; | 141 bool own_library_loader_; |
| 141 KeyboardLibrary* keyboard_lib_; | |
| 142 InputMethodLibrary* input_method_lib_; | |
| 143 LoginLibrary* login_lib_; | |
| 144 MountLibrary* mount_lib_; | |
| 145 NetworkLibrary* network_lib_; | |
| 146 PowerLibrary* power_lib_; | |
| 147 ScreenLockLibrary* screen_lock_lib_; | |
| 148 SpeechSynthesisLibrary* speech_synthesis_lib_; | |
| 149 SynapticsLibrary* synaptics_lib_; | |
| 150 SyslogsLibrary* syslogs_lib_; | |
| 151 SystemLibrary* system_lib_; | |
| 152 UpdateLibrary* update_lib_; | |
| 153 | 142 |
| 154 bool own_library_loader_; | 143 // This template supports the creation, setting and optional deletion of |
| 155 bool own_cryptohome_lib_; | 144 // the cros libraries. |
| 156 bool own_keyboard_lib_; | 145 template <class L> |
| 157 bool own_input_method_lib_; | 146 class Library { |
| 158 bool own_login_lib_; | 147 public: |
| 159 bool own_mount_lib_; | 148 Library() : library_(NULL), own_(true) {} |
| 160 bool own_network_lib_; | |
| 161 bool own_power_lib_; | |
| 162 bool own_screen_lock_lib_; | |
| 163 bool own_speech_synthesis_lib_; | |
| 164 bool own_synaptics_lib_; | |
| 165 bool own_syslogs_lib_; | |
| 166 bool own_system_lib_; | |
| 167 bool own_update_lib_; | |
| 168 | 149 |
| 150 ~Library() { |
| 151 if (own_) |
| 152 delete library_; |
| 153 } |
| 154 |
| 155 L* GetDefaultImpl(bool use_stub_impl) { |
| 156 if (!library_) { |
| 157 own_ = true; |
| 158 library_ = L::GetImpl(use_stub_impl); |
| 159 } |
| 160 return library_; |
| 161 } |
| 162 |
| 163 void SetImpl(L* library, bool own) { |
| 164 if (library != library_) { |
| 165 if (own_) |
| 166 delete library_; |
| 167 library_ = library; |
| 168 own_ = own; |
| 169 } |
| 170 } |
| 171 |
| 172 private: |
| 173 L* library_; |
| 174 bool own_; |
| 175 }; |
| 176 |
| 177 Library<CryptohomeLibrary> crypto_lib_; |
| 178 Library<KeyboardLibrary> keyboard_lib_; |
| 179 Library<InputMethodLibrary> input_method_lib_; |
| 180 Library<LoginLibrary> login_lib_; |
| 181 Library<MountLibrary> mount_lib_; |
| 182 Library<NetworkLibrary> network_lib_; |
| 183 Library<PowerLibrary> power_lib_; |
| 184 Library<ScreenLockLibrary> screen_lock_lib_; |
| 185 Library<SpeechSynthesisLibrary> speech_synthesis_lib_; |
| 186 Library<SynapticsLibrary> synaptics_lib_; |
| 187 Library<SyslogsLibrary> syslogs_lib_; |
| 188 Library<SystemLibrary> system_lib_; |
| 189 Library<UpdateLibrary> update_lib_; |
| 190 |
| 191 // Stub implementations of the libraries should be used. |
| 192 bool use_stub_impl_; |
| 169 // True if libcros was successfully loaded. | 193 // True if libcros was successfully loaded. |
| 170 bool loaded_; | 194 bool loaded_; |
| 171 // True if the last load attempt had an error. | 195 // True if the last load attempt had an error. |
| 172 bool load_error_; | 196 bool load_error_; |
| 173 // Contains the error string from the last load attempt. | 197 // Contains the error string from the last load attempt. |
| 174 std::string load_error_string_; | 198 std::string load_error_string_; |
| 175 TestApi* test_api_; | 199 TestApi* test_api_; |
| 176 | 200 |
| 177 DISALLOW_COPY_AND_ASSIGN(CrosLibrary); | 201 DISALLOW_COPY_AND_ASSIGN(CrosLibrary); |
| 178 }; | 202 }; |
| 179 | 203 |
| 180 } // namespace chromeos | 204 } // namespace chromeos |
| 181 | 205 |
| 182 #endif // CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ | 206 #endif // CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ |
| OLD | NEW |