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

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

Issue 8533013: SessionRestore: Store session cookies and restore them if chrome crashes or auto-restarts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years 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/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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 160 }
161 161
162 FilePath GetCachePath(const FilePath& base) { 162 FilePath GetCachePath(const FilePath& base) {
163 return base.Append(chrome::kCacheDirname); 163 return base.Append(chrome::kCacheDirname);
164 } 164 }
165 165
166 FilePath GetMediaCachePath(const FilePath& base) { 166 FilePath GetMediaCachePath(const FilePath& base) {
167 return base.Append(chrome::kMediaCacheDirname); 167 return base.Append(chrome::kMediaCacheDirname);
168 } 168 }
169 169
170 void SaveSessionStateOnIOThread(
171 net::URLRequestContextGetter* url_request_context_getter) {
172 url_request_context_getter->GetURLRequestContext()->cookie_store()->
173 GetCookieMonster()->SaveSessionCookies();
174 }
175
170 } // namespace 176 } // namespace
171 177
172 // static 178 // static
173 Profile* Profile::CreateProfile(const FilePath& path) { 179 Profile* Profile::CreateProfile(const FilePath& path) {
174 if (!file_util::PathExists(path)) { 180 if (!file_util::PathExists(path)) {
175 // TODO(tc): http://b/1094718 Bad things happen if we can't write to the 181 // TODO(tc): http://b/1094718 Bad things happen if we can't write to the
176 // profile directory. We should eventually be able to run in this 182 // profile directory. We should eventually be able to run in this
177 // situation. 183 // situation.
178 if (!file_util::CreateDirectory(path)) 184 if (!file_util::CreateDirectory(path))
179 return NULL; 185 return NULL;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 host_zoom_map_(NULL), 228 host_zoom_map_(NULL),
223 history_service_created_(false), 229 history_service_created_(false),
224 favicon_service_created_(false), 230 favicon_service_created_(false),
225 created_web_data_service_(false), 231 created_web_data_service_(false),
226 created_password_store_(false), 232 created_password_store_(false),
227 start_time_(Time::Now()), 233 start_time_(Time::Now()),
228 #if defined(OS_WIN) 234 #if defined(OS_WIN)
229 checked_instant_promo_(false), 235 checked_instant_promo_(false),
230 #endif 236 #endif
231 delegate_(delegate), 237 delegate_(delegate),
232 predictor_(NULL) { 238 predictor_(NULL),
239 session_restore_enabled_(false) {
233 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << 240 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
234 "profile files to the root directory!"; 241 "profile files to the root directory!";
235 242
236 create_session_service_timer_.Start(FROM_HERE, 243 create_session_service_timer_.Start(FROM_HERE,
237 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, 244 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
238 &ProfileImpl::EnsureSessionServiceCreated); 245 &ProfileImpl::EnsureSessionServiceCreated);
239 246
240 // Determine if prefetch is enabled for this profile. 247 // Determine if prefetch is enabled for this profile.
241 // If not profile_manager is present, it means we are in a unittest. 248 // If not profile_manager is present, it means we are in a unittest.
242 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 249 const CommandLine* command_line = CommandLine::ForCurrentProcess();
243 predictor_ = chrome_browser_net::Predictor::CreatePredictor( 250 predictor_ = chrome_browser_net::Predictor::CreatePredictor(
244 !command_line->HasSwitch(switches::kDisablePreconnect), 251 !command_line->HasSwitch(switches::kDisablePreconnect),
245 g_browser_process->profile_manager() == NULL); 252 g_browser_process->profile_manager() == NULL);
246 253
254 session_restore_enabled_ =
255 command_line->HasSwitch(switches::kEnableRestoreSessionState);
247 if (delegate_) { 256 if (delegate_) {
248 prefs_.reset(PrefService::CreatePrefService( 257 prefs_.reset(PrefService::CreatePrefService(
249 GetPrefFilePath(), 258 GetPrefFilePath(),
250 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), 259 new ExtensionPrefStore(GetExtensionPrefValueMap(), false),
251 true)); 260 true));
252 // Wait for the notification that prefs has been loaded (successfully or 261 // Wait for the notification that prefs has been loaded (successfully or
253 // not). 262 // not).
254 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, 263 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED,
255 content::Source<PrefService>(prefs_.get())); 264 content::Source<PrefService>(prefs_.get()));
256 } else { 265 } else {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 int media_cache_max_size; 359 int media_cache_max_size;
351 GetCacheParameters(true, &media_cache_path, &media_cache_max_size); 360 GetCacheParameters(true, &media_cache_path, &media_cache_max_size);
352 media_cache_path = GetMediaCachePath(media_cache_path); 361 media_cache_path = GetMediaCachePath(media_cache_path);
353 362
354 FilePath extensions_cookie_path = GetPath(); 363 FilePath extensions_cookie_path = GetPath();
355 extensions_cookie_path = 364 extensions_cookie_path =
356 extensions_cookie_path.Append(chrome::kExtensionsCookieFilename); 365 extensions_cookie_path.Append(chrome::kExtensionsCookieFilename);
357 366
358 FilePath app_path = GetPath().Append(chrome::kIsolatedAppStateDirname); 367 FilePath app_path = GetPath().Append(chrome::kIsolatedAppStateDirname);
359 368
369 bool restore_old_session_cookies =
370 session_restore_enabled_ &&
371 (!DidLastSessionExitCleanly() ||
372 CommandLine::ForCurrentProcess()->HasSwitch(
373 switches::kRestoreLastSession));
374
360 // Make sure we initialize the ProfileIOData after everything else has been 375 // Make sure we initialize the ProfileIOData after everything else has been
361 // initialized that we might be reading from the IO thread. 376 // initialized that we might be reading from the IO thread.
362 377
363 io_data_.Init(cookie_path, origin_bound_cert_path, cache_path, 378 io_data_.Init(cookie_path, origin_bound_cert_path, cache_path,
364 cache_max_size, media_cache_path, media_cache_max_size, 379 cache_max_size, media_cache_path, media_cache_max_size,
365 extensions_cookie_path, app_path, predictor_, 380 extensions_cookie_path, app_path, predictor_,
366 g_browser_process->local_state(), 381 g_browser_process->local_state(),
367 g_browser_process->io_thread()); 382 g_browser_process->io_thread(),
383 restore_old_session_cookies);
368 384
369 ChromePluginServiceFilter::GetInstance()->RegisterResourceContext( 385 ChromePluginServiceFilter::GetInstance()->RegisterResourceContext(
370 PluginPrefs::GetForProfile(this), &GetResourceContext()); 386 PluginPrefs::GetForProfile(this), &GetResourceContext());
371 387
372 // Creation has been finished. 388 // Creation has been finished.
373 if (delegate_) 389 if (delegate_)
374 delegate_->OnProfileCreated(this, true); 390 delegate_->OnProfileCreated(this, true);
375 391
376 content::NotificationService::current()->Notify( 392 content::NotificationService::current()->Notify(
377 chrome::NOTIFICATION_PROFILE_CREATED, 393 chrome::NOTIFICATION_PROFILE_CREATED,
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 return GURL(chrome::kChromeUINewTabURL); 1560 return GURL(chrome::kChromeUINewTabURL);
1545 return home_page; 1561 return home_page;
1546 } 1562 }
1547 1563
1548 NetworkActionPredictor* ProfileImpl::GetNetworkActionPredictor() { 1564 NetworkActionPredictor* ProfileImpl::GetNetworkActionPredictor() {
1549 if (!network_action_predictor_.get()) 1565 if (!network_action_predictor_.get())
1550 network_action_predictor_.reset(new NetworkActionPredictor(this)); 1566 network_action_predictor_.reset(new NetworkActionPredictor(this));
1551 return network_action_predictor_.get(); 1567 return network_action_predictor_.get();
1552 } 1568 }
1553 1569
1570 void ProfileImpl::SaveSessionState() {
1571 if (!session_restore_enabled_)
1572 return;
1573 BrowserThread::PostTask(
1574 BrowserThread::IO, FROM_HERE,
1575 base::Bind(&SaveSessionStateOnIOThread,
1576 make_scoped_refptr(GetRequestContext())));
erikwright (departed) 2011/11/29 13:43:22 I'm under the impression that Bind automatically i
marja 2011/11/29 14:58:21 If I remove it, the compile-time assert p1_is_refc
1577 }
1578
1554 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() { 1579 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() {
1555 if (!spellcheck_profile_.get()) 1580 if (!spellcheck_profile_.get())
1556 spellcheck_profile_.reset(new SpellCheckProfile(path_)); 1581 spellcheck_profile_.reset(new SpellCheckProfile(path_));
1557 return spellcheck_profile_.get(); 1582 return spellcheck_profile_.get();
1558 } 1583 }
1559 1584
1560 void ProfileImpl::UpdateProfileUserNameCache() { 1585 void ProfileImpl::UpdateProfileUserNameCache() {
1561 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1586 ProfileManager* profile_manager = g_browser_process->profile_manager();
1562 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 1587 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
1563 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); 1588 size_t index = cache.GetIndexOfProfileWithPath(GetPath());
(...skipping 13 matching lines...) Expand all
1577 FilePath* cache_path, 1602 FilePath* cache_path,
1578 int* max_size) { 1603 int* max_size) {
1579 DCHECK(cache_path); 1604 DCHECK(cache_path);
1580 DCHECK(max_size); 1605 DCHECK(max_size);
1581 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); 1606 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir));
1582 if (!path.empty()) 1607 if (!path.empty())
1583 *cache_path = path; 1608 *cache_path = path;
1584 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : 1609 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) :
1585 prefs_->GetInteger(prefs::kDiskCacheSize); 1610 prefs_->GetInteger(prefs::kDiskCacheSize);
1586 } 1611 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698