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 NetworkLibrary; | 23 class NetworkLibrary; |
24 class PowerLibrary; | 24 class PowerLibrary; |
25 class ScreenLockLibrary; | 25 class ScreenLockLibrary; |
26 class UpdateLibrary; | |
27 | 26 |
28 // This class handles access to sub-parts of ChromeOS library. it provides | 27 // This class handles access to sub-parts of ChromeOS library. it provides |
29 // a level of indirection so individual libraries that it exposes can | 28 // a level of indirection so individual libraries that it exposes can |
30 // be mocked for testing. | 29 // be mocked for testing. |
31 class CrosLibrary { | 30 class CrosLibrary { |
32 public: | 31 public: |
33 // This class provides access to internal members of CrosLibrary class for | 32 // This class provides access to internal members of CrosLibrary class for |
34 // purpose of testing (i.e. replacement of members' implementation with | 33 // purpose of testing (i.e. replacement of members' implementation with |
35 // mock objects). | 34 // mock objects). |
36 class TestApi { | 35 class TestApi { |
37 public: | 36 public: |
38 // Resets the stub implementation of the library and loads libcros. | 37 // Resets the stub implementation of the library and loads libcros. |
39 // Used by tests that need to run with libcros (i.e. on a device). | 38 // Used by tests that need to run with libcros (i.e. on a device). |
40 void ResetUseStubImpl(); | 39 void ResetUseStubImpl(); |
41 | 40 |
42 // Passing true for own for these setters will cause them to be deleted | 41 // Passing true for own for these setters will cause them to be deleted |
43 // when the CrosLibrary is deleted (or other mocks are set). | 42 // when the CrosLibrary is deleted (or other mocks are set). |
44 // Setter for LibraryLoader. | 43 // Setter for LibraryLoader. |
45 void SetLibraryLoader(LibraryLoader* loader, bool own); | 44 void SetLibraryLoader(LibraryLoader* loader, bool own); |
46 void SetCertLibrary(CertLibrary* library, bool own); | 45 void SetCertLibrary(CertLibrary* library, bool own); |
47 void SetBurnLibrary(BurnLibrary* library, bool own); | 46 void SetBurnLibrary(BurnLibrary* library, bool own); |
48 void SetCryptohomeLibrary(CryptohomeLibrary* library, bool own); | 47 void SetCryptohomeLibrary(CryptohomeLibrary* library, bool own); |
49 void SetNetworkLibrary(NetworkLibrary* library, bool own); | 48 void SetNetworkLibrary(NetworkLibrary* library, bool own); |
50 void SetPowerLibrary(PowerLibrary* library, bool own); | 49 void SetPowerLibrary(PowerLibrary* library, bool own); |
51 void SetScreenLockLibrary(ScreenLockLibrary* library, bool own); | 50 void SetScreenLockLibrary(ScreenLockLibrary* library, bool own); |
52 void SetUpdateLibrary(UpdateLibrary* library, bool own); | |
53 | 51 |
54 private: | 52 private: |
55 friend class CrosLibrary; | 53 friend class CrosLibrary; |
56 explicit TestApi(CrosLibrary* library) : library_(library) {} | 54 explicit TestApi(CrosLibrary* library) : library_(library) {} |
57 CrosLibrary* library_; | 55 CrosLibrary* library_; |
58 }; | 56 }; |
59 | 57 |
60 // Sets the global instance. Must be called before any calls to Get(). | 58 // Sets the global instance. Must be called before any calls to Get(). |
61 static void Initialize(bool use_stub); | 59 static void Initialize(bool use_stub); |
62 | 60 |
63 // Destroys the global instance. Must be called before AtExitManager is | 61 // Destroys the global instance. Must be called before AtExitManager is |
64 // destroyed to ensure a clean shutdown. | 62 // destroyed to ensure a clean shutdown. |
65 static void Shutdown(); | 63 static void Shutdown(); |
66 | 64 |
67 // Gets the global instance. Returns NULL if Initialize() has not been | 65 // Gets the global instance. Returns NULL if Initialize() has not been |
68 // called (or Shutdown() has been called). | 66 // called (or Shutdown() has been called). |
69 static CrosLibrary* Get(); | 67 static CrosLibrary* Get(); |
70 | 68 |
71 BurnLibrary* GetBurnLibrary(); | 69 BurnLibrary* GetBurnLibrary(); |
72 CertLibrary* GetCertLibrary(); | 70 CertLibrary* GetCertLibrary(); |
73 CryptohomeLibrary* GetCryptohomeLibrary(); | 71 CryptohomeLibrary* GetCryptohomeLibrary(); |
74 NetworkLibrary* GetNetworkLibrary(); | 72 NetworkLibrary* GetNetworkLibrary(); |
75 PowerLibrary* GetPowerLibrary(); | 73 PowerLibrary* GetPowerLibrary(); |
76 ScreenLockLibrary* GetScreenLockLibrary(); | 74 ScreenLockLibrary* GetScreenLockLibrary(); |
77 UpdateLibrary* GetUpdateLibrary(); | |
78 | 75 |
79 // Getter for Test API that gives access to internal members of this class. | 76 // Getter for Test API that gives access to internal members of this class. |
80 TestApi* GetTestApi(); | 77 TestApi* GetTestApi(); |
81 | 78 |
82 bool libcros_loaded() { return libcros_loaded_; } | 79 bool libcros_loaded() { return libcros_loaded_; } |
83 | 80 |
84 // Returns an unlocalized string describing the last load error (if any). | 81 // Returns an unlocalized string describing the last load error (if any). |
85 const std::string& load_error_string() { | 82 const std::string& load_error_string() { |
86 return load_error_string_; | 83 return load_error_string_; |
87 } | 84 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 L* library_; | 129 L* library_; |
133 bool own_; | 130 bool own_; |
134 }; | 131 }; |
135 | 132 |
136 Library<BurnLibrary> burn_lib_; | 133 Library<BurnLibrary> burn_lib_; |
137 Library<CertLibrary> cert_lib_; | 134 Library<CertLibrary> cert_lib_; |
138 Library<CryptohomeLibrary> crypto_lib_; | 135 Library<CryptohomeLibrary> crypto_lib_; |
139 Library<NetworkLibrary> network_lib_; | 136 Library<NetworkLibrary> network_lib_; |
140 Library<PowerLibrary> power_lib_; | 137 Library<PowerLibrary> power_lib_; |
141 Library<ScreenLockLibrary> screen_lock_lib_; | 138 Library<ScreenLockLibrary> screen_lock_lib_; |
142 Library<UpdateLibrary> update_lib_; | |
143 | 139 |
144 // Stub implementations of the libraries should be used. | 140 // Stub implementations of the libraries should be used. |
145 bool use_stub_impl_; | 141 bool use_stub_impl_; |
146 // True if libcros was successfully loaded. | 142 // True if libcros was successfully loaded. |
147 bool libcros_loaded_; | 143 bool libcros_loaded_; |
148 // True if the last load attempt had an error. | 144 // True if the last load attempt had an error. |
149 bool load_error_; | 145 bool load_error_; |
150 // Contains the error string from the last load attempt. | 146 // Contains the error string from the last load attempt. |
151 std::string load_error_string_; | 147 std::string load_error_string_; |
152 scoped_ptr<TestApi> test_api_; | 148 scoped_ptr<TestApi> test_api_; |
(...skipping 13 matching lines...) Expand all Loading... |
166 chromeos::CrosLibrary::Shutdown(); | 162 chromeos::CrosLibrary::Shutdown(); |
167 } | 163 } |
168 | 164 |
169 private: | 165 private: |
170 DISALLOW_COPY_AND_ASSIGN(ScopedStubCrosEnabler); | 166 DISALLOW_COPY_AND_ASSIGN(ScopedStubCrosEnabler); |
171 }; | 167 }; |
172 | 168 |
173 } // namespace chromeos | 169 } // namespace chromeos |
174 | 170 |
175 #endif // CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ | 171 #endif // CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ |
OLD | NEW |