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

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
176 void RestoreSessionStateOnIOThread(
177 net::URLRequestContextGetter* url_request_context_getter) {
178 url_request_context_getter->GetURLRequestContext()->cookie_store()->
179 GetCookieMonster()->RestoreOldSessionCookies();
180 }
181
182 void DiscardSessionStateOnIOThread(
183 net::URLRequestContextGetter* url_request_context_getter) {
184 url_request_context_getter->GetURLRequestContext()->cookie_store()->
185 GetCookieMonster()->DiscardOldSessionCookies();
186 }
187
170 } // namespace 188 } // namespace
171 189
172 // static 190 // static
173 Profile* Profile::CreateProfile(const FilePath& path) { 191 Profile* Profile::CreateProfile(const FilePath& path) {
174 if (!file_util::PathExists(path)) { 192 if (!file_util::PathExists(path)) {
175 // TODO(tc): http://b/1094718 Bad things happen if we can't write to the 193 // 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 194 // profile directory. We should eventually be able to run in this
177 // situation. 195 // situation.
178 if (!file_util::CreateDirectory(path)) 196 if (!file_util::CreateDirectory(path))
179 return NULL; 197 return NULL;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 host_zoom_map_(NULL), 240 host_zoom_map_(NULL),
223 history_service_created_(false), 241 history_service_created_(false),
224 favicon_service_created_(false), 242 favicon_service_created_(false),
225 created_web_data_service_(false), 243 created_web_data_service_(false),
226 created_password_store_(false), 244 created_password_store_(false),
227 start_time_(Time::Now()), 245 start_time_(Time::Now()),
228 #if defined(OS_WIN) 246 #if defined(OS_WIN)
229 checked_instant_promo_(false), 247 checked_instant_promo_(false),
230 #endif 248 #endif
231 delegate_(delegate), 249 delegate_(delegate),
232 predictor_(NULL) { 250 predictor_(NULL),
251 session_restore_enabled_(false) {
233 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << 252 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
234 "profile files to the root directory!"; 253 "profile files to the root directory!";
235 254
236 create_session_service_timer_.Start(FROM_HERE, 255 create_session_service_timer_.Start(FROM_HERE,
237 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, 256 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
238 &ProfileImpl::EnsureSessionServiceCreated); 257 &ProfileImpl::EnsureSessionServiceCreated);
239 258
240 // Determine if prefetch is enabled for this profile. 259 // Determine if prefetch is enabled for this profile.
241 // If not profile_manager is present, it means we are in a unittest. 260 // If not profile_manager is present, it means we are in a unittest.
242 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 261 const CommandLine* command_line = CommandLine::ForCurrentProcess();
(...skipping 11 matching lines...) Expand all
254 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, 273 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED,
255 content::Source<PrefService>(prefs_.get())); 274 content::Source<PrefService>(prefs_.get()));
256 } else { 275 } else {
257 // Load prefs synchronously. 276 // Load prefs synchronously.
258 prefs_.reset(PrefService::CreatePrefService( 277 prefs_.reset(PrefService::CreatePrefService(
259 GetPrefFilePath(), 278 GetPrefFilePath(),
260 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), 279 new ExtensionPrefStore(GetExtensionPrefValueMap(), false),
261 false)); 280 false));
262 OnPrefsLoaded(true); 281 OnPrefsLoaded(true);
263 } 282 }
283
284 session_restore_enabled_ =
285 command_line->HasSwitch(switches::kEnableRestoreSessionState);
264 } 286 }
265 287
266 void ProfileImpl::DoFinalInit() { 288 void ProfileImpl::DoFinalInit() {
267 PrefService* prefs = GetPrefs(); 289 PrefService* prefs = GetPrefs();
268 pref_change_registrar_.Init(prefs); 290 pref_change_registrar_.Init(prefs);
269 pref_change_registrar_.Add(prefs::kSpellCheckDictionary, this); 291 pref_change_registrar_.Add(prefs::kSpellCheckDictionary, this);
270 pref_change_registrar_.Add(prefs::kEnableSpellCheck, this); 292 pref_change_registrar_.Add(prefs::kEnableSpellCheck, this);
271 pref_change_registrar_.Add(prefs::kEnableAutoSpellCorrect, this); 293 pref_change_registrar_.Add(prefs::kEnableAutoSpellCorrect, this);
272 pref_change_registrar_.Add(prefs::kSpeechInputFilterProfanities, this); 294 pref_change_registrar_.Add(prefs::kSpeechInputFilterProfanities, this);
273 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); 295 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this);
(...skipping 1270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 return GURL(chrome::kChromeUINewTabURL); 1566 return GURL(chrome::kChromeUINewTabURL);
1545 return home_page; 1567 return home_page;
1546 } 1568 }
1547 1569
1548 NetworkActionPredictor* ProfileImpl::GetNetworkActionPredictor() { 1570 NetworkActionPredictor* ProfileImpl::GetNetworkActionPredictor() {
1549 if (!network_action_predictor_.get()) 1571 if (!network_action_predictor_.get())
1550 network_action_predictor_.reset(new NetworkActionPredictor(this)); 1572 network_action_predictor_.reset(new NetworkActionPredictor(this));
1551 return network_action_predictor_.get(); 1573 return network_action_predictor_.get();
1552 } 1574 }
1553 1575
1576 void ProfileImpl::SaveSessionState() {
1577 if (!session_restore_enabled_)
1578 return;
1579 BrowserThread::PostTask(
1580 BrowserThread::IO, FROM_HERE,
1581 base::Bind(&SaveSessionStateOnIOThread,
1582 make_scoped_refptr(GetRequestContext())));
1583 }
1584
1585 void ProfileImpl::RestoreSessionState() {
1586 if (!session_restore_enabled_)
1587 return;
1588 BrowserThread::PostTask(
1589 BrowserThread::IO, FROM_HERE,
1590 base::Bind(&RestoreSessionStateOnIOThread,
1591 make_scoped_refptr(GetRequestContext())));
1592 }
1593
1594 void ProfileImpl::DiscardSessionState() {
1595 if (!session_restore_enabled_)
1596 return;
1597 BrowserThread::PostTask(
1598 BrowserThread::IO, FROM_HERE,
1599 base::Bind(&DiscardSessionStateOnIOThread,
1600 make_scoped_refptr(GetRequestContext())));
1601 }
1602
1554 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() { 1603 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() {
1555 if (!spellcheck_profile_.get()) 1604 if (!spellcheck_profile_.get())
1556 spellcheck_profile_.reset(new SpellCheckProfile(path_)); 1605 spellcheck_profile_.reset(new SpellCheckProfile(path_));
1557 return spellcheck_profile_.get(); 1606 return spellcheck_profile_.get();
1558 } 1607 }
1559 1608
1560 void ProfileImpl::UpdateProfileUserNameCache() { 1609 void ProfileImpl::UpdateProfileUserNameCache() {
1561 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1610 ProfileManager* profile_manager = g_browser_process->profile_manager();
1562 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 1611 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
1563 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); 1612 size_t index = cache.GetIndexOfProfileWithPath(GetPath());
(...skipping 13 matching lines...) Expand all
1577 FilePath* cache_path, 1626 FilePath* cache_path,
1578 int* max_size) { 1627 int* max_size) {
1579 DCHECK(cache_path); 1628 DCHECK(cache_path);
1580 DCHECK(max_size); 1629 DCHECK(max_size);
1581 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); 1630 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir));
1582 if (!path.empty()) 1631 if (!path.empty())
1583 *cache_path = path; 1632 *cache_path = path;
1584 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : 1633 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) :
1585 prefs_->GetInteger(prefs::kDiskCacheSize); 1634 prefs_->GetInteger(prefs::kDiskCacheSize);
1586 } 1635 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698