Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: chrome/browser/profiles/profile_impl.cc

Issue 6901031: Profile shouldn't own Session/TabRestore services. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mac build Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/environment.h" 9 #include "base/environment.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "chrome/browser/policy/configuration_policy_provider.h" 51 #include "chrome/browser/policy/configuration_policy_provider.h"
52 #include "chrome/browser/policy/profile_policy_connector.h" 52 #include "chrome/browser/policy/profile_policy_connector.h"
53 #include "chrome/browser/prefs/browser_prefs.h" 53 #include "chrome/browser/prefs/browser_prefs.h"
54 #include "chrome/browser/prefs/pref_value_store.h" 54 #include "chrome/browser/prefs/pref_value_store.h"
55 #include "chrome/browser/prerender/prerender_manager.h" 55 #include "chrome/browser/prerender/prerender_manager.h"
56 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" 56 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
57 #include "chrome/browser/profiles/profile_dependency_manager.h" 57 #include "chrome/browser/profiles/profile_dependency_manager.h"
58 #include "chrome/browser/profiles/profile_manager.h" 58 #include "chrome/browser/profiles/profile_manager.h"
59 #include "chrome/browser/search_engines/template_url_fetcher.h" 59 #include "chrome/browser/search_engines/template_url_fetcher.h"
60 #include "chrome/browser/search_engines/template_url_model.h" 60 #include "chrome/browser/search_engines/template_url_model.h"
61 #include "chrome/browser/sessions/session_service.h" 61 #include "chrome/browser/sessions/session_service_factory.h"
62 #include "chrome/browser/sessions/tab_restore_service.h"
63 #include "chrome/browser/spellcheck_host.h" 62 #include "chrome/browser/spellcheck_host.h"
64 #include "chrome/browser/ssl/ssl_host_state.h" 63 #include "chrome/browser/ssl/ssl_host_state.h"
65 #include "chrome/browser/status_icons/status_tray.h" 64 #include "chrome/browser/status_icons/status_tray.h"
66 #include "chrome/browser/sync/profile_sync_factory_impl.h" 65 #include "chrome/browser/sync/profile_sync_factory_impl.h"
67 #include "chrome/browser/sync/profile_sync_service.h" 66 #include "chrome/browser/sync/profile_sync_service.h"
68 #include "chrome/browser/tabs/pinned_tab_service_factory.h" 67 #include "chrome/browser/tabs/pinned_tab_service_factory.h"
69 #include "chrome/browser/transport_security_persister.h" 68 #include "chrome/browser/transport_security_persister.h"
70 #include "chrome/browser/ui/browser_list.h" 69 #include "chrome/browser/ui/browser_list.h"
71 #include "chrome/browser/ui/find_bar/find_bar_state.h" 70 #include "chrome/browser/ui/find_bar/find_bar_state.h"
72 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 71 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 favicon_service_created_(false), 270 favicon_service_created_(false),
272 created_web_data_service_(false), 271 created_web_data_service_(false),
273 created_password_store_(false), 272 created_password_store_(false),
274 created_download_manager_(false), 273 created_download_manager_(false),
275 start_time_(Time::Now()), 274 start_time_(Time::Now()),
276 spellcheck_host_(NULL), 275 spellcheck_host_(NULL),
277 spellcheck_host_ready_(false), 276 spellcheck_host_ready_(false),
278 #if defined(OS_WIN) 277 #if defined(OS_WIN)
279 checked_instant_promo_(false), 278 checked_instant_promo_(false),
280 #endif 279 #endif
281 shutdown_session_service_(false),
282 delegate_(delegate) { 280 delegate_(delegate) {
283 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << 281 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
284 "profile files to the root directory!"; 282 "profile files to the root directory!";
285 create_session_service_timer_.Start( 283 create_session_service_timer_.Start(
286 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, 284 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
287 &ProfileImpl::EnsureSessionServiceCreated); 285 &ProfileImpl::EnsureSessionServiceCreated);
288 286
289 if (delegate_) { 287 if (delegate_) {
290 prefs_.reset(PrefService::CreatePrefServiceAsync( 288 prefs_.reset(PrefService::CreatePrefServiceAsync(
291 GetPrefFilePath(), 289 GetPrefFilePath(),
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 } 581 }
584 582
585 ProfileImpl::~ProfileImpl() { 583 ProfileImpl::~ProfileImpl() {
586 NotificationService::current()->Notify( 584 NotificationService::current()->Notify(
587 NotificationType::PROFILE_DESTROYED, 585 NotificationType::PROFILE_DESTROYED,
588 Source<Profile>(this), 586 Source<Profile>(this),
589 NotificationService::NoDetails()); 587 NotificationService::NoDetails());
590 588
591 GetPolicyConnector()->Shutdown(); 589 GetPolicyConnector()->Shutdown();
592 590
591 StopCreateSessionServiceTimer();
592
593 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); 593 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this);
594 594
595 tab_restore_service_.reset();
596
597 StopCreateSessionServiceTimer();
598 // TemplateURLModel schedules a task on the WebDataService from its 595 // TemplateURLModel schedules a task on the WebDataService from its
599 // destructor. Delete it first to ensure the task gets scheduled before we 596 // destructor. Delete it first to ensure the task gets scheduled before we
600 // shut down the database. 597 // shut down the database.
601 template_url_model_.reset(); 598 template_url_model_.reset();
602 599
603 // DownloadManager is lazily created, so check before accessing it. 600 // DownloadManager is lazily created, so check before accessing it.
604 if (download_manager_.get()) { 601 if (download_manager_.get()) {
605 // The download manager queries the history system and should be shut down 602 // The download manager queries the history system and should be shut down
606 // before the history is shut down so it can properly cancel all requests. 603 // before the history is shut down so it can properly cancel all requests.
607 download_manager_->Shutdown(); 604 download_manager_->Shutdown();
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 } 1156 }
1160 1157
1161 fileapi::FileSystemContext* ProfileImpl::GetFileSystemContext() { 1158 fileapi::FileSystemContext* ProfileImpl::GetFileSystemContext() {
1162 if (!file_system_context_.get()) 1159 if (!file_system_context_.get())
1163 file_system_context_ = CreateFileSystemContext( 1160 file_system_context_ = CreateFileSystemContext(
1164 GetPath(), IsOffTheRecord(), GetExtensionSpecialStoragePolicy()); 1161 GetPath(), IsOffTheRecord(), GetExtensionSpecialStoragePolicy());
1165 DCHECK(file_system_context_.get()); 1162 DCHECK(file_system_context_.get());
1166 return file_system_context_.get(); 1163 return file_system_context_.get();
1167 } 1164 }
1168 1165
1169 SessionService* ProfileImpl::GetSessionService() {
1170 if (!session_service_.get() && !shutdown_session_service_) {
1171 session_service_.reset(new SessionService(this));
1172 session_service_->ResetFromCurrentBrowsers();
1173 }
1174 return session_service_.get();
1175 }
1176
1177 void ProfileImpl::ShutdownSessionService() {
1178 if (shutdown_session_service_)
1179 return;
1180
1181 // We're about to exit, force creation of the session service if it hasn't
1182 // been created yet. We do this to ensure session state matches the point in
1183 // time the user exited.
1184 GetSessionService();
1185 shutdown_session_service_ = true;
1186 session_service_.reset();
1187 }
1188
1189 bool ProfileImpl::HasSessionService() const {
1190 return (session_service_.get() != NULL);
1191 }
1192
1193 bool ProfileImpl::HasProfileSyncService() const { 1166 bool ProfileImpl::HasProfileSyncService() const {
1194 return (sync_service_.get() != NULL); 1167 return (sync_service_.get() != NULL);
1195 } 1168 }
1196 1169
1197 bool ProfileImpl::DidLastSessionExitCleanly() { 1170 bool ProfileImpl::DidLastSessionExitCleanly() {
1198 // last_session_exited_cleanly_ is set when the preferences are loaded. Force 1171 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1199 // it to be set by asking for the prefs. 1172 // it to be set by asking for the prefs.
1200 GetPrefs(); 1173 GetPrefs();
1201 return last_session_exited_cleanly_; 1174 return last_session_exited_cleanly_;
1202 } 1175 }
(...skipping 14 matching lines...) Expand all
1217 if (profile == static_cast<Profile*>(this)) 1190 if (profile == static_cast<Profile*>(this))
1218 return true; 1191 return true;
1219 Profile* otr_profile = off_the_record_profile_.get(); 1192 Profile* otr_profile = off_the_record_profile_.get();
1220 return otr_profile && profile == otr_profile; 1193 return otr_profile && profile == otr_profile;
1221 } 1194 }
1222 1195
1223 Time ProfileImpl::GetStartTime() const { 1196 Time ProfileImpl::GetStartTime() const {
1224 return start_time_; 1197 return start_time_;
1225 } 1198 }
1226 1199
1227 TabRestoreService* ProfileImpl::GetTabRestoreService() {
1228 if (!tab_restore_service_.get())
1229 tab_restore_service_.reset(new TabRestoreService(this));
1230 return tab_restore_service_.get();
1231 }
1232
1233 history::TopSites* ProfileImpl::GetTopSites() { 1200 history::TopSites* ProfileImpl::GetTopSites() {
1234 if (!top_sites_.get()) { 1201 if (!top_sites_.get()) {
1235 top_sites_ = new history::TopSites(this); 1202 top_sites_ = new history::TopSites(this);
1236 top_sites_->Init(GetPath().Append(chrome::kTopSitesFilename)); 1203 top_sites_->Init(GetPath().Append(chrome::kTopSitesFilename));
1237 } 1204 }
1238 return top_sites_; 1205 return top_sites_;
1239 } 1206 }
1240 1207
1241 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { 1208 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() {
1242 return top_sites_; 1209 return top_sites_;
1243 } 1210 }
1244 1211
1245 void ProfileImpl::ResetTabRestoreService() {
1246 tab_restore_service_.reset();
1247 }
1248
1249 SpellCheckHost* ProfileImpl::GetSpellCheckHost() { 1212 SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1250 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL; 1213 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1251 } 1214 }
1252 1215
1253 void ProfileImpl::ReinitializeSpellCheckHost(bool force) { 1216 void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1254 // If we are already loading the spellchecker, and this is just a hint to 1217 // If we are already loading the spellchecker, and this is just a hint to
1255 // load the spellchecker, do nothing. 1218 // load the spellchecker, do nothing.
1256 if (!force && spellcheck_host_.get()) 1219 if (!force && spellcheck_host_.get())
1257 return; 1220 return;
1258 1221
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 GetProfileSyncService(); // Causes lazy-load if sync is enabled. 1307 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1345 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED, 1308 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1346 Source<Profile>(this)); 1309 Source<Profile>(this));
1347 } 1310 }
1348 } 1311 }
1349 1312
1350 void ProfileImpl::StopCreateSessionServiceTimer() { 1313 void ProfileImpl::StopCreateSessionServiceTimer() {
1351 create_session_service_timer_.Stop(); 1314 create_session_service_timer_.Stop();
1352 } 1315 }
1353 1316
1317 void ProfileImpl::EnsureSessionServiceCreated() {
1318 SessionServiceFactory::GetForProfile(this);
1319 }
1320
1354 TokenService* ProfileImpl::GetTokenService() { 1321 TokenService* ProfileImpl::GetTokenService() {
1355 if (!token_service_.get()) { 1322 if (!token_service_.get()) {
1356 token_service_.reset(new TokenService()); 1323 token_service_.reset(new TokenService());
1357 } 1324 }
1358 return token_service_.get(); 1325 return token_service_.get();
1359 } 1326 }
1360 1327
1361 ProfileSyncService* ProfileImpl::GetProfileSyncService() { 1328 ProfileSyncService* ProfileImpl::GetProfileSyncService() {
1362 #if defined(OS_CHROMEOS) 1329 #if defined(OS_CHROMEOS)
1363 if (!sync_service_.get()) { 1330 if (!sync_service_.get()) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 return pref_proxy_config_tracker_; 1530 return pref_proxy_config_tracker_;
1564 } 1531 }
1565 1532
1566 prerender::PrerenderManager* ProfileImpl::GetPrerenderManager() { 1533 prerender::PrerenderManager* ProfileImpl::GetPrerenderManager() {
1567 if (!prerender::PrerenderManager::IsPrerenderingPossible()) 1534 if (!prerender::PrerenderManager::IsPrerenderingPossible())
1568 return NULL; 1535 return NULL;
1569 if (!prerender_manager_.get()) 1536 if (!prerender_manager_.get())
1570 prerender_manager_.reset(new prerender::PrerenderManager(this)); 1537 prerender_manager_.reset(new prerender::PrerenderManager(this));
1571 return prerender_manager_.get(); 1538 return prerender_manager_.get();
1572 } 1539 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698