| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/cronet/android/url_request_context_peer.h" | 5 #include "components/cronet/android/url_request_context_adapter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "components/cronet/url_request_context_config.h" | 10 #include "components/cronet/url_request_context_config.h" |
| 11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 #include "net/base/net_log_logger.h" | 12 #include "net/base/net_log_logger.h" |
| 13 #include "net/cert/cert_verifier.h" | 13 #include "net/cert/cert_verifier.h" |
| 14 #include "net/http/http_auth_handler_factory.h" | 14 #include "net/http/http_auth_handler_factory.h" |
| 15 #include "net/http/http_network_layer.h" | 15 #include "net/http/http_network_layer.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 const std::string& cookie_line, | 87 const std::string& cookie_line, |
| 88 net::CookieOptions* options) OVERRIDE { | 88 net::CookieOptions* options) OVERRIDE { |
| 89 return false; | 89 return false; |
| 90 } | 90 } |
| 91 | 91 |
| 92 virtual bool OnCanAccessFile(const net::URLRequest& request, | 92 virtual bool OnCanAccessFile(const net::URLRequest& request, |
| 93 const base::FilePath& path) const OVERRIDE { | 93 const base::FilePath& path) const OVERRIDE { |
| 94 return false; | 94 return false; |
| 95 } | 95 } |
| 96 | 96 |
| 97 virtual bool OnCanThrottleRequest(const net::URLRequest& request) | 97 virtual bool OnCanThrottleRequest( |
| 98 const OVERRIDE { | 98 const net::URLRequest& request) const OVERRIDE { |
| 99 return false; | 99 return false; |
| 100 } | 100 } |
| 101 | 101 |
| 102 virtual int OnBeforeSocketStreamConnect( | 102 virtual int OnBeforeSocketStreamConnect( |
| 103 net::SocketStream* stream, | 103 net::SocketStream* stream, |
| 104 const net::CompletionCallback& callback) OVERRIDE { | 104 const net::CompletionCallback& callback) OVERRIDE { |
| 105 return net::OK; | 105 return net::OK; |
| 106 } | 106 } |
| 107 | 107 |
| 108 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); | 108 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 } // namespace | 111 } // namespace |
| 112 | 112 |
| 113 namespace cronet { | 113 namespace cronet { |
| 114 | 114 |
| 115 URLRequestContextPeer::URLRequestContextPeer( | 115 URLRequestContextAdapter::URLRequestContextAdapter( |
| 116 URLRequestContextPeerDelegate* delegate, | 116 URLRequestContextAdapterDelegate* delegate, |
| 117 std::string user_agent) { | 117 std::string user_agent) { |
| 118 delegate_ = delegate; | 118 delegate_ = delegate; |
| 119 user_agent_ = user_agent; | 119 user_agent_ = user_agent; |
| 120 } | 120 } |
| 121 | 121 |
| 122 void URLRequestContextPeer::Initialize( | 122 void URLRequestContextAdapter::Initialize( |
| 123 scoped_ptr<URLRequestContextConfig> config) { | 123 scoped_ptr<URLRequestContextConfig> config) { |
| 124 network_thread_ = new base::Thread("network"); | 124 network_thread_ = new base::Thread("network"); |
| 125 base::Thread::Options options; | 125 base::Thread::Options options; |
| 126 options.message_loop_type = base::MessageLoop::TYPE_IO; | 126 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 127 network_thread_->StartWithOptions(options); | 127 network_thread_->StartWithOptions(options); |
| 128 | 128 |
| 129 GetNetworkTaskRunner()->PostTask( | 129 GetNetworkTaskRunner()->PostTask( |
| 130 FROM_HERE, | 130 FROM_HERE, |
| 131 base::Bind(&URLRequestContextPeer::InitializeURLRequestContext, | 131 base::Bind(&URLRequestContextAdapter::InitializeURLRequestContext, |
| 132 this, | 132 this, |
| 133 Passed(&config))); | 133 Passed(&config))); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void URLRequestContextPeer::InitializeURLRequestContext( | 136 void URLRequestContextAdapter::InitializeURLRequestContext( |
| 137 scoped_ptr<URLRequestContextConfig> config) { | 137 scoped_ptr<URLRequestContextConfig> config) { |
| 138 // TODO(mmenke): Add method to have the builder enable SPDY. | 138 // TODO(mmenke): Add method to have the builder enable SPDY. |
| 139 net::URLRequestContextBuilder context_builder; | 139 net::URLRequestContextBuilder context_builder; |
| 140 context_builder.set_network_delegate(new BasicNetworkDelegate()); | 140 context_builder.set_network_delegate(new BasicNetworkDelegate()); |
| 141 context_builder.set_proxy_config_service( | 141 context_builder.set_proxy_config_service( |
| 142 new net::ProxyConfigServiceFixed(net::ProxyConfig())); | 142 new net::ProxyConfigServiceFixed(net::ProxyConfig())); |
| 143 config->ConfigureURLRequestContextBuilder(&context_builder); | 143 config->ConfigureURLRequestContextBuilder(&context_builder); |
| 144 | 144 |
| 145 context_.reset(context_builder.Build()); | 145 context_.reset(context_builder.Build()); |
| 146 | 146 |
| 147 if (VLOG_IS_ON(2)) { | 147 if (VLOG_IS_ON(2)) { |
| 148 net_log_observer_.reset(new NetLogObserver()); | 148 net_log_observer_.reset(new NetLogObserver()); |
| 149 context_->net_log()->AddThreadSafeObserver(net_log_observer_.get(), | 149 context_->net_log()->AddThreadSafeObserver(net_log_observer_.get(), |
| 150 net::NetLog::LOG_ALL_BUT_BYTES); | 150 net::NetLog::LOG_ALL_BUT_BYTES); |
| 151 } | 151 } |
| 152 | 152 |
| 153 delegate_->OnContextInitialized(this); | 153 delegate_->OnContextInitialized(this); |
| 154 } | 154 } |
| 155 | 155 |
| 156 URLRequestContextPeer::~URLRequestContextPeer() { | 156 URLRequestContextAdapter::~URLRequestContextAdapter() { |
| 157 if (net_log_observer_) { | 157 if (net_log_observer_) { |
| 158 context_->net_log()->RemoveThreadSafeObserver(net_log_observer_.get()); | 158 context_->net_log()->RemoveThreadSafeObserver(net_log_observer_.get()); |
| 159 net_log_observer_.reset(); | 159 net_log_observer_.reset(); |
| 160 } | 160 } |
| 161 StopNetLog(); | 161 StopNetLog(); |
| 162 // TODO(mef): Ensure that |network_thread_| is destroyed properly. | 162 // TODO(mef): Ensure that |network_thread_| is destroyed properly. |
| 163 } | 163 } |
| 164 | 164 |
| 165 const std::string& URLRequestContextPeer::GetUserAgent(const GURL& url) const { | 165 const std::string& URLRequestContextAdapter::GetUserAgent( |
| 166 const GURL& url) const { |
| 166 return user_agent_; | 167 return user_agent_; |
| 167 } | 168 } |
| 168 | 169 |
| 169 net::URLRequestContext* URLRequestContextPeer::GetURLRequestContext() { | 170 net::URLRequestContext* URLRequestContextAdapter::GetURLRequestContext() { |
| 170 if (!context_) { | 171 if (!context_) { |
| 171 LOG(ERROR) << "URLRequestContext is not set up"; | 172 LOG(ERROR) << "URLRequestContext is not set up"; |
| 172 } | 173 } |
| 173 return context_.get(); | 174 return context_.get(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 scoped_refptr<base::SingleThreadTaskRunner> | 177 scoped_refptr<base::SingleThreadTaskRunner> |
| 177 URLRequestContextPeer::GetNetworkTaskRunner() const { | 178 URLRequestContextAdapter::GetNetworkTaskRunner() const { |
| 178 return network_thread_->message_loop_proxy(); | 179 return network_thread_->message_loop_proxy(); |
| 179 } | 180 } |
| 180 | 181 |
| 181 void URLRequestContextPeer::StartNetLogToFile(const std::string& file_name) { | 182 void URLRequestContextAdapter::StartNetLogToFile(const std::string& file_name) { |
| 182 // Do nothing if already logging to a file. | 183 // Do nothing if already logging to a file. |
| 183 if (net_log_logger_) | 184 if (net_log_logger_) |
| 184 return; | 185 return; |
| 185 | 186 |
| 186 base::FilePath file_path(file_name); | 187 base::FilePath file_path(file_name); |
| 187 FILE* file = base::OpenFile(file_path, "w"); | 188 FILE* file = base::OpenFile(file_path, "w"); |
| 188 if (!file) | 189 if (!file) |
| 189 return; | 190 return; |
| 190 | 191 |
| 191 scoped_ptr<base::Value> constants(net::NetLogLogger::GetConstants()); | 192 scoped_ptr<base::Value> constants(net::NetLogLogger::GetConstants()); |
| 192 net_log_logger_.reset(new net::NetLogLogger(file, *constants)); | 193 net_log_logger_.reset(new net::NetLogLogger(file, *constants)); |
| 193 net_log_logger_->StartObserving(context_->net_log()); | 194 net_log_logger_->StartObserving(context_->net_log()); |
| 194 } | 195 } |
| 195 | 196 |
| 196 void URLRequestContextPeer::StopNetLog() { | 197 void URLRequestContextAdapter::StopNetLog() { |
| 197 if (net_log_logger_) { | 198 if (net_log_logger_) { |
| 198 net_log_logger_->StopObserving(); | 199 net_log_logger_->StopObserving(); |
| 199 net_log_logger_.reset(); | 200 net_log_logger_.reset(); |
| 200 } | 201 } |
| 201 } | 202 } |
| 202 | 203 |
| 203 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { | 204 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { |
| 204 VLOG(2) << "Net log entry: type=" << entry.type() | 205 VLOG(2) << "Net log entry: type=" << entry.type() |
| 205 << ", source=" << entry.source().type | 206 << ", source=" << entry.source().type << ", phase=" << entry.phase(); |
| 206 << ", phase=" << entry.phase(); | |
| 207 } | 207 } |
| 208 | 208 |
| 209 } // namespace cronet | 209 } // namespace cronet |
| OLD | NEW |