OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 template <typename T> struct DefaultLazyInstanceTraits; | 14 template <typename T> struct DefaultLazyInstanceTraits; |
15 } | 15 } |
16 | 16 |
17 namespace chromeos { | 17 namespace chromeos { |
18 | 18 |
19 class BurnLibrary; | 19 class BurnLibrary; |
20 class CertLibrary; | 20 class CertLibrary; |
21 class CryptohomeLibrary; | 21 class CryptohomeLibrary; |
22 class LibraryLoader; | 22 class LibraryLoader; |
23 class LoginLibrary; | 23 class LoginLibrary; |
24 class MountLibrary; | 24 class MountLibrary; |
25 class NetworkLibrary; | 25 class NetworkLibrary; |
26 class PowerLibrary; | 26 class PowerLibrary; |
27 class ScreenLockLibrary; | 27 class ScreenLockLibrary; |
28 class SpeechSynthesisLibrary; | |
29 class UpdateLibrary; | 28 class UpdateLibrary; |
30 | 29 |
31 // This class handles access to sub-parts of ChromeOS library. it provides | 30 // This class handles access to sub-parts of ChromeOS library. it provides |
32 // a level of indirection so individual libraries that it exposes can | 31 // a level of indirection so individual libraries that it exposes can |
33 // be mocked for testing. | 32 // be mocked for testing. |
34 class CrosLibrary { | 33 class CrosLibrary { |
35 public: | 34 public: |
36 // This class provides access to internal members of CrosLibrary class for | 35 // This class provides access to internal members of CrosLibrary class for |
37 // purpose of testing (i.e. replacement of members' implementation with | 36 // purpose of testing (i.e. replacement of members' implementation with |
38 // mock objects). | 37 // mock objects). |
39 class TestApi { | 38 class TestApi { |
40 public: | 39 public: |
41 // Resets the stub implementation of the library and loads libcros. | 40 // Resets the stub implementation of the library and loads libcros. |
42 // Used by tests that need to run with libcros (i.e. on a device). | 41 // Used by tests that need to run with libcros (i.e. on a device). |
43 void ResetUseStubImpl(); | 42 void ResetUseStubImpl(); |
44 | 43 |
45 // Passing true for own for these setters will cause them to be deleted | 44 // Passing true for own for these setters will cause them to be deleted |
46 // when the CrosLibrary is deleted (or other mocks are set). | 45 // when the CrosLibrary is deleted (or other mocks are set). |
47 // Setter for LibraryLoader. | 46 // Setter for LibraryLoader. |
48 void SetLibraryLoader(LibraryLoader* loader, bool own); | 47 void SetLibraryLoader(LibraryLoader* loader, bool own); |
49 void SetCertLibrary(CertLibrary* library, bool own); | 48 void SetCertLibrary(CertLibrary* library, bool own); |
50 void SetBurnLibrary(BurnLibrary* library, bool own); | 49 void SetBurnLibrary(BurnLibrary* library, bool own); |
51 void SetCryptohomeLibrary(CryptohomeLibrary* library, bool own); | 50 void SetCryptohomeLibrary(CryptohomeLibrary* library, bool own); |
52 void SetLoginLibrary(LoginLibrary* library, bool own); | 51 void SetLoginLibrary(LoginLibrary* library, bool own); |
53 void SetMountLibrary(MountLibrary* library, bool own); | 52 void SetMountLibrary(MountLibrary* library, bool own); |
54 void SetNetworkLibrary(NetworkLibrary* library, bool own); | 53 void SetNetworkLibrary(NetworkLibrary* library, bool own); |
55 void SetPowerLibrary(PowerLibrary* library, bool own); | 54 void SetPowerLibrary(PowerLibrary* library, bool own); |
56 void SetScreenLockLibrary(ScreenLockLibrary* library, bool own); | 55 void SetScreenLockLibrary(ScreenLockLibrary* library, bool own); |
57 void SetSpeechSynthesisLibrary(SpeechSynthesisLibrary* library, bool own); | |
58 void SetUpdateLibrary(UpdateLibrary* library, bool own); | 56 void SetUpdateLibrary(UpdateLibrary* library, bool own); |
59 | 57 |
60 private: | 58 private: |
61 friend class CrosLibrary; | 59 friend class CrosLibrary; |
62 explicit TestApi(CrosLibrary* library) : library_(library) {} | 60 explicit TestApi(CrosLibrary* library) : library_(library) {} |
63 CrosLibrary* library_; | 61 CrosLibrary* library_; |
64 }; | 62 }; |
65 | 63 |
66 // Sets the global instance. Must be called before any calls to Get(). | 64 // Sets the global instance. Must be called before any calls to Get(). |
67 static void Initialize(bool use_stub); | 65 static void Initialize(bool use_stub); |
68 | 66 |
69 // Destroys the global instance. Must be called before AtExitManager is | 67 // Destroys the global instance. Must be called before AtExitManager is |
70 // destroyed to ensure a clean shutdown. | 68 // destroyed to ensure a clean shutdown. |
71 static void Shutdown(); | 69 static void Shutdown(); |
72 | 70 |
73 // Gets the global instance. Returns NULL if Initialize() has not been | 71 // Gets the global instance. Returns NULL if Initialize() has not been |
74 // called (or Shutdown() has been called). | 72 // called (or Shutdown() has been called). |
75 static CrosLibrary* Get(); | 73 static CrosLibrary* Get(); |
76 | 74 |
77 BurnLibrary* GetBurnLibrary(); | 75 BurnLibrary* GetBurnLibrary(); |
78 CertLibrary* GetCertLibrary(); | 76 CertLibrary* GetCertLibrary(); |
79 CryptohomeLibrary* GetCryptohomeLibrary(); | 77 CryptohomeLibrary* GetCryptohomeLibrary(); |
80 LoginLibrary* GetLoginLibrary(); | 78 LoginLibrary* GetLoginLibrary(); |
81 MountLibrary* GetMountLibrary(); | 79 MountLibrary* GetMountLibrary(); |
82 NetworkLibrary* GetNetworkLibrary(); | 80 NetworkLibrary* GetNetworkLibrary(); |
83 PowerLibrary* GetPowerLibrary(); | 81 PowerLibrary* GetPowerLibrary(); |
84 ScreenLockLibrary* GetScreenLockLibrary(); | 82 ScreenLockLibrary* GetScreenLockLibrary(); |
85 SpeechSynthesisLibrary* GetSpeechSynthesisLibrary(); | |
86 UpdateLibrary* GetUpdateLibrary(); | 83 UpdateLibrary* GetUpdateLibrary(); |
87 | 84 |
88 // Getter for Test API that gives access to internal members of this class. | 85 // Getter for Test API that gives access to internal members of this class. |
89 TestApi* GetTestApi(); | 86 TestApi* GetTestApi(); |
90 | 87 |
91 // TODO(stevenjb): Deprecate this. Libraries should fall back to stub | 88 // TODO(stevenjb): Deprecate this. Libraries should fall back to stub |
92 // implementations if libcros_loaded() is false, and/or use libcros_loaded() | 89 // implementations if libcros_loaded() is false, and/or use libcros_loaded() |
93 // to protect calls to libcros. http://crosbug.com/19886 | 90 // to protect calls to libcros. http://crosbug.com/19886 |
94 bool EnsureLoaded() { return use_stub_impl_ || libcros_loaded_; } | 91 bool EnsureLoaded() { return use_stub_impl_ || libcros_loaded_; } |
95 | 92 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 }; | 145 }; |
149 | 146 |
150 Library<BurnLibrary> burn_lib_; | 147 Library<BurnLibrary> burn_lib_; |
151 Library<CertLibrary> cert_lib_; | 148 Library<CertLibrary> cert_lib_; |
152 Library<CryptohomeLibrary> crypto_lib_; | 149 Library<CryptohomeLibrary> crypto_lib_; |
153 Library<LoginLibrary> login_lib_; | 150 Library<LoginLibrary> login_lib_; |
154 Library<MountLibrary> mount_lib_; | 151 Library<MountLibrary> mount_lib_; |
155 Library<NetworkLibrary> network_lib_; | 152 Library<NetworkLibrary> network_lib_; |
156 Library<PowerLibrary> power_lib_; | 153 Library<PowerLibrary> power_lib_; |
157 Library<ScreenLockLibrary> screen_lock_lib_; | 154 Library<ScreenLockLibrary> screen_lock_lib_; |
158 Library<SpeechSynthesisLibrary> speech_synthesis_lib_; | |
159 Library<UpdateLibrary> update_lib_; | 155 Library<UpdateLibrary> update_lib_; |
160 | 156 |
161 // Stub implementations of the libraries should be used. | 157 // Stub implementations of the libraries should be used. |
162 bool use_stub_impl_; | 158 bool use_stub_impl_; |
163 // True if libcros was successfully loaded. | 159 // True if libcros was successfully loaded. |
164 bool libcros_loaded_; | 160 bool libcros_loaded_; |
165 // True if the last load attempt had an error. | 161 // True if the last load attempt had an error. |
166 bool load_error_; | 162 bool load_error_; |
167 // Contains the error string from the last load attempt. | 163 // Contains the error string from the last load attempt. |
168 std::string load_error_string_; | 164 std::string load_error_string_; |
(...skipping 14 matching lines...) Expand all Loading... |
183 chromeos::CrosLibrary::Shutdown(); | 179 chromeos::CrosLibrary::Shutdown(); |
184 } | 180 } |
185 | 181 |
186 private: | 182 private: |
187 DISALLOW_COPY_AND_ASSIGN(ScopedStubCrosEnabler); | 183 DISALLOW_COPY_AND_ASSIGN(ScopedStubCrosEnabler); |
188 }; | 184 }; |
189 | 185 |
190 } // namespace chromeos | 186 } // namespace chromeos |
191 | 187 |
192 #endif // CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ | 188 #endif // CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ |
OLD | NEW |