Implement nacl_irt_memory for non-sfi mode.
[chromium-blink-merge.git] / chrome / test / base / testing_browser_process.cc
blob20a42a002d16b30b307131312c6f23d8023e1999
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/test/base/testing_browser_process.h"
7 #include "base/prefs/pref_service.h"
8 #include "base/strings/string_util.h"
9 #include "build/build_config.h"
10 #include "chrome/browser/background/background_mode_manager.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/browser_process_impl.h"
13 #include "chrome/browser/extensions/chrome_extensions_browser_client.h"
14 #include "chrome/browser/printing/print_job_manager.h"
15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/ui/bookmarks/bookmark_prompt_controller.h"
17 #include "chrome/test/base/testing_browser_process_platform_part.h"
18 #include "content/public/browser/notification_service.h"
19 #include "net/url_request/url_request_context_getter.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/message_center/message_center.h"
23 #if !defined(OS_IOS)
24 #include "chrome/browser/notifications/notification_ui_manager.h"
25 #include "chrome/browser/prerender/prerender_tracker.h"
26 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
27 #include "chrome/browser/thumbnails/render_widget_snapshot_taker.h"
28 #endif
30 #if !defined(OS_IOS) && !defined(OS_ANDROID)
31 #include "chrome/browser/media_galleries/media_file_system_registry.h"
32 #include "chrome/browser/storage_monitor/storage_monitor.h"
33 #include "chrome/browser/storage_monitor/test_storage_monitor.h"
34 #endif
36 #if defined(ENABLE_CONFIGURATION_POLICY)
37 #include "components/policy/core/browser/browser_policy_connector.h"
38 #else
39 #include "components/policy/core/common/policy_service_stub.h"
40 #endif // defined(ENABLE_CONFIGURATION_POLICY)
42 #if defined(ENABLE_FULL_PRINTING)
43 #include "chrome/browser/printing/background_printing_manager.h"
44 #include "chrome/browser/printing/print_preview_dialog_controller.h"
45 #endif
47 // static
48 TestingBrowserProcess* TestingBrowserProcess::GetGlobal() {
49 return static_cast<TestingBrowserProcess*>(g_browser_process);
52 // static
53 void TestingBrowserProcess::CreateInstance() {
54 DCHECK(!g_browser_process);
55 g_browser_process = new TestingBrowserProcess;
58 // static
59 void TestingBrowserProcess::DeleteInstance() {
60 // g_browser_process must be NULL during its own destruction.
61 BrowserProcess* browser_process = g_browser_process;
62 g_browser_process = NULL;
63 delete browser_process;
66 TestingBrowserProcess::TestingBrowserProcess()
67 : notification_service_(content::NotificationService::Create()),
68 module_ref_count_(0),
69 app_locale_("en"),
70 #if !defined(OS_IOS)
71 render_widget_snapshot_taker_(new RenderWidgetSnapshotTaker),
72 #endif
73 local_state_(NULL),
74 io_thread_(NULL),
75 system_request_context_(NULL),
76 platform_part_(new TestingBrowserProcessPlatformPart()),
77 extensions_browser_client_(
78 new extensions::ChromeExtensionsBrowserClient) {
79 extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get());
82 TestingBrowserProcess::~TestingBrowserProcess() {
83 EXPECT_FALSE(local_state_);
84 #if defined(ENABLE_CONFIGURATION_POLICY)
85 SetBrowserPolicyConnector(NULL);
86 #endif
87 extensions::ExtensionsBrowserClient::Set(NULL);
89 // Destructors for some objects owned by TestingBrowserProcess will use
90 // g_browser_process if it is not NULL, so it must be NULL before proceeding.
91 DCHECK_EQ(static_cast<BrowserProcess*>(NULL), g_browser_process);
94 void TestingBrowserProcess::ResourceDispatcherHostCreated() {
97 void TestingBrowserProcess::EndSession() {
100 MetricsService* TestingBrowserProcess::metrics_service() {
101 return NULL;
104 IOThread* TestingBrowserProcess::io_thread() {
105 return io_thread_;
108 WatchDogThread* TestingBrowserProcess::watchdog_thread() {
109 return NULL;
112 ProfileManager* TestingBrowserProcess::profile_manager() {
113 #if defined(OS_IOS)
114 NOTIMPLEMENTED();
115 return NULL;
116 #else
117 return profile_manager_.get();
118 #endif
121 void TestingBrowserProcess::SetProfileManager(ProfileManager* profile_manager) {
122 #if !defined(OS_IOS)
123 // NotificationUIManager can contain references to elements in the current
124 // ProfileManager (for example, the MessageCenterSettingsController maintains
125 // a pointer to the ProfileInfoCache). So when we change the ProfileManager
126 // (typically during test shutdown) make sure to reset any objects that might
127 // maintain references to it. See SetLocalState() for a description of a
128 // similar situation.
129 notification_ui_manager_.reset();
130 profile_manager_.reset(profile_manager);
131 #endif
134 PrefService* TestingBrowserProcess::local_state() {
135 return local_state_;
138 chrome_variations::VariationsService*
139 TestingBrowserProcess::variations_service() {
140 return NULL;
143 policy::BrowserPolicyConnector*
144 TestingBrowserProcess::browser_policy_connector() {
145 #if defined(ENABLE_CONFIGURATION_POLICY)
146 if (!browser_policy_connector_)
147 browser_policy_connector_ = platform_part_->CreateBrowserPolicyConnector();
148 return browser_policy_connector_.get();
149 #else
150 return NULL;
151 #endif
154 policy::PolicyService* TestingBrowserProcess::policy_service() {
155 #if defined(OS_IOS)
156 NOTIMPLEMENTED();
157 return NULL;
158 #elif defined(ENABLE_CONFIGURATION_POLICY)
159 return browser_policy_connector()->GetPolicyService();
160 #else
161 if (!policy_service_)
162 policy_service_.reset(new policy::PolicyServiceStub());
163 return policy_service_.get();
164 #endif
167 IconManager* TestingBrowserProcess::icon_manager() {
168 return NULL;
171 GLStringManager* TestingBrowserProcess::gl_string_manager() {
172 return NULL;
175 GpuModeManager* TestingBrowserProcess::gpu_mode_manager() {
176 return NULL;
179 RenderWidgetSnapshotTaker*
180 TestingBrowserProcess::GetRenderWidgetSnapshotTaker() {
181 #if defined(OS_IOS)
182 NOTREACHED();
183 return NULL;
184 #else
185 return render_widget_snapshot_taker_.get();
186 #endif
189 BackgroundModeManager* TestingBrowserProcess::background_mode_manager() {
190 return NULL;
193 void TestingBrowserProcess::set_background_mode_manager_for_test(
194 scoped_ptr<BackgroundModeManager> manager) {
195 NOTREACHED();
198 StatusTray* TestingBrowserProcess::status_tray() {
199 return NULL;
202 SafeBrowsingService* TestingBrowserProcess::safe_browsing_service() {
203 #if defined(OS_IOS)
204 NOTIMPLEMENTED();
205 return NULL;
206 #else
207 return sb_service_.get();
208 #endif
211 safe_browsing::ClientSideDetectionService*
212 TestingBrowserProcess::safe_browsing_detection_service() {
213 return NULL;
216 net::URLRequestContextGetter* TestingBrowserProcess::system_request_context() {
217 return system_request_context_;
220 BrowserProcessPlatformPart* TestingBrowserProcess::platform_part() {
221 return platform_part_.get();
224 extensions::EventRouterForwarder*
225 TestingBrowserProcess::extension_event_router_forwarder() {
226 return NULL;
229 NotificationUIManager* TestingBrowserProcess::notification_ui_manager() {
230 #if defined(ENABLE_NOTIFICATIONS)
231 if (!notification_ui_manager_.get())
232 notification_ui_manager_.reset(
233 NotificationUIManager::Create(local_state()));
234 return notification_ui_manager_.get();
235 #else
236 NOTIMPLEMENTED();
237 return NULL;
238 #endif
241 message_center::MessageCenter* TestingBrowserProcess::message_center() {
242 return message_center::MessageCenter::Get();
245 IntranetRedirectDetector* TestingBrowserProcess::intranet_redirect_detector() {
246 return NULL;
249 AutomationProviderList* TestingBrowserProcess::GetAutomationProviderList() {
250 return NULL;
253 void TestingBrowserProcess::CreateDevToolsHttpProtocolHandler(
254 chrome::HostDesktopType host_desktop_type,
255 const std::string& ip,
256 int port,
257 const std::string& frontend_url) {
260 unsigned int TestingBrowserProcess::AddRefModule() {
261 return ++module_ref_count_;
264 unsigned int TestingBrowserProcess::ReleaseModule() {
265 DCHECK_GT(module_ref_count_, 0U);
266 return --module_ref_count_;
269 bool TestingBrowserProcess::IsShuttingDown() {
270 return false;
273 printing::PrintJobManager* TestingBrowserProcess::print_job_manager() {
274 #if defined(ENABLE_FULL_PRINTING)
275 if (!print_job_manager_.get())
276 print_job_manager_.reset(new printing::PrintJobManager());
277 return print_job_manager_.get();
278 #else
279 NOTIMPLEMENTED();
280 return NULL;
281 #endif
284 printing::PrintPreviewDialogController*
285 TestingBrowserProcess::print_preview_dialog_controller() {
286 #if defined(ENABLE_FULL_PRINTING)
287 if (!print_preview_dialog_controller_.get())
288 print_preview_dialog_controller_ =
289 new printing::PrintPreviewDialogController();
290 return print_preview_dialog_controller_.get();
291 #else
292 NOTIMPLEMENTED();
293 return NULL;
294 #endif
297 printing::BackgroundPrintingManager*
298 TestingBrowserProcess::background_printing_manager() {
299 #if defined(ENABLE_FULL_PRINTING)
300 if (!background_printing_manager_.get()) {
301 background_printing_manager_.reset(
302 new printing::BackgroundPrintingManager());
304 return background_printing_manager_.get();
305 #else
306 NOTIMPLEMENTED();
307 return NULL;
308 #endif
311 const std::string& TestingBrowserProcess::GetApplicationLocale() {
312 return app_locale_;
315 void TestingBrowserProcess::SetApplicationLocale(
316 const std::string& app_locale) {
317 app_locale_ = app_locale;
320 DownloadStatusUpdater* TestingBrowserProcess::download_status_updater() {
321 return NULL;
324 DownloadRequestLimiter* TestingBrowserProcess::download_request_limiter() {
325 return NULL;
328 ChromeNetLog* TestingBrowserProcess::net_log() {
329 return NULL;
332 prerender::PrerenderTracker* TestingBrowserProcess::prerender_tracker() {
333 #if defined(OS_IOS)
334 NOTIMPLEMENTED();
335 return NULL;
336 #else
337 if (!prerender_tracker_.get())
338 prerender_tracker_.reset(new prerender::PrerenderTracker());
339 return prerender_tracker_.get();
340 #endif
343 component_updater::ComponentUpdateService*
344 TestingBrowserProcess::component_updater() {
345 return NULL;
348 CRLSetFetcher* TestingBrowserProcess::crl_set_fetcher() {
349 return NULL;
352 component_updater::PnaclComponentInstaller*
353 TestingBrowserProcess::pnacl_component_installer() {
354 return NULL;
357 BookmarkPromptController* TestingBrowserProcess::bookmark_prompt_controller() {
358 #if defined(OS_IOS)
359 NOTIMPLEMENTED();
360 return NULL;
361 #else
362 return bookmark_prompt_controller_.get();
363 #endif
366 StorageMonitor* TestingBrowserProcess::storage_monitor() {
367 #if defined(OS_IOS) || defined(OS_ANDROID)
368 NOTIMPLEMENTED();
369 return NULL;
370 #else
371 return storage_monitor_.get();
372 #endif
375 MediaFileSystemRegistry* TestingBrowserProcess::media_file_system_registry() {
376 #if defined(OS_IOS) || defined(OS_ANDROID)
377 NOTIMPLEMENTED();
378 return NULL;
379 #else
380 if (!media_file_system_registry_)
381 media_file_system_registry_.reset(new MediaFileSystemRegistry());
382 return media_file_system_registry_.get();
383 #endif
386 bool TestingBrowserProcess::created_local_state() const {
387 return (local_state_ != NULL);
390 #if defined(ENABLE_WEBRTC)
391 WebRtcLogUploader* TestingBrowserProcess::webrtc_log_uploader() {
392 return NULL;
394 #endif
396 void TestingBrowserProcess::SetBookmarkPromptController(
397 BookmarkPromptController* controller) {
398 #if !defined(OS_IOS)
399 bookmark_prompt_controller_.reset(controller);
400 #endif
403 void TestingBrowserProcess::SetSystemRequestContext(
404 net::URLRequestContextGetter* context_getter) {
405 system_request_context_ = context_getter;
408 void TestingBrowserProcess::SetLocalState(PrefService* local_state) {
409 if (!local_state) {
410 // The local_state_ PrefService is owned outside of TestingBrowserProcess,
411 // but some of the members of TestingBrowserProcess hold references to it
412 // (for example, via PrefNotifier members). But given our test
413 // infrastructure which tears down individual tests before freeing the
414 // TestingBrowserProcess, there's not a good way to make local_state outlive
415 // these dependencies. As a workaround, whenever local_state_ is cleared
416 // (assumedly as part of exiting the test and freeing TestingBrowserProcess)
417 // any components owned by TestingBrowserProcess that depend on local_state
418 // are also freed.
419 #if !defined(OS_IOS)
420 notification_ui_manager_.reset();
421 #endif
422 #if defined(ENABLE_CONFIGURATION_POLICY)
423 SetBrowserPolicyConnector(NULL);
424 #endif
426 local_state_ = local_state;
429 void TestingBrowserProcess::SetIOThread(IOThread* io_thread) {
430 io_thread_ = io_thread;
433 void TestingBrowserProcess::SetBrowserPolicyConnector(
434 policy::BrowserPolicyConnector* connector) {
435 #if defined(ENABLE_CONFIGURATION_POLICY)
436 if (browser_policy_connector_) {
437 browser_policy_connector_->Shutdown();
439 browser_policy_connector_.reset(connector);
440 #else
441 CHECK(false);
442 #endif
445 void TestingBrowserProcess::SetSafeBrowsingService(
446 SafeBrowsingService* sb_service) {
447 #if !defined(OS_IOS)
448 NOTIMPLEMENTED();
449 sb_service_ = sb_service;
450 #endif
453 void TestingBrowserProcess::SetStorageMonitor(
454 scoped_ptr<StorageMonitor> storage_monitor) {
455 #if !defined(OS_IOS) && !defined(OS_ANDROID)
456 storage_monitor_ = storage_monitor.Pass();
457 #endif
460 ///////////////////////////////////////////////////////////////////////////////
462 TestingBrowserProcessInitializer::TestingBrowserProcessInitializer() {
463 TestingBrowserProcess::CreateInstance();
466 TestingBrowserProcessInitializer::~TestingBrowserProcessInitializer() {
467 TestingBrowserProcess::DeleteInstance();