Use "= delete" for DISALLOW_COPY and DISALLOW_ASSIGN.
[chromium-blink-merge.git] / content / shell / browser / shell_browser_context.cc
blobb81ae1c6b1537ff35c794338679faa5ac6e81f05
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/browser/shell_permission_manager.h"
19 #include "content/shell/common/shell_switches.h"
21 #if defined(OS_WIN)
22 #include "base/base_paths_win.h"
23 #elif defined(OS_LINUX)
24 #include "base/nix/xdg_util.h"
25 #elif defined(OS_MACOSX)
26 #include "base/base_paths_mac.h"
27 #endif
29 namespace content {
31 ShellBrowserContext::ShellResourceContext::ShellResourceContext()
32 : getter_(NULL) {
35 ShellBrowserContext::ShellResourceContext::~ShellResourceContext() {
38 net::HostResolver*
39 ShellBrowserContext::ShellResourceContext::GetHostResolver() {
40 CHECK(getter_);
41 return getter_->host_resolver();
44 net::URLRequestContext*
45 ShellBrowserContext::ShellResourceContext::GetRequestContext() {
46 CHECK(getter_);
47 return getter_->GetURLRequestContext();
50 ShellBrowserContext::ShellBrowserContext(bool off_the_record,
51 net::NetLog* net_log)
52 : resource_context_(new ShellResourceContext),
53 ignore_certificate_errors_(false),
54 off_the_record_(off_the_record),
55 net_log_(net_log),
56 guest_manager_(NULL) {
57 InitWhileIOAllowed();
60 ShellBrowserContext::~ShellBrowserContext() {
61 if (resource_context_) {
62 BrowserThread::DeleteSoon(
63 BrowserThread::IO, FROM_HERE, resource_context_.release());
67 void ShellBrowserContext::InitWhileIOAllowed() {
68 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
69 if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors))
70 ignore_certificate_errors_ = true;
71 if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
72 path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
73 return;
75 #if defined(OS_WIN)
76 CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
77 path_ = path_.Append(std::wstring(L"content_shell"));
78 #elif defined(OS_LINUX)
79 scoped_ptr<base::Environment> env(base::Environment::Create());
80 base::FilePath config_dir(
81 base::nix::GetXDGDirectory(env.get(),
82 base::nix::kXdgConfigHomeEnvVar,
83 base::nix::kDotConfigDir));
84 path_ = config_dir.Append("content_shell");
85 #elif defined(OS_MACOSX)
86 CHECK(PathService::Get(base::DIR_APP_DATA, &path_));
87 path_ = path_.Append("Chromium Content Shell");
88 #elif defined(OS_ANDROID)
89 CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path_));
90 path_ = path_.Append(FILE_PATH_LITERAL("content_shell"));
91 #else
92 NOTIMPLEMENTED();
93 #endif
95 if (!base::PathExists(path_))
96 base::CreateDirectory(path_);
99 scoped_ptr<ZoomLevelDelegate> ShellBrowserContext::CreateZoomLevelDelegate(
100 const base::FilePath&) {
101 return scoped_ptr<ZoomLevelDelegate>();
104 base::FilePath ShellBrowserContext::GetPath() const {
105 return path_;
108 bool ShellBrowserContext::IsOffTheRecord() const {
109 return off_the_record_;
112 DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
113 if (!download_manager_delegate_.get()) {
114 download_manager_delegate_.reset(new ShellDownloadManagerDelegate());
115 download_manager_delegate_->SetDownloadManager(
116 BrowserContext::GetDownloadManager(this));
119 return download_manager_delegate_.get();
122 net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() {
123 return GetDefaultStoragePartition(this)->GetURLRequestContext();
126 ShellURLRequestContextGetter*
127 ShellBrowserContext::CreateURLRequestContextGetter(
128 ProtocolHandlerMap* protocol_handlers,
129 URLRequestInterceptorScopedVector request_interceptors) {
130 return new ShellURLRequestContextGetter(
131 ignore_certificate_errors_,
132 GetPath(),
133 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
134 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE),
135 protocol_handlers,
136 request_interceptors.Pass(),
137 net_log_);
140 net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
141 ProtocolHandlerMap* protocol_handlers,
142 URLRequestInterceptorScopedVector request_interceptors) {
143 DCHECK(!url_request_getter_.get());
144 url_request_getter_ = CreateURLRequestContextGetter(
145 protocol_handlers, request_interceptors.Pass());
146 resource_context_->set_url_request_context_getter(url_request_getter_.get());
147 return url_request_getter_.get();
150 net::URLRequestContextGetter*
151 ShellBrowserContext::GetRequestContextForRenderProcess(
152 int renderer_child_id) {
153 return GetRequestContext();
156 net::URLRequestContextGetter*
157 ShellBrowserContext::GetMediaRequestContext() {
158 return GetRequestContext();
161 net::URLRequestContextGetter*
162 ShellBrowserContext::GetMediaRequestContextForRenderProcess(
163 int renderer_child_id) {
164 return GetRequestContext();
167 net::URLRequestContextGetter*
168 ShellBrowserContext::GetMediaRequestContextForStoragePartition(
169 const base::FilePath& partition_path,
170 bool in_memory) {
171 return GetRequestContext();
174 net::URLRequestContextGetter*
175 ShellBrowserContext::CreateRequestContextForStoragePartition(
176 const base::FilePath& partition_path,
177 bool in_memory,
178 ProtocolHandlerMap* protocol_handlers,
179 URLRequestInterceptorScopedVector request_interceptors) {
180 return NULL;
183 ResourceContext* ShellBrowserContext::GetResourceContext() {
184 return resource_context_.get();
187 BrowserPluginGuestManager* ShellBrowserContext::GetGuestManager() {
188 return guest_manager_;
191 storage::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
192 return NULL;
195 PushMessagingService* ShellBrowserContext::GetPushMessagingService() {
196 return NULL;
199 SSLHostStateDelegate* ShellBrowserContext::GetSSLHostStateDelegate() {
200 return NULL;
203 PermissionManager* ShellBrowserContext::GetPermissionManager() {
204 if (!permission_manager_.get())
205 permission_manager_.reset(new ShellPermissionManager());
206 return permission_manager_.get();
209 } // namespace content