Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1778)

Side by Side Diff: headless/lib/browser/headless_browser_context_impl.cc

Issue 2043603004: headless: Introduce a browser context (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "headless/lib/browser/headless_browser_context.h" 5 #include "headless/lib/browser/headless_browser_context_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h"
9 #include "base/path_service.h" 10 #include "base/path_service.h"
10 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/resource_context.h" 12 #include "content/public/browser/resource_context.h"
12 #include "content/public/browser/storage_partition.h" 13 #include "content/public/browser/storage_partition.h"
14 #include "headless/lib/browser/headless_browser_impl.h"
13 #include "headless/lib/browser/headless_url_request_context_getter.h" 15 #include "headless/lib/browser/headless_url_request_context_getter.h"
14 #include "net/url_request/url_request_context.h" 16 #include "net/url_request/url_request_context.h"
15 17
16 namespace headless { 18 namespace headless {
17 19
18 // Contains net::URLRequestContextGetter required for resource loading. 20 // Contains net::URLRequestContextGetter required for resource loading.
19 // Must be destructed on the IO thread as per content::ResourceContext 21 // Must be destructed on the IO thread as per content::ResourceContext
20 // requirements. 22 // requirements.
21 class HeadlessResourceContext : public content::ResourceContext { 23 class HeadlessResourceContext : public content::ResourceContext {
22 public: 24 public:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 net::HostResolver* HeadlessResourceContext::GetHostResolver() { 59 net::HostResolver* HeadlessResourceContext::GetHostResolver() {
58 CHECK(url_request_context_getter_); 60 CHECK(url_request_context_getter_);
59 return url_request_context_getter_->GetURLRequestContext()->host_resolver(); 61 return url_request_context_getter_->GetURLRequestContext()->host_resolver();
60 } 62 }
61 63
62 net::URLRequestContext* HeadlessResourceContext::GetRequestContext() { 64 net::URLRequestContext* HeadlessResourceContext::GetRequestContext() {
63 CHECK(url_request_context_getter_); 65 CHECK(url_request_context_getter_);
64 return url_request_context_getter_->GetURLRequestContext(); 66 return url_request_context_getter_->GetURLRequestContext();
65 } 67 }
66 68
67 HeadlessBrowserContext::HeadlessBrowserContext( 69 HeadlessBrowserContextImpl::HeadlessBrowserContextImpl(
68 HeadlessBrowser::Options* options) 70 HeadlessBrowser::Options* options)
69 : resource_context_(new HeadlessResourceContext), options_(options) { 71 : resource_context_(new HeadlessResourceContext), options_(options) {
70 InitWhileIOAllowed(); 72 InitWhileIOAllowed();
71 } 73 }
72 74
73 HeadlessBrowserContext::~HeadlessBrowserContext() { 75 HeadlessBrowserContextImpl::~HeadlessBrowserContextImpl() {
74 if (resource_context_) { 76 if (resource_context_) {
75 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, 77 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
76 resource_context_.release()); 78 resource_context_.release());
77 } 79 }
78 } 80 }
79 81
80 void HeadlessBrowserContext::InitWhileIOAllowed() { 82 // static
83 HeadlessBrowserContextImpl* HeadlessBrowserContextImpl::From(
84 HeadlessBrowserContext* browser_context) {
85 return reinterpret_cast<HeadlessBrowserContextImpl*>(browser_context);
86 }
87
88 void HeadlessBrowserContextImpl::InitWhileIOAllowed() {
81 // TODO(skyostil): Allow the embedder to override this. 89 // TODO(skyostil): Allow the embedder to override this.
82 PathService::Get(base::DIR_EXE, &path_); 90 PathService::Get(base::DIR_EXE, &path_);
83 BrowserContext::Initialize(this, path_); 91 BrowserContext::Initialize(this, path_);
84 } 92 }
85 93
86 std::unique_ptr<content::ZoomLevelDelegate> 94 std::unique_ptr<content::ZoomLevelDelegate>
87 HeadlessBrowserContext::CreateZoomLevelDelegate( 95 HeadlessBrowserContextImpl::CreateZoomLevelDelegate(
88 const base::FilePath& partition_path) { 96 const base::FilePath& partition_path) {
89 return std::unique_ptr<content::ZoomLevelDelegate>(); 97 return std::unique_ptr<content::ZoomLevelDelegate>();
90 } 98 }
91 99
92 base::FilePath HeadlessBrowserContext::GetPath() const { 100 base::FilePath HeadlessBrowserContextImpl::GetPath() const {
93 return path_; 101 return path_;
94 } 102 }
95 103
96 bool HeadlessBrowserContext::IsOffTheRecord() const { 104 bool HeadlessBrowserContextImpl::IsOffTheRecord() const {
97 return false; 105 return false;
98 } 106 }
99 107
100 content::ResourceContext* HeadlessBrowserContext::GetResourceContext() { 108 content::ResourceContext* HeadlessBrowserContextImpl::GetResourceContext() {
101 return resource_context_.get(); 109 return resource_context_.get();
102 } 110 }
103 111
104 content::DownloadManagerDelegate* 112 content::DownloadManagerDelegate*
105 HeadlessBrowserContext::GetDownloadManagerDelegate() { 113 HeadlessBrowserContextImpl::GetDownloadManagerDelegate() {
106 return nullptr; 114 return nullptr;
107 } 115 }
108 116
109 content::BrowserPluginGuestManager* HeadlessBrowserContext::GetGuestManager() { 117 content::BrowserPluginGuestManager*
118 HeadlessBrowserContextImpl::GetGuestManager() {
110 // TODO(altimin): Should be non-null? (is null in content/shell). 119 // TODO(altimin): Should be non-null? (is null in content/shell).
111 return nullptr; 120 return nullptr;
112 } 121 }
113 122
114 storage::SpecialStoragePolicy* 123 storage::SpecialStoragePolicy*
115 HeadlessBrowserContext::GetSpecialStoragePolicy() { 124 HeadlessBrowserContextImpl::GetSpecialStoragePolicy() {
116 return nullptr; 125 return nullptr;
117 } 126 }
118 127
119 content::PushMessagingService* 128 content::PushMessagingService*
120 HeadlessBrowserContext::GetPushMessagingService() { 129 HeadlessBrowserContextImpl::GetPushMessagingService() {
121 return nullptr; 130 return nullptr;
122 } 131 }
123 132
124 content::SSLHostStateDelegate* 133 content::SSLHostStateDelegate*
125 HeadlessBrowserContext::GetSSLHostStateDelegate() { 134 HeadlessBrowserContextImpl::GetSSLHostStateDelegate() {
126 return nullptr; 135 return nullptr;
127 } 136 }
128 137
129 content::PermissionManager* HeadlessBrowserContext::GetPermissionManager() { 138 content::PermissionManager* HeadlessBrowserContextImpl::GetPermissionManager() {
130 return nullptr; 139 return nullptr;
131 } 140 }
132 141
133 content::BackgroundSyncController* 142 content::BackgroundSyncController*
134 HeadlessBrowserContext::GetBackgroundSyncController() { 143 HeadlessBrowserContextImpl::GetBackgroundSyncController() {
135 return nullptr; 144 return nullptr;
136 } 145 }
137 146
138 net::URLRequestContextGetter* HeadlessBrowserContext::CreateRequestContext( 147 net::URLRequestContextGetter* HeadlessBrowserContextImpl::CreateRequestContext(
139 content::ProtocolHandlerMap* protocol_handlers, 148 content::ProtocolHandlerMap* protocol_handlers,
140 content::URLRequestInterceptorScopedVector request_interceptors) { 149 content::URLRequestInterceptorScopedVector request_interceptors) {
141 scoped_refptr<HeadlessURLRequestContextGetter> url_request_context_getter( 150 scoped_refptr<HeadlessURLRequestContextGetter> url_request_context_getter(
142 new HeadlessURLRequestContextGetter( 151 new HeadlessURLRequestContextGetter(
143 content::BrowserThread::GetMessageLoopProxyForThread( 152 content::BrowserThread::GetMessageLoopProxyForThread(
144 content::BrowserThread::IO), 153 content::BrowserThread::IO),
145 content::BrowserThread::GetMessageLoopProxyForThread( 154 content::BrowserThread::GetMessageLoopProxyForThread(
146 content::BrowserThread::FILE), 155 content::BrowserThread::FILE),
147 protocol_handlers, std::move(request_interceptors), options())); 156 protocol_handlers, std::move(request_interceptors), options()));
148 resource_context_->set_url_request_context_getter(url_request_context_getter); 157 resource_context_->set_url_request_context_getter(url_request_context_getter);
149 return url_request_context_getter.get(); 158 return url_request_context_getter.get();
150 } 159 }
151 160
152 net::URLRequestContextGetter* 161 net::URLRequestContextGetter*
153 HeadlessBrowserContext::CreateRequestContextForStoragePartition( 162 HeadlessBrowserContextImpl::CreateRequestContextForStoragePartition(
154 const base::FilePath& partition_path, 163 const base::FilePath& partition_path,
155 bool in_memory, 164 bool in_memory,
156 content::ProtocolHandlerMap* protocol_handlers, 165 content::ProtocolHandlerMap* protocol_handlers,
157 content::URLRequestInterceptorScopedVector request_interceptors) { 166 content::URLRequestInterceptorScopedVector request_interceptors) {
158 return nullptr; 167 return nullptr;
159 } 168 }
160 169
161 net::URLRequestContextGetter* 170 net::URLRequestContextGetter*
162 HeadlessBrowserContext::CreateMediaRequestContext() { 171 HeadlessBrowserContextImpl::CreateMediaRequestContext() {
163 return resource_context_->url_request_context_getter(); 172 return resource_context_->url_request_context_getter();
164 } 173 }
165 174
166 net::URLRequestContextGetter* 175 net::URLRequestContextGetter*
167 HeadlessBrowserContext::CreateMediaRequestContextForStoragePartition( 176 HeadlessBrowserContextImpl::CreateMediaRequestContextForStoragePartition(
168 const base::FilePath& partition_path, 177 const base::FilePath& partition_path,
169 bool in_memory) { 178 bool in_memory) {
170 return nullptr; 179 return nullptr;
171 } 180 }
172 181
173 void HeadlessBrowserContext::SetOptionsForTesting( 182 void HeadlessBrowserContextImpl::SetOptionsForTesting(
174 HeadlessBrowser::Options* options) { 183 HeadlessBrowser::Options* options) {
175 options_ = options; 184 options_ = options;
176 } 185 }
177 186
187 HeadlessBrowserContext::Builder::Builder(HeadlessBrowserImpl* browser)
188 : browser_(browser) {}
189
190 HeadlessBrowserContext::Builder::~Builder() = default;
191
192 HeadlessBrowserContext::Builder::Builder(Builder&&) = default;
193
194 std::unique_ptr<HeadlessBrowserContext>
195 HeadlessBrowserContext::Builder::Build() {
196 return base::WrapUnique(new HeadlessBrowserContextImpl(browser_->options()));
197 }
198
178 } // namespace headless 199 } // namespace headless
OLDNEW
« no previous file with comments | « headless/lib/browser/headless_browser_context_impl.h ('k') | headless/lib/browser/headless_browser_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698