OLD | NEW |
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/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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 } | 161 } |
162 | 162 |
163 FilePath GetCachePath(const FilePath& base) { | 163 FilePath GetCachePath(const FilePath& base) { |
164 return base.Append(chrome::kCacheDirname); | 164 return base.Append(chrome::kCacheDirname); |
165 } | 165 } |
166 | 166 |
167 FilePath GetMediaCachePath(const FilePath& base) { | 167 FilePath GetMediaCachePath(const FilePath& base) { |
168 return base.Append(chrome::kMediaCacheDirname); | 168 return base.Append(chrome::kMediaCacheDirname); |
169 } | 169 } |
170 | 170 |
| 171 void SaveSessionStateOnIOThread( |
| 172 net::URLRequestContextGetter* url_request_context_getter) { |
| 173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 174 url_request_context_getter->GetURLRequestContext()->cookie_store()-> |
| 175 GetCookieMonster()->SaveSessionCookies(); |
| 176 } |
| 177 |
171 } // namespace | 178 } // namespace |
172 | 179 |
173 // static | 180 // static |
174 Profile* Profile::CreateProfile(const FilePath& path) { | 181 Profile* Profile::CreateProfile(const FilePath& path) { |
175 if (!file_util::PathExists(path)) { | 182 if (!file_util::PathExists(path)) { |
176 // TODO(tc): http://b/1094718 Bad things happen if we can't write to the | 183 // TODO(tc): http://b/1094718 Bad things happen if we can't write to the |
177 // profile directory. We should eventually be able to run in this | 184 // profile directory. We should eventually be able to run in this |
178 // situation. | 185 // situation. |
179 if (!file_util::CreateDirectory(path)) | 186 if (!file_util::CreateDirectory(path)) |
180 return NULL; | 187 return NULL; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 host_zoom_map_(NULL), | 230 host_zoom_map_(NULL), |
224 history_service_created_(false), | 231 history_service_created_(false), |
225 favicon_service_created_(false), | 232 favicon_service_created_(false), |
226 created_web_data_service_(false), | 233 created_web_data_service_(false), |
227 created_password_store_(false), | 234 created_password_store_(false), |
228 start_time_(Time::Now()), | 235 start_time_(Time::Now()), |
229 #if defined(OS_WIN) | 236 #if defined(OS_WIN) |
230 checked_instant_promo_(false), | 237 checked_instant_promo_(false), |
231 #endif | 238 #endif |
232 delegate_(delegate), | 239 delegate_(delegate), |
233 predictor_(NULL) { | 240 predictor_(NULL), |
| 241 session_restore_enabled_(false) { |
234 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << | 242 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
235 "profile files to the root directory!"; | 243 "profile files to the root directory!"; |
236 | 244 |
237 create_session_service_timer_.Start(FROM_HERE, | 245 create_session_service_timer_.Start(FROM_HERE, |
238 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, | 246 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, |
239 &ProfileImpl::EnsureSessionServiceCreated); | 247 &ProfileImpl::EnsureSessionServiceCreated); |
240 | 248 |
241 // Determine if prefetch is enabled for this profile. | 249 // Determine if prefetch is enabled for this profile. |
242 // If not profile_manager is present, it means we are in a unittest. | 250 // If not profile_manager is present, it means we are in a unittest. |
243 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 251 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
244 predictor_ = chrome_browser_net::Predictor::CreatePredictor( | 252 predictor_ = chrome_browser_net::Predictor::CreatePredictor( |
245 !command_line->HasSwitch(switches::kDisablePreconnect), | 253 !command_line->HasSwitch(switches::kDisablePreconnect), |
246 g_browser_process->profile_manager() == NULL); | 254 g_browser_process->profile_manager() == NULL); |
247 | 255 |
| 256 session_restore_enabled_ = |
| 257 command_line->HasSwitch(switches::kEnableRestoreSessionState); |
248 if (delegate_) { | 258 if (delegate_) { |
249 prefs_.reset(PrefService::CreatePrefService( | 259 prefs_.reset(PrefService::CreatePrefService( |
250 GetPrefFilePath(), | 260 GetPrefFilePath(), |
251 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), | 261 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), |
252 true)); | 262 true)); |
253 // Wait for the notification that prefs has been loaded (successfully or | 263 // Wait for the notification that prefs has been loaded (successfully or |
254 // not). | 264 // not). |
255 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, | 265 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, |
256 content::Source<PrefService>(prefs_.get())); | 266 content::Source<PrefService>(prefs_.get())); |
257 } else { | 267 } else { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 int media_cache_max_size; | 361 int media_cache_max_size; |
352 GetCacheParameters(true, &media_cache_path, &media_cache_max_size); | 362 GetCacheParameters(true, &media_cache_path, &media_cache_max_size); |
353 media_cache_path = GetMediaCachePath(media_cache_path); | 363 media_cache_path = GetMediaCachePath(media_cache_path); |
354 | 364 |
355 FilePath extensions_cookie_path = GetPath(); | 365 FilePath extensions_cookie_path = GetPath(); |
356 extensions_cookie_path = | 366 extensions_cookie_path = |
357 extensions_cookie_path.Append(chrome::kExtensionsCookieFilename); | 367 extensions_cookie_path.Append(chrome::kExtensionsCookieFilename); |
358 | 368 |
359 FilePath app_path = GetPath().Append(chrome::kIsolatedAppStateDirname); | 369 FilePath app_path = GetPath().Append(chrome::kIsolatedAppStateDirname); |
360 | 370 |
| 371 bool restore_old_session_cookies = |
| 372 session_restore_enabled_ && |
| 373 (!DidLastSessionExitCleanly() || |
| 374 CommandLine::ForCurrentProcess()->HasSwitch( |
| 375 switches::kRestoreLastSession)); |
| 376 |
361 // Make sure we initialize the ProfileIOData after everything else has been | 377 // Make sure we initialize the ProfileIOData after everything else has been |
362 // initialized that we might be reading from the IO thread. | 378 // initialized that we might be reading from the IO thread. |
363 | 379 |
364 io_data_.Init(cookie_path, origin_bound_cert_path, cache_path, | 380 io_data_.Init(cookie_path, origin_bound_cert_path, cache_path, |
365 cache_max_size, media_cache_path, media_cache_max_size, | 381 cache_max_size, media_cache_path, media_cache_max_size, |
366 extensions_cookie_path, app_path, predictor_, | 382 extensions_cookie_path, app_path, predictor_, |
367 g_browser_process->local_state(), | 383 g_browser_process->local_state(), |
368 g_browser_process->io_thread()); | 384 g_browser_process->io_thread(), |
| 385 restore_old_session_cookies); |
369 | 386 |
370 ChromePluginServiceFilter::GetInstance()->RegisterResourceContext( | 387 ChromePluginServiceFilter::GetInstance()->RegisterResourceContext( |
371 PluginPrefs::GetForProfile(this), &GetResourceContext()); | 388 PluginPrefs::GetForProfile(this), &GetResourceContext()); |
372 | 389 |
373 // Creation has been finished. | 390 // Creation has been finished. |
374 if (delegate_) | 391 if (delegate_) |
375 delegate_->OnProfileCreated(this, true); | 392 delegate_->OnProfileCreated(this, true); |
376 | 393 |
377 content::NotificationService::current()->Notify( | 394 content::NotificationService::current()->Notify( |
378 chrome::NOTIFICATION_PROFILE_CREATED, | 395 chrome::NOTIFICATION_PROFILE_CREATED, |
(...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 return GURL(chrome::kChromeUINewTabURL); | 1573 return GURL(chrome::kChromeUINewTabURL); |
1557 return home_page; | 1574 return home_page; |
1558 } | 1575 } |
1559 | 1576 |
1560 NetworkActionPredictor* ProfileImpl::GetNetworkActionPredictor() { | 1577 NetworkActionPredictor* ProfileImpl::GetNetworkActionPredictor() { |
1561 if (!network_action_predictor_.get()) | 1578 if (!network_action_predictor_.get()) |
1562 network_action_predictor_.reset(new NetworkActionPredictor(this)); | 1579 network_action_predictor_.reset(new NetworkActionPredictor(this)); |
1563 return network_action_predictor_.get(); | 1580 return network_action_predictor_.get(); |
1564 } | 1581 } |
1565 | 1582 |
| 1583 void ProfileImpl::SaveSessionState() { |
| 1584 if (!session_restore_enabled_) |
| 1585 return; |
| 1586 BrowserThread::PostTask( |
| 1587 BrowserThread::IO, FROM_HERE, |
| 1588 base::Bind(&SaveSessionStateOnIOThread, |
| 1589 make_scoped_refptr(GetRequestContext()))); |
| 1590 } |
| 1591 |
1566 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() { | 1592 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() { |
1567 if (!spellcheck_profile_.get()) | 1593 if (!spellcheck_profile_.get()) |
1568 spellcheck_profile_.reset(new SpellCheckProfile(path_)); | 1594 spellcheck_profile_.reset(new SpellCheckProfile(path_)); |
1569 return spellcheck_profile_.get(); | 1595 return spellcheck_profile_.get(); |
1570 } | 1596 } |
1571 | 1597 |
1572 void ProfileImpl::UpdateProfileUserNameCache() { | 1598 void ProfileImpl::UpdateProfileUserNameCache() { |
1573 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1599 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
1574 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1600 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
1575 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); | 1601 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); |
(...skipping 13 matching lines...) Expand all Loading... |
1589 FilePath* cache_path, | 1615 FilePath* cache_path, |
1590 int* max_size) { | 1616 int* max_size) { |
1591 DCHECK(cache_path); | 1617 DCHECK(cache_path); |
1592 DCHECK(max_size); | 1618 DCHECK(max_size); |
1593 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); | 1619 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); |
1594 if (!path.empty()) | 1620 if (!path.empty()) |
1595 *cache_path = path; | 1621 *cache_path = path; |
1596 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1622 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
1597 prefs_->GetInteger(prefs::kDiskCacheSize); | 1623 prefs_->GetInteger(prefs::kDiskCacheSize); |
1598 } | 1624 } |
OLD | NEW |