OLD | NEW |
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" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/app/locales/locale_settings.h" | 15 #include "chrome/app/locales/locale_settings.h" |
16 #include "chrome/browser/bookmarks/bookmark_model.h" | 16 #include "chrome/browser/bookmarks/bookmark_model.h" |
17 #include "chrome/browser/browser_list.h" | 17 #include "chrome/browser/browser_list.h" |
18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/download/download_manager.h" | 19 #include "chrome/browser/download/download_manager.h" |
20 #include "chrome/browser/extensions/extensions_service.h" | 20 #include "chrome/browser/extensions/extensions_service.h" |
21 #include "chrome/browser/greasemonkey_master.h" | 21 #include "chrome/browser/greasemonkey_master.h" |
22 #include "chrome/browser/history/history.h" | 22 #include "chrome/browser/history/history.h" |
23 #include "chrome/browser/navigation_controller.h" | 23 #include "chrome/browser/navigation_controller.h" |
| 24 #include "chrome/browser/net/chrome_url_request_context.h" |
24 #include "chrome/browser/profile_manager.h" | 25 #include "chrome/browser/profile_manager.h" |
25 #include "chrome/browser/render_process_host.h" | 26 #include "chrome/browser/render_process_host.h" |
26 #include "chrome/browser/sessions/session_service.h" | 27 #include "chrome/browser/sessions/session_service.h" |
27 #include "chrome/browser/sessions/tab_restore_service.h" | 28 #include "chrome/browser/sessions/tab_restore_service.h" |
28 #include "chrome/browser/spellchecker.h" | 29 #include "chrome/browser/spellchecker.h" |
29 #include "chrome/browser/template_url_fetcher.h" | 30 #include "chrome/browser/template_url_fetcher.h" |
30 #include "chrome/browser/template_url_model.h" | 31 #include "chrome/browser/template_url_model.h" |
31 #include "chrome/browser/visitedlink_master.h" | 32 #include "chrome/browser/visitedlink_master.h" |
32 #include "chrome/browser/webdata/web_data_service.h" | 33 #include "chrome/browser/webdata/web_data_service.h" |
33 #include "chrome/common/chrome_constants.h" | 34 #include "chrome/common/chrome_constants.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 Profile* Profile::CreateProfile(const std::wstring& path) { | 70 Profile* Profile::CreateProfile(const std::wstring& path) { |
70 return new ProfileImpl(path); | 71 return new ProfileImpl(path); |
71 } | 72 } |
72 | 73 |
73 //static | 74 //static |
74 URLRequestContext* Profile::GetDefaultRequestContext() { | 75 URLRequestContext* Profile::GetDefaultRequestContext() { |
75 return default_request_context_; | 76 return default_request_context_; |
76 } | 77 } |
77 | 78 |
78 | 79 |
79 // Sets up proxy info if it was specified, otherwise returns NULL. The | |
80 // returned pointer MUST be deleted by the caller if non-NULL. | |
81 static net::ProxyInfo* CreateProxyInfo(const CommandLine& command_line) { | |
82 net::ProxyInfo* proxy_info = NULL; | |
83 | |
84 if (command_line.HasSwitch(switches::kProxyServer)) { | |
85 proxy_info = new net::ProxyInfo(); | |
86 const std::wstring& proxy_server = | |
87 command_line.GetSwitchValue(switches::kProxyServer); | |
88 proxy_info->UseNamedProxy(WideToASCII(proxy_server)); | |
89 } | |
90 | |
91 return proxy_info; | |
92 } | |
93 | |
94 // Releases the URLRequestContext and sends out a notification about it. | |
95 // Note: runs on IO thread. | |
96 static void ReleaseURLRequestContext(URLRequestContext* context) { | |
97 NotificationService::current()->Notify(NOTIFY_URL_REQUEST_CONTEXT_RELEASED, | |
98 Source<URLRequestContext>(context), | |
99 NotificationService::NoDetails()); | |
100 context->Release(); | |
101 } | |
102 | |
103 // A context for URLRequests issued relative to this profile. | |
104 class ProfileImpl::RequestContext : public URLRequestContext, | |
105 public NotificationObserver { | |
106 public: | |
107 // |cookie_store_path| is the local disk path at which the cookie store | |
108 // is persisted. | |
109 RequestContext(const std::wstring& cookie_store_path, | |
110 const std::wstring& disk_cache_path, | |
111 PrefService* prefs) | |
112 : prefs_(prefs) { | |
113 cookie_store_ = NULL; | |
114 | |
115 // setup user agent | |
116 user_agent_ = webkit_glue::GetUserAgent(); | |
117 // set up Accept-Language and Accept-Charset header values | |
118 // TODO(jungshik) : This may slow down http requests. Perhaps, | |
119 // we have to come up with a better way to set up these values. | |
120 accept_language_ = WideToASCII(prefs_->GetString(prefs::kAcceptLanguages)); | |
121 accept_charset_ = WideToASCII(prefs_->GetString(prefs::kDefaultCharset)); | |
122 accept_charset_ += ",*,utf-8"; | |
123 | |
124 CommandLine command_line; | |
125 | |
126 scoped_ptr<net::ProxyInfo> proxy_info(CreateProxyInfo(command_line)); | |
127 proxy_service_ = net::ProxyService::Create(proxy_info.get()); | |
128 | |
129 net::HttpCache* cache = | |
130 new net::HttpCache(proxy_service_, disk_cache_path, 0); | |
131 | |
132 bool record_mode = chrome::kRecordModeEnabled && | |
133 CommandLine().HasSwitch(switches::kRecordMode); | |
134 bool playback_mode = CommandLine().HasSwitch(switches::kPlaybackMode); | |
135 | |
136 if (record_mode || playback_mode) { | |
137 // Don't use existing cookies and use an in-memory store. | |
138 cookie_store_ = new net::CookieMonster(); | |
139 cache->set_mode( | |
140 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); | |
141 } | |
142 http_transaction_factory_ = cache; | |
143 | |
144 // setup cookie store | |
145 if (!cookie_store_) { | |
146 DCHECK(!cookie_store_path.empty()); | |
147 cookie_db_.reset(new SQLitePersistentCookieStore( | |
148 cookie_store_path, g_browser_process->db_thread()->message_loop())); | |
149 cookie_store_ = new net::CookieMonster(cookie_db_.get()); | |
150 } | |
151 | |
152 cookie_policy_.SetType(net::CookiePolicy::FromInt( | |
153 prefs_->GetInteger(prefs::kCookieBehavior))); | |
154 | |
155 // The first request context to be created is the one for the default | |
156 // profile - at least until we support multiple profiles. | |
157 if (!default_request_context_) | |
158 default_request_context_ = this; | |
159 NotificationService::current()->Notify( | |
160 NOTIFY_DEFAULT_REQUEST_CONTEXT_AVAILABLE, | |
161 NotificationService::AllSources(), NotificationService::NoDetails()); | |
162 | |
163 // Register for notifications about prefs. | |
164 prefs_->AddPrefObserver(prefs::kAcceptLanguages, this); | |
165 prefs_->AddPrefObserver(prefs::kCookieBehavior, this); | |
166 } | |
167 | |
168 // NotificationObserver implementation. | |
169 virtual void Observe(NotificationType type, | |
170 const NotificationSource& source, | |
171 const NotificationDetails& details) { | |
172 if (NOTIFY_PREF_CHANGED == type) { | |
173 std::wstring* pref_name_in = Details<std::wstring>(details).ptr(); | |
174 PrefService* prefs = Source<PrefService>(source).ptr(); | |
175 DCHECK(pref_name_in && prefs); | |
176 if (*pref_name_in == prefs::kAcceptLanguages) { | |
177 std::string accept_language = | |
178 WideToASCII(prefs->GetString(prefs::kAcceptLanguages)); | |
179 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | |
180 NewRunnableMethod(this, | |
181 &RequestContext::OnAcceptLanguageChange, | |
182 accept_language)); | |
183 } else if (*pref_name_in == prefs::kCookieBehavior) { | |
184 net::CookiePolicy::Type type = net::CookiePolicy::FromInt( | |
185 prefs_->GetInteger(prefs::kCookieBehavior)); | |
186 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | |
187 NewRunnableMethod(this, | |
188 &RequestContext::OnCookiePolicyChange, | |
189 type)); | |
190 } | |
191 } | |
192 } | |
193 | |
194 // Since ProfileImpl::RequestContext will be destroyed on IO thread, but all | |
195 // PrefService observers are needed to clear in before destroying ProfileImpl. | |
196 // So we use to CleanupBeforeDestroy to do this thing. This function need to | |
197 // be called on destructor of ProfileImpl. | |
198 void CleanupBeforeDestroy() { | |
199 // Unregister for pref notifications. | |
200 prefs_->RemovePrefObserver(prefs::kAcceptLanguages, this); | |
201 prefs_->RemovePrefObserver(prefs::kCookieBehavior, this); | |
202 prefs_ = NULL; | |
203 } | |
204 | |
205 void OnAcceptLanguageChange(std::string accept_language) { | |
206 DCHECK(MessageLoop::current() == | |
207 ChromeThread::GetMessageLoop(ChromeThread::IO)); | |
208 accept_language_ = accept_language; | |
209 } | |
210 | |
211 void OnCookiePolicyChange(net::CookiePolicy::Type type) { | |
212 DCHECK(MessageLoop::current() == | |
213 ChromeThread::GetMessageLoop(ChromeThread::IO)); | |
214 cookie_policy_.SetType(type); | |
215 } | |
216 | |
217 virtual ~RequestContext() { | |
218 DCHECK(NULL == prefs_); | |
219 delete cookie_store_; | |
220 delete http_transaction_factory_; | |
221 delete proxy_service_; | |
222 | |
223 if (default_request_context_ == this) | |
224 default_request_context_ = NULL; | |
225 } | |
226 | |
227 private: | |
228 scoped_ptr<SQLitePersistentCookieStore> cookie_db_; | |
229 PrefService* prefs_; | |
230 }; | |
231 | |
232 //////////////////////////////////////////////////////////////////////////////// | |
233 // | |
234 // An URLRequestContext proxy for OffTheRecord. This request context is | |
235 // really a proxy to the original profile's request context but set | |
236 // is_off_the_record_ to true. | |
237 // | |
238 // TODO(ACW). Do we need to share the FtpAuthCache with the real request context | |
239 // see bug 974328 | |
240 // | |
241 // TODO(jackson): http://b/issue?id=1197350 Remove duplicated code from above. | |
242 // | |
243 //////////////////////////////////////////////////////////////////////////////// | |
244 class OffTheRecordRequestContext : public URLRequestContext, | |
245 public NotificationObserver { | |
246 public: | |
247 explicit OffTheRecordRequestContext(Profile* profile) { | |
248 DCHECK(!profile->IsOffTheRecord()); | |
249 prefs_ = profile->GetPrefs(); | |
250 DCHECK(prefs_); | |
251 | |
252 // The OffTheRecordRequestContext is owned by the OffTheRecordProfileImpl | |
253 // 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. | |
255 original_context_ = profile->GetRequestContext(); | |
256 | |
257 // Share the same proxy service as the original profile. This proxy | |
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(); | |
261 | |
262 http_transaction_factory_ = new net::HttpCache(proxy_service_, 0); | |
263 cookie_store_ = new net::CookieMonster; | |
264 cookie_policy_.SetType(net::CookiePolicy::FromInt( | |
265 prefs_->GetInteger(prefs::kCookieBehavior))); | |
266 user_agent_ = original_context_->user_agent(); | |
267 accept_language_ = original_context_->accept_language(); | |
268 accept_charset_ = original_context_->accept_charset(); | |
269 is_off_the_record_ = true; | |
270 | |
271 // Register for notifications about prefs. | |
272 prefs_->AddPrefObserver(prefs::kAcceptLanguages, this); | |
273 prefs_->AddPrefObserver(prefs::kCookieBehavior, this); | |
274 } | |
275 | |
276 // Since OffTheRecordProfileImpl maybe be destroyed after destroying | |
277 // PrefService, but all PrefService observers are needed to clear in | |
278 // before destroying PrefService. So we use to CleanupBeforeDestroy | |
279 // to do this thing. This function need to be called on destructor | |
280 // of ProfileImpl. | |
281 void CleanupBeforeDestroy() { | |
282 // Unregister for pref notifications. | |
283 prefs_->RemovePrefObserver(prefs::kAcceptLanguages, this); | |
284 prefs_->RemovePrefObserver(prefs::kCookieBehavior, this); | |
285 prefs_ = NULL; | |
286 } | |
287 | |
288 // NotificationObserver implementation. | |
289 virtual void Observe(NotificationType type, | |
290 const NotificationSource& source, | |
291 const NotificationDetails& details) { | |
292 if (NOTIFY_PREF_CHANGED == type) { | |
293 std::wstring* pref_name_in = Details<std::wstring>(details).ptr(); | |
294 PrefService* prefs = Source<PrefService>(source).ptr(); | |
295 DCHECK(pref_name_in && prefs); | |
296 if (*pref_name_in == prefs::kAcceptLanguages) { | |
297 std::string accept_language = | |
298 WideToASCII(prefs->GetString(prefs::kAcceptLanguages)); | |
299 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | |
300 NewRunnableMethod( | |
301 this, | |
302 &OffTheRecordRequestContext::OnAcceptLanguageChange, | |
303 accept_language)); | |
304 } else if (*pref_name_in == prefs::kCookieBehavior) { | |
305 net::CookiePolicy::Type type = net::CookiePolicy::FromInt( | |
306 prefs_->GetInteger(prefs::kCookieBehavior)); | |
307 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | |
308 NewRunnableMethod(this, | |
309 &OffTheRecordRequestContext::OnCookiePolicyChange, | |
310 type)); | |
311 } | |
312 } | |
313 } | |
314 | |
315 void OnAcceptLanguageChange(std::string accept_language) { | |
316 DCHECK(MessageLoop::current() == | |
317 ChromeThread::GetMessageLoop(ChromeThread::IO)); | |
318 accept_language_ = accept_language; | |
319 } | |
320 | |
321 void OnCookiePolicyChange(net::CookiePolicy::Type type) { | |
322 DCHECK(MessageLoop::current() == | |
323 ChromeThread::GetMessageLoop(ChromeThread::IO)); | |
324 cookie_policy_.SetType(type); | |
325 } | |
326 | |
327 virtual ~OffTheRecordRequestContext() { | |
328 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. | |
334 // There is nothing else to delete. | |
335 } | |
336 | |
337 private: | |
338 // The original (non off the record) URLRequestContext. | |
339 scoped_refptr<URLRequestContext> original_context_; | |
340 PrefService* prefs_; | |
341 | |
342 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordRequestContext); | |
343 }; | |
344 | |
345 //////////////////////////////////////////////////////////////////////////////// | 80 //////////////////////////////////////////////////////////////////////////////// |
346 // | 81 // |
347 // OffTheRecordProfileImpl is a profile subclass that wraps an existing profile | 82 // OffTheRecordProfileImpl is a profile subclass that wraps an existing profile |
348 // to make it suitable for the off the record mode. | 83 // to make it suitable for the off the record mode. |
349 // | 84 // |
350 //////////////////////////////////////////////////////////////////////////////// | 85 //////////////////////////////////////////////////////////////////////////////// |
351 class OffTheRecordProfileImpl : public Profile, | 86 class OffTheRecordProfileImpl : public Profile, |
352 public NotificationObserver { | 87 public NotificationObserver { |
353 public: | 88 public: |
354 explicit OffTheRecordProfileImpl(Profile* real_profile) | 89 explicit OffTheRecordProfileImpl(Profile* real_profile) |
355 : profile_(real_profile), | 90 : profile_(real_profile), |
356 start_time_(Time::Now()) { | 91 start_time_(Time::Now()) { |
357 request_context_ = new OffTheRecordRequestContext(real_profile); | 92 request_context_ = ChromeURLRequestContext::CreateOffTheRecord(this); |
358 request_context_->AddRef(); | 93 request_context_->AddRef(); |
359 // Register for browser close notifications so we can detect when the last | 94 // Register for browser close notifications so we can detect when the last |
360 // off-the-record window is closed, in which case we can clean our states | 95 // off-the-record window is closed, in which case we can clean our states |
361 // (cookies, downloads...). | 96 // (cookies, downloads...). |
362 NotificationService::current()->AddObserver( | 97 NotificationService::current()->AddObserver( |
363 this, NOTIFY_BROWSER_CLOSED, NotificationService::AllSources()); | 98 this, NOTIFY_BROWSER_CLOSED, NotificationService::AllSources()); |
364 } | 99 } |
365 | 100 |
366 virtual ~OffTheRecordProfileImpl() { | 101 virtual ~OffTheRecordProfileImpl() { |
367 if (request_context_) { | 102 if (request_context_) { |
368 request_context_->CleanupBeforeDestroy(); | 103 request_context_->CleanupOnUIThread(); |
| 104 |
369 // Clean up request context on IO thread. | 105 // Clean up request context on IO thread. |
370 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 106 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
371 NewRunnableFunction(&ReleaseURLRequestContext, request_context_)); | 107 NewRunnableMethod(request_context_, |
| 108 &base::RefCountedThreadSafe<URLRequestContext>::Release)); |
372 request_context_ = NULL; | 109 request_context_ = NULL; |
373 } | 110 } |
374 NotificationService::current()->RemoveObserver( | 111 NotificationService::current()->RemoveObserver( |
375 this, NOTIFY_BROWSER_CLOSED, NotificationService::AllSources()); | 112 this, NOTIFY_BROWSER_CLOSED, NotificationService::AllSources()); |
376 } | 113 } |
377 | 114 |
378 virtual std::wstring GetPath() { return profile_->GetPath(); } | 115 virtual std::wstring GetPath() { return profile_->GetPath(); } |
379 | 116 |
380 virtual bool IsOffTheRecord() { | 117 virtual bool IsOffTheRecord() { |
381 return true; | 118 return true; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 // Note that we check against 1 as this notification is sent before the | 275 // Note that we check against 1 as this notification is sent before the |
539 // browser window is actually removed from the list. | 276 // browser window is actually removed from the list. |
540 if (BrowserList::GetBrowserCount(this) <= 1) | 277 if (BrowserList::GetBrowserCount(this) <= 1) |
541 ExitedOffTheRecordMode(); | 278 ExitedOffTheRecordMode(); |
542 } | 279 } |
543 | 280 |
544 private: | 281 private: |
545 // The real underlying profile. | 282 // The real underlying profile. |
546 Profile* profile_; | 283 Profile* profile_; |
547 | 284 |
548 // A proxy to the real request context. | 285 // The context to use for requests made from this OTR session. |
549 OffTheRecordRequestContext* request_context_; | 286 ChromeURLRequestContext* request_context_; |
550 | 287 |
551 // The download manager that only stores downloaded items in memory. | 288 // The download manager that only stores downloaded items in memory. |
552 scoped_refptr<DownloadManager> download_manager_; | 289 scoped_refptr<DownloadManager> download_manager_; |
553 | 290 |
554 // Time we were started. | 291 // Time we were started. |
555 Time start_time_; | 292 Time start_time_; |
556 | 293 |
557 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl); | 294 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl); |
558 }; | 295 }; |
559 | 296 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 if (spellchecker_) { | 358 if (spellchecker_) { |
622 // The spellchecker must be deleted on the I/O thread. During testing, we | 359 // The spellchecker must be deleted on the I/O thread. During testing, we |
623 // don't have an I/O thread. | 360 // don't have an I/O thread. |
624 if (io_thread) | 361 if (io_thread) |
625 io_thread->message_loop()->ReleaseSoon(FROM_HERE, spellchecker_); | 362 io_thread->message_loop()->ReleaseSoon(FROM_HERE, spellchecker_); |
626 else | 363 else |
627 spellchecker_->Release(); | 364 spellchecker_->Release(); |
628 } | 365 } |
629 | 366 |
630 if (request_context_) { | 367 if (request_context_) { |
631 request_context_->CleanupBeforeDestroy(); | 368 request_context_->CleanupOnUIThread(); |
| 369 |
| 370 if (default_request_context_ == request_context_) |
| 371 default_request_context_ = NULL; |
| 372 |
632 // Clean up request context on IO thread. | 373 // Clean up request context on IO thread. |
633 io_thread->message_loop()->PostTask(FROM_HERE, | 374 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
634 NewRunnableFunction(&ReleaseURLRequestContext, request_context_)); | 375 NewRunnableMethod(request_context_, |
| 376 &base::RefCountedThreadSafe<URLRequestContext>::Release)); |
635 request_context_ = NULL; | 377 request_context_ = NULL; |
636 } | 378 } |
637 | 379 |
638 // HistoryService may call into the BookmarkModel, as such we need to | 380 // HistoryService may call into the BookmarkModel, as such we need to |
639 // delete HistoryService before the BookmarkModel. The destructor for | 381 // delete HistoryService before the BookmarkModel. The destructor for |
640 // HistoryService will join with HistoryService's backend thread so that | 382 // HistoryService will join with HistoryService's backend thread so that |
641 // by the time the destructor has finished we're sure it will no longer call | 383 // by the time the destructor has finished we're sure it will no longer call |
642 // into the BookmarkModel. | 384 // into the BookmarkModel. |
643 history_service_ = NULL; | 385 history_service_ = NULL; |
644 bookmark_bar_model_.reset(); | 386 bookmark_bar_model_.reset(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 file_util::AppendToPath(&pref_file_path, chrome::kPreferencesFilename); | 488 file_util::AppendToPath(&pref_file_path, chrome::kPreferencesFilename); |
747 return pref_file_path; | 489 return pref_file_path; |
748 } | 490 } |
749 | 491 |
750 URLRequestContext* ProfileImpl::GetRequestContext() { | 492 URLRequestContext* ProfileImpl::GetRequestContext() { |
751 if (!request_context_) { | 493 if (!request_context_) { |
752 std::wstring cookie_path = GetPath(); | 494 std::wstring cookie_path = GetPath(); |
753 file_util::AppendToPath(&cookie_path, chrome::kCookieFilename); | 495 file_util::AppendToPath(&cookie_path, chrome::kCookieFilename); |
754 std::wstring cache_path = GetPath(); | 496 std::wstring cache_path = GetPath(); |
755 file_util::AppendToPath(&cache_path, chrome::kCacheDirname); | 497 file_util::AppendToPath(&cache_path, chrome::kCacheDirname); |
756 request_context_ = | 498 request_context_ = ChromeURLRequestContext::CreateOriginal( |
757 new ProfileImpl::RequestContext(cookie_path, cache_path, GetPrefs()); | 499 this, cookie_path, cache_path); |
758 request_context_->AddRef(); | 500 request_context_->AddRef(); |
759 | 501 |
| 502 // The first request context is always a normal (non-OTR) request context. |
| 503 // Even when Chromium is started in OTR mode, a normal profile is always |
| 504 // created first. |
| 505 if (!default_request_context_) { |
| 506 default_request_context_ = request_context_; |
| 507 NotificationService::current()->Notify( |
| 508 NOTIFY_DEFAULT_REQUEST_CONTEXT_AVAILABLE, |
| 509 NotificationService::AllSources(), NotificationService::NoDetails()); |
| 510 } |
| 511 |
760 DCHECK(request_context_->cookie_store()); | 512 DCHECK(request_context_->cookie_store()); |
761 } | 513 } |
762 | 514 |
763 return request_context_; | 515 return request_context_; |
764 } | 516 } |
765 | 517 |
766 HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) { | 518 HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) { |
767 if (!history_service_created_) { | 519 if (!history_service_created_) { |
768 history_service_created_ = true; | 520 history_service_created_ = true; |
769 scoped_refptr<HistoryService> history(new HistoryService(this)); | 521 scoped_refptr<HistoryService> history(new HistoryService(this)); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 } | 759 } |
1008 | 760 |
1009 #ifdef CHROME_PERSONALIZATION | 761 #ifdef CHROME_PERSONALIZATION |
1010 ProfilePersonalization* ProfileImpl::GetProfilePersonalization() { | 762 ProfilePersonalization* ProfileImpl::GetProfilePersonalization() { |
1011 if (!personalization_.get()) | 763 if (!personalization_.get()) |
1012 personalization_.reset( | 764 personalization_.reset( |
1013 Personalization::CreateProfilePersonalization(this)); | 765 Personalization::CreateProfilePersonalization(this)); |
1014 return personalization_.get(); | 766 return personalization_.get(); |
1015 } | 767 } |
1016 #endif | 768 #endif |
OLD | NEW |