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

Side by Side Diff: content/shell/shell_browser_context.cc

Issue 11308362: Add StoragePartition's ProtocolHandlers at URLRequestContext construction time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync (r175140) Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/shell/shell_browser_context.h" 5 #include "content/shell/shell_browser_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/environment.h" 9 #include "base/environment.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/resource_context.h"
16 #include "content/public/common/content_switches.h"
15 #include "content/shell/shell_download_manager_delegate.h" 17 #include "content/shell/shell_download_manager_delegate.h"
16 #include "content/shell/shell_resource_context.h"
17 #include "content/shell/shell_switches.h" 18 #include "content/shell/shell_switches.h"
18 #include "content/shell/shell_url_request_context_getter.h" 19 #include "content/shell/shell_url_request_context_getter.h"
19 #include "content/public/common/content_switches.h"
20 20
21 #if defined(OS_WIN) 21 #if defined(OS_WIN)
22 #include "base/base_paths_win.h" 22 #include "base/base_paths_win.h"
23 #elif defined(OS_LINUX) 23 #elif defined(OS_LINUX)
24 #include "base/nix/xdg_util.h" 24 #include "base/nix/xdg_util.h"
25 #elif defined(OS_MACOSX) 25 #elif defined(OS_MACOSX)
26 #include "base/base_paths_mac.h" 26 #include "base/base_paths_mac.h"
27 #endif 27 #endif
28 28
29 namespace content { 29 namespace content {
30 30
31 class ShellBrowserContext::ShellResourceContext : public ResourceContext {
32 public:
33 ShellResourceContext() : getter_(NULL) {}
34 virtual ~ShellResourceContext() {}
35
36 private:
37 friend class ShellBrowserContext;
38
39 // ResourceContext implementation:
40 virtual net::HostResolver* GetHostResolver() OVERRIDE {
41 CHECK(getter_);
42 return getter_->host_resolver();
43 }
44 virtual net::URLRequestContext* GetRequestContext() OVERRIDE {
45 CHECK(getter_);
46 return getter_->GetURLRequestContext();
47 }
48
49 ShellURLRequestContextGetter* getter_;
50
51 DISALLOW_COPY_AND_ASSIGN(ShellResourceContext);
52 };
53
31 ShellBrowserContext::ShellBrowserContext(bool off_the_record) 54 ShellBrowserContext::ShellBrowserContext(bool off_the_record)
32 : off_the_record_(off_the_record), 55 : off_the_record_(off_the_record),
33 ignore_certificate_errors_(false) { 56 ignore_certificate_errors_(false),
57 resource_context_(new ShellResourceContext()) {
34 InitWhileIOAllowed(); 58 InitWhileIOAllowed();
35 } 59 }
36 60
37 ShellBrowserContext::~ShellBrowserContext() { 61 ShellBrowserContext::~ShellBrowserContext() {
38 if (resource_context_.get()) { 62 if (resource_context_.get()) {
39 BrowserThread::DeleteSoon( 63 BrowserThread::DeleteSoon(
40 BrowserThread::IO, FROM_HERE, resource_context_.release()); 64 BrowserThread::IO, FROM_HERE, resource_context_.release());
41 } 65 }
42 } 66 }
43 67
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 112
89 if (!download_manager_delegate_.get()) { 113 if (!download_manager_delegate_.get()) {
90 download_manager_delegate_ = new ShellDownloadManagerDelegate(); 114 download_manager_delegate_ = new ShellDownloadManagerDelegate();
91 download_manager_delegate_->SetDownloadManager(manager); 115 download_manager_delegate_->SetDownloadManager(manager);
92 } 116 }
93 117
94 return download_manager_delegate_.get(); 118 return download_manager_delegate_.get();
95 } 119 }
96 120
97 net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() { 121 net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() {
98 if (!url_request_getter_) { 122 CHECK(url_request_getter_.get());
mmenke 2013/01/08 17:19:26 Is there a reason this is a CHECK, but there's a D
mmenke 2013/01/08 17:19:26 The get() and the one in the DHCECK can be removed
pauljensen 2013/01/21 06:24:56 Done.
pauljensen 2013/01/21 06:24:56 I made this just go through the StoragePartition n
99 url_request_getter_ = new ShellURLRequestContextGetter( 123 return url_request_getter_.get();
100 ignore_certificate_errors_, 124 }
101 GetPath(), 125
102 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), 126 net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
103 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE)); 127 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
104 } 128 blob_protocol_handler,
105 return url_request_getter_; 129 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
130 file_system_protocol_handler,
131 scoped_ptr<net::URLRequestJobFactory::Interceptor>
132 developer_protocol_handler) {
133 DCHECK(!url_request_getter_.get());
134 url_request_getter_ = new ShellURLRequestContextGetter(
135 ignore_certificate_errors_,
136 GetPath(),
137 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
138 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE),
139 blob_protocol_handler.Pass(),
140 file_system_protocol_handler.Pass(),
141 developer_protocol_handler.Pass());
142 resource_context_->getter_ = url_request_getter_.get();
mmenke 2013/01/08 17:19:26 I don't like digging into the guts of a class when
pauljensen 2013/01/21 06:24:56 This line of code is gone now that I made GetResou
143 return url_request_getter_.get();
106 } 144 }
107 145
108 net::URLRequestContextGetter* 146 net::URLRequestContextGetter*
109 ShellBrowserContext::GetRequestContextForRenderProcess( 147 ShellBrowserContext::GetRequestContextForRenderProcess(
110 int renderer_child_id) { 148 int renderer_child_id) {
111 return GetRequestContext(); 149 return GetRequestContext();
112 } 150 }
113 151
114 net::URLRequestContextGetter* 152 net::URLRequestContextGetter*
115 ShellBrowserContext::GetMediaRequestContext() { 153 ShellBrowserContext::GetMediaRequestContext() {
116 return GetRequestContext(); 154 return GetRequestContext();
117 } 155 }
118 156
119 net::URLRequestContextGetter* 157 net::URLRequestContextGetter*
120 ShellBrowserContext::GetMediaRequestContextForRenderProcess( 158 ShellBrowserContext::GetMediaRequestContextForRenderProcess(
121 int renderer_child_id) { 159 int renderer_child_id) {
122 return GetRequestContext(); 160 return GetRequestContext();
123 } 161 }
124 162
125 net::URLRequestContextGetter* 163 net::URLRequestContextGetter*
126 ShellBrowserContext::GetMediaRequestContextForStoragePartition( 164 ShellBrowserContext::GetMediaRequestContextForStoragePartition(
127 const FilePath& partition_path, 165 const FilePath& partition_path,
128 bool in_memory) { 166 bool in_memory) {
129 return GetRequestContext(); 167 return GetRequestContext();
130 } 168 }
131 169
132 net::URLRequestContextGetter* 170 net::URLRequestContextGetter*
133 ShellBrowserContext::GetRequestContextForStoragePartition( 171 ShellBrowserContext::CreateRequestContextForStoragePartition(
134 const FilePath& partition_path, 172 const FilePath& partition_path,
135 bool in_memory) { 173 bool in_memory,
174 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
175 blob_protocol_handler,
176 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
177 file_system_protocol_handler,
178 scoped_ptr<net::URLRequestJobFactory::Interceptor>
179 developer_protocol_handler) {
136 return NULL; 180 return NULL;
137 } 181 }
138 182
139 ResourceContext* ShellBrowserContext::GetResourceContext() { 183 ResourceContext* ShellBrowserContext::GetResourceContext() {
mmenke 2013/01/08 17:19:26 Suggest we go back to lazy init here, getting the
pauljensen 2013/01/21 06:24:56 Done. I had taken away the lazy init previously be
140 if (!resource_context_.get()) {
141 resource_context_.reset(new ShellResourceContext(
142 static_cast<ShellURLRequestContextGetter*>(GetRequestContext())));
143 }
144 return resource_context_.get(); 184 return resource_context_.get();
145 } 185 }
146 186
147 GeolocationPermissionContext* 187 GeolocationPermissionContext*
148 ShellBrowserContext::GetGeolocationPermissionContext() { 188 ShellBrowserContext::GetGeolocationPermissionContext() {
149 return NULL; 189 return NULL;
150 } 190 }
151 191
152 SpeechRecognitionPreferences* 192 SpeechRecognitionPreferences*
153 ShellBrowserContext::GetSpeechRecognitionPreferences() { 193 ShellBrowserContext::GetSpeechRecognitionPreferences() {
154 return NULL; 194 return NULL;
155 } 195 }
156 196
157 quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() { 197 quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
158 return NULL; 198 return NULL;
159 } 199 }
160 200
161 } // namespace content 201 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698