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" |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 ProfileImpl::ProfileImpl(const FilePath& path, | 219 ProfileImpl::ProfileImpl(const FilePath& path, |
220 Delegate* delegate, | 220 Delegate* delegate, |
221 CreateMode create_mode) | 221 CreateMode create_mode) |
222 : path_(path), | 222 : path_(path), |
223 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( | 223 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( |
224 new VisitedLinkEventListener(this))), | 224 new VisitedLinkEventListener(this))), |
225 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), | 225 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), |
226 host_content_settings_map_(NULL), | 226 host_content_settings_map_(NULL), |
227 history_service_created_(false), | 227 history_service_created_(false), |
228 favicon_service_created_(false), | 228 favicon_service_created_(false), |
229 created_web_data_service_(false), | |
230 clear_local_state_on_exit_(false), | 229 clear_local_state_on_exit_(false), |
231 start_time_(Time::Now()), | 230 start_time_(Time::Now()), |
232 delegate_(delegate), | 231 delegate_(delegate), |
233 predictor_(NULL), | 232 predictor_(NULL), |
234 session_restore_enabled_(false) { | 233 session_restore_enabled_(false) { |
235 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << | 234 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
236 "profile files to the root directory!"; | 235 "profile files to the root directory!"; |
237 | 236 |
238 #if defined(ENABLE_SESSION_SERVICE) | 237 #if defined(ENABLE_SESSION_SERVICE) |
239 create_session_service_timer_.Start(FROM_HERE, | 238 create_session_service_timer_.Start(FROM_HERE, |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 if (io_data_.HasMainRequestContext() && | 502 if (io_data_.HasMainRequestContext() && |
504 default_request_context_ == GetRequestContext()) { | 503 default_request_context_ == GetRequestContext()) { |
505 default_request_context_ = NULL; | 504 default_request_context_ = NULL; |
506 } | 505 } |
507 | 506 |
508 // Destroy OTR profile and its profile services first. | 507 // Destroy OTR profile and its profile services first. |
509 DestroyOffTheRecordProfile(); | 508 DestroyOffTheRecordProfile(); |
510 | 509 |
511 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); | 510 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); |
512 | 511 |
513 // Both HistoryService and WebDataService maintain threads for background | 512 // The HistoryService maintains threads for background processing. Its |
514 // processing. Its possible each thread still has tasks on it that have | 513 // possible each thread still has tasks on it that have increased the ref |
515 // increased the ref count of the service. In such a situation, when we | 514 // count of the service. In such a situation, when we decrement the refcount, |
516 // decrement the refcount, it won't be 0, and the threads/databases aren't | 515 // it won't be 0, and the threads/databases aren't properly shut down. By |
517 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the | 516 // explicitly calling Cleanup/Shutdown we ensure the databases are properly |
518 // databases are properly closed. | 517 // closed. |
519 if (web_data_service_.get()) | |
520 web_data_service_->Shutdown(); | |
521 | 518 |
522 if (top_sites_.get()) | 519 if (top_sites_.get()) |
523 top_sites_->Shutdown(); | 520 top_sites_->Shutdown(); |
524 | 521 |
525 if (bookmark_bar_model_.get()) { | 522 if (bookmark_bar_model_.get()) { |
526 // It's possible that bookmarks haven't loaded and history is waiting for | 523 // It's possible that bookmarks haven't loaded and history is waiting for |
527 // bookmarks to complete loading. In such a situation history can't shutdown | 524 // bookmarks to complete loading. In such a situation history can't shutdown |
528 // (meaning if we invoked history_service_->Cleanup now, we would | 525 // (meaning if we invoked history_service_->Cleanup now, we would |
529 // deadlock). To break the deadlock we tell BookmarkModel it's about to be | 526 // deadlock). To break the deadlock we tell BookmarkModel it's about to be |
530 // deleted so that it can release the signal history is waiting on, allowing | 527 // deleted so that it can release the signal history is waiting on, allowing |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 history::ShortcutsBackend* ProfileImpl::GetShortcutsBackend() { | 822 history::ShortcutsBackend* ProfileImpl::GetShortcutsBackend() { |
826 // This is called on one thread only - UI, so no magic is needed to protect | 823 // This is called on one thread only - UI, so no magic is needed to protect |
827 // against the multiple concurrent calls. | 824 // against the multiple concurrent calls. |
828 if (!shortcuts_backend_.get()) { | 825 if (!shortcuts_backend_.get()) { |
829 shortcuts_backend_ = new history::ShortcutsBackend(GetPath(), this); | 826 shortcuts_backend_ = new history::ShortcutsBackend(GetPath(), this); |
830 CHECK(shortcuts_backend_->Init()); | 827 CHECK(shortcuts_backend_->Init()); |
831 } | 828 } |
832 return shortcuts_backend_.get(); | 829 return shortcuts_backend_.get(); |
833 } | 830 } |
834 | 831 |
835 WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) { | |
836 if (!created_web_data_service_) | |
837 CreateWebDataService(); | |
838 return web_data_service_.get(); | |
839 } | |
840 | |
841 WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() { | |
842 return web_data_service_.get(); | |
843 } | |
844 | |
845 void ProfileImpl::CreateWebDataService() { | |
846 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL); | |
847 created_web_data_service_ = true; | |
848 scoped_refptr<WebDataService> wds(new WebDataService()); | |
849 if (!wds->Init(GetPath())) | |
850 return; | |
851 web_data_service_.swap(wds); | |
852 } | |
853 | |
854 DownloadManager* ProfileImpl::GetDownloadManager() { | 832 DownloadManager* ProfileImpl::GetDownloadManager() { |
855 return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager(); | 833 return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager(); |
856 } | 834 } |
857 | 835 |
858 bool ProfileImpl::DidLastSessionExitCleanly() { | 836 bool ProfileImpl::DidLastSessionExitCleanly() { |
859 // last_session_exited_cleanly_ is set when the preferences are loaded. Force | 837 // last_session_exited_cleanly_ is set when the preferences are loaded. Force |
860 // it to be set by asking for the prefs. | 838 // it to be set by asking for the prefs. |
861 GetPrefs(); | 839 GetPrefs(); |
862 return last_session_exited_cleanly_; | 840 return last_session_exited_cleanly_; |
863 } | 841 } |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 if (!path.empty()) | 1152 if (!path.empty()) |
1175 *cache_path = path; | 1153 *cache_path = path; |
1176 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1154 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
1177 prefs_->GetInteger(prefs::kDiskCacheSize); | 1155 prefs_->GetInteger(prefs::kDiskCacheSize); |
1178 } | 1156 } |
1179 | 1157 |
1180 base::Callback<ChromeURLDataManagerBackend*(void)> | 1158 base::Callback<ChromeURLDataManagerBackend*(void)> |
1181 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { | 1159 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { |
1182 return io_data_.GetChromeURLDataManagerBackendGetter(); | 1160 return io_data_.GetChromeURLDataManagerBackendGetter(); |
1183 } | 1161 } |
OLD | NEW |