Chromium Code Reviews| 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" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "chrome/app/locales/locale_settings.h" | 13 #include "chrome/app/locales/locale_settings.h" |
| 14 #include "chrome/browser/browser_list.h" | 14 #include "chrome/browser/browser_list.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/extensions/extensions_service.h" | 16 #include "chrome/browser/extensions/extensions_service.h" |
| 17 #include "chrome/browser/extensions/user_script_master.h" | 17 #include "chrome/browser/extensions/user_script_master.h" |
| 18 #include "chrome/browser/net/chrome_url_request_context.h" | 18 #include "chrome/browser/net/chrome_url_request_context.h" |
| 19 #include "chrome/browser/profile_manager.h" | 19 #include "chrome/browser/profile_manager.h" |
| 20 #include "chrome/browser/renderer_host/render_process_host.h" | 20 #include "chrome/browser/renderer_host/render_process_host.h" |
| 21 #include "chrome/browser/search_engines/template_url_model.h" | 21 #include "chrome/browser/search_engines/template_url_model.h" |
| 22 #include "chrome/browser/ssl/ssl_host_state.h" | |
| 22 #include "chrome/browser/visitedlink_master.h" | 23 #include "chrome/browser/visitedlink_master.h" |
| 23 #include "chrome/browser/webdata/web_data_service.h" | 24 #include "chrome/browser/webdata/web_data_service.h" |
| 24 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
| 25 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/notification_service.h" | 28 #include "chrome/common/notification_service.h" |
| 28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 29 #include "chrome/common/pref_service.h" | 30 #include "chrome/common/pref_service.h" |
| 30 #include "chrome/common/render_messages.h" | 31 #include "chrome/common/render_messages.h" |
| 31 #include "chrome/common/resource_bundle.h" | 32 #include "chrome/common/resource_bundle.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 52 using base::Time; | 53 using base::Time; |
| 53 using base::TimeDelta; | 54 using base::TimeDelta; |
| 54 | 55 |
| 55 // Delay, in milliseconds, before we explicitly create the SessionService. | 56 // Delay, in milliseconds, before we explicitly create the SessionService. |
| 56 static const int kCreateSessionServiceDelayMS = 500; | 57 static const int kCreateSessionServiceDelayMS = 500; |
| 57 | 58 |
| 58 // A pointer to the request context for the default profile. See comments on | 59 // A pointer to the request context for the default profile. See comments on |
| 59 // Profile::GetDefaultRequestContext. | 60 // Profile::GetDefaultRequestContext. |
| 60 URLRequestContext* Profile::default_request_context_; | 61 URLRequestContext* Profile::default_request_context_; |
| 61 | 62 |
| 62 //static | 63 // static |
| 63 void Profile::RegisterUserPrefs(PrefService* prefs) { | 64 void Profile::RegisterUserPrefs(PrefService* prefs) { |
| 64 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true); | 65 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true); |
| 65 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true); | 66 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true); |
| 66 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true); | 67 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true); |
| 67 #if defined(OS_MACOSX) | 68 #if defined(OS_MACOSX) |
| 68 // MASSIVE HACK!!! We don't have localization working yet. Undo this once we | 69 // MASSIVE HACK!!! We don't have localization working yet. Undo this once we |
| 69 // do. TODO(port): take this out | 70 // do. TODO(port): take this out |
| 70 prefs->RegisterStringPref(prefs::kSpellCheckDictionary, | 71 prefs->RegisterStringPref(prefs::kSpellCheckDictionary, |
| 71 L"IDS_SPELLCHECK_DICTIONARY"); | 72 L"IDS_SPELLCHECK_DICTIONARY"); |
| 72 #elif defined(OS_WIN) || defined(OS_LINUX) | 73 #elif defined(OS_WIN) || defined(OS_LINUX) |
| 73 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary, | 74 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary, |
| 74 IDS_SPELLCHECK_DICTIONARY); | 75 IDS_SPELLCHECK_DICTIONARY); |
| 75 #endif | 76 #endif |
| 76 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true); | 77 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true); |
| 77 } | 78 } |
| 78 | 79 |
| 79 //static | 80 // static |
| 80 Profile* Profile::CreateProfile(const FilePath& path) { | 81 Profile* Profile::CreateProfile(const FilePath& path) { |
| 81 return new ProfileImpl(path); | 82 return new ProfileImpl(path); |
| 82 } | 83 } |
| 83 | 84 |
| 84 //static | 85 // static |
| 85 URLRequestContext* Profile::GetDefaultRequestContext() { | 86 URLRequestContext* Profile::GetDefaultRequestContext() { |
| 86 return default_request_context_; | 87 return default_request_context_; |
| 87 } | 88 } |
| 88 | 89 |
| 89 | 90 |
| 90 //////////////////////////////////////////////////////////////////////////////// | 91 //////////////////////////////////////////////////////////////////////////////// |
| 91 // | 92 // |
| 92 // OffTheRecordProfileImpl is a profile subclass that wraps an existing profile | 93 // OffTheRecordProfileImpl is a profile subclass that wraps an existing profile |
| 93 // to make it suitable for the off the record mode. | 94 // to make it suitable for the off the record mode. |
| 94 // | 95 // |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 } | 146 } |
| 146 | 147 |
| 147 virtual ExtensionsService* GetExtensionsService() { | 148 virtual ExtensionsService* GetExtensionsService() { |
| 148 return profile_->GetExtensionsService(); | 149 return profile_->GetExtensionsService(); |
| 149 } | 150 } |
| 150 | 151 |
| 151 virtual UserScriptMaster* GetUserScriptMaster() { | 152 virtual UserScriptMaster* GetUserScriptMaster() { |
| 152 return profile_->GetUserScriptMaster(); | 153 return profile_->GetUserScriptMaster(); |
| 153 } | 154 } |
| 154 | 155 |
| 156 virtual SSLHostState* GetSSLHostState() { | |
| 157 if (!ssl_host_state_.get()) | |
| 158 ssl_host_state_.reset(new SSLHostState()); | |
| 159 | |
| 160 DCHECK(ssl_host_state_->CalledOnValidThread()); | |
| 161 return ssl_host_state_.get(); | |
| 162 } | |
| 163 | |
| 155 virtual HistoryService* GetHistoryService(ServiceAccessType sat) { | 164 virtual HistoryService* GetHistoryService(ServiceAccessType sat) { |
| 156 if (sat == EXPLICIT_ACCESS) { | 165 if (sat == EXPLICIT_ACCESS) { |
| 157 return profile_->GetHistoryService(sat); | 166 return profile_->GetHistoryService(sat); |
| 158 } else { | 167 } else { |
| 159 NOTREACHED() << "This profile is OffTheRecord"; | 168 NOTREACHED() << "This profile is OffTheRecord"; |
| 160 return NULL; | 169 return NULL; |
| 161 } | 170 } |
| 162 } | 171 } |
| 163 | 172 |
| 164 virtual WebDataService* GetWebDataService(ServiceAccessType sat) { | 173 virtual WebDataService* GetWebDataService(ServiceAccessType sat) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 private: | 308 private: |
| 300 // The real underlying profile. | 309 // The real underlying profile. |
| 301 Profile* profile_; | 310 Profile* profile_; |
| 302 | 311 |
| 303 // The context to use for requests made from this OTR session. | 312 // The context to use for requests made from this OTR session. |
| 304 ChromeURLRequestContext* request_context_; | 313 ChromeURLRequestContext* request_context_; |
| 305 | 314 |
| 306 // The download manager that only stores downloaded items in memory. | 315 // The download manager that only stores downloaded items in memory. |
| 307 scoped_refptr<DownloadManager> download_manager_; | 316 scoped_refptr<DownloadManager> download_manager_; |
| 308 | 317 |
| 318 // We don't want SSLHostState from the OTR profile to leak back to the main | |
| 319 // profile because then the main profile would learn some of the host names | |
|
wtc
2009/02/12 21:41:46
I like this comment!
| |
| 320 // the user visited while OTR. | |
| 321 scoped_ptr<SSLHostState> ssl_host_state_; | |
| 322 | |
| 309 // Time we were started. | 323 // Time we were started. |
| 310 Time start_time_; | 324 Time start_time_; |
| 311 | 325 |
| 312 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl); | 326 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl); |
| 313 }; | 327 }; |
| 314 | 328 |
| 315 ProfileImpl::ProfileImpl(const FilePath& path) | 329 ProfileImpl::ProfileImpl(const FilePath& path) |
| 316 : path_(path), | 330 : path_(path), |
| 317 off_the_record_(false), | 331 off_the_record_(false), |
| 318 #ifdef CHROME_PERSONALIZATION | 332 #ifdef CHROME_PERSONALIZATION |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 336 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this); | 350 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this); |
| 337 } | 351 } |
| 338 | 352 |
| 339 void ProfileImpl::InitExtensions() { | 353 void ProfileImpl::InitExtensions() { |
| 340 if (user_script_master_ || extensions_service_) | 354 if (user_script_master_ || extensions_service_) |
| 341 return; // Already initialized. | 355 return; // Already initialized. |
| 342 | 356 |
| 343 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 357 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 344 bool user_scripts_enabled = | 358 bool user_scripts_enabled = |
| 345 command_line->HasSwitch(switches::kEnableUserScripts); | 359 command_line->HasSwitch(switches::kEnableUserScripts); |
| 346 bool extensions_enabled = | 360 bool extensions_enabled = |
| 347 command_line->HasSwitch(switches::kEnableExtensions); | 361 command_line->HasSwitch(switches::kEnableExtensions); |
| 348 | 362 |
| 349 FilePath script_dir; | 363 FilePath script_dir; |
| 350 if (user_scripts_enabled) { | 364 if (user_scripts_enabled) { |
| 351 script_dir = GetPath(); | 365 script_dir = GetPath(); |
| 352 script_dir = script_dir.Append(chrome::kUserScriptsDirname); | 366 script_dir = script_dir.Append(chrome::kUserScriptsDirname); |
| 353 } | 367 } |
| 354 | 368 |
| 355 user_script_master_ = new UserScriptMaster( | 369 user_script_master_ = new UserScriptMaster( |
| 356 g_browser_process->file_thread()->message_loop(), script_dir); | 370 g_browser_process->file_thread()->message_loop(), script_dir); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 } | 506 } |
| 493 | 507 |
| 494 ExtensionsService* ProfileImpl::GetExtensionsService() { | 508 ExtensionsService* ProfileImpl::GetExtensionsService() { |
| 495 return extensions_service_.get(); | 509 return extensions_service_.get(); |
| 496 } | 510 } |
| 497 | 511 |
| 498 UserScriptMaster* ProfileImpl::GetUserScriptMaster() { | 512 UserScriptMaster* ProfileImpl::GetUserScriptMaster() { |
| 499 return user_script_master_.get(); | 513 return user_script_master_.get(); |
| 500 } | 514 } |
| 501 | 515 |
| 516 SSLHostState* ProfileImpl::GetSSLHostState() { | |
| 517 if (!ssl_host_state_.get()) | |
| 518 ssl_host_state_.reset(new SSLHostState()); | |
| 519 | |
| 520 DCHECK(ssl_host_state_->CalledOnValidThread()); | |
| 521 return ssl_host_state_.get(); | |
| 522 } | |
| 523 | |
| 502 PrefService* ProfileImpl::GetPrefs() { | 524 PrefService* ProfileImpl::GetPrefs() { |
| 503 if (!prefs_.get()) { | 525 if (!prefs_.get()) { |
| 504 prefs_.reset(new PrefService(GetPrefFilePath().ToWStringHack())); | 526 prefs_.reset(new PrefService(GetPrefFilePath().ToWStringHack())); |
| 505 | 527 |
| 506 // The Profile class and ProfileManager class may read some prefs so | 528 // The Profile class and ProfileManager class may read some prefs so |
| 507 // register known prefs as soon as possible. | 529 // register known prefs as soon as possible. |
| 508 Profile::RegisterUserPrefs(prefs_.get()); | 530 Profile::RegisterUserPrefs(prefs_.get()); |
| 509 ProfileManager::RegisterUserPrefs(prefs_.get()); | 531 ProfileManager::RegisterUserPrefs(prefs_.get()); |
| 510 | 532 |
| 511 // The last session exited cleanly if there is no pref for | 533 // The last session exited cleanly if there is no pref for |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 677 TabRestoreService* ProfileImpl::GetTabRestoreService() { | 699 TabRestoreService* ProfileImpl::GetTabRestoreService() { |
| 678 if (!tab_restore_service_.get()) | 700 if (!tab_restore_service_.get()) |
| 679 tab_restore_service_ = new TabRestoreService(this); | 701 tab_restore_service_ = new TabRestoreService(this); |
| 680 return tab_restore_service_.get(); | 702 return tab_restore_service_.get(); |
| 681 } | 703 } |
| 682 | 704 |
| 683 void ProfileImpl::ResetTabRestoreService() { | 705 void ProfileImpl::ResetTabRestoreService() { |
| 684 tab_restore_service_ = NULL; | 706 tab_restore_service_ = NULL; |
| 685 } | 707 } |
| 686 | 708 |
| 687 // To be run in the IO thread to notify all resource message filters that the | 709 // To be run in the IO thread to notify all resource message filters that the |
| 688 // spellchecker has changed. | 710 // spellchecker has changed. |
| 689 class NotifySpellcheckerChangeTask : public Task { | 711 class NotifySpellcheckerChangeTask : public Task { |
| 690 public: | 712 public: |
| 691 NotifySpellcheckerChangeTask( | 713 NotifySpellcheckerChangeTask( |
| 692 Profile* profile, | 714 Profile* profile, |
| 693 const SpellcheckerReinitializedDetails& spellchecker) | 715 const SpellcheckerReinitializedDetails& spellchecker) |
| 694 : profile_(profile), | 716 : profile_(profile), |
| 695 spellchecker_(spellchecker) { | 717 spellchecker_(spellchecker) { |
| 696 } | 718 } |
| 697 | 719 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 721 last_spellchecker->Release(); | 743 last_spellchecker->Release(); |
| 722 } | 744 } |
| 723 | 745 |
| 724 // Retrieve the (perhaps updated recently) dictionary name from preferences. | 746 // Retrieve the (perhaps updated recently) dictionary name from preferences. |
| 725 PrefService* prefs = GetPrefs(); | 747 PrefService* prefs = GetPrefs(); |
| 726 bool enable_spellcheck = prefs->GetBoolean(prefs::kEnableSpellCheck); | 748 bool enable_spellcheck = prefs->GetBoolean(prefs::kEnableSpellCheck); |
| 727 | 749 |
| 728 if (enable_spellcheck) { | 750 if (enable_spellcheck) { |
| 729 std::wstring dict_dir; | 751 std::wstring dict_dir; |
| 730 PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir); | 752 PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir); |
| 731 // Note that, as the object pointed to by previously by spellchecker_ | 753 // Note that, as the object pointed to by previously by spellchecker_ |
| 732 // is being deleted in the io thread, the spellchecker_ can be made to point | 754 // is being deleted in the io thread, the spellchecker_ can be made to point |
| 733 // to a new object (RE-initialized) in parallel in this UI thread. | 755 // to a new object (RE-initialized) in parallel in this UI thread. |
| 734 spellchecker_ = new SpellChecker(dict_dir, | 756 spellchecker_ = new SpellChecker(dict_dir, |
| 735 prefs->GetString(prefs::kSpellCheckDictionary), GetRequestContext(), | 757 prefs->GetString(prefs::kSpellCheckDictionary), GetRequestContext(), |
| 736 std::wstring()); | 758 std::wstring()); |
| 737 spellchecker_->AddRef(); // Manual refcounting. | 759 spellchecker_->AddRef(); // Manual refcounting. |
| 738 } else { | 760 } else { |
| 739 spellchecker_ = NULL; | 761 spellchecker_ = NULL; |
| 740 } | 762 } |
| 741 | 763 |
| 742 if (need_to_broadcast && io_thread) { // Notify resource message filters. | 764 if (need_to_broadcast && io_thread) { // Notify resource message filters. |
| 743 SpellcheckerReinitializedDetails scoped_spellchecker; | 765 SpellcheckerReinitializedDetails scoped_spellchecker; |
| 744 scoped_spellchecker.spellchecker = spellchecker_; | 766 scoped_spellchecker.spellchecker = spellchecker_; |
| 745 if (io_thread) { | 767 if (io_thread) { |
| 746 io_thread->message_loop()->PostTask( | 768 io_thread->message_loop()->PostTask( |
| 747 FROM_HERE, | 769 FROM_HERE, |
| 748 new NotifySpellcheckerChangeTask(this, scoped_spellchecker)); | 770 new NotifySpellcheckerChangeTask(this, scoped_spellchecker)); |
| 749 } | 771 } |
| 750 } | 772 } |
| 751 } | 773 } |
| 752 | 774 |
| 753 void ProfileImpl::ReinitializeSpellChecker() { | 775 void ProfileImpl::ReinitializeSpellChecker() { |
| 754 InitializeSpellChecker(true); | 776 InitializeSpellChecker(true); |
| 755 } | 777 } |
| 756 | 778 |
| 757 SpellChecker* ProfileImpl::GetSpellChecker() { | 779 SpellChecker* ProfileImpl::GetSpellChecker() { |
| 758 if (!spellchecker_) { | 780 if (!spellchecker_) { |
| 759 // This is where spellchecker gets initialized. Note that this is being | 781 // This is where spellchecker gets initialized. Note that this is being |
| 760 // initialized in the ui_thread. However, this is not a problem as long as | 782 // initialized in the ui_thread. However, this is not a problem as long as |
| 761 // it is *used* in the io thread. | 783 // it is *used* in the io thread. |
| 762 // TODO (sidchat) One day, change everything so that spellchecker gets | 784 // TODO(sidchat): One day, change everything so that spellchecker gets |
| 763 // initialized in the IO thread itself. | 785 // initialized in the IO thread itself. |
| 764 InitializeSpellChecker(false); | 786 InitializeSpellChecker(false); |
| 765 } | 787 } |
| 766 | 788 |
| 767 return spellchecker_; | 789 return spellchecker_; |
| 768 } | 790 } |
| 769 | 791 |
| 770 void ProfileImpl::MarkAsCleanShutdown() { | 792 void ProfileImpl::MarkAsCleanShutdown() { |
| 771 if (prefs_.get()) { | 793 if (prefs_.get()) { |
| 772 // The session cleanly exited, set kSessionExitedCleanly appropriately. | 794 // The session cleanly exited, set kSessionExitedCleanly appropriately. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 797 } | 819 } |
| 798 | 820 |
| 799 #ifdef CHROME_PERSONALIZATION | 821 #ifdef CHROME_PERSONALIZATION |
| 800 ProfilePersonalization* ProfileImpl::GetProfilePersonalization() { | 822 ProfilePersonalization* ProfileImpl::GetProfilePersonalization() { |
| 801 if (!personalization_.get()) | 823 if (!personalization_.get()) |
| 802 personalization_.reset( | 824 personalization_.reset( |
| 803 Personalization::CreateProfilePersonalization(this)); | 825 Personalization::CreateProfilePersonalization(this)); |
| 804 return personalization_.get(); | 826 return personalization_.get(); |
| 805 } | 827 } |
| 806 #endif | 828 #endif |
| OLD | NEW |