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

Side by Side Diff: chrome/browser/net/chrome_url_request_context.cc

Issue 49027: Disk cache: First pass to make it possible to have... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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
« no previous file with comments | « chrome/browser/net/chrome_url_request_context.h ('k') | net/base/cache_type.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/browser/net/chrome_url_request_context.h" 5 #include "chrome/browser/net/chrome_url_request_context.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_thread.h" 10 #include "chrome/browser/chrome_thread.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 context->cookie_store_ = new net::CookieMonster(context->cookie_db_.get()); 101 context->cookie_store_ = new net::CookieMonster(context->cookie_db_.get());
102 } 102 }
103 103
104 return context; 104 return context;
105 } 105 }
106 106
107 // static 107 // static
108 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia( 108 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia(
109 Profile* profile, const FilePath& disk_cache_path) { 109 Profile* profile, const FilePath& disk_cache_path) {
110 DCHECK(!profile->IsOffTheRecord()); 110 DCHECK(!profile->IsOffTheRecord());
111 return CreateRequestContextForMedia(profile, disk_cache_path); 111 return CreateRequestContextForMedia(profile, disk_cache_path, false);
112 } 112 }
113 113
114 // static 114 // static
115 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord( 115 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord(
116 Profile* profile) { 116 Profile* profile) {
117 DCHECK(profile->IsOffTheRecord()); 117 DCHECK(profile->IsOffTheRecord());
118 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); 118 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
119 119
120 // Share the same proxy service as the original profile. This proxy 120 // Share the same proxy service as the original profile. This proxy
121 // service's lifespan is dependent on the lifespan of the original profile, 121 // service's lifespan is dependent on the lifespan of the original profile,
122 // which we reference (see above). 122 // which we reference (see above).
123 context->proxy_service_ = 123 context->proxy_service_ =
124 profile->GetOriginalProfile()->GetRequestContext()->proxy_service(); 124 profile->GetOriginalProfile()->GetRequestContext()->proxy_service();
125 125
126 context->http_transaction_factory_ = 126 context->http_transaction_factory_ =
127 new net::HttpCache(context->proxy_service_, 0); 127 new net::HttpCache(context->proxy_service_, 0);
128 context->cookie_store_ = new net::CookieMonster; 128 context->cookie_store_ = new net::CookieMonster;
129 129
130 return context; 130 return context;
131 } 131 }
132 132
133 // static 133 // static
134 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecordForMedia( 134 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecordForMedia(
135 Profile* profile, const FilePath& disk_cache_path) { 135 Profile* profile, const FilePath& disk_cache_path) {
136 // TODO(hclam): since we don't have an implementation of disk cache backend 136 // TODO(hclam): since we don't have an implementation of disk cache backend
137 // for media files in OTR mode, we create a request context just like the 137 // for media files in OTR mode, we create a request context just like the
138 // original one. 138 // original one.
139 DCHECK(profile->IsOffTheRecord()); 139 DCHECK(profile->IsOffTheRecord());
140 return CreateRequestContextForMedia(profile, disk_cache_path); 140 return CreateRequestContextForMedia(profile, disk_cache_path, true);
141 } 141 }
142 142
143 // static 143 // static
144 ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia( 144 ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia(
145 Profile* profile, const FilePath& disk_cache_path) { 145 Profile* profile, const FilePath& disk_cache_path, bool off_the_record) {
146 URLRequestContext* original_context = 146 URLRequestContext* original_context =
147 profile->GetOriginalProfile()->GetRequestContext(); 147 profile->GetOriginalProfile()->GetRequestContext();
148 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); 148 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
149 // Share the same proxy service of the common profile. 149 // Share the same proxy service of the common profile.
150 context->proxy_service_ = original_context->proxy_service(); 150 context->proxy_service_ = original_context->proxy_service();
151 // Also share the cookie store of the common profile. 151 // Also share the cookie store of the common profile.
152 context->cookie_store_ = original_context->cookie_store(); 152 context->cookie_store_ = original_context->cookie_store();
153 153
154 // Create a media cache with maximum size of kint32max (2GB). 154 // Create a media cache with maximum size of kint32max (2GB).
155 // TODO(hclam): make the maximum size of media cache configurable. 155 // TODO(hclam): make the maximum size of media cache configurable.
156 net::HttpCache* original_cache = 156 net::HttpCache* original_cache =
157 original_context->http_transaction_factory()->GetCache(); 157 original_context->http_transaction_factory()->GetCache();
158 net::HttpCache* cache; 158 net::HttpCache* cache;
159 if (original_cache) { 159 if (original_cache) {
160 // Try to reuse HttpNetworkSession in the original context, assuming that 160 // Try to reuse HttpNetworkSession in the original context, assuming that
161 // HttpTransactionFactory (network_layer()) of HttpCache is implemented 161 // HttpTransactionFactory (network_layer()) of HttpCache is implemented
162 // by HttpNetworkLayer so we can reuse HttpNetworkSession within it. This 162 // by HttpNetworkLayer so we can reuse HttpNetworkSession within it. This
163 // assumption will be invalid if the original HttpCache is constructed with 163 // assumption will be invalid if the original HttpCache is constructed with
164 // HttpCache(HttpTransactionFactory*, disk_cache::Backend*) constructor. 164 // HttpCache(HttpTransactionFactory*, disk_cache::Backend*) constructor.
165 net::HttpNetworkLayer* original_network_layer = 165 net::HttpNetworkLayer* original_network_layer =
166 static_cast<net::HttpNetworkLayer*>(original_cache->network_layer()); 166 static_cast<net::HttpNetworkLayer*>(original_cache->network_layer());
167 cache = new net::HttpCache(original_network_layer->GetSession(), 167 cache = new net::HttpCache(original_network_layer->GetSession(),
168 disk_cache_path.ToWStringHack(), kint32max); 168 disk_cache_path.ToWStringHack(), kint32max);
169 } else { 169 } else {
170 // If original HttpCache doesn't exist, simply construct one with a whole 170 // If original HttpCache doesn't exist, simply construct one with a whole
171 // new set of network stack. 171 // new set of network stack.
172 cache = new net::HttpCache(original_context->proxy_service(), 172 cache = new net::HttpCache(original_context->proxy_service(),
173 disk_cache_path.ToWStringHack(), kint32max); 173 disk_cache_path.ToWStringHack(), kint32max);
174 } 174 }
175
175 // Set the cache type to media. 176 // Set the cache type to media.
176 cache->set_type(net::HttpCache::MEDIA); 177 if (off_the_record) {
178 cache->set_type(net::TEMP_MEDIA_CACHE);
179 } else {
180 cache->set_type(net::MEDIA_CACHE);
181 }
177 182
178 context->http_transaction_factory_ = cache; 183 context->http_transaction_factory_ = cache;
179 return context; 184 return context;
180 } 185 }
181 186
182 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) 187 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile)
183 : prefs_(profile->GetPrefs()), 188 : prefs_(profile->GetPrefs()),
184 is_off_the_record_(profile->IsOffTheRecord()) { 189 is_off_the_record_(profile->IsOffTheRecord()) {
185 // Set up Accept-Language and Accept-Charset header values 190 // Set up Accept-Language and Accept-Charset header values
186 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader( 191 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader(
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 311
307 delete cookie_store_; 312 delete cookie_store_;
308 delete ftp_transaction_factory_; 313 delete ftp_transaction_factory_;
309 delete http_transaction_factory_; 314 delete http_transaction_factory_;
310 315
311 // Do not delete the proxy service in the case of OTR, as it is owned by the 316 // Do not delete the proxy service in the case of OTR, as it is owned by the
312 // original URLRequestContext. 317 // original URLRequestContext.
313 if (!is_off_the_record_) 318 if (!is_off_the_record_)
314 delete proxy_service_; 319 delete proxy_service_;
315 } 320 }
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_url_request_context.h ('k') | net/base/cache_type.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698