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 "android_webview/browser/net/aw_url_request_context_getter.h" | 5 #include "android_webview/browser/net/aw_url_request_context_getter.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "android_webview/browser/aw_browser_context.h" | 9 #include "android_webview/browser/aw_browser_context.h" |
10 #include "android_webview/browser/aw_content_browser_client.h" | 10 #include "android_webview/browser/aw_content_browser_client.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 | 44 |
45 // All network stack initialization is done on the synchronous Init call when | 45 // All network stack initialization is done on the synchronous Init call when |
46 // the IO thread is created. | 46 // the IO thread is created. |
47 BrowserThread::SetDelegate(BrowserThread::IO, this); | 47 BrowserThread::SetDelegate(BrowserThread::IO, this); |
48 } | 48 } |
49 | 49 |
50 AwURLRequestContextGetter::~AwURLRequestContextGetter() { | 50 AwURLRequestContextGetter::~AwURLRequestContextGetter() { |
51 BrowserThread::SetDelegate(BrowserThread::IO, NULL); | 51 BrowserThread::SetDelegate(BrowserThread::IO, NULL); |
52 } | 52 } |
53 | 53 |
54 void AwURLRequestContextGetter::InitializeOnUiThread() { | |
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
56 | |
57 cookie_store_ = content::CreatePersistentCookieStore( | |
58 browser_context_->GetPath().Append(FILE_PATH_LITERAL("Cookies")), | |
59 false, | |
60 NULL, | |
61 NULL); | |
62 cookie_store_->GetCookieMonster()->SetPersistSessionCookies(true); | |
63 | |
64 // The CookieMonster must be passed here so it happens synchronously to | |
65 // the main thread initialization (to avoid race condition in another | |
66 // thread trying to access the CookieManager API). | |
awong
2013/07/11 20:43:48
This comment is slightly out of date. We're alread
| |
67 DidCreateCookieMonster(cookie_store_->GetCookieMonster()); | |
68 } | |
69 | |
54 void AwURLRequestContextGetter::Init() { | 70 void AwURLRequestContextGetter::Init() { |
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
56 | 72 |
57 net::URLRequestContextBuilder builder; | 73 net::URLRequestContextBuilder builder; |
58 builder.set_user_agent(content::GetUserAgent(GURL())); | 74 builder.set_user_agent(content::GetUserAgent(GURL())); |
59 builder.set_network_delegate(new AwNetworkDelegate()); | 75 builder.set_network_delegate(new AwNetworkDelegate()); |
60 #if !defined(DISABLE_FTP_SUPPORT) | 76 #if !defined(DISABLE_FTP_SUPPORT) |
61 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. | 77 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. |
62 #endif | 78 #endif |
63 builder.set_proxy_config_service(proxy_config_service_.release()); | 79 builder.set_proxy_config_service(proxy_config_service_.release()); |
(...skipping 13 matching lines...) Expand all Loading... | |
77 net::HttpCache* main_cache = new net::HttpCache( | 93 net::HttpCache* main_cache = new net::HttpCache( |
78 network_session_params, | 94 network_session_params, |
79 new net::HttpCache::DefaultBackend( | 95 new net::HttpCache::DefaultBackend( |
80 net::DISK_CACHE, | 96 net::DISK_CACHE, |
81 cache_type, | 97 cache_type, |
82 browser_context_->GetPath().Append(FILE_PATH_LITERAL("Cache")), | 98 browser_context_->GetPath().Append(FILE_PATH_LITERAL("Cache")), |
83 10 * 1024 * 1024, // 10M | 99 10 * 1024 * 1024, // 10M |
84 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE))); | 100 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE))); |
85 main_http_factory_.reset(main_cache); | 101 main_http_factory_.reset(main_cache); |
86 url_request_context_->set_http_transaction_factory(main_cache); | 102 url_request_context_->set_http_transaction_factory(main_cache); |
87 | 103 url_request_context_->set_cookie_store(cookie_store_.get()); |
joth
2013/07/16 20:19:52
url_request_context_->set_cookie_store(cookie_stor
| |
88 scoped_refptr<net::CookieStore> cookie_store = | 104 // release our copy of cookie_store_, now url_request_context owns it |
89 content::CreatePersistentCookieStore( | 105 cookie_store_ = NULL; |
90 browser_context_->GetPath().Append(FILE_PATH_LITERAL("Cookies")), | |
91 false, | |
92 NULL, | |
93 NULL); | |
94 cookie_store->GetCookieMonster()->SetPersistSessionCookies(true); | |
95 url_request_context_->set_cookie_store(cookie_store.get()); | |
96 | |
97 // The CookieMonster must be passed here so it happens synchronously to | |
98 // the main thread initialization (to avoid race condition in another | |
99 // thread trying to access the CookieManager API). | |
100 DidCreateCookieMonster( | |
101 url_request_context_->cookie_store()->GetCookieMonster()); | |
102 } | 106 } |
103 | 107 |
104 void AwURLRequestContextGetter::PopulateNetworkSessionParams( | 108 void AwURLRequestContextGetter::PopulateNetworkSessionParams( |
105 net::HttpNetworkSession::Params* params) { | 109 net::HttpNetworkSession::Params* params) { |
106 net::URLRequestContext* context = url_request_context_.get(); | 110 net::URLRequestContext* context = url_request_context_.get(); |
107 params->host_resolver = context->host_resolver(); | 111 params->host_resolver = context->host_resolver(); |
108 params->cert_verifier = context->cert_verifier(); | 112 params->cert_verifier = context->cert_verifier(); |
109 params->server_bound_cert_service = context->server_bound_cert_service(); | 113 params->server_bound_cert_service = context->server_bound_cert_service(); |
110 params->transport_security_state = context->transport_security_state(); | 114 params->transport_security_state = context->transport_security_state(); |
111 params->proxy_service = context->proxy_service(); | 115 params->proxy_service = context->proxy_service(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 AwURLRequestContextGetter::GetNetworkTaskRunner() const { | 191 AwURLRequestContextGetter::GetNetworkTaskRunner() const { |
188 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 192 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
189 } | 193 } |
190 | 194 |
191 void AwURLRequestContextGetter::SetProtocolHandlers( | 195 void AwURLRequestContextGetter::SetProtocolHandlers( |
192 content::ProtocolHandlerMap* protocol_handlers) { | 196 content::ProtocolHandlerMap* protocol_handlers) { |
193 std::swap(protocol_handlers_, *protocol_handlers); | 197 std::swap(protocol_handlers_, *protocol_handlers); |
194 } | 198 } |
195 | 199 |
196 } // namespace android_webview | 200 } // namespace android_webview |
OLD | NEW |