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

Side by Side Diff: headless/lib/browser/headless_browser_context.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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "headless/lib/browser/headless_browser_context.h"
6
7 #include <memory>
8
9 #include "base/path_service.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/resource_context.h"
12 #include "content/public/browser/storage_partition.h"
13 #include "headless/lib/browser/headless_url_request_context_getter.h"
14 #include "net/url_request/url_request_context.h"
15
16 namespace headless {
17
18 // Contains net::URLRequestContextGetter required for resource loading.
19 // Must be destructed on the IO thread as per content::ResourceContext
20 // requirements.
21 class HeadlessResourceContext : public content::ResourceContext {
22 public:
23 HeadlessResourceContext();
24 ~HeadlessResourceContext() override;
25
26 // ResourceContext implementation:
27 net::HostResolver* GetHostResolver() override;
28 net::URLRequestContext* GetRequestContext() override;
29
30 // Configure the URL request context getter to be used for resource fetching.
31 // Must be called before any of the other methods of this class are used. Must
32 // be called on the browser UI thread.
33 void set_url_request_context_getter(
34 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) {
35 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
36 url_request_context_getter_ = std::move(url_request_context_getter);
37 }
38
39 net::URLRequestContextGetter* url_request_context_getter() {
40 return url_request_context_getter_.get();
41 }
42
43 private:
44 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
45
46 DISALLOW_COPY_AND_ASSIGN(HeadlessResourceContext);
47 };
48
49 HeadlessResourceContext::HeadlessResourceContext() {
50 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
51 }
52
53 HeadlessResourceContext::~HeadlessResourceContext() {
54 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
55 }
56
57 net::HostResolver* HeadlessResourceContext::GetHostResolver() {
58 CHECK(url_request_context_getter_);
59 return url_request_context_getter_->GetURLRequestContext()->host_resolver();
60 }
61
62 net::URLRequestContext* HeadlessResourceContext::GetRequestContext() {
63 CHECK(url_request_context_getter_);
64 return url_request_context_getter_->GetURLRequestContext();
65 }
66
67 HeadlessBrowserContext::HeadlessBrowserContext(
68 HeadlessBrowser::Options* options)
69 : resource_context_(new HeadlessResourceContext), options_(options) {
70 InitWhileIOAllowed();
71 }
72
73 HeadlessBrowserContext::~HeadlessBrowserContext() {
74 if (resource_context_) {
75 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
76 resource_context_.release());
77 }
78 }
79
80 void HeadlessBrowserContext::InitWhileIOAllowed() {
81 // TODO(skyostil): Allow the embedder to override this.
82 PathService::Get(base::DIR_EXE, &path_);
83 BrowserContext::Initialize(this, path_);
84 }
85
86 std::unique_ptr<content::ZoomLevelDelegate>
87 HeadlessBrowserContext::CreateZoomLevelDelegate(
88 const base::FilePath& partition_path) {
89 return std::unique_ptr<content::ZoomLevelDelegate>();
90 }
91
92 base::FilePath HeadlessBrowserContext::GetPath() const {
93 return path_;
94 }
95
96 bool HeadlessBrowserContext::IsOffTheRecord() const {
97 return false;
98 }
99
100 content::ResourceContext* HeadlessBrowserContext::GetResourceContext() {
101 return resource_context_.get();
102 }
103
104 content::DownloadManagerDelegate*
105 HeadlessBrowserContext::GetDownloadManagerDelegate() {
106 return nullptr;
107 }
108
109 content::BrowserPluginGuestManager* HeadlessBrowserContext::GetGuestManager() {
110 // TODO(altimin): Should be non-null? (is null in content/shell).
111 return nullptr;
112 }
113
114 storage::SpecialStoragePolicy*
115 HeadlessBrowserContext::GetSpecialStoragePolicy() {
116 return nullptr;
117 }
118
119 content::PushMessagingService*
120 HeadlessBrowserContext::GetPushMessagingService() {
121 return nullptr;
122 }
123
124 content::SSLHostStateDelegate*
125 HeadlessBrowserContext::GetSSLHostStateDelegate() {
126 return nullptr;
127 }
128
129 content::PermissionManager* HeadlessBrowserContext::GetPermissionManager() {
130 return nullptr;
131 }
132
133 content::BackgroundSyncController*
134 HeadlessBrowserContext::GetBackgroundSyncController() {
135 return nullptr;
136 }
137
138 net::URLRequestContextGetter* HeadlessBrowserContext::CreateRequestContext(
139 content::ProtocolHandlerMap* protocol_handlers,
140 content::URLRequestInterceptorScopedVector request_interceptors) {
141 scoped_refptr<HeadlessURLRequestContextGetter> url_request_context_getter(
142 new HeadlessURLRequestContextGetter(
143 content::BrowserThread::GetMessageLoopProxyForThread(
144 content::BrowserThread::IO),
145 content::BrowserThread::GetMessageLoopProxyForThread(
146 content::BrowserThread::FILE),
147 protocol_handlers, std::move(request_interceptors), options()));
148 resource_context_->set_url_request_context_getter(url_request_context_getter);
149 return url_request_context_getter.get();
150 }
151
152 net::URLRequestContextGetter*
153 HeadlessBrowserContext::CreateRequestContextForStoragePartition(
154 const base::FilePath& partition_path,
155 bool in_memory,
156 content::ProtocolHandlerMap* protocol_handlers,
157 content::URLRequestInterceptorScopedVector request_interceptors) {
158 return nullptr;
159 }
160
161 net::URLRequestContextGetter*
162 HeadlessBrowserContext::CreateMediaRequestContext() {
163 return resource_context_->url_request_context_getter();
164 }
165
166 net::URLRequestContextGetter*
167 HeadlessBrowserContext::CreateMediaRequestContextForStoragePartition(
168 const base::FilePath& partition_path,
169 bool in_memory) {
170 return nullptr;
171 }
172
173 void HeadlessBrowserContext::SetOptionsForTesting(
174 HeadlessBrowser::Options* options) {
175 options_ = options;
176 }
177
178 } // namespace headless
OLDNEW
« no previous file with comments | « headless/lib/browser/headless_browser_context.h ('k') | headless/lib/browser/headless_browser_context_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698