Introduce the PlatformNotificationContext class.
[chromium-blink-merge.git] / content / shell / browser / shell_browser_context.cc
blobd8b895e8bb85481398ca41772c864d1dee223c87
1 // Copyright 2013 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 "content/shell/browser/shell_browser_context.h"
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/environment.h"
10 #include "base/files/file_util.h"
11 #include "base/logging.h"
12 #include "base/path_service.h"
13 #include "base/threading/thread.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/storage_partition.h"
16 #include "content/public/common/content_switches.h"
17 #include "content/shell/browser/shell_download_manager_delegate.h"
18 #include "content/shell/common/shell_switches.h"
20 #if defined(OS_WIN)
21 #include "base/base_paths_win.h"
22 #elif defined(OS_LINUX)
23 #include "base/nix/xdg_util.h"
24 #elif defined(OS_MACOSX)
25 #include "base/base_paths_mac.h"
26 #endif
28 namespace content {
30 ShellBrowserContext::ShellResourceContext::ShellResourceContext()
31 : getter_(NULL) {
34 ShellBrowserContext::ShellResourceContext::~ShellResourceContext() {
37 net::HostResolver*
38 ShellBrowserContext::ShellResourceContext::GetHostResolver() {
39 CHECK(getter_);
40 return getter_->host_resolver();
43 net::URLRequestContext*
44 ShellBrowserContext::ShellResourceContext::GetRequestContext() {
45 CHECK(getter_);
46 return getter_->GetURLRequestContext();
49 ShellBrowserContext::ShellBrowserContext(bool off_the_record,
50 net::NetLog* net_log)
51 : resource_context_(new ShellResourceContext),
52 ignore_certificate_errors_(false),
53 off_the_record_(off_the_record),
54 net_log_(net_log),
55 guest_manager_(NULL) {
56 InitWhileIOAllowed();
59 ShellBrowserContext::~ShellBrowserContext() {
60 if (resource_context_) {
61 BrowserThread::DeleteSoon(
62 BrowserThread::IO, FROM_HERE, resource_context_.release());
66 void ShellBrowserContext::InitWhileIOAllowed() {
67 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
68 if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors))
69 ignore_certificate_errors_ = true;
70 if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
71 path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
72 return;
74 #if defined(OS_WIN)
75 CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
76 path_ = path_.Append(std::wstring(L"content_shell"));
77 #elif defined(OS_LINUX)
78 scoped_ptr<base::Environment> env(base::Environment::Create());
79 base::FilePath config_dir(
80 base::nix::GetXDGDirectory(env.get(),
81 base::nix::kXdgConfigHomeEnvVar,
82 base::nix::kDotConfigDir));
83 path_ = config_dir.Append("content_shell");
84 #elif defined(OS_MACOSX)
85 CHECK(PathService::Get(base::DIR_APP_DATA, &path_));
86 path_ = path_.Append("Chromium Content Shell");
87 #elif defined(OS_ANDROID)
88 CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path_));
89 path_ = path_.Append(FILE_PATH_LITERAL("content_shell"));
90 #else
91 NOTIMPLEMENTED();
92 #endif
94 if (!base::PathExists(path_))
95 base::CreateDirectory(path_);
98 scoped_ptr<ZoomLevelDelegate> ShellBrowserContext::CreateZoomLevelDelegate(
99 const base::FilePath&) {
100 return scoped_ptr<ZoomLevelDelegate>();
103 base::FilePath ShellBrowserContext::GetPath() const {
104 return path_;
107 bool ShellBrowserContext::IsOffTheRecord() const {
108 return off_the_record_;
111 DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
112 if (!download_manager_delegate_.get()) {
113 download_manager_delegate_.reset(new ShellDownloadManagerDelegate());
114 download_manager_delegate_->SetDownloadManager(
115 BrowserContext::GetDownloadManager(this));
118 return download_manager_delegate_.get();
121 net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() {
122 return GetDefaultStoragePartition(this)->GetURLRequestContext();
125 ShellURLRequestContextGetter*
126 ShellBrowserContext::CreateURLRequestContextGetter(
127 ProtocolHandlerMap* protocol_handlers,
128 URLRequestInterceptorScopedVector request_interceptors) {
129 return new ShellURLRequestContextGetter(
130 ignore_certificate_errors_,
131 GetPath(),
132 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
133 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE),
134 protocol_handlers,
135 request_interceptors.Pass(),
136 net_log_);
139 net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
140 ProtocolHandlerMap* protocol_handlers,
141 URLRequestInterceptorScopedVector request_interceptors) {
142 DCHECK(!url_request_getter_.get());
143 url_request_getter_ = CreateURLRequestContextGetter(
144 protocol_handlers, request_interceptors.Pass());
145 resource_context_->set_url_request_context_getter(url_request_getter_.get());
146 return url_request_getter_.get();
149 net::URLRequestContextGetter*
150 ShellBrowserContext::GetRequestContextForRenderProcess(
151 int renderer_child_id) {
152 return GetRequestContext();
155 net::URLRequestContextGetter*
156 ShellBrowserContext::GetMediaRequestContext() {
157 return GetRequestContext();
160 net::URLRequestContextGetter*
161 ShellBrowserContext::GetMediaRequestContextForRenderProcess(
162 int renderer_child_id) {
163 return GetRequestContext();
166 net::URLRequestContextGetter*
167 ShellBrowserContext::GetMediaRequestContextForStoragePartition(
168 const base::FilePath& partition_path,
169 bool in_memory) {
170 return GetRequestContext();
173 net::URLRequestContextGetter*
174 ShellBrowserContext::CreateRequestContextForStoragePartition(
175 const base::FilePath& partition_path,
176 bool in_memory,
177 ProtocolHandlerMap* protocol_handlers,
178 URLRequestInterceptorScopedVector request_interceptors) {
179 return NULL;
182 ResourceContext* ShellBrowserContext::GetResourceContext() {
183 return resource_context_.get();
186 BrowserPluginGuestManager* ShellBrowserContext::GetGuestManager() {
187 return guest_manager_;
190 storage::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
191 return NULL;
194 PushMessagingService* ShellBrowserContext::GetPushMessagingService() {
195 return NULL;
198 SSLHostStateDelegate* ShellBrowserContext::GetSSLHostStateDelegate() {
199 return NULL;
202 } // namespace content