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