Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: chrome/browser/chromeos/cros/cros_library.cc

Issue 3076029: Allow chrome for cros to be started with a username / password (Closed)
Patch Set: Only declare StubLogin on cros builds Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "chrome/browser/chromeos/cros/cros_library.h" 5 #include "chrome/browser/chromeos/cros/cros_library.h"
6 6
7 #include "chrome/browser/chromeos/cros/cros_library_loader.h" 7 #include "chrome/browser/chromeos/cros/cros_library_loader.h"
8 #include "chrome/browser/chromeos/cros/cryptohome_library.h" 8 #include "chrome/browser/chromeos/cros/cryptohome_library.h"
9 #include "chrome/browser/chromeos/cros/input_method_library.h" 9 #include "chrome/browser/chromeos/cros/input_method_library.h"
10 #include "chrome/browser/chromeos/cros/keyboard_library.h" 10 #include "chrome/browser/chromeos/cros/keyboard_library.h"
11 #include "chrome/browser/chromeos/cros/login_library.h" 11 #include "chrome/browser/chromeos/cros/login_library.h"
12 #include "chrome/browser/chromeos/cros/mount_library.h" 12 #include "chrome/browser/chromeos/cros/mount_library.h"
13 #include "chrome/browser/chromeos/cros/network_library.h" 13 #include "chrome/browser/chromeos/cros/network_library.h"
14 #include "chrome/browser/chromeos/cros/power_library.h" 14 #include "chrome/browser/chromeos/cros/power_library.h"
15 #include "chrome/browser/chromeos/cros/screen_lock_library.h" 15 #include "chrome/browser/chromeos/cros/screen_lock_library.h"
16 #include "chrome/browser/chromeos/cros/speech_synthesis_library.h" 16 #include "chrome/browser/chromeos/cros/speech_synthesis_library.h"
17 #include "chrome/browser/chromeos/cros/synaptics_library.h" 17 #include "chrome/browser/chromeos/cros/synaptics_library.h"
18 #include "chrome/browser/chromeos/cros/syslogs_library.h" 18 #include "chrome/browser/chromeos/cros/syslogs_library.h"
19 #include "chrome/browser/chromeos/cros/system_library.h" 19 #include "chrome/browser/chromeos/cros/system_library.h"
20 #include "chrome/browser/chromeos/cros/update_library.h" 20 #include "chrome/browser/chromeos/cros/update_library.h"
21 21
22 namespace chromeos { 22 namespace chromeos {
23 23
24 CrosLibrary::CrosLibrary() : library_loader_(NULL), 24 CrosLibrary::CrosLibrary() : library_loader_(NULL),
25 crypto_lib_(NULL),
26 keyboard_lib_(NULL),
27 input_method_lib_(NULL),
28 login_lib_(NULL),
29 mount_lib_(NULL),
30 network_lib_(NULL),
31 power_lib_(NULL),
32 screen_lock_lib_(NULL),
33 speech_synthesis_lib_(NULL),
34 synaptics_lib_(NULL),
35 syslogs_lib_(NULL),
36 system_lib_(NULL),
37 update_lib_(NULL),
38 own_library_loader_(true),
39 own_cryptohome_lib_(true),
40 own_keyboard_lib_(true),
41 own_input_method_lib_(true),
42 own_login_lib_(true),
43 own_mount_lib_(true),
44 own_network_lib_(true),
45 own_power_lib_(true),
46 own_screen_lock_lib_(true),
47 own_speech_synthesis_lib_(true),
48 own_synaptics_lib_(true),
49 own_syslogs_lib_(true),
50 own_system_lib_(true),
51 own_update_lib_(true),
52 loaded_(false), 25 loaded_(false),
53 load_error_(false), 26 load_error_(false),
54 test_api_(NULL) { 27 test_api_(NULL) {
55
56 } 28 }
57 29
58 CrosLibrary::~CrosLibrary() { 30 CrosLibrary::~CrosLibrary() {
59 if (own_library_loader_) 31 if (own_library_loader_)
60 delete library_loader_; 32 delete library_loader_;
61 if (own_cryptohome_lib_)
62 delete crypto_lib_;
63 if (own_keyboard_lib_)
64 delete keyboard_lib_;
65 if (own_input_method_lib_)
66 delete input_method_lib_;
67 if (own_login_lib_)
68 delete login_lib_;
69 if (own_mount_lib_)
70 delete mount_lib_;
71 if (own_network_lib_)
72 delete network_lib_;
73 if (own_power_lib_)
74 delete power_lib_;
75 if (own_screen_lock_lib_)
76 delete screen_lock_lib_;
77 if (own_speech_synthesis_lib_)
78 delete speech_synthesis_lib_;
79 if (own_synaptics_lib_)
80 delete synaptics_lib_;
81 if (own_syslogs_lib_)
82 delete syslogs_lib_;
83 if (own_system_lib_)
84 delete system_lib_;
85 if (own_update_lib_)
86 delete update_lib_;
87 delete test_api_;
88 } 33 }
89 34
90 // static 35 // static
91 CrosLibrary* CrosLibrary::Get() { 36 CrosLibrary* CrosLibrary::Get() {
92 return Singleton<CrosLibrary>::get(); 37 return Singleton<CrosLibrary>::get();
93 } 38 }
94 39
95 CryptohomeLibrary* CrosLibrary::GetCryptohomeLibrary() { 40 CryptohomeLibrary* CrosLibrary::GetCryptohomeLibrary() {
96 if (!crypto_lib_) 41 return crypto_lib_.GetDefaultImpl(use_stub_impl_);
97 crypto_lib_ = new CryptohomeLibraryImpl();
98 return crypto_lib_;
99 } 42 }
100 43
101 KeyboardLibrary* CrosLibrary::GetKeyboardLibrary() { 44 KeyboardLibrary* CrosLibrary::GetKeyboardLibrary() {
102 if (!keyboard_lib_) 45 return keyboard_lib_.GetDefaultImpl(use_stub_impl_);
103 keyboard_lib_ = new KeyboardLibraryImpl();
104 return keyboard_lib_;
105 } 46 }
106 47
107 InputMethodLibrary* CrosLibrary::GetInputMethodLibrary() { 48 InputMethodLibrary* CrosLibrary::GetInputMethodLibrary() {
108 if (!input_method_lib_) 49 return input_method_lib_.GetDefaultImpl(use_stub_impl_);
109 input_method_lib_ = new InputMethodLibraryImpl();
110 return input_method_lib_;
111 } 50 }
112 51
113 LoginLibrary* CrosLibrary::GetLoginLibrary() { 52 LoginLibrary* CrosLibrary::GetLoginLibrary() {
114 if (!login_lib_) 53 return login_lib_.GetDefaultImpl(use_stub_impl_);
115 login_lib_ = new LoginLibraryImpl();
116 return login_lib_;
117 } 54 }
118 55
119 MountLibrary* CrosLibrary::GetMountLibrary() { 56 MountLibrary* CrosLibrary::GetMountLibrary() {
120 if (!mount_lib_) 57 return mount_lib_.GetDefaultImpl(use_stub_impl_);
121 mount_lib_ = new MountLibraryImpl();
122 return mount_lib_;
123 } 58 }
124 59
125 NetworkLibrary* CrosLibrary::GetNetworkLibrary() { 60 NetworkLibrary* CrosLibrary::GetNetworkLibrary() {
126 if (!network_lib_) 61 return network_lib_.GetDefaultImpl(use_stub_impl_);
127 network_lib_ = new NetworkLibraryImpl();
128 return network_lib_;
129 } 62 }
130 63
131 PowerLibrary* CrosLibrary::GetPowerLibrary() { 64 PowerLibrary* CrosLibrary::GetPowerLibrary() {
132 if (!power_lib_) 65 return power_lib_.GetDefaultImpl(use_stub_impl_);
133 power_lib_ = new PowerLibraryImpl();
134 return power_lib_;
135 } 66 }
136 67
137 ScreenLockLibrary* CrosLibrary::GetScreenLockLibrary() { 68 ScreenLockLibrary* CrosLibrary::GetScreenLockLibrary() {
138 if (!screen_lock_lib_) 69 return screen_lock_lib_.GetDefaultImpl(use_stub_impl_);
139 screen_lock_lib_ = new ScreenLockLibraryImpl();
140 return screen_lock_lib_;
141 } 70 }
142 71
143 SpeechSynthesisLibrary* CrosLibrary::GetSpeechSynthesisLibrary() { 72 SpeechSynthesisLibrary* CrosLibrary::GetSpeechSynthesisLibrary() {
144 if (!speech_synthesis_lib_) 73 return speech_synthesis_lib_.GetDefaultImpl(use_stub_impl_);
145 speech_synthesis_lib_ = new SpeechSynthesisLibraryImpl();
146 return speech_synthesis_lib_;
147 } 74 }
148 75
149 SynapticsLibrary* CrosLibrary::GetSynapticsLibrary() { 76 SynapticsLibrary* CrosLibrary::GetSynapticsLibrary() {
150 if (!synaptics_lib_) 77 return synaptics_lib_.GetDefaultImpl(use_stub_impl_);
151 synaptics_lib_ = new SynapticsLibraryImpl();
152 return synaptics_lib_;
153 } 78 }
154 79
155 SyslogsLibrary* CrosLibrary::GetSyslogsLibrary() { 80 SyslogsLibrary* CrosLibrary::GetSyslogsLibrary() {
156 if (!syslogs_lib_) 81 return syslogs_lib_.GetDefaultImpl(use_stub_impl_);
157 syslogs_lib_ = new SyslogsLibraryImpl();
158 return syslogs_lib_;
159 } 82 }
160 83
161 SystemLibrary* CrosLibrary::GetSystemLibrary() { 84 SystemLibrary* CrosLibrary::GetSystemLibrary() {
162 if (!system_lib_) 85 return system_lib_.GetDefaultImpl(use_stub_impl_);
163 system_lib_ = new SystemLibraryImpl();
164 return system_lib_;
165 } 86 }
166 87
167 UpdateLibrary* CrosLibrary::GetUpdateLibrary() { 88 UpdateLibrary* CrosLibrary::GetUpdateLibrary() {
168 if (!update_lib_) 89 return update_lib_.GetDefaultImpl(use_stub_impl_);
169 update_lib_ = new UpdateLibraryImpl();
170 return update_lib_;
171 } 90 }
172 91
173 bool CrosLibrary::EnsureLoaded() { 92 bool CrosLibrary::EnsureLoaded() {
93 if (use_stub_impl_)
94 return true;
95
174 if (!loaded_ && !load_error_) { 96 if (!loaded_ && !load_error_) {
175 if (!library_loader_) 97 if (!library_loader_)
176 library_loader_ = new CrosLibraryLoader(); 98 library_loader_ = new CrosLibraryLoader();
177 loaded_ = library_loader_->Load(&load_error_string_); 99 loaded_ = library_loader_->Load(&load_error_string_);
178 load_error_ = !loaded_; 100 load_error_ = !loaded_;
179 } 101 }
180 return loaded_; 102 return loaded_;
181 } 103 }
182 104
183 CrosLibrary::TestApi* CrosLibrary::GetTestApi() { 105 CrosLibrary::TestApi* CrosLibrary::GetTestApi() {
184 if (!test_api_) 106 if (!test_api_)
185 test_api_ = new TestApi(this); 107 test_api_ = new TestApi(this);
186 return test_api_; 108 return test_api_;
187 } 109 }
188 110
111 void CrosLibrary::TestApi::SetUseStubImpl() {
112 library_->use_stub_impl_ = true;
113 }
114
189 void CrosLibrary::TestApi::SetLibraryLoader(LibraryLoader* loader, bool own) { 115 void CrosLibrary::TestApi::SetLibraryLoader(LibraryLoader* loader, bool own) {
190 if (library_->library_loader_ == loader) 116 if (library_->library_loader_ == loader)
191 return; 117 return;
192 if (library_->own_library_loader_) 118 if (library_->own_library_loader_)
193 delete library_->library_loader_; 119 delete library_->library_loader_;
194 library_->own_library_loader_ = own; 120 library_->own_library_loader_ = own;
195 library_->library_loader_ = loader; 121 library_->library_loader_ = loader;
196 // Reset load flags when loader changes. Otherwise some tests are really not 122 // Reset load flags when loader changes. Otherwise some tests are really not
197 // going to be happy. 123 // going to be happy.
198 library_->loaded_ = false; 124 library_->loaded_ = false;
199 library_->load_error_ = false; 125 library_->load_error_ = false;
200 } 126 }
201 127
202 void CrosLibrary::TestApi::SetCryptohomeLibrary(CryptohomeLibrary* library, 128 void CrosLibrary::TestApi::SetCryptohomeLibrary(
203 bool own) { 129 CryptohomeLibrary* library, bool own) {
204 if (library_->own_cryptohome_lib_) 130 library_->crypto_lib_.SetImpl(library, own);
205 delete library_->crypto_lib_;
206 library_->own_cryptohome_lib_ = own;
207 library_->crypto_lib_ = library;
208 } 131 }
209 132
210 void CrosLibrary::TestApi::SetKeyboardLibrary(KeyboardLibrary* library, 133 void CrosLibrary::TestApi::SetKeyboardLibrary(
211 bool own) { 134 KeyboardLibrary* library, bool own) {
212 if (library_->own_keyboard_lib_) 135 library_->keyboard_lib_.SetImpl(library, own);
213 delete library_->keyboard_lib_;
214 library_->own_keyboard_lib_ = own;
215 library_->keyboard_lib_ = library;
216 } 136 }
217 137
218 void CrosLibrary::TestApi::SetInputMethodLibrary(InputMethodLibrary* library, 138 void CrosLibrary::TestApi::SetInputMethodLibrary(
219 bool own) { 139 InputMethodLibrary* library, bool own) {
220 if (library_->own_input_method_lib_) 140 library_->input_method_lib_.SetImpl(library, own);
221 delete library_->input_method_lib_;
222 library_->own_input_method_lib_ = own;
223 library_->input_method_lib_ = library;
224 } 141 }
225 142
226 void CrosLibrary::TestApi::SetLoginLibrary(LoginLibrary* library, bool own) { 143 void CrosLibrary::TestApi::SetLoginLibrary(
227 if (library_->own_login_lib_) 144 LoginLibrary* library, bool own) {
228 delete library_->login_lib_; 145 library_->login_lib_.SetImpl(library, own);
229 library_->own_login_lib_ = own;
230 library_->login_lib_ = library;
231 } 146 }
232 147
233 void CrosLibrary::TestApi::SetMountLibrary(MountLibrary* library, bool own) { 148 void CrosLibrary::TestApi::SetMountLibrary(
234 if (library_->own_mount_lib_) 149 MountLibrary* library, bool own) {
235 delete library_->mount_lib_; 150 library_->mount_lib_.SetImpl(library, own);
236 library_->own_mount_lib_ = own;
237 library_->mount_lib_ = library;
238 } 151 }
239 152
240 void CrosLibrary::TestApi::SetNetworkLibrary(NetworkLibrary* library, 153 void CrosLibrary::TestApi::SetNetworkLibrary(
241 bool own) { 154 NetworkLibrary* library, bool own) {
242 if (library_->own_network_lib_) 155 library_->network_lib_.SetImpl(library, own);
243 delete library_->network_lib_;
244 library_->own_network_lib_ = own;
245 library_->network_lib_ = library;
246 } 156 }
247 157
248 void CrosLibrary::TestApi::SetPowerLibrary(PowerLibrary* library, bool own) { 158 void CrosLibrary::TestApi::SetPowerLibrary(
249 if (library_->own_power_lib_) 159 PowerLibrary* library, bool own) {
250 delete library_->power_lib_; 160 library_->power_lib_.SetImpl(library, own);
251 library_->own_power_lib_ = own;
252 library_->power_lib_ = library;
253 } 161 }
254 162
255 void CrosLibrary::TestApi::SetScreenLockLibrary(ScreenLockLibrary* library, 163 void CrosLibrary::TestApi::SetScreenLockLibrary(
256 bool own) { 164 ScreenLockLibrary* library, bool own) {
257 if (library_->own_screen_lock_lib_) 165 library_->screen_lock_lib_.SetImpl(library, own);
258 delete library_->screen_lock_lib_;
259 library_->own_screen_lock_lib_ = own;
260 library_->screen_lock_lib_ = library;
261 } 166 }
262 167
263 void CrosLibrary::TestApi::SetSpeechSynthesisLibrary( 168 void CrosLibrary::TestApi::SetSpeechSynthesisLibrary(
264 SpeechSynthesisLibrary* library, bool own) { 169 SpeechSynthesisLibrary* library, bool own) {
265 if (library_->own_speech_synthesis_lib_) 170 library_->speech_synthesis_lib_.SetImpl(library, own);
266 delete library_->speech_synthesis_lib_;
267 library_->own_speech_synthesis_lib_ = own;
268 library_->speech_synthesis_lib_ = library;
269 } 171 }
270 172
271 void CrosLibrary::TestApi::SetSynapticsLibrary(SynapticsLibrary* library, 173 void CrosLibrary::TestApi::SetSynapticsLibrary(
272 bool own) { 174 SynapticsLibrary* library, bool own) {
273 if (library_->own_synaptics_lib_) 175 library_->synaptics_lib_.SetImpl(library, own);
274 delete library_->synaptics_lib_;
275 library_->own_synaptics_lib_ = own;
276 library_->synaptics_lib_ = library;
277 } 176 }
278 177
279 void CrosLibrary::TestApi::SetSyslogsLibrary(SyslogsLibrary* library, 178 void CrosLibrary::TestApi::SetSyslogsLibrary(
280 bool own) { 179 SyslogsLibrary* library, bool own) {
281 if (library_->syslogs_lib_) 180 library_->syslogs_lib_.SetImpl(library, own);
282 delete library_->syslogs_lib_;
283 library_->own_syslogs_lib_ = own;
284 library_->syslogs_lib_ = library;
285 } 181 }
286 182
287 void CrosLibrary::TestApi::SetSystemLibrary(SystemLibrary* library, 183 void CrosLibrary::TestApi::SetSystemLibrary(
288 bool own) { 184 SystemLibrary* library, bool own) {
289 if (library_->system_lib_) 185 library_->system_lib_.SetImpl(library, own);
290 delete library_->system_lib_;
291 library_->own_system_lib_ = own;
292 library_->system_lib_ = library;
293 } 186 }
294 187
295 void CrosLibrary::TestApi::SetUpdateLibrary(UpdateLibrary* library, 188 void CrosLibrary::TestApi::SetUpdateLibrary(
296 bool own) { 189 UpdateLibrary* library, bool own) {
297 if (library_->update_lib_) 190 library_->update_lib_.SetImpl(library, own);
298 delete library_->update_lib_;
299 library_->own_update_lib_ = own;
300 library_->update_lib_ = library;
301 } 191 }
302 192
303 } // namespace chromeos 193 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/cros_library.h ('k') | chrome/browser/chromeos/cros/cryptohome_library.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698