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/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // | 93 // |
94 // OffTheRecordProfileImpl is a profile subclass that wraps an existing profile | 94 // OffTheRecordProfileImpl is a profile subclass that wraps an existing profile |
95 // to make it suitable for the off the record mode. | 95 // to make it suitable for the off the record mode. |
96 // | 96 // |
97 //////////////////////////////////////////////////////////////////////////////// | 97 //////////////////////////////////////////////////////////////////////////////// |
98 class OffTheRecordProfileImpl : public Profile, | 98 class OffTheRecordProfileImpl : public Profile, |
99 public NotificationObserver { | 99 public NotificationObserver { |
100 public: | 100 public: |
101 explicit OffTheRecordProfileImpl(Profile* real_profile) | 101 explicit OffTheRecordProfileImpl(Profile* real_profile) |
102 : profile_(real_profile), | 102 : profile_(real_profile), |
103 media_request_context_(NULL), | |
104 extensions_request_context_(NULL), | 103 extensions_request_context_(NULL), |
105 start_time_(Time::Now()) { | 104 start_time_(Time::Now()) { |
106 request_context_ = ChromeURLRequestContext::CreateOffTheRecord(this); | 105 request_context_ = ChromeURLRequestContext::CreateOffTheRecord(this); |
107 request_context_->AddRef(); | 106 request_context_->AddRef(); |
108 | 107 |
109 extension_process_manager_.reset(new ExtensionProcessManager(this)); | 108 extension_process_manager_.reset(new ExtensionProcessManager(this)); |
110 | 109 |
111 // Register for browser close notifications so we can detect when the last | 110 // Register for browser close notifications so we can detect when the last |
112 // off-the-record window is closed, in which case we can clean our states | 111 // off-the-record window is closed, in which case we can clean our states |
113 // (cookies, downloads...). | 112 // (cookies, downloads...). |
114 registrar_.Add(this, NotificationType::BROWSER_CLOSED, | 113 registrar_.Add(this, NotificationType::BROWSER_CLOSED, |
115 NotificationService::AllSources()); | 114 NotificationService::AllSources()); |
116 } | 115 } |
117 | 116 |
118 virtual ~OffTheRecordProfileImpl() { | 117 virtual ~OffTheRecordProfileImpl() { |
119 CleanupRequestContext(request_context_); | 118 CleanupRequestContext(request_context_); |
120 CleanupRequestContext(media_request_context_); | |
121 CleanupRequestContext(extensions_request_context_); | 119 CleanupRequestContext(extensions_request_context_); |
122 } | 120 } |
123 | 121 |
124 virtual FilePath GetPath() { return profile_->GetPath(); } | 122 virtual FilePath GetPath() { return profile_->GetPath(); } |
125 | 123 |
126 virtual bool IsOffTheRecord() { | 124 virtual bool IsOffTheRecord() { |
127 return true; | 125 return true; |
128 } | 126 } |
129 | 127 |
130 virtual Profile* GetOffTheRecordProfile() { | 128 virtual Profile* GetOffTheRecordProfile() { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 228 |
231 virtual ThemeProvider* GetThemeProvider() { | 229 virtual ThemeProvider* GetThemeProvider() { |
232 return GetOriginalProfile()->GetThemeProvider(); | 230 return GetOriginalProfile()->GetThemeProvider(); |
233 } | 231 } |
234 | 232 |
235 virtual URLRequestContext* GetRequestContext() { | 233 virtual URLRequestContext* GetRequestContext() { |
236 return request_context_; | 234 return request_context_; |
237 } | 235 } |
238 | 236 |
239 virtual URLRequestContext* GetRequestContextForMedia() { | 237 virtual URLRequestContext* GetRequestContextForMedia() { |
240 if (!media_request_context_) { | 238 // In OTR mode, media request context is the same as the original one. |
241 FilePath cache_path = GetPath(); | 239 return request_context_; |
242 | |
243 // Override the cache location if specified by the user. | |
244 const std::wstring user_cache_dir( | |
245 CommandLine::ForCurrentProcess()->GetSwitchValue( | |
246 switches::kDiskCacheDir)); | |
247 if (!user_cache_dir.empty()) { | |
248 cache_path = FilePath::FromWStringHack(user_cache_dir); | |
249 } | |
250 | |
251 cache_path = cache_path.Append(chrome::kOffTheRecordMediaCacheDirname); | |
252 media_request_context_ = | |
253 ChromeURLRequestContext::CreateOffTheRecordForMedia( | |
254 this, cache_path); | |
255 media_request_context_->AddRef(); | |
256 | |
257 DCHECK(media_request_context_->cookie_store()); | |
258 } | |
259 return media_request_context_; | |
260 } | 240 } |
261 | 241 |
262 URLRequestContext* GetRequestContextForExtensions() { | 242 URLRequestContext* GetRequestContextForExtensions() { |
263 if (!extensions_request_context_) { | 243 if (!extensions_request_context_) { |
264 extensions_request_context_ = | 244 extensions_request_context_ = |
265 ChromeURLRequestContext::CreateOffTheRecordForExtensions(this); | 245 ChromeURLRequestContext::CreateOffTheRecordForExtensions(this); |
266 extensions_request_context_->AddRef(); | 246 extensions_request_context_->AddRef(); |
267 | 247 |
268 DCHECK(extensions_request_context_->cookie_store()); | 248 DCHECK(extensions_request_context_->cookie_store()); |
269 } | 249 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 350 |
371 private: | 351 private: |
372 NotificationRegistrar registrar_; | 352 NotificationRegistrar registrar_; |
373 | 353 |
374 // The real underlying profile. | 354 // The real underlying profile. |
375 Profile* profile_; | 355 Profile* profile_; |
376 | 356 |
377 // The context to use for requests made from this OTR session. | 357 // The context to use for requests made from this OTR session. |
378 ChromeURLRequestContext* request_context_; | 358 ChromeURLRequestContext* request_context_; |
379 | 359 |
380 // The context for requests for media resources. | |
381 ChromeURLRequestContext* media_request_context_; | |
382 | |
383 ChromeURLRequestContext* extensions_request_context_; | 360 ChromeURLRequestContext* extensions_request_context_; |
384 | 361 |
385 // The download manager that only stores downloaded items in memory. | 362 // The download manager that only stores downloaded items in memory. |
386 scoped_refptr<DownloadManager> download_manager_; | 363 scoped_refptr<DownloadManager> download_manager_; |
387 | 364 |
388 // The download manager that only stores downloaded items in memory. | 365 // The download manager that only stores downloaded items in memory. |
389 scoped_refptr<BrowserThemeProvider> theme_provider_; | 366 scoped_refptr<BrowserThemeProvider> theme_provider_; |
390 | 367 |
391 // We don't want SSLHostState from the OTR profile to leak back to the main | 368 // We don't want SSLHostState from the OTR profile to leak back to the main |
392 // profile because then the main profile would learn some of the host names | 369 // profile because then the main profile would learn some of the host names |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 | 988 |
1012 void ProfileImpl::StopCreateSessionServiceTimer() { | 989 void ProfileImpl::StopCreateSessionServiceTimer() { |
1013 create_session_service_timer_.Stop(); | 990 create_session_service_timer_.Stop(); |
1014 } | 991 } |
1015 | 992 |
1016 #ifdef CHROME_PERSONALIZATION | 993 #ifdef CHROME_PERSONALIZATION |
1017 ProfilePersonalization* ProfileImpl::GetProfilePersonalization() { | 994 ProfilePersonalization* ProfileImpl::GetProfilePersonalization() { |
1018 return personalization_.get(); | 995 return personalization_.get(); |
1019 } | 996 } |
1020 #endif | 997 #endif |
OLD | NEW |