| 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 "chrome/browser/profiles/off_the_record_profile_impl.h" | 5 #include "chrome/browser/profiles/off_the_record_profile_impl.h" | 
| 6 | 6 | 
| 7 #include "base/bind.h" | 7 #include "base/bind.h" | 
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" | 
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" | 
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 37 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 37 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 
| 38 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 38 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 
| 39 #include "chrome/common/chrome_constants.h" | 39 #include "chrome/common/chrome_constants.h" | 
| 40 #include "chrome/common/chrome_notification_types.h" | 40 #include "chrome/common/chrome_notification_types.h" | 
| 41 #include "chrome/common/chrome_paths.h" | 41 #include "chrome/common/chrome_paths.h" | 
| 42 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" | 
| 43 #include "chrome/common/extensions/extension.h" | 43 #include "chrome/common/extensions/extension.h" | 
| 44 #include "chrome/common/json_pref_store.h" | 44 #include "chrome/common/json_pref_store.h" | 
| 45 #include "chrome/common/pref_names.h" | 45 #include "chrome/common/pref_names.h" | 
| 46 #include "chrome/common/render_messages.h" | 46 #include "chrome/common/render_messages.h" | 
| 47 #include "content/browser/appcache/chrome_appcache_service.h" |  | 
| 48 #include "content/browser/chrome_blob_storage_context.h" |  | 
| 49 #include "content/browser/file_system/browser_file_system_helper.h" |  | 
| 50 #include "content/browser/in_process_webkit/webkit_context.h" | 47 #include "content/browser/in_process_webkit/webkit_context.h" | 
| 51 #include "content/public/browser/browser_thread.h" | 48 #include "content/public/browser/browser_thread.h" | 
| 52 #include "content/public/browser/host_zoom_map.h" | 49 #include "content/public/browser/host_zoom_map.h" | 
| 53 #include "content/public/browser/notification_service.h" | 50 #include "content/public/browser/notification_service.h" | 
| 54 #include "content/public/browser/web_contents.h" | 51 #include "content/public/browser/web_contents.h" | 
| 55 #include "net/base/transport_security_state.h" | 52 #include "net/base/transport_security_state.h" | 
| 56 #include "net/http/http_server_properties.h" | 53 #include "net/http/http_server_properties.h" | 
| 57 #include "webkit/database/database_tracker.h" | 54 #include "webkit/database/database_tracker.h" | 
| 58 #include "webkit/quota/quota_manager.h" |  | 
| 59 | 55 | 
| 60 #if defined(OS_CHROMEOS) | 56 #if defined(OS_CHROMEOS) | 
| 61 #include "chrome/browser/chromeos/preferences.h" | 57 #include "chrome/browser/chromeos/preferences.h" | 
| 62 #include "chrome/browser/chromeos/proxy_config_service_impl.h" | 58 #include "chrome/browser/chromeos/proxy_config_service_impl.h" | 
| 63 #endif | 59 #endif | 
| 64 | 60 | 
| 65 using content::BrowserThread; | 61 using content::BrowserThread; | 
| 66 using content::DownloadManager; | 62 using content::DownloadManager; | 
| 67 using content::HostZoomMap; | 63 using content::HostZoomMap; | 
| 68 | 64 | 
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 126 | 122 | 
| 127   ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext( | 123   ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext( | 
| 128     io_data_.GetResourceContextNoInit()); | 124     io_data_.GetResourceContextNoInit()); | 
| 129 | 125 | 
| 130   ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); | 126   ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); | 
| 131 | 127 | 
| 132   BrowserThread::PostTask( | 128   BrowserThread::PostTask( | 
| 133       BrowserThread::IO, FROM_HERE, | 129       BrowserThread::IO, FROM_HERE, | 
| 134       base::Bind(&NotifyOTRProfileDestroyedOnIOThread, profile_, this)); | 130       base::Bind(&NotifyOTRProfileDestroyedOnIOThread, profile_, this)); | 
| 135 | 131 | 
| 136   // Clean up all DB files/directories |  | 
| 137   if (db_tracker_) { |  | 
| 138     BrowserThread::PostTask( |  | 
| 139         BrowserThread::FILE, FROM_HERE, |  | 
| 140         base::Bind(&webkit_database::DatabaseTracker::Shutdown, |  | 
| 141                    db_tracker_.get())); |  | 
| 142   } |  | 
| 143 |  | 
| 144   BrowserList::RemoveObserver(this); | 132   BrowserList::RemoveObserver(this); | 
| 145 | 133 | 
| 146   if (host_content_settings_map_) | 134   if (host_content_settings_map_) | 
| 147     host_content_settings_map_->ShutdownOnUIThread(); | 135     host_content_settings_map_->ShutdownOnUIThread(); | 
| 148 | 136 | 
| 149   if (pref_proxy_config_tracker_.get()) | 137   if (pref_proxy_config_tracker_.get()) | 
| 150     pref_proxy_config_tracker_->DetachFromPrefService(); | 138     pref_proxy_config_tracker_->DetachFromPrefService(); | 
| 151 | 139 | 
| 152   ExtensionService* extension_service = GetExtensionService(); | 140   ExtensionService* extension_service = GetExtensionService(); | 
| 153   if (extension_service) { | 141   if (extension_service) { | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 183 } | 171 } | 
| 184 | 172 | 
| 185 bool OffTheRecordProfileImpl::HasOffTheRecordProfile() { | 173 bool OffTheRecordProfileImpl::HasOffTheRecordProfile() { | 
| 186   return true; | 174   return true; | 
| 187 } | 175 } | 
| 188 | 176 | 
| 189 Profile* OffTheRecordProfileImpl::GetOriginalProfile() { | 177 Profile* OffTheRecordProfileImpl::GetOriginalProfile() { | 
| 190   return profile_; | 178   return profile_; | 
| 191 } | 179 } | 
| 192 | 180 | 
| 193 ChromeAppCacheService* OffTheRecordProfileImpl::GetAppCacheService() { |  | 
| 194   CreateQuotaManagerAndClients(); |  | 
| 195   return appcache_service_; |  | 
| 196 } |  | 
| 197 |  | 
| 198 webkit_database::DatabaseTracker* |  | 
| 199     OffTheRecordProfileImpl::GetDatabaseTracker() { |  | 
| 200   CreateQuotaManagerAndClients(); |  | 
| 201   return db_tracker_; |  | 
| 202 } |  | 
| 203 |  | 
| 204 VisitedLinkMaster* OffTheRecordProfileImpl::GetVisitedLinkMaster() { | 181 VisitedLinkMaster* OffTheRecordProfileImpl::GetVisitedLinkMaster() { | 
| 205   // We don't provide access to the VisitedLinkMaster when we're OffTheRecord | 182   // We don't provide access to the VisitedLinkMaster when we're OffTheRecord | 
| 206   // because we don't want to leak the sites that the user has visited before. | 183   // because we don't want to leak the sites that the user has visited before. | 
| 207   return NULL; | 184   return NULL; | 
| 208 } | 185 } | 
| 209 | 186 | 
| 210 ExtensionService* OffTheRecordProfileImpl::GetExtensionService() { | 187 ExtensionService* OffTheRecordProfileImpl::GetExtensionService() { | 
| 211   return GetOriginalProfile()->GetExtensionService(); | 188   return GetOriginalProfile()->GetExtensionService(); | 
| 212 } | 189 } | 
| 213 | 190 | 
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 306 } | 283 } | 
| 307 | 284 | 
| 308 TemplateURLFetcher* OffTheRecordProfileImpl::GetTemplateURLFetcher() { | 285 TemplateURLFetcher* OffTheRecordProfileImpl::GetTemplateURLFetcher() { | 
| 309   return profile_->GetTemplateURLFetcher(); | 286   return profile_->GetTemplateURLFetcher(); | 
| 310 } | 287 } | 
| 311 | 288 | 
| 312 DownloadManager* OffTheRecordProfileImpl::GetDownloadManager() { | 289 DownloadManager* OffTheRecordProfileImpl::GetDownloadManager() { | 
| 313   return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager(); | 290   return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager(); | 
| 314 } | 291 } | 
| 315 | 292 | 
| 316 fileapi::FileSystemContext* OffTheRecordProfileImpl::GetFileSystemContext() { |  | 
| 317   CreateQuotaManagerAndClients(); |  | 
| 318   return file_system_context_.get(); |  | 
| 319 } |  | 
| 320 |  | 
| 321 net::URLRequestContextGetter* OffTheRecordProfileImpl::GetRequestContext() { | 293 net::URLRequestContextGetter* OffTheRecordProfileImpl::GetRequestContext() { | 
| 322   return io_data_.GetMainRequestContextGetter(); | 294   return io_data_.GetMainRequestContextGetter(); | 
| 323 } | 295 } | 
| 324 | 296 | 
| 325 quota::QuotaManager* OffTheRecordProfileImpl::GetQuotaManager() { |  | 
| 326   CreateQuotaManagerAndClients(); |  | 
| 327   return quota_manager_.get(); |  | 
| 328 } |  | 
| 329 |  | 
| 330 net::URLRequestContextGetter* | 297 net::URLRequestContextGetter* | 
| 331     OffTheRecordProfileImpl::GetRequestContextForRenderProcess( | 298     OffTheRecordProfileImpl::GetRequestContextForRenderProcess( | 
| 332         int renderer_child_id) { | 299         int renderer_child_id) { | 
| 333   if (GetExtensionService()) { | 300   if (GetExtensionService()) { | 
| 334     const Extension* installed_app = GetExtensionService()-> | 301     const Extension* installed_app = GetExtensionService()-> | 
| 335         GetInstalledAppForRenderer(renderer_child_id); | 302         GetInstalledAppForRenderer(renderer_child_id); | 
| 336     if (installed_app != NULL && installed_app->is_storage_isolated() && | 303     if (installed_app != NULL && installed_app->is_storage_isolated() && | 
| 337         installed_app->HasAPIPermission( | 304         installed_app->HasAPIPermission( | 
| 338             ExtensionAPIPermission::kExperimental)) { | 305             ExtensionAPIPermission::kExperimental)) { | 
| 339       return GetRequestContextForIsolatedApp(installed_app->id()); | 306       return GetRequestContextForIsolatedApp(installed_app->id()); | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 402 } | 369 } | 
| 403 | 370 | 
| 404 UserStyleSheetWatcher* OffTheRecordProfileImpl::GetUserStyleSheetWatcher() { | 371 UserStyleSheetWatcher* OffTheRecordProfileImpl::GetUserStyleSheetWatcher() { | 
| 405   return profile_->GetUserStyleSheetWatcher(); | 372   return profile_->GetUserStyleSheetWatcher(); | 
| 406 } | 373 } | 
| 407 | 374 | 
| 408 bool OffTheRecordProfileImpl::DidLastSessionExitCleanly() { | 375 bool OffTheRecordProfileImpl::DidLastSessionExitCleanly() { | 
| 409   return profile_->DidLastSessionExitCleanly(); | 376   return profile_->DidLastSessionExitCleanly(); | 
| 410 } | 377 } | 
| 411 | 378 | 
|  | 379 quota::SpecialStoragePolicy* | 
|  | 380     OffTheRecordProfileImpl::GetSpecialStoragePolicy() { | 
|  | 381   return GetExtensionSpecialStoragePolicy(); | 
|  | 382 } | 
|  | 383 | 
| 412 BookmarkModel* OffTheRecordProfileImpl::GetBookmarkModel() { | 384 BookmarkModel* OffTheRecordProfileImpl::GetBookmarkModel() { | 
| 413   return profile_->GetBookmarkModel(); | 385   return profile_->GetBookmarkModel(); | 
| 414 } | 386 } | 
| 415 | 387 | 
| 416 ProtocolHandlerRegistry* OffTheRecordProfileImpl::GetProtocolHandlerRegistry() { | 388 ProtocolHandlerRegistry* OffTheRecordProfileImpl::GetProtocolHandlerRegistry() { | 
| 417   return profile_->GetProtocolHandlerRegistry(); | 389   return profile_->GetProtocolHandlerRegistry(); | 
| 418 } | 390 } | 
| 419 | 391 | 
| 420 TokenService* OffTheRecordProfileImpl::GetTokenService() { | 392 TokenService* OffTheRecordProfileImpl::GetTokenService() { | 
| 421   return NULL; | 393   return NULL; | 
| 422 } | 394 } | 
| 423 | 395 | 
| 424 bool OffTheRecordProfileImpl::IsSameProfile(Profile* profile) { | 396 bool OffTheRecordProfileImpl::IsSameProfile(Profile* profile) { | 
| 425   return (profile == this) || (profile == profile_); | 397   return (profile == this) || (profile == profile_); | 
| 426 } | 398 } | 
| 427 | 399 | 
| 428 Time OffTheRecordProfileImpl::GetStartTime() const { | 400 Time OffTheRecordProfileImpl::GetStartTime() const { | 
| 429   return start_time_; | 401   return start_time_; | 
| 430 } | 402 } | 
| 431 | 403 | 
| 432 WebKitContext* OffTheRecordProfileImpl::GetWebKitContext() { |  | 
| 433   CreateQuotaManagerAndClients(); |  | 
| 434   return webkit_context_.get(); |  | 
| 435 } |  | 
| 436 |  | 
| 437 history::TopSites* OffTheRecordProfileImpl::GetTopSitesWithoutCreating() { | 404 history::TopSites* OffTheRecordProfileImpl::GetTopSitesWithoutCreating() { | 
| 438   return NULL; | 405   return NULL; | 
| 439 } | 406 } | 
| 440 | 407 | 
| 441 history::TopSites* OffTheRecordProfileImpl::GetTopSites() { | 408 history::TopSites* OffTheRecordProfileImpl::GetTopSites() { | 
| 442   return NULL; | 409   return NULL; | 
| 443 } | 410 } | 
| 444 | 411 | 
| 445 void OffTheRecordProfileImpl::MarkAsCleanShutdown() { | 412 void OffTheRecordProfileImpl::MarkAsCleanShutdown() { | 
| 446 } | 413 } | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 480   // The preferences are associated with the regular user profile. | 447   // The preferences are associated with the regular user profile. | 
| 481 } | 448 } | 
| 482 #endif  // defined(OS_CHROMEOS) | 449 #endif  // defined(OS_CHROMEOS) | 
| 483 | 450 | 
| 484 void OffTheRecordProfileImpl::OnBrowserAdded(const Browser* browser) { | 451 void OffTheRecordProfileImpl::OnBrowserAdded(const Browser* browser) { | 
| 485 } | 452 } | 
| 486 | 453 | 
| 487 void OffTheRecordProfileImpl::OnBrowserRemoved(const Browser* browser) { | 454 void OffTheRecordProfileImpl::OnBrowserRemoved(const Browser* browser) { | 
| 488 } | 455 } | 
| 489 | 456 | 
| 490 ChromeBlobStorageContext* OffTheRecordProfileImpl::GetBlobStorageContext() { |  | 
| 491   if (!blob_storage_context_) { |  | 
| 492     blob_storage_context_ = new ChromeBlobStorageContext(); |  | 
| 493     BrowserThread::PostTask( |  | 
| 494         BrowserThread::IO, FROM_HERE, |  | 
| 495         base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, |  | 
| 496                    blob_storage_context_.get())); |  | 
| 497   } |  | 
| 498   return blob_storage_context_; |  | 
| 499 } |  | 
| 500 |  | 
| 501 ExtensionInfoMap* OffTheRecordProfileImpl::GetExtensionInfoMap() { | 457 ExtensionInfoMap* OffTheRecordProfileImpl::GetExtensionInfoMap() { | 
| 502   return profile_->GetExtensionInfoMap(); | 458   return profile_->GetExtensionInfoMap(); | 
| 503 } | 459 } | 
| 504 | 460 | 
| 505 ChromeURLDataManager* OffTheRecordProfileImpl::GetChromeURLDataManager() { | 461 ChromeURLDataManager* OffTheRecordProfileImpl::GetChromeURLDataManager() { | 
| 506   if (!chrome_url_data_manager_.get()) | 462   if (!chrome_url_data_manager_.get()) | 
| 507     chrome_url_data_manager_.reset(new ChromeURLDataManager( | 463     chrome_url_data_manager_.reset(new ChromeURLDataManager( | 
| 508         io_data_.GetChromeURLDataManagerBackendGetter())); | 464         io_data_.GetChromeURLDataManagerBackendGetter())); | 
| 509   return chrome_url_data_manager_.get(); | 465   return chrome_url_data_manager_.get(); | 
| 510 } | 466 } | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 550   if (type == content::NOTIFICATION_ZOOM_LEVEL_CHANGED) { | 506   if (type == content::NOTIFICATION_ZOOM_LEVEL_CHANGED) { | 
| 551     const std::string& host = | 507     const std::string& host = | 
| 552         *(content::Details<const std::string>(details).ptr()); | 508         *(content::Details<const std::string>(details).ptr()); | 
| 553     if (!host.empty()) { | 509     if (!host.empty()) { | 
| 554       double level = profile_->GetHostZoomMap()->GetZoomLevel(host); | 510       double level = profile_->GetHostZoomMap()->GetZoomLevel(host); | 
| 555       GetHostZoomMap()->SetZoomLevel(host, level); | 511       GetHostZoomMap()->SetZoomLevel(host, level); | 
| 556     } | 512     } | 
| 557   } | 513   } | 
| 558 } | 514 } | 
| 559 | 515 | 
| 560 void OffTheRecordProfileImpl::CreateQuotaManagerAndClients() { |  | 
| 561   if (quota_manager_.get()) { |  | 
| 562     DCHECK(file_system_context_.get()); |  | 
| 563     DCHECK(db_tracker_.get()); |  | 
| 564     DCHECK(webkit_context_.get()); |  | 
| 565     return; |  | 
| 566   } |  | 
| 567 |  | 
| 568   // All of the clients have to be created and registered with the |  | 
| 569   // QuotaManager prior to the QuotaManger being used. So we do them |  | 
| 570   // all together here prior to handing out a reference to anything |  | 
| 571   // that utlizes the QuotaManager. |  | 
| 572   quota_manager_ = new quota::QuotaManager( |  | 
| 573       IsOffTheRecord(), |  | 
| 574       GetPath(), |  | 
| 575       BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |  | 
| 576       BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |  | 
| 577       GetExtensionSpecialStoragePolicy()); |  | 
| 578 |  | 
| 579   // Each consumer is responsible for registering its QuotaClient during |  | 
| 580   // its construction. |  | 
| 581   file_system_context_ = CreateFileSystemContext( |  | 
| 582       GetPath(), IsOffTheRecord(), |  | 
| 583       GetExtensionSpecialStoragePolicy(), |  | 
| 584       quota_manager_->proxy()); |  | 
| 585   db_tracker_ = new webkit_database::DatabaseTracker( |  | 
| 586       GetPath(), IsOffTheRecord(), false, GetExtensionSpecialStoragePolicy(), |  | 
| 587       quota_manager_->proxy(), |  | 
| 588       BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |  | 
| 589   webkit_context_ = new WebKitContext( |  | 
| 590       IsOffTheRecord(), GetPath(), GetExtensionSpecialStoragePolicy(), |  | 
| 591       false, quota_manager_->proxy(), |  | 
| 592       BrowserThread::GetMessageLoopProxyForThread( |  | 
| 593           BrowserThread::WEBKIT_DEPRECATED)); |  | 
| 594   appcache_service_ = new ChromeAppCacheService(quota_manager_->proxy()); |  | 
| 595   BrowserThread::PostTask( |  | 
| 596     BrowserThread::IO, FROM_HERE, |  | 
| 597     base::Bind(&ChromeAppCacheService::InitializeOnIOThread, |  | 
| 598                appcache_service_.get(), |  | 
| 599                IsOffTheRecord() |  | 
| 600                    ? FilePath() : GetPath().Append(chrome::kAppCacheDirname), |  | 
| 601                io_data_.GetResourceContextNoInit(), |  | 
| 602                make_scoped_refptr(GetExtensionSpecialStoragePolicy()))); |  | 
| 603 } |  | 
| 604 |  | 
| 605 #if defined(OS_CHROMEOS) | 516 #if defined(OS_CHROMEOS) | 
| 606 // Special case of the OffTheRecordProfileImpl which is used while Guest | 517 // Special case of the OffTheRecordProfileImpl which is used while Guest | 
| 607 // session in CrOS. | 518 // session in CrOS. | 
| 608 class GuestSessionProfile : public OffTheRecordProfileImpl { | 519 class GuestSessionProfile : public OffTheRecordProfileImpl { | 
| 609  public: | 520  public: | 
| 610   explicit GuestSessionProfile(Profile* real_profile) | 521   explicit GuestSessionProfile(Profile* real_profile) | 
| 611       : OffTheRecordProfileImpl(real_profile) { | 522       : OffTheRecordProfileImpl(real_profile) { | 
| 612   } | 523   } | 
| 613 | 524 | 
| 614   virtual void InitChromeOSPreferences() { | 525   virtual void InitChromeOSPreferences() { | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 626   OffTheRecordProfileImpl* profile = NULL; | 537   OffTheRecordProfileImpl* profile = NULL; | 
| 627 #if defined(OS_CHROMEOS) | 538 #if defined(OS_CHROMEOS) | 
| 628   if (Profile::IsGuestSession()) | 539   if (Profile::IsGuestSession()) | 
| 629     profile = new GuestSessionProfile(this); | 540     profile = new GuestSessionProfile(this); | 
| 630 #endif | 541 #endif | 
| 631   if (!profile) | 542   if (!profile) | 
| 632     profile = new OffTheRecordProfileImpl(this); | 543     profile = new OffTheRecordProfileImpl(this); | 
| 633   profile->Init(); | 544   profile->Init(); | 
| 634   return profile; | 545   return profile; | 
| 635 } | 546 } | 
| OLD | NEW | 
|---|