summaryrefslogtreecommitdiffstats
path: root/chrome/test/testing_browser_process.h
blob: d544f820ec8e18f9b8a700d5b69ff78ed80314c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// An implementation of BrowserProcess for unit tests that fails for most
// services. By preventing creation of services, we reduce dependencies and
// keep the profile clean. Clients of this class must handle the NULL return
// value, however.

#ifndef CHROME_TEST_TESTING_BROWSER_PROCESS_H_
#define CHROME_TEST_TESTING_BROWSER_PROCESS_H_
#pragma once

#include "build/build_config.h"

#include <string>

#include "base/scoped_ptr.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/notification_service.h"

class IOThread;
class GoogleURLTracker;
class PrefService;

namespace base {
class WaitableEvent;
}

namespace policy {
class BrowserPolicyConnector;
}

namespace ui {
class Clipboard;
}

class TestingBrowserProcess : public BrowserProcess {
 public:
  TestingBrowserProcess();
  virtual ~TestingBrowserProcess();

  virtual void EndSession();

  virtual ResourceDispatcherHost* resource_dispatcher_host();

  virtual MetricsService* metrics_service();

  virtual IOThread* io_thread();

#if defined(OS_LINUX)
  virtual base::Thread* background_x11_thread();
#endif

  virtual base::Thread* file_thread();

  virtual base::Thread* db_thread();

  virtual base::Thread* cache_thread();

  virtual ProfileManager* profile_manager();

  virtual PrefService* local_state();

  virtual policy::BrowserPolicyConnector* browser_policy_connector();

  virtual IconManager* icon_manager();

  virtual ThumbnailGenerator* GetThumbnailGenerator();

  virtual DevToolsManager* devtools_manager();

  virtual SidebarManager* sidebar_manager();

  virtual TabCloseableStateWatcher* tab_closeable_state_watcher();

  virtual safe_browsing::ClientSideDetectionService*
      safe_browsing_detection_service();

  virtual ui::Clipboard* clipboard();

  virtual NotificationUIManager* notification_ui_manager();

  virtual GoogleURLTracker* google_url_tracker();

  virtual IntranetRedirectDetector* intranet_redirect_detector();

  virtual AutomationProviderList* InitAutomationProviderList();

  virtual void InitDevToolsHttpProtocolHandler(
      const std::string& ip,
      int port,
      const std::string& frontend_url);

  virtual void InitDevToolsLegacyProtocolHandler(int port);

  virtual unsigned int AddRefModule();
  virtual unsigned int ReleaseModule();

  virtual bool IsShuttingDown();

  virtual printing::PrintJobManager* print_job_manager();

  virtual printing::PrintPreviewTabController* print_preview_tab_controller();

  virtual const std::string& GetApplicationLocale();

  virtual void SetApplicationLocale(const std::string& app_locale);

  virtual DownloadStatusUpdater* download_status_updater();

  virtual base::WaitableEvent* shutdown_event();

  virtual bool plugin_finder_disabled() const;

  virtual void CheckForInspectorFiles() {}

#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
  virtual void StartAutoupdateTimer() {}
#endif

  virtual bool have_inspector_files() const;

  virtual ChromeNetLog* net_log();

#if defined(IPC_MESSAGE_LOG_ENABLED)
  virtual void SetIPCLoggingEnabled(bool enable) {}
#endif

  void SetPrefService(PrefService* pref_service);
  void SetGoogleURLTracker(GoogleURLTracker* google_url_tracker);
  void SetProfileManager(ProfileManager* profile_manager);

 private:
  NotificationService notification_service_;
  scoped_ptr<base::WaitableEvent> shutdown_event_;
  unsigned int module_ref_count_;
  scoped_ptr<ui::Clipboard> clipboard_;
  std::string app_locale_;

  PrefService* pref_service_;
  scoped_ptr<policy::BrowserPolicyConnector> browser_policy_connector_;
  scoped_ptr<GoogleURLTracker> google_url_tracker_;
  scoped_ptr<ProfileManager> profile_manager_;

  DISALLOW_COPY_AND_ASSIGN(TestingBrowserProcess);
};

// Scoper to put a TestingBrowserProcess in |g_browser_process|.
class ScopedTestingBrowserProcess {
 public:
  ScopedTestingBrowserProcess();
  ~ScopedTestingBrowserProcess();

  TestingBrowserProcess* get() {
    return browser_process_.get();
  }

 private:
  // TODO(phajdan.jr): Temporary, for http://crbug.com/61062.
  // After the transition is over, we should just stack-allocate it.
  scoped_ptr<TestingBrowserProcess> browser_process_;

  DISALLOW_COPY_AND_ASSIGN(ScopedTestingBrowserProcess);
};

#endif  // CHROME_TEST_TESTING_BROWSER_PROCESS_H_