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/profile_impl.h" | 5 #include "chrome/browser/profiles/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/environment.h" | 10 #include "base/environment.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/string_tokenizer.h" | 15 #include "base/string_tokenizer.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 #include "base/version.h" | 19 #include "base/version.h" |
20 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 20 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
21 #include "chrome/browser/background/background_contents_service_factory.h" | 21 #include "chrome/browser/background/background_contents_service_factory.h" |
22 #include "chrome/browser/background/background_mode_manager.h" | 22 #include "chrome/browser/background/background_mode_manager.h" |
23 #include "chrome/browser/bookmarks/bookmark_model.h" | 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
25 #include "chrome/browser/chrome_plugin_service_filter.h" | 25 #include "chrome/browser/chrome_plugin_service_filter.h" |
26 #include "chrome/browser/content_settings/cookie_settings.h" | 26 #include "chrome/browser/content_settings/cookie_settings.h" |
27 #include "chrome/browser/content_settings/host_content_settings_map.h" | 27 #include "chrome/browser/content_settings/host_content_settings_map.h" |
28 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 28 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
29 #include "chrome/browser/download/download_service.h" | 29 #include "chrome/browser/download/download_service.h" |
30 #include "chrome/browser/download/download_service_factory.h" | 30 #include "chrome/browser/download/download_service_factory.h" |
31 #include "chrome/browser/extensions/extension_event_router.h" | 31 #include "chrome/browser/extensions/extension_event_router.h" |
32 #include "chrome/browser/extensions/extension_pref_store.h" | 32 #include "chrome/browser/extensions/extension_pref_store.h" |
33 #include "chrome/browser/extensions/extension_pref_value_map.h" | 33 #include "chrome/browser/extensions/extension_pref_value_map.h" |
34 #include "chrome/browser/extensions/extension_pref_value_map_factory.h" | 34 #include "chrome/browser/extensions/extension_pref_value_map_factory.h" |
35 #include "chrome/browser/extensions/extension_process_manager.h" | 35 #include "chrome/browser/extensions/extension_process_manager.h" |
36 #include "chrome/browser/extensions/extension_service.h" | 36 #include "chrome/browser/extensions/extension_service.h" |
37 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 37 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
38 #include "chrome/browser/extensions/extension_system.h" | 38 #include "chrome/browser/extensions/extension_system.h" |
39 #include "chrome/browser/extensions/user_script_master.h" | 39 #include "chrome/browser/extensions/user_script_master.h" |
40 #include "chrome/browser/favicon/favicon_service.h" | 40 #include "chrome/browser/favicon/favicon_service.h" |
41 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" | 41 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
42 #include "chrome/browser/history/history.h" | 42 #include "chrome/browser/history/history.h" |
43 #include "chrome/browser/history/history_service_factory.h" | |
43 #include "chrome/browser/history/shortcuts_backend.h" | 44 #include "chrome/browser/history/shortcuts_backend.h" |
44 #include "chrome/browser/history/top_sites.h" | 45 #include "chrome/browser/history/top_sites.h" |
45 #include "chrome/browser/instant/instant_controller.h" | 46 #include "chrome/browser/instant/instant_controller.h" |
46 #include "chrome/browser/metrics/metrics_service.h" | 47 #include "chrome/browser/metrics/metrics_service.h" |
47 #include "chrome/browser/net/chrome_url_request_context.h" | 48 #include "chrome/browser/net/chrome_url_request_context.h" |
48 #include "chrome/browser/net/net_pref_observer.h" | 49 #include "chrome/browser/net/net_pref_observer.h" |
49 #include "chrome/browser/net/predictor.h" | 50 #include "chrome/browser/net/predictor.h" |
50 #include "chrome/browser/net/proxy_service_factory.h" | 51 #include "chrome/browser/net/proxy_service_factory.h" |
51 #include "chrome/browser/net/ssl_config_service_manager.h" | 52 #include "chrome/browser/net/ssl_config_service_manager.h" |
52 #include "chrome/browser/net/url_fixer_upper.h" | 53 #include "chrome/browser/net/url_fixer_upper.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 } | 218 } |
218 | 219 |
219 ProfileImpl::ProfileImpl(const FilePath& path, | 220 ProfileImpl::ProfileImpl(const FilePath& path, |
220 Delegate* delegate, | 221 Delegate* delegate, |
221 CreateMode create_mode) | 222 CreateMode create_mode) |
222 : path_(path), | 223 : path_(path), |
223 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( | 224 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( |
224 new VisitedLinkEventListener(this))), | 225 new VisitedLinkEventListener(this))), |
225 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), | 226 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), |
226 host_content_settings_map_(NULL), | 227 host_content_settings_map_(NULL), |
227 history_service_created_(false), | |
228 favicon_service_created_(false), | 228 favicon_service_created_(false), |
229 clear_local_state_on_exit_(false), | 229 clear_local_state_on_exit_(false), |
230 start_time_(Time::Now()), | 230 start_time_(Time::Now()), |
231 delegate_(delegate), | 231 delegate_(delegate), |
232 predictor_(NULL), | 232 predictor_(NULL), |
233 session_restore_enabled_(false) { | 233 session_restore_enabled_(false) { |
234 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << | 234 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
235 "profile files to the root directory!"; | 235 "profile files to the root directory!"; |
236 | 236 |
237 #if defined(ENABLE_SESSION_SERVICE) | 237 #if defined(ENABLE_SESSION_SERVICE) |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 // The HistoryService maintains threads for background processing. Its | 512 // The HistoryService maintains threads for background processing. Its |
513 // possible each thread still has tasks on it that have increased the ref | 513 // possible each thread still has tasks on it that have increased the ref |
514 // count of the service. In such a situation, when we decrement the refcount, | 514 // count of the service. In such a situation, when we decrement the refcount, |
515 // it won't be 0, and the threads/databases aren't properly shut down. By | 515 // it won't be 0, and the threads/databases aren't properly shut down. By |
516 // explicitly calling Cleanup/Shutdown we ensure the databases are properly | 516 // explicitly calling Cleanup/Shutdown we ensure the databases are properly |
517 // closed. | 517 // closed. |
518 | 518 |
519 if (top_sites_.get()) | 519 if (top_sites_.get()) |
520 top_sites_->Shutdown(); | 520 top_sites_->Shutdown(); |
521 | 521 |
522 if (bookmark_bar_model_.get()) { | |
523 // It's possible that bookmarks haven't loaded and history is waiting for | |
524 // bookmarks to complete loading. In such a situation history can't shutdown | |
525 // (meaning if we invoked history_service_->Cleanup now, we would | |
526 // deadlock). To break the deadlock we tell BookmarkModel it's about to be | |
527 // deleted so that it can release the signal history is waiting on, allowing | |
528 // history to shutdown (history_service_->Cleanup to complete). In such a | |
529 // scenario history sees an incorrect view of bookmarks, but it's better | |
530 // than a deadlock. | |
531 bookmark_bar_model_->Cleanup(); | |
532 } | |
533 | |
534 if (history_service_.get()) | |
535 history_service_->Cleanup(); | |
536 | |
537 // HistoryService may call into the BookmarkModel, as such we need to | |
sky
2012/05/21 14:23:06
How is this handled now?
rpetterson
2012/05/21 18:01:49
HistoryService is marked as being dependent on the
sky
2012/05/21 20:37:17
What you have is fine. I just wanted to make sure
| |
538 // delete HistoryService before the BookmarkModel. The destructor for | |
539 // HistoryService will join with HistoryService's backend thread so that | |
540 // by the time the destructor has finished we're sure it will no longer call | |
541 // into the BookmarkModel. | |
542 history_service_ = NULL; | |
543 bookmark_bar_model_.reset(); | |
544 | |
545 // FaviconService depends on HistoryServce so make sure we delete | 522 // FaviconService depends on HistoryServce so make sure we delete |
546 // HistoryService first. | 523 // HistoryService first. |
547 favicon_service_.reset(); | 524 favicon_service_.reset(); |
548 | 525 |
549 if (pref_proxy_config_tracker_.get()) | 526 if (pref_proxy_config_tracker_.get()) |
550 pref_proxy_config_tracker_->DetachFromPrefService(); | 527 pref_proxy_config_tracker_->DetachFromPrefService(); |
551 | 528 |
552 if (protocol_handler_registry_) | 529 if (protocol_handler_registry_) |
553 protocol_handler_registry_->Finalize(); | 530 protocol_handler_registry_->Finalize(); |
554 | 531 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
787 | 764 |
788 GAIAInfoUpdateService* ProfileImpl::GetGAIAInfoUpdateService() { | 765 GAIAInfoUpdateService* ProfileImpl::GetGAIAInfoUpdateService() { |
789 if (!gaia_info_update_service_.get() && | 766 if (!gaia_info_update_service_.get() && |
790 GAIAInfoUpdateService::ShouldUseGAIAProfileInfo(this)) { | 767 GAIAInfoUpdateService::ShouldUseGAIAProfileInfo(this)) { |
791 gaia_info_update_service_.reset(new GAIAInfoUpdateService(this)); | 768 gaia_info_update_service_.reset(new GAIAInfoUpdateService(this)); |
792 } | 769 } |
793 return gaia_info_update_service_.get(); | 770 return gaia_info_update_service_.get(); |
794 } | 771 } |
795 | 772 |
796 HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) { | 773 HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) { |
797 // If saving history is disabled, only allow explicit access. | 774 return HistoryServiceFactory::GetForProfile(this, sat).get(); |
798 if (GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) && | |
799 sat != EXPLICIT_ACCESS) | |
800 return NULL; | |
801 | |
802 if (!history_service_created_) { | |
803 history_service_created_ = true; | |
804 scoped_refptr<HistoryService> history(new HistoryService(this)); | |
805 if (!history->Init(GetPath(), GetBookmarkModel())) | |
806 return NULL; | |
807 history_service_.swap(history); | |
808 } | |
809 return history_service_.get(); | |
810 } | 775 } |
811 | 776 |
812 HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() { | 777 HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() { |
813 return history_service_.get(); | 778 return HistoryServiceFactory::GetForProfileIfExists(this).get(); |
814 } | 779 } |
815 | 780 |
816 AutocompleteClassifier* ProfileImpl::GetAutocompleteClassifier() { | 781 AutocompleteClassifier* ProfileImpl::GetAutocompleteClassifier() { |
817 if (!autocomplete_classifier_.get()) | 782 if (!autocomplete_classifier_.get()) |
818 autocomplete_classifier_.reset(new AutocompleteClassifier(this)); | 783 autocomplete_classifier_.reset(new AutocompleteClassifier(this)); |
819 return autocomplete_classifier_.get(); | 784 return autocomplete_classifier_.get(); |
820 } | 785 } |
821 | 786 |
822 history::ShortcutsBackend* ProfileImpl::GetShortcutsBackend() { | 787 history::ShortcutsBackend* ProfileImpl::GetShortcutsBackend() { |
823 // This is called on one thread only - UI, so no magic is needed to protect | 788 // This is called on one thread only - UI, so no magic is needed to protect |
(...skipping 14 matching lines...) Expand all Loading... | |
838 // it to be set by asking for the prefs. | 803 // it to be set by asking for the prefs. |
839 GetPrefs(); | 804 GetPrefs(); |
840 return last_session_exited_cleanly_; | 805 return last_session_exited_cleanly_; |
841 } | 806 } |
842 | 807 |
843 quota::SpecialStoragePolicy* ProfileImpl::GetSpecialStoragePolicy() { | 808 quota::SpecialStoragePolicy* ProfileImpl::GetSpecialStoragePolicy() { |
844 return GetExtensionSpecialStoragePolicy(); | 809 return GetExtensionSpecialStoragePolicy(); |
845 } | 810 } |
846 | 811 |
847 BookmarkModel* ProfileImpl::GetBookmarkModel() { | 812 BookmarkModel* ProfileImpl::GetBookmarkModel() { |
848 if (!bookmark_bar_model_.get()) { | 813 return BookmarkModelFactory::GetForProfile(this); |
849 bookmark_bar_model_.reset(new BookmarkModel(this)); | |
850 bookmark_bar_model_->Load(); | |
851 } | |
852 return bookmark_bar_model_.get(); | |
853 } | 814 } |
854 | 815 |
855 ProtocolHandlerRegistry* ProfileImpl::GetProtocolHandlerRegistry() { | 816 ProtocolHandlerRegistry* ProfileImpl::GetProtocolHandlerRegistry() { |
856 return protocol_handler_registry_.get(); | 817 return protocol_handler_registry_.get(); |
857 } | 818 } |
858 | 819 |
859 bool ProfileImpl::IsSameProfile(Profile* profile) { | 820 bool ProfileImpl::IsSameProfile(Profile* profile) { |
860 if (profile == static_cast<Profile*>(this)) | 821 if (profile == static_cast<Profile*>(this)) |
861 return true; | 822 return true; |
862 Profile* otr_profile = off_the_record_profile_.get(); | 823 Profile* otr_profile = off_the_record_profile_.get(); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1152 if (!path.empty()) | 1113 if (!path.empty()) |
1153 *cache_path = path; | 1114 *cache_path = path; |
1154 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1115 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
1155 prefs_->GetInteger(prefs::kDiskCacheSize); | 1116 prefs_->GetInteger(prefs::kDiskCacheSize); |
1156 } | 1117 } |
1157 | 1118 |
1158 base::Callback<ChromeURLDataManagerBackend*(void)> | 1119 base::Callback<ChromeURLDataManagerBackend*(void)> |
1159 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { | 1120 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { |
1160 return io_data_.GetChromeURLDataManagerBackendGetter(); | 1121 return io_data_.GetChromeURLDataManagerBackendGetter(); |
1161 } | 1122 } |
OLD | NEW |