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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 ProfileImpl::ProfileImpl(const FilePath& path, | 220 ProfileImpl::ProfileImpl(const FilePath& path, |
221 Delegate* delegate, | 221 Delegate* delegate, |
222 CreateMode create_mode) | 222 CreateMode create_mode) |
223 : path_(path), | 223 : path_(path), |
224 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( | 224 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( |
225 new VisitedLinkEventListener(this))), | 225 new VisitedLinkEventListener(this))), |
226 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), | 226 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), |
227 host_content_settings_map_(NULL), | 227 host_content_settings_map_(NULL), |
228 history_service_created_(false), | 228 history_service_created_(false), |
229 favicon_service_created_(false), | 229 favicon_service_created_(false), |
230 created_web_data_service_(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, |
240 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, | 239 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 if (io_data_.HasMainRequestContext() && | 477 if (io_data_.HasMainRequestContext() && |
479 default_request_context_ == GetRequestContext()) { | 478 default_request_context_ == GetRequestContext()) { |
480 default_request_context_ = NULL; | 479 default_request_context_ = NULL; |
481 } | 480 } |
482 | 481 |
483 // Destroy OTR profile and its profile services first. | 482 // Destroy OTR profile and its profile services first. |
484 DestroyOffTheRecordProfile(); | 483 DestroyOffTheRecordProfile(); |
485 | 484 |
486 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); | 485 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); |
487 | 486 |
488 // Both HistoryService and WebDataService maintain threads for background | 487 // HistoryService maintains threads for background |
489 // processing. Its possible each thread still has tasks on it that have | 488 // processing. Its possible each thread still has tasks on it that have |
490 // increased the ref count of the service. In such a situation, when we | 489 // increased the ref count of the service. In such a situation, when we |
491 // decrement the refcount, it won't be 0, and the threads/databases aren't | 490 // decrement the refcount, it won't be 0, and the threads/databases aren't |
492 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the | 491 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the |
493 // databases are properly closed. | 492 // databases are properly closed. |
494 if (web_data_service_.get()) | |
495 web_data_service_->Shutdown(); | |
496 | 493 |
497 if (top_sites_.get()) | 494 if (top_sites_.get()) |
498 top_sites_->Shutdown(); | 495 top_sites_->Shutdown(); |
499 | 496 |
500 if (bookmark_bar_model_.get()) { | 497 if (bookmark_bar_model_.get()) { |
501 // It's possible that bookmarks haven't loaded and history is waiting for | 498 // It's possible that bookmarks haven't loaded and history is waiting for |
502 // bookmarks to complete loading. In such a situation history can't shutdown | 499 // bookmarks to complete loading. In such a situation history can't shutdown |
503 // (meaning if we invoked history_service_->Cleanup now, we would | 500 // (meaning if we invoked history_service_->Cleanup now, we would |
504 // deadlock). To break the deadlock we tell BookmarkModel it's about to be | 501 // deadlock). To break the deadlock we tell BookmarkModel it's about to be |
505 // deleted so that it can release the signal history is waiting on, allowing | 502 // deleted so that it can release the signal history is waiting on, allowing |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 history::ShortcutsBackend* ProfileImpl::GetShortcutsBackend() { | 800 history::ShortcutsBackend* ProfileImpl::GetShortcutsBackend() { |
804 // This is called on one thread only - UI, so no magic is needed to protect | 801 // This is called on one thread only - UI, so no magic is needed to protect |
805 // against the multiple concurrent calls. | 802 // against the multiple concurrent calls. |
806 if (!shortcuts_backend_.get()) { | 803 if (!shortcuts_backend_.get()) { |
807 shortcuts_backend_ = new history::ShortcutsBackend(GetPath(), this); | 804 shortcuts_backend_ = new history::ShortcutsBackend(GetPath(), this); |
808 CHECK(shortcuts_backend_->Init()); | 805 CHECK(shortcuts_backend_->Init()); |
809 } | 806 } |
810 return shortcuts_backend_.get(); | 807 return shortcuts_backend_.get(); |
811 } | 808 } |
812 | 809 |
813 WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) { | |
814 if (!created_web_data_service_) | |
815 CreateWebDataService(); | |
816 return web_data_service_.get(); | |
817 } | |
818 | |
819 WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() { | |
820 return web_data_service_.get(); | |
821 } | |
822 | |
823 void ProfileImpl::CreateWebDataService() { | |
824 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL); | |
825 created_web_data_service_ = true; | |
826 scoped_refptr<WebDataService> wds(new WebDataService()); | |
827 if (!wds->Init(GetPath())) | |
828 return; | |
829 web_data_service_.swap(wds); | |
830 } | |
831 | |
832 DownloadManager* ProfileImpl::GetDownloadManager() { | 810 DownloadManager* ProfileImpl::GetDownloadManager() { |
833 return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager(); | 811 return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager(); |
834 } | 812 } |
835 | 813 |
836 bool ProfileImpl::DidLastSessionExitCleanly() { | 814 bool ProfileImpl::DidLastSessionExitCleanly() { |
837 // last_session_exited_cleanly_ is set when the preferences are loaded. Force | 815 // last_session_exited_cleanly_ is set when the preferences are loaded. Force |
838 // it to be set by asking for the prefs. | 816 // it to be set by asking for the prefs. |
839 GetPrefs(); | 817 GetPrefs(); |
840 return last_session_exited_cleanly_; | 818 return last_session_exited_cleanly_; |
841 } | 819 } |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 FilePath* cache_path, | 1132 FilePath* cache_path, |
1155 int* max_size) { | 1133 int* max_size) { |
1156 DCHECK(cache_path); | 1134 DCHECK(cache_path); |
1157 DCHECK(max_size); | 1135 DCHECK(max_size); |
1158 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); | 1136 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); |
1159 if (!path.empty()) | 1137 if (!path.empty()) |
1160 *cache_path = path; | 1138 *cache_path = path; |
1161 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1139 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
1162 prefs_->GetInteger(prefs::kDiskCacheSize); | 1140 prefs_->GetInteger(prefs::kDiskCacheSize); |
1163 } | 1141 } |
OLD | NEW |