| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/singleton.h" | 10 #include "base/singleton.h" |
| 11 | 11 |
| 12 namespace chromeos { | 12 namespace chromeos { |
| 13 | 13 |
| 14 class CryptohomeLibrary; | 14 class CryptohomeLibrary; |
| 15 class LanguageLibrary; | 15 class LanguageLibrary; |
| 16 class LibraryLoader; | 16 class LibraryLoader; |
| 17 class LoginLibrary; | 17 class LoginLibrary; |
| 18 class MountLibrary; | 18 class MountLibrary; |
| 19 class NetworkLibrary; | 19 class NetworkLibrary; |
| 20 class PowerLibrary; | 20 class PowerLibrary; |
| 21 class SpeechSynthesisLibrary; |
| 21 class SynapticsLibrary; | 22 class SynapticsLibrary; |
| 22 | 23 |
| 23 // This class handles access to sub-parts of ChromeOS library. it provides | 24 // This class handles access to sub-parts of ChromeOS library. it provides |
| 24 // a level of indirection so individual libraries that it exposes can | 25 // a level of indirection so individual libraries that it exposes can |
| 25 // be mocked for testing. | 26 // be mocked for testing. |
| 26 class CrosLibrary { | 27 class CrosLibrary { |
| 27 public: | 28 public: |
| 28 | 29 |
| 29 // This class provides access to internal members of CrosLibrary class for | 30 // This class provides access to internal members of CrosLibrary class for |
| 30 // purpose of testing (i.e. replacement of members' implementation with | 31 // purpose of testing (i.e. replacement of members' implementation with |
| 31 // mock objects). | 32 // mock objects). |
| 32 class TestApi { | 33 class TestApi { |
| 33 public: | 34 public: |
| 34 // Passing true for own for these setters will cause them to be deleted | 35 // Passing true for own for these setters will cause them to be deleted |
| 35 // when the CrosLibrary is deleted (or other mocks are set). | 36 // when the CrosLibrary is deleted (or other mocks are set). |
| 36 // Setter for LibraryLoader. | 37 // Setter for LibraryLoader. |
| 37 void SetLibraryLoader(LibraryLoader* loader, bool own); | 38 void SetLibraryLoader(LibraryLoader* loader, bool own); |
| 38 // Setter for CryptohomeLibrary. | 39 // Setter for CryptohomeLibrary. |
| 39 void SetCryptohomeLibrary(CryptohomeLibrary* library, bool own); | 40 void SetCryptohomeLibrary(CryptohomeLibrary* library, bool own); |
| 40 // Setter for LanguageLibrary | 41 // Setter for LanguageLibrary |
| 41 void SetLanguageLibrary(LanguageLibrary* library, bool own); | 42 void SetLanguageLibrary(LanguageLibrary* library, bool own); |
| 42 // Setter for LoginLibrary. | 43 // Setter for LoginLibrary. |
| 43 void SetLoginLibrary(LoginLibrary* library, bool own); | 44 void SetLoginLibrary(LoginLibrary* library, bool own); |
| 44 // Setter for MountLibrary. | 45 // Setter for MountLibrary. |
| 45 void SetMountLibrary(MountLibrary* library, bool own); | 46 void SetMountLibrary(MountLibrary* library, bool own); |
| 46 // Setter for NetworkLibrary. | 47 // Setter for NetworkLibrary. |
| 47 void SetNetworkLibrary(NetworkLibrary* library, bool own); | 48 void SetNetworkLibrary(NetworkLibrary* library, bool own); |
| 48 // Setter for PowerLibrary. | 49 // Setter for PowerLibrary. |
| 49 void SetPowerLibrary(PowerLibrary* library, bool own); | 50 void SetPowerLibrary(PowerLibrary* library, bool own); |
| 51 // Setter for SpeechSynthesisLibrary. |
| 52 void SetSpeechSynthesisLibrary(SpeechSynthesisLibrary* library, bool own); |
| 50 // Setter for SynapticsLibrary. | 53 // Setter for SynapticsLibrary. |
| 51 void SetSynapticsLibrary(SynapticsLibrary* library, bool own); | 54 void SetSynapticsLibrary(SynapticsLibrary* library, bool own); |
| 52 | 55 |
| 53 private: | 56 private: |
| 54 friend class CrosLibrary; | 57 friend class CrosLibrary; |
| 55 explicit TestApi(CrosLibrary* library) : library_(library) {} | 58 explicit TestApi(CrosLibrary* library) : library_(library) {} |
| 56 CrosLibrary* library_; | 59 CrosLibrary* library_; |
| 57 }; | 60 }; |
| 58 | 61 |
| 59 // This gets the CrosLibrary. | 62 // This gets the CrosLibrary. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 70 | 73 |
| 71 // Getter for MountLibrary | 74 // Getter for MountLibrary |
| 72 MountLibrary* GetMountLibrary(); | 75 MountLibrary* GetMountLibrary(); |
| 73 | 76 |
| 74 // Getter for NetworkLibrary | 77 // Getter for NetworkLibrary |
| 75 NetworkLibrary* GetNetworkLibrary(); | 78 NetworkLibrary* GetNetworkLibrary(); |
| 76 | 79 |
| 77 // Getter for PowerLibrary | 80 // Getter for PowerLibrary |
| 78 PowerLibrary* GetPowerLibrary(); | 81 PowerLibrary* GetPowerLibrary(); |
| 79 | 82 |
| 83 // This gets the singleton SpeechSynthesisLibrary. |
| 84 SpeechSynthesisLibrary* GetSpeechSynthesisLibrary(); |
| 85 |
| 80 // This gets the singleton SynapticsLibrary. | 86 // This gets the singleton SynapticsLibrary. |
| 81 SynapticsLibrary* GetSynapticsLibrary(); | 87 SynapticsLibrary* GetSynapticsLibrary(); |
| 82 | 88 |
| 83 // Getter for Test API that gives access to internal members of this class. | 89 // Getter for Test API that gives access to internal members of this class. |
| 84 TestApi* GetTestApi(); | 90 TestApi* GetTestApi(); |
| 85 | 91 |
| 86 // Ensures that the library is loaded, loading it if needed. If the library | 92 // Ensures that the library is loaded, loading it if needed. If the library |
| 87 // could not be loaded, returns false. | 93 // could not be loaded, returns false. |
| 88 bool EnsureLoaded(); | 94 bool EnsureLoaded(); |
| 89 | 95 |
| 90 // Returns an unlocalized string describing the last load error (if any). | 96 // Returns an unlocalized string describing the last load error (if any). |
| 91 const std::string& load_error_string() { | 97 const std::string& load_error_string() { |
| 92 return load_error_string_; | 98 return load_error_string_; |
| 93 } | 99 } |
| 94 | 100 |
| 95 private: | 101 private: |
| 96 friend struct DefaultSingletonTraits<chromeos::CrosLibrary>; | 102 friend struct DefaultSingletonTraits<chromeos::CrosLibrary>; |
| 97 friend class CrosLibrary::TestApi; | 103 friend class CrosLibrary::TestApi; |
| 98 | 104 |
| 99 CrosLibrary(); | 105 CrosLibrary(); |
| 100 virtual ~CrosLibrary(); | 106 virtual ~CrosLibrary(); |
| 101 | 107 |
| 102 LibraryLoader* library_loader_; | 108 LibraryLoader* library_loader_; |
| 103 CryptohomeLibrary* crypto_lib_; | 109 CryptohomeLibrary* crypto_lib_; |
| 104 LanguageLibrary* language_lib_; | 110 LanguageLibrary* language_lib_; |
| 105 LoginLibrary* login_lib_; | 111 LoginLibrary* login_lib_; |
| 106 MountLibrary* mount_lib_; | 112 MountLibrary* mount_lib_; |
| 107 NetworkLibrary* network_lib_; | 113 NetworkLibrary* network_lib_; |
| 108 PowerLibrary* power_lib_; | 114 PowerLibrary* power_lib_; |
| 115 SpeechSynthesisLibrary* speech_synthesis_lib_; |
| 109 SynapticsLibrary* synaptics_lib_; | 116 SynapticsLibrary* synaptics_lib_; |
| 110 | 117 |
| 111 bool own_library_loader_; | 118 bool own_library_loader_; |
| 112 bool own_cryptohome_loader_; | 119 bool own_cryptohome_loader_; |
| 113 bool own_language_loader_; | 120 bool own_language_loader_; |
| 114 bool own_login_loader_; | 121 bool own_login_loader_; |
| 115 bool own_mount_loader_; | 122 bool own_mount_loader_; |
| 116 bool own_network_loader_; | 123 bool own_network_loader_; |
| 117 bool own_power_loader_; | 124 bool own_power_loader_; |
| 125 bool own_speech_synthesis_library_; |
| 118 bool own_synaptics_library_; | 126 bool own_synaptics_library_; |
| 119 | 127 |
| 120 // True if libcros was successfully loaded. | 128 // True if libcros was successfully loaded. |
| 121 bool loaded_; | 129 bool loaded_; |
| 122 // True if the last load attempt had an error. | 130 // True if the last load attempt had an error. |
| 123 bool load_error_; | 131 bool load_error_; |
| 124 // Contains the error string from the last load attempt. | 132 // Contains the error string from the last load attempt. |
| 125 std::string load_error_string_; | 133 std::string load_error_string_; |
| 126 TestApi* test_api_; | 134 TestApi* test_api_; |
| 127 | 135 |
| 128 DISALLOW_COPY_AND_ASSIGN(CrosLibrary); | 136 DISALLOW_COPY_AND_ASSIGN(CrosLibrary); |
| 129 }; | 137 }; |
| 130 | 138 |
| 131 } // namespace chromeos | 139 } // namespace chromeos |
| 132 | 140 |
| 133 #endif // CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ | 141 #endif // CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ |
| OLD | NEW |