OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sessions/session_service.h" | 5 #include "chrome/browser/sessions/session_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 // SessionService ------------------------------------------------------------- | 228 // SessionService ------------------------------------------------------------- |
229 | 229 |
230 SessionService::SessionService(Profile* profile) | 230 SessionService::SessionService(Profile* profile) |
231 : BaseSessionService(SESSION_RESTORE, profile, base::FilePath()), | 231 : BaseSessionService(SESSION_RESTORE, profile, base::FilePath()), |
232 has_open_trackable_browsers_(false), | 232 has_open_trackable_browsers_(false), |
233 move_on_new_browser_(false), | 233 move_on_new_browser_(false), |
234 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), | 234 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), |
235 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), | 235 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), |
236 save_delay_in_hrs_(base::TimeDelta::FromHours(8)), | 236 save_delay_in_hrs_(base::TimeDelta::FromHours(8)), |
237 force_browser_not_alive_with_no_windows_(false) { | 237 force_browser_not_alive_with_no_windows_(false), |
| 238 weak_factory_(this) { |
238 Init(); | 239 Init(); |
239 } | 240 } |
240 | 241 |
241 SessionService::SessionService(const base::FilePath& save_path) | 242 SessionService::SessionService(const base::FilePath& save_path) |
242 : BaseSessionService(SESSION_RESTORE, NULL, save_path), | 243 : BaseSessionService(SESSION_RESTORE, NULL, save_path), |
243 has_open_trackable_browsers_(false), | 244 has_open_trackable_browsers_(false), |
244 move_on_new_browser_(false), | 245 move_on_new_browser_(false), |
245 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), | 246 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), |
246 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), | 247 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), |
247 save_delay_in_hrs_(base::TimeDelta::FromHours(8)), | 248 save_delay_in_hrs_(base::TimeDelta::FromHours(8)), |
248 force_browser_not_alive_with_no_windows_(false) { | 249 force_browser_not_alive_with_no_windows_(false), |
| 250 weak_factory_(this) { |
249 Init(); | 251 Init(); |
250 } | 252 } |
251 | 253 |
252 SessionService::~SessionService() { | 254 SessionService::~SessionService() { |
253 // The BrowserList should outlive the SessionService since it's static and | 255 // The BrowserList should outlive the SessionService since it's static and |
254 // the SessionService is a KeyedService. | 256 // the SessionService is a KeyedService. |
255 BrowserList::RemoveObserver(this); | 257 BrowserList::RemoveObserver(this); |
256 Save(); | 258 Save(); |
257 } | 259 } |
258 | 260 |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 kCommandSetTabUserAgentOverride, tab_id.id(), user_agent_override)); | 566 kCommandSetTabUserAgentOverride, tab_id.id(), user_agent_override)); |
565 } | 567 } |
566 | 568 |
567 base::CancelableTaskTracker::TaskId SessionService::GetLastSession( | 569 base::CancelableTaskTracker::TaskId SessionService::GetLastSession( |
568 const SessionCallback& callback, | 570 const SessionCallback& callback, |
569 base::CancelableTaskTracker* tracker) { | 571 base::CancelableTaskTracker* tracker) { |
570 // OnGotSessionCommands maps the SessionCommands to browser state, then run | 572 // OnGotSessionCommands maps the SessionCommands to browser state, then run |
571 // the callback. | 573 // the callback. |
572 return ScheduleGetLastSessionCommands( | 574 return ScheduleGetLastSessionCommands( |
573 base::Bind(&SessionService::OnGotSessionCommands, | 575 base::Bind(&SessionService::OnGotSessionCommands, |
574 base::Unretained(this), callback), | 576 weak_factory_.GetWeakPtr(), callback), |
575 tracker); | 577 tracker); |
576 } | 578 } |
577 | 579 |
578 void SessionService::Save() { | 580 void SessionService::Save() { |
579 bool had_commands = !pending_commands().empty(); | 581 bool had_commands = !pending_commands().empty(); |
580 BaseSessionService::Save(); | 582 BaseSessionService::Save(); |
581 if (had_commands) { | 583 if (had_commands) { |
582 RecordSessionUpdateHistogramData(chrome::NOTIFICATION_SESSION_SERVICE_SAVED, | 584 RecordSessionUpdateHistogramData(chrome::NOTIFICATION_SESSION_SERVICE_SAVED, |
583 &last_updated_save_time_); | 585 &last_updated_save_time_); |
584 content::NotificationService::current()->Notify( | 586 content::NotificationService::current()->Notify( |
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1847 return; | 1849 return; |
1848 } | 1850 } |
1849 | 1851 |
1850 // Check for any open windows for the current profile that we aren't tracking. | 1852 // Check for any open windows for the current profile that we aren't tracking. |
1851 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 1853 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
1852 if ((*it)->profile() == profile()) | 1854 if ((*it)->profile() == profile()) |
1853 return; | 1855 return; |
1854 } | 1856 } |
1855 DeleteSessionOnlyData(profile()); | 1857 DeleteSessionOnlyData(profile()); |
1856 } | 1858 } |
OLD | NEW |