| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/pickle.h" | 17 #include "base/pickle.h" |
| 18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 19 #include "chrome/browser/background/background_mode_manager.h" | 19 #include "chrome/browser/background/background_mode_manager.h" |
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 22 #include "chrome/browser/defaults.h" | 22 #include "chrome/browser/defaults.h" |
| 23 #include "chrome/browser/extensions/tab_helper.h" | 23 #include "chrome/browser/extensions/tab_helper.h" |
| 24 #include "chrome/browser/prefs/session_startup_pref.h" | 24 #include "chrome/browser/prefs/session_startup_pref.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 27 #include "chrome/browser/sessions/base_session_service_delegate_impl.h" | 27 #include "chrome/browser/sessions/session_common_utils.h" |
| 28 #include "chrome/browser/sessions/session_data_deleter.h" | 28 #include "chrome/browser/sessions/session_data_deleter.h" |
| 29 #include "chrome/browser/sessions/session_restore.h" | 29 #include "chrome/browser/sessions/session_restore.h" |
| 30 #include "chrome/browser/sessions/session_service_utils.h" | 30 #include "chrome/browser/sessions/session_service_utils.h" |
| 31 #include "chrome/browser/sessions/session_tab_helper.h" | 31 #include "chrome/browser/sessions/session_tab_helper.h" |
| 32 #include "chrome/browser/ui/browser_iterator.h" | 32 #include "chrome/browser/ui/browser_iterator.h" |
| 33 #include "chrome/browser/ui/browser_list.h" | 33 #include "chrome/browser/ui/browser_list.h" |
| 34 #include "chrome/browser/ui/browser_tabstrip.h" | 34 #include "chrome/browser/ui/browser_tabstrip.h" |
| 35 #include "chrome/browser/ui/browser_window.h" | 35 #include "chrome/browser/ui/browser_window.h" |
| 36 #include "chrome/browser/ui/host_desktop.h" | 36 #include "chrome/browser/ui/host_desktop.h" |
| 37 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 37 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 57 using content::WebContents; | 57 using content::WebContents; |
| 58 using sessions::ContentSerializedNavigationBuilder; | 58 using sessions::ContentSerializedNavigationBuilder; |
| 59 using sessions::SerializedNavigationEntry; | 59 using sessions::SerializedNavigationEntry; |
| 60 | 60 |
| 61 // Every kWritesPerReset commands triggers recreating the file. | 61 // Every kWritesPerReset commands triggers recreating the file. |
| 62 static const int kWritesPerReset = 250; | 62 static const int kWritesPerReset = 250; |
| 63 | 63 |
| 64 // SessionService ------------------------------------------------------------- | 64 // SessionService ------------------------------------------------------------- |
| 65 | 65 |
| 66 SessionService::SessionService(Profile* profile) | 66 SessionService::SessionService(Profile* profile) |
| 67 : BaseSessionServiceDelegateImpl(true), | 67 : profile_(profile), |
| 68 profile_(profile), | 68 should_use_delayed_save_(true), |
| 69 base_session_service_( | 69 base_session_service_(new sessions::BaseSessionService( |
| 70 new sessions::BaseSessionService( | 70 sessions::BaseSessionService::SESSION_RESTORE, |
| 71 sessions::BaseSessionService::SESSION_RESTORE, | 71 profile->GetPath(), |
| 72 profile->GetPath(), | 72 this)), |
| 73 this)), | |
| 74 has_open_trackable_browsers_(false), | 73 has_open_trackable_browsers_(false), |
| 75 move_on_new_browser_(false), | 74 move_on_new_browser_(false), |
| 76 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), | 75 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), |
| 77 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), | 76 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), |
| 78 save_delay_in_hrs_(base::TimeDelta::FromHours(8)), | 77 save_delay_in_hrs_(base::TimeDelta::FromHours(8)), |
| 79 force_browser_not_alive_with_no_windows_(false), | 78 force_browser_not_alive_with_no_windows_(false), |
| 80 weak_factory_(this) { | 79 weak_factory_(this) { |
| 81 // We should never be created when incognito. | 80 // We should never be created when incognito. |
| 82 DCHECK(!profile->IsOffTheRecord()); | 81 DCHECK(!profile->IsOffTheRecord()); |
| 83 Init(); | 82 Init(); |
| 84 } | 83 } |
| 85 | 84 |
| 86 SessionService::SessionService(const base::FilePath& save_path) | 85 SessionService::SessionService(const base::FilePath& save_path) |
| 87 : BaseSessionServiceDelegateImpl(false), | 86 : profile_(NULL), |
| 88 profile_(NULL), | 87 should_use_delayed_save_(false), |
| 89 base_session_service_( | 88 base_session_service_(new sessions::BaseSessionService( |
| 90 new sessions::BaseSessionService( | 89 sessions::BaseSessionService::SESSION_RESTORE, |
| 91 sessions::BaseSessionService::SESSION_RESTORE, | 90 save_path, |
| 92 save_path, | 91 this)), |
| 93 this)), | |
| 94 has_open_trackable_browsers_(false), | 92 has_open_trackable_browsers_(false), |
| 95 move_on_new_browser_(false), | 93 move_on_new_browser_(false), |
| 96 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), | 94 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), |
| 97 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), | 95 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), |
| 98 save_delay_in_hrs_(base::TimeDelta::FromHours(8)), | 96 save_delay_in_hrs_(base::TimeDelta::FromHours(8)), |
| 99 force_browser_not_alive_with_no_windows_(false), | 97 force_browser_not_alive_with_no_windows_(false), |
| 100 weak_factory_(this) { | 98 weak_factory_(this) { |
| 101 Init(); | 99 Init(); |
| 102 } | 100 } |
| 103 | 101 |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 base::CancelableTaskTracker* tracker) { | 500 base::CancelableTaskTracker* tracker) { |
| 503 // OnGotSessionCommands maps the SessionCommands to browser state, then run | 501 // OnGotSessionCommands maps the SessionCommands to browser state, then run |
| 504 // the callback. | 502 // the callback. |
| 505 return base_session_service_->ScheduleGetLastSessionCommands( | 503 return base_session_service_->ScheduleGetLastSessionCommands( |
| 506 base::Bind(&SessionService::OnGotSessionCommands, | 504 base::Bind(&SessionService::OnGotSessionCommands, |
| 507 weak_factory_.GetWeakPtr(), | 505 weak_factory_.GetWeakPtr(), |
| 508 callback), | 506 callback), |
| 509 tracker); | 507 tracker); |
| 510 } | 508 } |
| 511 | 509 |
| 510 base::SequencedWorkerPool* SessionService::GetBlockingPool() { |
| 511 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 512 return content::BrowserThread::GetBlockingPool(); |
| 513 } |
| 514 |
| 515 bool SessionService::ShouldUseDelayedSave() { |
| 516 return should_use_delayed_save_; |
| 517 } |
| 518 |
| 512 void SessionService::OnSavedCommands() { | 519 void SessionService::OnSavedCommands() { |
| 513 RecordSessionUpdateHistogramData(chrome::NOTIFICATION_SESSION_SERVICE_SAVED, | 520 RecordSessionUpdateHistogramData(chrome::NOTIFICATION_SESSION_SERVICE_SAVED, |
| 514 &last_updated_save_time_); | 521 &last_updated_save_time_); |
| 515 content::NotificationService::current()->Notify( | 522 content::NotificationService::current()->Notify( |
| 516 chrome::NOTIFICATION_SESSION_SERVICE_SAVED, | 523 chrome::NOTIFICATION_SESSION_SERVICE_SAVED, |
| 517 content::Source<Profile>(profile()), | 524 content::Source<Profile>(profile()), |
| 518 content::NotificationService::NoDetails()); | 525 content::NotificationService::NoDetails()); |
| 519 } | 526 } |
| 520 | 527 |
| 521 void SessionService::Init() { | 528 void SessionService::Init() { |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 1116 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
| 1110 if ((*it)->profile() == profile()) | 1117 if ((*it)->profile() == profile()) |
| 1111 return; | 1118 return; |
| 1112 } | 1119 } |
| 1113 DeleteSessionOnlyData(profile()); | 1120 DeleteSessionOnlyData(profile()); |
| 1114 } | 1121 } |
| 1115 | 1122 |
| 1116 sessions::BaseSessionService* SessionService::GetBaseSessionServiceForTest() { | 1123 sessions::BaseSessionService* SessionService::GetBaseSessionServiceForTest() { |
| 1117 return base_session_service_.get(); | 1124 return base_session_service_.get(); |
| 1118 } | 1125 } |
| OLD | NEW |