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