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

Side by Side Diff: chrome/browser/profile.cc

Issue 13701: Use automatic memory management for URLRequestContext's members.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years 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 | « no previous file | net/build/net.vcproj » ('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/profile.h" 5 #include "chrome/browser/profile.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/lock.h" 10 #include "base/lock.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // A context for URLRequests issued relative to this profile. 103 // A context for URLRequests issued relative to this profile.
104 class ProfileImpl::RequestContext : public URLRequestContext, 104 class ProfileImpl::RequestContext : public URLRequestContext,
105 public NotificationObserver { 105 public NotificationObserver {
106 public: 106 public:
107 // |cookie_store_path| is the local disk path at which the cookie store 107 // |cookie_store_path| is the local disk path at which the cookie store
108 // is persisted. 108 // is persisted.
109 RequestContext(const std::wstring& cookie_store_path, 109 RequestContext(const std::wstring& cookie_store_path,
110 const std::wstring& disk_cache_path, 110 const std::wstring& disk_cache_path,
111 PrefService* prefs) 111 PrefService* prefs)
112 : prefs_(prefs) { 112 : prefs_(prefs) {
113 cookie_store_ = NULL;
114 113
115 // setup user agent 114 // setup user agent
116 user_agent_ = webkit_glue::GetUserAgent(); 115 user_agent_ = webkit_glue::GetUserAgent();
117 // set up Accept-Language and Accept-Charset header values 116 // set up Accept-Language and Accept-Charset header values
118 // TODO(jungshik) : This may slow down http requests. Perhaps, 117 // TODO(jungshik) : This may slow down http requests. Perhaps,
119 // we have to come up with a better way to set up these values. 118 // we have to come up with a better way to set up these values.
120 accept_language_ = WideToASCII(prefs_->GetString(prefs::kAcceptLanguages)); 119 accept_language_ = WideToASCII(prefs_->GetString(prefs::kAcceptLanguages));
121 accept_charset_ = WideToASCII(prefs_->GetString(prefs::kDefaultCharset)); 120 accept_charset_ = WideToASCII(prefs_->GetString(prefs::kDefaultCharset));
122 accept_charset_ += ",*,utf-8"; 121 accept_charset_ += ",*,utf-8";
123 122
124 CommandLine command_line; 123 CommandLine command_line;
125 124
126 scoped_ptr<net::ProxyInfo> proxy_info(CreateProxyInfo(command_line)); 125 scoped_ptr<net::ProxyInfo> proxy_info(CreateProxyInfo(command_line));
127 proxy_service_ = net::ProxyService::Create(proxy_info.get()); 126 proxy_service_ = net::ProxyService::Create(proxy_info.get());
128 127
129 net::HttpCache* cache = 128 net::HttpCache* cache =
130 new net::HttpCache(proxy_service_, disk_cache_path, 0); 129 new net::HttpCache(proxy_service_, disk_cache_path, 0);
131 130
132 bool record_mode = chrome::kRecordModeEnabled && 131 bool record_mode = chrome::kRecordModeEnabled &&
133 CommandLine().HasSwitch(switches::kRecordMode); 132 CommandLine().HasSwitch(switches::kRecordMode);
134 bool playback_mode = CommandLine().HasSwitch(switches::kPlaybackMode); 133 bool playback_mode = CommandLine().HasSwitch(switches::kPlaybackMode);
135 134
136 if (record_mode || playback_mode) { 135 if (record_mode || playback_mode) {
137 // Don't use existing cookies and use an in-memory store. 136 // Don't use existing cookies and use an in-memory store.
138 cookie_store_ = new net::CookieMonster(); 137 cookie_store_.reset(new net::CookieMonster());
139 cache->set_mode( 138 cache->set_mode(
140 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); 139 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK);
141 } 140 }
142 http_transaction_factory_ = cache; 141 http_transaction_factory_.reset(cache);
143 142
144 // setup cookie store 143 // setup cookie store
145 if (!cookie_store_) { 144 if (!cookie_store_.get()) {
146 DCHECK(!cookie_store_path.empty()); 145 DCHECK(!cookie_store_path.empty());
147 cookie_db_.reset(new SQLitePersistentCookieStore( 146 cookie_db_.reset(new SQLitePersistentCookieStore(
148 cookie_store_path, g_browser_process->db_thread()->message_loop())); 147 cookie_store_path, g_browser_process->db_thread()->message_loop()));
149 cookie_store_ = new net::CookieMonster(cookie_db_.get()); 148 cookie_store_.reset(new net::CookieMonster(cookie_db_.get()));
150 } 149 }
151 150
152 cookie_policy_.SetType(net::CookiePolicy::FromInt( 151 cookie_policy_.SetType(net::CookiePolicy::FromInt(
153 prefs_->GetInteger(prefs::kCookieBehavior))); 152 prefs_->GetInteger(prefs::kCookieBehavior)));
154 153
155 // The first request context to be created is the one for the default 154 // The first request context to be created is the one for the default
156 // profile - at least until we support multiple profiles. 155 // profile - at least until we support multiple profiles.
157 if (!default_request_context_) 156 if (!default_request_context_)
158 default_request_context_ = this; 157 default_request_context_ = this;
159 NotificationService::current()->Notify( 158 NotificationService::current()->Notify(
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 208 }
210 209
211 void OnCookiePolicyChange(net::CookiePolicy::Type type) { 210 void OnCookiePolicyChange(net::CookiePolicy::Type type) {
212 DCHECK(MessageLoop::current() == 211 DCHECK(MessageLoop::current() ==
213 ChromeThread::GetMessageLoop(ChromeThread::IO)); 212 ChromeThread::GetMessageLoop(ChromeThread::IO));
214 cookie_policy_.SetType(type); 213 cookie_policy_.SetType(type);
215 } 214 }
216 215
217 virtual ~RequestContext() { 216 virtual ~RequestContext() {
218 DCHECK(NULL == prefs_); 217 DCHECK(NULL == prefs_);
219 delete cookie_store_;
220 delete http_transaction_factory_;
221 delete proxy_service_;
222
223 if (default_request_context_ == this) 218 if (default_request_context_ == this)
224 default_request_context_ = NULL; 219 default_request_context_ = NULL;
225 } 220 }
226 221
227 private: 222 private:
228 scoped_ptr<SQLitePersistentCookieStore> cookie_db_; 223 scoped_ptr<SQLitePersistentCookieStore> cookie_db_;
229 PrefService* prefs_; 224 PrefService* prefs_;
230 }; 225 };
231 226
232 //////////////////////////////////////////////////////////////////////////////// 227 ////////////////////////////////////////////////////////////////////////////////
(...skipping 14 matching lines...) Expand all
247 explicit OffTheRecordRequestContext(Profile* profile) { 242 explicit OffTheRecordRequestContext(Profile* profile) {
248 DCHECK(!profile->IsOffTheRecord()); 243 DCHECK(!profile->IsOffTheRecord());
249 prefs_ = profile->GetPrefs(); 244 prefs_ = profile->GetPrefs();
250 DCHECK(prefs_); 245 DCHECK(prefs_);
251 246
252 // The OffTheRecordRequestContext is owned by the OffTheRecordProfileImpl 247 // The OffTheRecordRequestContext is owned by the OffTheRecordProfileImpl
253 // which is itself owned by the original profile. We reference the original 248 // which is itself owned by the original profile. We reference the original
254 // context to make sure it doesn't go away when we delete the object graph. 249 // context to make sure it doesn't go away when we delete the object graph.
255 original_context_ = profile->GetRequestContext(); 250 original_context_ = profile->GetRequestContext();
256 251
257 // Share the same proxy service as the original profile. This proxy 252 // Share the same proxy service as the original profile (adds a reference).
258 // service's lifespan is dependent on the lifespan of the original profile,
259 // which we reference (see above).
260 proxy_service_ = original_context_->proxy_service(); 253 proxy_service_ = original_context_->proxy_service();
261 254
262 http_transaction_factory_ = new net::HttpCache(proxy_service_, 0); 255 http_transaction_factory_.reset(
263 cookie_store_ = new net::CookieMonster; 256 new net::HttpCache(proxy_service_, 0));
257 cookie_store_.reset(new net::CookieMonster);
264 cookie_policy_.SetType(net::CookiePolicy::FromInt( 258 cookie_policy_.SetType(net::CookiePolicy::FromInt(
265 prefs_->GetInteger(prefs::kCookieBehavior))); 259 prefs_->GetInteger(prefs::kCookieBehavior)));
266 user_agent_ = original_context_->user_agent(); 260 user_agent_ = original_context_->user_agent();
267 accept_language_ = original_context_->accept_language(); 261 accept_language_ = original_context_->accept_language();
268 accept_charset_ = original_context_->accept_charset(); 262 accept_charset_ = original_context_->accept_charset();
269 is_off_the_record_ = true; 263 is_off_the_record_ = true;
270 264
271 // Register for notifications about prefs. 265 // Register for notifications about prefs.
272 prefs_->AddPrefObserver(prefs::kAcceptLanguages, this); 266 prefs_->AddPrefObserver(prefs::kAcceptLanguages, this);
273 prefs_->AddPrefObserver(prefs::kCookieBehavior, this); 267 prefs_->AddPrefObserver(prefs::kCookieBehavior, this);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 313 }
320 314
321 void OnCookiePolicyChange(net::CookiePolicy::Type type) { 315 void OnCookiePolicyChange(net::CookiePolicy::Type type) {
322 DCHECK(MessageLoop::current() == 316 DCHECK(MessageLoop::current() ==
323 ChromeThread::GetMessageLoop(ChromeThread::IO)); 317 ChromeThread::GetMessageLoop(ChromeThread::IO));
324 cookie_policy_.SetType(type); 318 cookie_policy_.SetType(type);
325 } 319 }
326 320
327 virtual ~OffTheRecordRequestContext() { 321 virtual ~OffTheRecordRequestContext() {
328 DCHECK(NULL == prefs_); 322 DCHECK(NULL == prefs_);
329 delete cookie_store_;
330 delete http_transaction_factory_;
331 // NOTE: do not delete |proxy_service_| as is owned by the original profile.
332
333 // The OffTheRecordRequestContext simply act as a proxy to the real context. 323 // The OffTheRecordRequestContext simply act as a proxy to the real context.
334 // There is nothing else to delete. 324 // There is nothing else to delete.
335 } 325 }
336 326
337 private: 327 private:
338 // The original (non off the record) URLRequestContext. 328 // The original (non off the record) URLRequestContext.
339 scoped_refptr<URLRequestContext> original_context_; 329 scoped_refptr<URLRequestContext> original_context_;
340 PrefService* prefs_; 330 PrefService* prefs_;
341 331
342 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordRequestContext); 332 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordRequestContext);
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 } 997 }
1008 998
1009 #ifdef CHROME_PERSONALIZATION 999 #ifdef CHROME_PERSONALIZATION
1010 ProfilePersonalization* ProfileImpl::GetProfilePersonalization() { 1000 ProfilePersonalization* ProfileImpl::GetProfilePersonalization() {
1011 if (!personalization_.get()) 1001 if (!personalization_.get())
1012 personalization_.reset( 1002 personalization_.reset(
1013 Personalization::CreateProfilePersonalization(this)); 1003 Personalization::CreateProfilePersonalization(this));
1014 return personalization_.get(); 1004 return personalization_.get();
1015 } 1005 }
1016 #endif 1006 #endif
OLDNEW
« no previous file with comments | « no previous file | net/build/net.vcproj » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698