Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / test / base / testing_browser_process.h
blob090689730f38baa870942d041c94a738d6e85187
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 // An implementation of BrowserProcess for unit tests that fails for most
6 // services. By preventing creation of services, we reduce dependencies and
7 // keep the profile clean. Clients of this class must handle the NULL return
8 // value, however.
10 #ifndef CHROME_TEST_BASE_TESTING_BROWSER_PROCESS_H_
11 #define CHROME_TEST_BASE_TESTING_BROWSER_PROCESS_H_
13 #include <string>
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "build/build_config.h"
18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/browser_process_platform_part.h"
21 class BackgroundModeManager;
22 class CRLSetFetcher;
23 class IOThread;
24 class MHTMLGenerationManager;
25 class NotificationUIManager;
26 class PrefService;
27 class WatchDogThread;
29 namespace content {
30 class NotificationService;
33 namespace extensions {
34 class ExtensionsBrowserClient;
37 namespace gcm {
38 class GCMDriver;
41 namespace policy {
42 class BrowserPolicyConnector;
43 class PolicyService;
46 class TestingBrowserProcess : public BrowserProcess {
47 public:
48 // Initializes |g_browser_process| with a new TestingBrowserProcess.
49 static void CreateInstance();
51 // Cleanly destroys |g_browser_process|, which has special deletion semantics.
52 static void DeleteInstance();
54 // Convenience method to get g_browser_process as a TestingBrowserProcess*.
55 static TestingBrowserProcess* GetGlobal();
57 void ResourceDispatcherHostCreated() override;
58 void EndSession() override;
59 MetricsServicesManager* GetMetricsServicesManager() override;
60 metrics::MetricsService* metrics_service() override;
61 rappor::RapporService* rappor_service() override;
62 IOThread* io_thread() override;
63 WatchDogThread* watchdog_thread() override;
64 ProfileManager* profile_manager() override;
65 PrefService* local_state() override;
66 chrome_variations::VariationsService* variations_service() override;
67 PromoResourceService* promo_resource_service() override;
68 policy::BrowserPolicyConnector* browser_policy_connector() override;
69 policy::PolicyService* policy_service() override;
70 IconManager* icon_manager() override;
71 GLStringManager* gl_string_manager() override;
72 GpuModeManager* gpu_mode_manager() override;
73 BackgroundModeManager* background_mode_manager() override;
74 void set_background_mode_manager_for_test(
75 scoped_ptr<BackgroundModeManager> manager) override;
76 StatusTray* status_tray() override;
77 SafeBrowsingService* safe_browsing_service() override;
78 safe_browsing::ClientSideDetectionService* safe_browsing_detection_service()
79 override;
80 net::URLRequestContextGetter* system_request_context() override;
81 BrowserProcessPlatformPart* platform_part() override;
83 extensions::EventRouterForwarder* extension_event_router_forwarder() override;
84 NotificationUIManager* notification_ui_manager() override;
85 message_center::MessageCenter* message_center() override;
86 IntranetRedirectDetector* intranet_redirect_detector() override;
87 void CreateDevToolsHttpProtocolHandler(
88 chrome::HostDesktopType host_desktop_type,
89 const std::string& ip,
90 uint16 port) override;
91 unsigned int AddRefModule() override;
92 unsigned int ReleaseModule() override;
93 bool IsShuttingDown() override;
94 printing::PrintJobManager* print_job_manager() override;
95 printing::PrintPreviewDialogController* print_preview_dialog_controller()
96 override;
97 printing::BackgroundPrintingManager* background_printing_manager() override;
98 const std::string& GetApplicationLocale() override;
99 void SetApplicationLocale(const std::string& app_locale) override;
100 DownloadStatusUpdater* download_status_updater() override;
101 DownloadRequestLimiter* download_request_limiter() override;
103 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
104 void StartAutoupdateTimer() override {}
105 #endif
107 ChromeNetLog* net_log() override;
108 component_updater::ComponentUpdateService* component_updater() override;
109 CRLSetFetcher* crl_set_fetcher() override;
110 component_updater::PnaclComponentInstaller* pnacl_component_installer()
111 override;
112 component_updater::SupervisedUserWhitelistInstaller*
113 supervised_user_whitelist_installer() override;
114 MediaFileSystemRegistry* media_file_system_registry() override;
115 bool created_local_state() const override;
117 #if defined(ENABLE_WEBRTC)
118 WebRtcLogUploader* webrtc_log_uploader() override;
119 #endif
121 network_time::NetworkTimeTracker* network_time_tracker() override;
123 gcm::GCMDriver* gcm_driver() override;
125 // Set the local state for tests. Consumer is responsible for cleaning it up
126 // afterwards (using ScopedTestingLocalState, for example).
127 void SetLocalState(PrefService* local_state);
128 void SetProfileManager(ProfileManager* profile_manager);
129 void SetIOThread(IOThread* io_thread);
130 void SetBrowserPolicyConnector(policy::BrowserPolicyConnector* connector);
131 void SetSafeBrowsingService(SafeBrowsingService* sb_service);
132 void SetSystemRequestContext(net::URLRequestContextGetter* context_getter);
134 private:
135 // See CreateInstance() and DestoryInstance() above.
136 TestingBrowserProcess();
137 ~TestingBrowserProcess() override;
139 scoped_ptr<content::NotificationService> notification_service_;
140 unsigned int module_ref_count_;
141 std::string app_locale_;
143 // TODO(ios): Add back members as more code is compiled.
144 #if !defined(OS_IOS)
145 #if defined(ENABLE_CONFIGURATION_POLICY)
146 scoped_ptr<policy::BrowserPolicyConnector> browser_policy_connector_;
147 #else
148 scoped_ptr<policy::PolicyService> policy_service_;
149 #endif
150 scoped_ptr<ProfileManager> profile_manager_;
151 scoped_ptr<NotificationUIManager> notification_ui_manager_;
153 #if defined(ENABLE_PRINTING)
154 scoped_ptr<printing::PrintJobManager> print_job_manager_;
155 #endif
157 #if defined(ENABLE_PRINT_PREVIEW)
158 scoped_ptr<printing::BackgroundPrintingManager> background_printing_manager_;
159 scoped_refptr<printing::PrintPreviewDialogController>
160 print_preview_dialog_controller_;
161 #endif
163 scoped_refptr<SafeBrowsingService> sb_service_;
164 #endif // !defined(OS_IOS)
166 scoped_ptr<network_time::NetworkTimeTracker> network_time_tracker_;
168 // The following objects are not owned by TestingBrowserProcess:
169 PrefService* local_state_;
170 IOThread* io_thread_;
171 net::URLRequestContextGetter* system_request_context_;
173 scoped_ptr<BrowserProcessPlatformPart> platform_part_;
175 #if defined(ENABLE_EXTENSIONS)
176 scoped_ptr<MediaFileSystemRegistry> media_file_system_registry_;
178 scoped_ptr<extensions::ExtensionsBrowserClient> extensions_browser_client_;
179 #endif
181 DISALLOW_COPY_AND_ASSIGN(TestingBrowserProcess);
184 // RAII (resource acquisition is initialization) for TestingBrowserProcess.
185 // Allows you to initialize TestingBrowserProcess/NotificationService before
186 // other member variables.
188 // This can be helpful if you are running a unit test inside the browser_tests
189 // suite because browser_tests do not make a TestingBrowserProcess for you.
191 // class MyUnitTestRunningAsBrowserTest : public testing::Test {
192 // ...stuff...
193 // private:
194 // TestingBrowserProcessInitializer initializer_;
195 // LocalState local_state_; // Needs a BrowserProcess to initialize.
196 // NotificationRegistrar registar_; // Needs NotificationService.
197 // };
198 class TestingBrowserProcessInitializer {
199 public:
200 TestingBrowserProcessInitializer();
201 ~TestingBrowserProcessInitializer();
203 private:
204 DISALLOW_COPY_AND_ASSIGN(TestingBrowserProcessInitializer);
207 #endif // CHROME_TEST_BASE_TESTING_BROWSER_PROCESS_H_