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

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: Rebase again and hope upload works this time 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
« no previous file with comments | « chrome/browser/profiles/profile_impl.h ('k') | chrome/browser/profiles/profile_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/profile_policy_connector.h" 51 #include "chrome/browser/policy/profile_policy_connector.h"
52 #include "chrome/browser/policy/profile_policy_connector_factory.h" 52 #include "chrome/browser/policy/profile_policy_connector_factory.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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 favicon_service_created_(false), 272 favicon_service_created_(false),
274 created_web_data_service_(false), 273 created_web_data_service_(false),
275 created_password_store_(false), 274 created_password_store_(false),
276 created_download_manager_(false), 275 created_download_manager_(false),
277 start_time_(Time::Now()), 276 start_time_(Time::Now()),
278 spellcheck_host_(NULL), 277 spellcheck_host_(NULL),
279 spellcheck_host_ready_(false), 278 spellcheck_host_ready_(false),
280 #if defined(OS_WIN) 279 #if defined(OS_WIN)
281 checked_instant_promo_(false), 280 checked_instant_promo_(false),
282 #endif 281 #endif
283 shutdown_session_service_(false),
284 delegate_(delegate) { 282 delegate_(delegate) {
285 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << 283 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
286 "profile files to the root directory!"; 284 "profile files to the root directory!";
287 create_session_service_timer_.Start( 285 create_session_service_timer_.Start(
288 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, 286 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
289 &ProfileImpl::EnsureSessionServiceCreated); 287 &ProfileImpl::EnsureSessionServiceCreated);
290 288
291 if (delegate_) { 289 if (delegate_) {
292 prefs_.reset(PrefService::CreatePrefServiceAsync( 290 prefs_.reset(PrefService::CreatePrefServiceAsync(
293 GetPrefFilePath(), 291 GetPrefFilePath(),
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 void ProfileImpl::set_last_selected_directory(const FilePath& path) { 578 void ProfileImpl::set_last_selected_directory(const FilePath& path) {
581 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); 579 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path);
582 } 580 }
583 581
584 ProfileImpl::~ProfileImpl() { 582 ProfileImpl::~ProfileImpl() {
585 NotificationService::current()->Notify( 583 NotificationService::current()->Notify(
586 NotificationType::PROFILE_DESTROYED, 584 NotificationType::PROFILE_DESTROYED,
587 Source<Profile>(this), 585 Source<Profile>(this),
588 NotificationService::NoDetails()); 586 NotificationService::NoDetails());
589 587
588 StopCreateSessionServiceTimer();
589
590 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); 590 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this);
591 591
592 tab_restore_service_.reset();
593
594 StopCreateSessionServiceTimer();
595 // TemplateURLModel schedules a task on the WebDataService from its 592 // TemplateURLModel schedules a task on the WebDataService from its
596 // destructor. Delete it first to ensure the task gets scheduled before we 593 // destructor. Delete it first to ensure the task gets scheduled before we
597 // shut down the database. 594 // shut down the database.
598 template_url_model_.reset(); 595 template_url_model_.reset();
599 596
600 // DownloadManager is lazily created, so check before accessing it. 597 // DownloadManager is lazily created, so check before accessing it.
601 if (download_manager_.get()) { 598 if (download_manager_.get()) {
602 // The download manager queries the history system and should be shut down 599 // The download manager queries the history system and should be shut down
603 // before the history is shut down so it can properly cancel all requests. 600 // before the history is shut down so it can properly cancel all requests.
604 download_manager_->Shutdown(); 601 download_manager_->Shutdown();
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 if (!quota_manager_.get()) { 1168 if (!quota_manager_.get()) {
1172 quota_manager_ = new quota::QuotaManager( 1169 quota_manager_ = new quota::QuotaManager(
1173 IsOffTheRecord(), 1170 IsOffTheRecord(),
1174 GetPath(), 1171 GetPath(),
1175 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), 1172 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
1176 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)); 1173 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB));
1177 } 1174 }
1178 return quota_manager_.get(); 1175 return quota_manager_.get();
1179 } 1176 }
1180 1177
1181 SessionService* ProfileImpl::GetSessionService() {
1182 if (!session_service_.get() && !shutdown_session_service_) {
1183 session_service_.reset(new SessionService(this));
1184 session_service_->ResetFromCurrentBrowsers();
1185 }
1186 return session_service_.get();
1187 }
1188
1189 void ProfileImpl::ShutdownSessionService() {
1190 if (shutdown_session_service_)
1191 return;
1192
1193 // We're about to exit, force creation of the session service if it hasn't
1194 // been created yet. We do this to ensure session state matches the point in
1195 // time the user exited.
1196 GetSessionService();
1197 shutdown_session_service_ = true;
1198 session_service_.reset();
1199 }
1200
1201 bool ProfileImpl::HasSessionService() const {
1202 return (session_service_.get() != NULL);
1203 }
1204
1205 bool ProfileImpl::HasProfileSyncService() const { 1178 bool ProfileImpl::HasProfileSyncService() const {
1206 return (sync_service_.get() != NULL); 1179 return (sync_service_.get() != NULL);
1207 } 1180 }
1208 1181
1209 bool ProfileImpl::DidLastSessionExitCleanly() { 1182 bool ProfileImpl::DidLastSessionExitCleanly() {
1210 // last_session_exited_cleanly_ is set when the preferences are loaded. Force 1183 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1211 // it to be set by asking for the prefs. 1184 // it to be set by asking for the prefs.
1212 GetPrefs(); 1185 GetPrefs();
1213 return last_session_exited_cleanly_; 1186 return last_session_exited_cleanly_;
1214 } 1187 }
(...skipping 14 matching lines...) Expand all
1229 if (profile == static_cast<Profile*>(this)) 1202 if (profile == static_cast<Profile*>(this))
1230 return true; 1203 return true;
1231 Profile* otr_profile = off_the_record_profile_.get(); 1204 Profile* otr_profile = off_the_record_profile_.get();
1232 return otr_profile && profile == otr_profile; 1205 return otr_profile && profile == otr_profile;
1233 } 1206 }
1234 1207
1235 Time ProfileImpl::GetStartTime() const { 1208 Time ProfileImpl::GetStartTime() const {
1236 return start_time_; 1209 return start_time_;
1237 } 1210 }
1238 1211
1239 TabRestoreService* ProfileImpl::GetTabRestoreService() {
1240 if (!tab_restore_service_.get())
1241 tab_restore_service_.reset(new TabRestoreService(this));
1242 return tab_restore_service_.get();
1243 }
1244
1245 history::TopSites* ProfileImpl::GetTopSites() { 1212 history::TopSites* ProfileImpl::GetTopSites() {
1246 if (!top_sites_.get()) { 1213 if (!top_sites_.get()) {
1247 top_sites_ = new history::TopSites(this); 1214 top_sites_ = new history::TopSites(this);
1248 top_sites_->Init(GetPath().Append(chrome::kTopSitesFilename)); 1215 top_sites_->Init(GetPath().Append(chrome::kTopSitesFilename));
1249 } 1216 }
1250 return top_sites_; 1217 return top_sites_;
1251 } 1218 }
1252 1219
1253 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { 1220 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() {
1254 return top_sites_; 1221 return top_sites_;
1255 } 1222 }
1256 1223
1257 void ProfileImpl::ResetTabRestoreService() {
1258 tab_restore_service_.reset();
1259 }
1260
1261 SpellCheckHost* ProfileImpl::GetSpellCheckHost() { 1224 SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1262 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL; 1225 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1263 } 1226 }
1264 1227
1265 void ProfileImpl::ReinitializeSpellCheckHost(bool force) { 1228 void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1266 // If we are already loading the spellchecker, and this is just a hint to 1229 // If we are already loading the spellchecker, and this is just a hint to
1267 // load the spellchecker, do nothing. 1230 // load the spellchecker, do nothing.
1268 if (!force && spellcheck_host_.get()) 1231 if (!force && spellcheck_host_.get())
1269 return; 1232 return;
1270 1233
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 GetProfileSyncService(); // Causes lazy-load if sync is enabled. 1322 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1360 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED, 1323 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1361 Source<Profile>(this)); 1324 Source<Profile>(this));
1362 } 1325 }
1363 } 1326 }
1364 1327
1365 void ProfileImpl::StopCreateSessionServiceTimer() { 1328 void ProfileImpl::StopCreateSessionServiceTimer() {
1366 create_session_service_timer_.Stop(); 1329 create_session_service_timer_.Stop();
1367 } 1330 }
1368 1331
1332 void ProfileImpl::EnsureSessionServiceCreated() {
1333 SessionServiceFactory::GetForProfile(this);
1334 }
1335
1369 TokenService* ProfileImpl::GetTokenService() { 1336 TokenService* ProfileImpl::GetTokenService() {
1370 if (!token_service_.get()) { 1337 if (!token_service_.get()) {
1371 token_service_.reset(new TokenService()); 1338 token_service_.reset(new TokenService());
1372 } 1339 }
1373 return token_service_.get(); 1340 return token_service_.get();
1374 } 1341 }
1375 1342
1376 ProfileSyncService* ProfileImpl::GetProfileSyncService() { 1343 ProfileSyncService* ProfileImpl::GetProfileSyncService() {
1377 #if defined(OS_CHROMEOS) 1344 #if defined(OS_CHROMEOS)
1378 if (!sync_service_.get()) { 1345 if (!sync_service_.get()) {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 return pref_proxy_config_tracker_; 1538 return pref_proxy_config_tracker_;
1572 } 1539 }
1573 1540
1574 prerender::PrerenderManager* ProfileImpl::GetPrerenderManager() { 1541 prerender::PrerenderManager* ProfileImpl::GetPrerenderManager() {
1575 if (!prerender::PrerenderManager::IsPrerenderingPossible()) 1542 if (!prerender::PrerenderManager::IsPrerenderingPossible())
1576 return NULL; 1543 return NULL;
1577 if (!prerender_manager_.get()) 1544 if (!prerender_manager_.get())
1578 prerender_manager_.reset(new prerender::PrerenderManager(this)); 1545 prerender_manager_.reset(new prerender::PrerenderManager(this));
1579 return prerender_manager_.get(); 1546 return prerender_manager_.get();
1580 } 1547 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_impl.h ('k') | chrome/browser/profiles/profile_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698