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

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

Issue 1674263002: headless: Initial headless embedder API implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix shutdown memory leak. Created 4 years, 10 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 "base/path_service.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/resource_context.h"
10 #include "content/public/browser/storage_partition.h"
11 #include "headless/lib/browser/headless_url_request_context_getter.h"
12 #include "net/url_request/url_request_context.h"
13
14 namespace headless {
15
16 // Contains net::URLRequestContextGetter required for resource loading.
17 // Must be destructed on the IO thread as per content::ResourceContext
18 // requirements.
19 class HeadlessResourceContext : public content::ResourceContext {
20 public:
21 HeadlessResourceContext();
22 ~HeadlessResourceContext() override;
23
24 // ResourceContext implementation:
25 net::HostResolver* GetHostResolver() override;
26 net::URLRequestContext* GetRequestContext() override;
27
28 void set_url_request_context_getter(
Ryan Sleevi 2016/02/25 22:04:36 Document? What thread(s) can/is this called on?
Sami 2016/02/26 18:49:16 Done.
29 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) {
30 url_request_context_getter_ = url_request_context_getter;
Ryan Sleevi 2016/02/25 22:04:36 std::move
Sami 2016/02/26 18:49:16 Done.
31 }
32
33 private:
34 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
35
36 DISALLOW_COPY_AND_ASSIGN(HeadlessResourceContext);
37 };
38
39 HeadlessResourceContext::HeadlessResourceContext() {}
40
41 HeadlessResourceContext::~HeadlessResourceContext() {}
42
43 net::HostResolver* HeadlessResourceContext::GetHostResolver() {
44 CHECK(url_request_context_getter_);
Ryan Sleevi 2016/02/25 22:04:36 I assume the contract here that you're trying to d
Sami 2016/02/26 18:49:16 Indeed, added a comment to that effect.
45 return url_request_context_getter_->GetURLRequestContext()->host_resolver();
46 }
47
48 net::URLRequestContext* HeadlessResourceContext::GetRequestContext() {
49 CHECK(url_request_context_getter_);
50 return url_request_context_getter_->GetURLRequestContext();
51 }
52
53 HeadlessBrowserContext::HeadlessBrowserContext(
54 const HeadlessBrowser::Options& options)
55 : resource_context_(new HeadlessResourceContext), options_(options) {
56 InitWhileIOAllowed();
57 }
58
59 HeadlessBrowserContext::~HeadlessBrowserContext() {
60 if (resource_context_) {
61 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
62 resource_context_.release());
63 }
64 }
65
66 void HeadlessBrowserContext::InitWhileIOAllowed() {
67 // TODO(skyostil): Allow the embedder to override this.
68 PathService::Get(base::DIR_EXE, &path_);
69 }
70
71 scoped_ptr<content::ZoomLevelDelegate>
72 HeadlessBrowserContext::CreateZoomLevelDelegate(
73 const base::FilePath& partition_path) {
74 return scoped_ptr<content::ZoomLevelDelegate>();
75 }
76
77 base::FilePath HeadlessBrowserContext::GetPath() const {
78 return path_;
79 }
80
81 bool HeadlessBrowserContext::IsOffTheRecord() const {
82 return false;
83 }
84
85 net::URLRequestContextGetter* HeadlessBrowserContext::GetRequestContext() {
86 return GetDefaultStoragePartition(this)->GetURLRequestContext();
87 }
88
89 net::URLRequestContextGetter*
90 HeadlessBrowserContext::GetRequestContextForRenderProcess(
91 int renderer_child_id) {
92 return GetRequestContext();
93 }
94
95 net::URLRequestContextGetter* HeadlessBrowserContext::GetMediaRequestContext() {
96 return GetRequestContext();
97 }
98
99 net::URLRequestContextGetter*
100 HeadlessBrowserContext::GetMediaRequestContextForRenderProcess(
101 int renderer_child_id) {
102 return GetRequestContext();
103 }
104
105 net::URLRequestContextGetter*
106 HeadlessBrowserContext::GetMediaRequestContextForStoragePartition(
107 const base::FilePath& partition_path,
108 bool in_memory) {
109 return GetRequestContext();
110 }
111
112 content::ResourceContext* HeadlessBrowserContext::GetResourceContext() {
113 return resource_context_.get();
114 }
115
116 content::DownloadManagerDelegate*
117 HeadlessBrowserContext::GetDownloadManagerDelegate() {
118 return nullptr;
119 }
120
121 content::BrowserPluginGuestManager* HeadlessBrowserContext::GetGuestManager() {
122 // TODO(altimin): Should be non-null? (is null in content/shell).
123 return nullptr;
124 }
125
126 storage::SpecialStoragePolicy*
127 HeadlessBrowserContext::GetSpecialStoragePolicy() {
128 return nullptr;
129 }
130
131 content::PushMessagingService*
132 HeadlessBrowserContext::GetPushMessagingService() {
133 return nullptr;
134 }
135
136 content::SSLHostStateDelegate*
137 HeadlessBrowserContext::GetSSLHostStateDelegate() {
138 return nullptr;
139 }
140
141 content::PermissionManager* HeadlessBrowserContext::GetPermissionManager() {
142 return nullptr;
143 }
144
145 content::BackgroundSyncController*
146 HeadlessBrowserContext::GetBackgroundSyncController() {
147 return nullptr;
148 }
149
150 void HeadlessBrowserContext::SetURLRequestContextGetter(
151 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) {
152 resource_context_->set_url_request_context_getter(url_request_context_getter);
153 }
154
155 } // namespace headless
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698