Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/shell/shell_download_manager_delegate.h" | 15 #include "content/shell/shell_download_manager_delegate.h" |
| 16 #include "content/shell/shell_resource_context.h" | |
| 17 #include "content/shell/shell_switches.h" | 16 #include "content/shell/shell_switches.h" |
| 18 #include "content/shell/shell_url_request_context_getter.h" | 17 #include "content/shell/shell_url_request_context_getter.h" |
| 19 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
| 20 | 19 |
| 21 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
| 22 #include "base/base_paths_win.h" | 21 #include "base/base_paths_win.h" |
| 23 #elif defined(OS_LINUX) | 22 #elif defined(OS_LINUX) |
| 24 #include "base/nix/xdg_util.h" | 23 #include "base/nix/xdg_util.h" |
| 25 #elif defined(OS_MACOSX) | 24 #elif defined(OS_MACOSX) |
| 26 #include "base/base_paths_mac.h" | 25 #include "base/base_paths_mac.h" |
| 27 #endif | 26 #endif |
| 28 | 27 |
| 29 namespace content { | 28 namespace content { |
| 30 | 29 |
| 30 class ShellResourceContext : public ResourceContext { | |
|
awong
2012/12/13 01:06:15
Dunk this in an anonymous namespace to be safe.
pauljensen
2012/12/13 17:58:44
I don't think I can do that because it's declared
| |
| 31 public: | |
| 32 ShellResourceContext() : getter_(NULL) {} | |
| 33 virtual ~ShellResourceContext() {} | |
| 34 | |
| 35 private: | |
| 36 friend class ShellBrowserContext; | |
| 37 | |
| 38 // ResourceContext implementation: | |
| 39 virtual net::HostResolver* GetHostResolver() OVERRIDE { | |
| 40 CHECK(getter_); | |
| 41 return getter_->host_resolver(); | |
| 42 } | |
| 43 virtual net::URLRequestContext* GetRequestContext() OVERRIDE { | |
| 44 CHECK(getter_); | |
| 45 return getter_->GetURLRequestContext(); | |
| 46 } | |
| 47 | |
| 48 ShellURLRequestContextGetter* getter_; | |
| 49 | |
| 50 DISALLOW_COPY_AND_ASSIGN(ShellResourceContext); | |
| 51 }; | |
| 52 | |
| 31 ShellBrowserContext::ShellBrowserContext(bool off_the_record) | 53 ShellBrowserContext::ShellBrowserContext(bool off_the_record) |
| 32 : off_the_record_(off_the_record), | 54 : off_the_record_(off_the_record), |
| 33 ignore_certificate_errors_(false) { | 55 ignore_certificate_errors_(false), |
| 56 resource_context_(new ShellResourceContext()) { | |
| 34 InitWhileIOAllowed(); | 57 InitWhileIOAllowed(); |
| 35 } | 58 } |
| 36 | 59 |
| 37 ShellBrowserContext::~ShellBrowserContext() { | 60 ShellBrowserContext::~ShellBrowserContext() { |
| 38 if (resource_context_.get()) { | 61 if (resource_context_.get()) { |
| 39 BrowserThread::DeleteSoon( | 62 BrowserThread::DeleteSoon( |
| 40 BrowserThread::IO, FROM_HERE, resource_context_.release()); | 63 BrowserThread::IO, FROM_HERE, resource_context_.release()); |
| 41 } | 64 } |
| 42 } | 65 } |
| 43 | 66 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 | 111 |
| 89 if (!download_manager_delegate_.get()) { | 112 if (!download_manager_delegate_.get()) { |
| 90 download_manager_delegate_ = new ShellDownloadManagerDelegate(); | 113 download_manager_delegate_ = new ShellDownloadManagerDelegate(); |
| 91 download_manager_delegate_->SetDownloadManager(manager); | 114 download_manager_delegate_->SetDownloadManager(manager); |
| 92 } | 115 } |
| 93 | 116 |
| 94 return download_manager_delegate_.get(); | 117 return download_manager_delegate_.get(); |
| 95 } | 118 } |
| 96 | 119 |
| 97 net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() { | 120 net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() { |
| 98 if (!url_request_getter_) { | 121 CHECK(url_request_getter_.get()); |
| 99 url_request_getter_ = new ShellURLRequestContextGetter( | 122 return url_request_getter_.get(); |
| 100 ignore_certificate_errors_, | 123 } |
| 101 GetPath(), | 124 |
| 102 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), | 125 net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext( |
| 103 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE)); | 126 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 104 } | 127 blob_protocol_handler, |
| 105 return url_request_getter_; | 128 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 129 file_system_protocol_handler, | |
| 130 scoped_ptr<net::URLRequestJobFactory::Interceptor> | |
| 131 developer_protocol_handler) { | |
| 132 DCHECK(!url_request_getter_.get()); | |
| 133 url_request_getter_ = new ShellURLRequestContextGetter( | |
| 134 ignore_certificate_errors_, | |
| 135 GetPath(), | |
| 136 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), | |
| 137 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE), | |
| 138 blob_protocol_handler.Pass(), | |
| 139 file_system_protocol_handler.Pass(), | |
| 140 developer_protocol_handler.Pass()); | |
| 141 resource_context_->getter_ = url_request_getter_.get(); | |
| 142 return url_request_getter_.get(); | |
| 106 } | 143 } |
| 107 | 144 |
| 108 net::URLRequestContextGetter* | 145 net::URLRequestContextGetter* |
| 109 ShellBrowserContext::GetRequestContextForRenderProcess( | 146 ShellBrowserContext::GetRequestContextForRenderProcess( |
| 110 int renderer_child_id) { | 147 int renderer_child_id) { |
| 111 return GetRequestContext(); | 148 return GetRequestContext(); |
| 112 } | 149 } |
| 113 | 150 |
| 114 net::URLRequestContextGetter* | 151 net::URLRequestContextGetter* |
| 115 ShellBrowserContext::GetMediaRequestContext() { | 152 ShellBrowserContext::GetMediaRequestContext() { |
| 116 return GetRequestContext(); | 153 return GetRequestContext(); |
| 117 } | 154 } |
| 118 | 155 |
| 119 net::URLRequestContextGetter* | 156 net::URLRequestContextGetter* |
| 120 ShellBrowserContext::GetMediaRequestContextForRenderProcess( | 157 ShellBrowserContext::GetMediaRequestContextForRenderProcess( |
| 121 int renderer_child_id) { | 158 int renderer_child_id) { |
| 122 return GetRequestContext(); | 159 return GetRequestContext(); |
| 123 } | 160 } |
| 124 | 161 |
| 125 net::URLRequestContextGetter* | 162 net::URLRequestContextGetter* |
| 126 ShellBrowserContext::GetMediaRequestContextForStoragePartition( | 163 ShellBrowserContext::GetMediaRequestContextForStoragePartition( |
| 127 const FilePath& partition_path, | 164 const FilePath& partition_path, |
| 128 bool in_memory) { | 165 bool in_memory) { |
| 129 return GetRequestContext(); | 166 return GetRequestContext(); |
| 130 } | 167 } |
| 131 | 168 |
| 132 net::URLRequestContextGetter* | 169 net::URLRequestContextGetter* |
| 133 ShellBrowserContext::GetRequestContextForStoragePartition( | 170 ShellBrowserContext::CreateRequestContextForStoragePartition( |
| 134 const FilePath& partition_path, | 171 const FilePath& partition_path, |
| 135 bool in_memory) { | 172 bool in_memory, |
| 173 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 174 blob_protocol_handler, | |
| 175 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 176 file_system_protocol_handler, | |
| 177 scoped_ptr<net::URLRequestJobFactory::Interceptor> | |
| 178 developer_protocol_handler) { | |
| 136 return NULL; | 179 return NULL; |
| 137 } | 180 } |
| 138 | 181 |
| 139 ResourceContext* ShellBrowserContext::GetResourceContext() { | 182 ResourceContext* ShellBrowserContext::GetResourceContext() { |
| 140 if (!resource_context_.get()) { | |
| 141 resource_context_.reset(new ShellResourceContext( | |
| 142 static_cast<ShellURLRequestContextGetter*>(GetRequestContext()))); | |
| 143 } | |
| 144 return resource_context_.get(); | 183 return resource_context_.get(); |
| 145 } | 184 } |
| 146 | 185 |
| 147 GeolocationPermissionContext* | 186 GeolocationPermissionContext* |
| 148 ShellBrowserContext::GetGeolocationPermissionContext() { | 187 ShellBrowserContext::GetGeolocationPermissionContext() { |
| 149 return NULL; | 188 return NULL; |
| 150 } | 189 } |
| 151 | 190 |
| 152 SpeechRecognitionPreferences* | 191 SpeechRecognitionPreferences* |
| 153 ShellBrowserContext::GetSpeechRecognitionPreferences() { | 192 ShellBrowserContext::GetSpeechRecognitionPreferences() { |
| 154 return NULL; | 193 return NULL; |
| 155 } | 194 } |
| 156 | 195 |
| 157 quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() { | 196 quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() { |
| 158 return NULL; | 197 return NULL; |
| 159 } | 198 } |
| 160 | 199 |
| 161 } // namespace content | 200 } // namespace content |
| OLD | NEW |