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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 } | 226 } |
226 | 227 |
227 ProfileImpl::ProfileImpl(const FilePath& path, | 228 ProfileImpl::ProfileImpl(const FilePath& path, |
228 Delegate* delegate, | 229 Delegate* delegate, |
229 CreateMode create_mode) | 230 CreateMode create_mode) |
230 : path_(path), | 231 : path_(path), |
231 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( | 232 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( |
232 new VisitedLinkEventListener(this))), | 233 new VisitedLinkEventListener(this))), |
233 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), | 234 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), |
234 host_content_settings_map_(NULL), | 235 host_content_settings_map_(NULL), |
235 history_service_created_(false), | |
236 favicon_service_created_(false), | 236 favicon_service_created_(false), |
237 start_time_(Time::Now()), | 237 start_time_(Time::Now()), |
238 delegate_(delegate), | 238 delegate_(delegate), |
239 predictor_(NULL), | 239 predictor_(NULL), |
240 session_restore_enabled_(false) { | 240 session_restore_enabled_(false) { |
241 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << | 241 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
242 "profile files to the root directory!"; | 242 "profile files to the root directory!"; |
243 | 243 |
244 #if defined(ENABLE_SESSION_SERVICE) | 244 #if defined(ENABLE_SESSION_SERVICE) |
245 create_session_service_timer_.Start(FROM_HERE, | 245 create_session_service_timer_.Start(FROM_HERE, |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 // The HistoryService maintains threads for background processing. Its | 508 // The HistoryService maintains threads for background processing. Its |
509 // possible each thread still has tasks on it that have increased the ref | 509 // possible each thread still has tasks on it that have increased the ref |
510 // count of the service. In such a situation, when we decrement the refcount, | 510 // count of the service. In such a situation, when we decrement the refcount, |
511 // it won't be 0, and the threads/databases aren't properly shut down. By | 511 // it won't be 0, and the threads/databases aren't properly shut down. By |
512 // explicitly calling Cleanup/Shutdown we ensure the databases are properly | 512 // explicitly calling Cleanup/Shutdown we ensure the databases are properly |
513 // closed. | 513 // closed. |
514 | 514 |
515 if (top_sites_.get()) | 515 if (top_sites_.get()) |
516 top_sites_->Shutdown(); | 516 top_sites_->Shutdown(); |
517 | 517 |
518 if (bookmark_bar_model_.get()) { | |
519 // It's possible that bookmarks haven't loaded and history is waiting for | |
520 // bookmarks to complete loading. In such a situation history can't shutdown | |
521 // (meaning if we invoked history_service_->Cleanup now, we would | |
522 // deadlock). To break the deadlock we tell BookmarkModel it's about to be | |
523 // deleted so that it can release the signal history is waiting on, allowing | |
524 // history to shutdown (history_service_->Cleanup to complete). In such a | |
525 // scenario history sees an incorrect view of bookmarks, but it's better | |
526 // than a deadlock. | |
527 bookmark_bar_model_->Cleanup(); | |
528 } | |
529 | |
530 if (history_service_.get()) | |
531 history_service_->Cleanup(); | |
532 | |
533 // HistoryService may call into the BookmarkModel, as such we need to | |
534 // delete HistoryService before the BookmarkModel. The destructor for | |
535 // HistoryService will join with HistoryService's backend thread so that | |
536 // by the time the destructor has finished we're sure it will no longer call | |
537 // into the BookmarkModel. | |
538 history_service_ = NULL; | |
539 bookmark_bar_model_.reset(); | |
540 | |
541 // FaviconService depends on HistoryServce so make sure we delete | 518 // FaviconService depends on HistoryServce so make sure we delete |
542 // HistoryService first. | 519 // HistoryService first. |
543 favicon_service_.reset(); | 520 favicon_service_.reset(); |
544 | 521 |
545 if (pref_proxy_config_tracker_.get()) | 522 if (pref_proxy_config_tracker_.get()) |
546 pref_proxy_config_tracker_->DetachFromPrefService(); | 523 pref_proxy_config_tracker_->DetachFromPrefService(); |
547 | 524 |
548 if (protocol_handler_registry_) | 525 if (protocol_handler_registry_) |
549 protocol_handler_registry_->Finalize(); | 526 protocol_handler_registry_->Finalize(); |
550 | 527 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 | 761 |
785 GAIAInfoUpdateService* ProfileImpl::GetGAIAInfoUpdateService() { | 762 GAIAInfoUpdateService* ProfileImpl::GetGAIAInfoUpdateService() { |
786 if (!gaia_info_update_service_.get() && | 763 if (!gaia_info_update_service_.get() && |
787 GAIAInfoUpdateService::ShouldUseGAIAProfileInfo(this)) { | 764 GAIAInfoUpdateService::ShouldUseGAIAProfileInfo(this)) { |
788 gaia_info_update_service_.reset(new GAIAInfoUpdateService(this)); | 765 gaia_info_update_service_.reset(new GAIAInfoUpdateService(this)); |
789 } | 766 } |
790 return gaia_info_update_service_.get(); | 767 return gaia_info_update_service_.get(); |
791 } | 768 } |
792 | 769 |
793 HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) { | 770 HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) { |
794 // If saving history is disabled, only allow explicit access. | 771 return HistoryServiceFactory::GetForProfile(this, sat).get(); |
795 if (GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) && | |
796 sat != EXPLICIT_ACCESS) | |
797 return NULL; | |
798 | |
799 if (!history_service_created_) { | |
800 history_service_created_ = true; | |
801 scoped_refptr<HistoryService> history(new HistoryService(this)); | |
802 if (!history->Init(GetPath(), GetBookmarkModel())) | |
803 return NULL; | |
804 history_service_.swap(history); | |
805 } | |
806 return history_service_.get(); | |
807 } | 772 } |
808 | 773 |
809 HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() { | 774 HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() { |
810 return history_service_.get(); | 775 return HistoryServiceFactory::GetForProfileIfExists(this).get(); |
811 } | 776 } |
812 | 777 |
813 AutocompleteClassifier* ProfileImpl::GetAutocompleteClassifier() { | 778 AutocompleteClassifier* ProfileImpl::GetAutocompleteClassifier() { |
814 if (!autocomplete_classifier_.get()) | 779 if (!autocomplete_classifier_.get()) |
815 autocomplete_classifier_.reset(new AutocompleteClassifier(this)); | 780 autocomplete_classifier_.reset(new AutocompleteClassifier(this)); |
816 return autocomplete_classifier_.get(); | 781 return autocomplete_classifier_.get(); |
817 } | 782 } |
818 | 783 |
819 history::ShortcutsBackend* ProfileImpl::GetShortcutsBackend() { | 784 history::ShortcutsBackend* ProfileImpl::GetShortcutsBackend() { |
820 // This is called on one thread only - UI, so no magic is needed to protect | 785 // This is called on one thread only - UI, so no magic is needed to protect |
(...skipping 15 matching lines...) Expand all Loading... |
836 // it to be set by asking for the prefs. | 801 // it to be set by asking for the prefs. |
837 GetPrefs(); | 802 GetPrefs(); |
838 return last_session_exited_cleanly_; | 803 return last_session_exited_cleanly_; |
839 } | 804 } |
840 | 805 |
841 quota::SpecialStoragePolicy* ProfileImpl::GetSpecialStoragePolicy() { | 806 quota::SpecialStoragePolicy* ProfileImpl::GetSpecialStoragePolicy() { |
842 return GetExtensionSpecialStoragePolicy(); | 807 return GetExtensionSpecialStoragePolicy(); |
843 } | 808 } |
844 | 809 |
845 BookmarkModel* ProfileImpl::GetBookmarkModel() { | 810 BookmarkModel* ProfileImpl::GetBookmarkModel() { |
846 if (!bookmark_bar_model_.get()) { | 811 return BookmarkModelFactory::GetForProfile(this); |
847 bookmark_bar_model_.reset(new BookmarkModel(this)); | |
848 bookmark_bar_model_->Load(); | |
849 } | |
850 return bookmark_bar_model_.get(); | |
851 } | 812 } |
852 | 813 |
853 ProtocolHandlerRegistry* ProfileImpl::GetProtocolHandlerRegistry() { | 814 ProtocolHandlerRegistry* ProfileImpl::GetProtocolHandlerRegistry() { |
854 return protocol_handler_registry_.get(); | 815 return protocol_handler_registry_.get(); |
855 } | 816 } |
856 | 817 |
857 bool ProfileImpl::IsSameProfile(Profile* profile) { | 818 bool ProfileImpl::IsSameProfile(Profile* profile) { |
858 if (profile == static_cast<Profile*>(this)) | 819 if (profile == static_cast<Profile*>(this)) |
859 return true; | 820 return true; |
860 Profile* otr_profile = off_the_record_profile_.get(); | 821 Profile* otr_profile = off_the_record_profile_.get(); |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 if (!path.empty()) | 1101 if (!path.empty()) |
1141 *cache_path = path; | 1102 *cache_path = path; |
1142 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1103 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
1143 prefs_->GetInteger(prefs::kDiskCacheSize); | 1104 prefs_->GetInteger(prefs::kDiskCacheSize); |
1144 } | 1105 } |
1145 | 1106 |
1146 base::Callback<ChromeURLDataManagerBackend*(void)> | 1107 base::Callback<ChromeURLDataManagerBackend*(void)> |
1147 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { | 1108 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { |
1148 return io_data_.GetChromeURLDataManagerBackendGetter(); | 1109 return io_data_.GetChromeURLDataManagerBackendGetter(); |
1149 } | 1110 } |
OLD | NEW |