| 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 } // namespace | 191 } // namespace |
| 192 | 192 |
| 193 // SessionService ------------------------------------------------------------- | 193 // SessionService ------------------------------------------------------------- |
| 194 | 194 |
| 195 SessionService::SessionService(Profile* profile) | 195 SessionService::SessionService(Profile* profile) |
| 196 : BaseSessionService(SESSION_RESTORE, profile, FilePath()), | 196 : BaseSessionService(SESSION_RESTORE, profile, FilePath()), |
| 197 has_open_trackable_browsers_(false), | 197 has_open_trackable_browsers_(false), |
| 198 move_on_new_browser_(false), | 198 move_on_new_browser_(false), |
| 199 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), | 199 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), |
| 200 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), | 200 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), |
| 201 save_delay_in_hrs_(base::TimeDelta::FromHours(8)) { | 201 save_delay_in_hrs_(base::TimeDelta::FromHours(8)), |
| 202 force_browser_not_alive_with_no_windows_(false) { |
| 202 Init(); | 203 Init(); |
| 203 } | 204 } |
| 204 | 205 |
| 205 SessionService::SessionService(const FilePath& save_path) | 206 SessionService::SessionService(const FilePath& save_path) |
| 206 : BaseSessionService(SESSION_RESTORE, NULL, save_path), | 207 : BaseSessionService(SESSION_RESTORE, NULL, save_path), |
| 207 has_open_trackable_browsers_(false), | 208 has_open_trackable_browsers_(false), |
| 208 move_on_new_browser_(false), | 209 move_on_new_browser_(false), |
| 209 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), | 210 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), |
| 210 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), | 211 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), |
| 211 save_delay_in_hrs_(base::TimeDelta::FromHours(8)) { | 212 save_delay_in_hrs_(base::TimeDelta::FromHours(8)), |
| 213 force_browser_not_alive_with_no_windows_(false) { |
| 212 Init(); | 214 Init(); |
| 213 } | 215 } |
| 214 | 216 |
| 215 SessionService::~SessionService() { | 217 SessionService::~SessionService() { |
| 216 Save(); | 218 Save(); |
| 217 } | 219 } |
| 218 | 220 |
| 219 bool SessionService::RestoreIfNecessary(const std::vector<GURL>& urls_to_open) { | 221 bool SessionService::RestoreIfNecessary(const std::vector<GURL>& urls_to_open) { |
| 220 return RestoreIfNecessary(urls_to_open, NULL); | 222 return RestoreIfNecessary(urls_to_open, NULL); |
| 221 } | 223 } |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 content::NotificationService::AllBrowserContextsAndSources()); | 520 content::NotificationService::AllBrowserContextsAndSources()); |
| 519 registrar_.Add( | 521 registrar_.Add( |
| 520 this, chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, | 522 this, chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, |
| 521 content::NotificationService::AllSources()); | 523 content::NotificationService::AllSources()); |
| 522 } | 524 } |
| 523 | 525 |
| 524 bool SessionService::ShouldNewWindowStartSession() { | 526 bool SessionService::ShouldNewWindowStartSession() { |
| 525 // ChromeOS and OSX have different ideas of application lifetime than | 527 // ChromeOS and OSX have different ideas of application lifetime than |
| 526 // the other platforms. | 528 // the other platforms. |
| 527 // On ChromeOS opening a new window should never start a new session. | 529 // On ChromeOS opening a new window should never start a new session. |
| 528 #if !defined(OS_CHROMEOS) | 530 #if defined(OS_CHROMEOS) |
| 531 if (!force_browser_not_alive_with_no_windows_) |
| 532 return false; |
| 533 #endif |
| 529 if (!has_open_trackable_browsers_ && | 534 if (!has_open_trackable_browsers_ && |
| 530 !BrowserInit::InSynchronousProfileLaunch() && | 535 !BrowserInit::InSynchronousProfileLaunch() && |
| 531 !SessionRestore::IsRestoring(profile()) | 536 !SessionRestore::IsRestoring(profile()) |
| 532 #if defined(OS_MACOSX) | 537 #if defined(OS_MACOSX) |
| 533 // On OSX, a new window should not start a new session if it was opened | 538 // On OSX, a new window should not start a new session if it was opened |
| 534 // from the dock or the menubar. | 539 // from the dock or the menubar. |
| 535 && !app_controller_mac::IsOpeningNewWindow() | 540 && !app_controller_mac::IsOpeningNewWindow() |
| 536 #endif // OS_MACOSX | 541 #endif // OS_MACOSX |
| 537 ) { | 542 ) { |
| 538 return true; | 543 return true; |
| 539 } | 544 } |
| 540 #endif // !OS_CHROMEOS | |
| 541 return false; | 545 return false; |
| 542 } | 546 } |
| 543 | 547 |
| 544 bool SessionService::RestoreIfNecessary(const std::vector<GURL>& urls_to_open, | 548 bool SessionService::RestoreIfNecessary(const std::vector<GURL>& urls_to_open, |
| 545 Browser* browser) { | 549 Browser* browser) { |
| 546 if (ShouldNewWindowStartSession()) { | 550 if (ShouldNewWindowStartSession()) { |
| 547 // We're going from no tabbed browsers to a tabbed browser (and not in | 551 // We're going from no tabbed browsers to a tabbed browser (and not in |
| 548 // process startup), restore the last session. | 552 // process startup), restore the last session. |
| 549 if (move_on_new_browser_) { | 553 if (move_on_new_browser_) { |
| 550 // Make the current session the last. | 554 // Make the current session the last. |
| (...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1618 50); | 1622 50); |
| 1619 if (use_long_period) { | 1623 if (use_long_period) { |
| 1620 std::string long_name_("SessionRestore.SaveLongPeriod"); | 1624 std::string long_name_("SessionRestore.SaveLongPeriod"); |
| 1621 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, | 1625 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, |
| 1622 delta, | 1626 delta, |
| 1623 save_delay_in_mins_, | 1627 save_delay_in_mins_, |
| 1624 save_delay_in_hrs_, | 1628 save_delay_in_hrs_, |
| 1625 50); | 1629 50); |
| 1626 } | 1630 } |
| 1627 } | 1631 } |
| OLD | NEW |