| 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/persistent_tab_restore_service.h" | 5 #include "chrome/browser/sessions/persistent_tab_restore_service.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/threading/sequenced_worker_pool.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/sessions/session_service.h" | 14 #include "chrome/browser/sessions/session_service.h" |
| 14 #include "chrome/browser/sessions/session_service_factory.h" | 15 #include "chrome/browser/sessions/session_service_factory.h" |
| 15 #include "chrome/browser/sessions/session_types.h" | 16 #include "chrome/browser/sessions/session_types.h" |
| 16 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 17 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 17 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 18 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
| 18 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
| 19 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 20 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 21 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // Navigate back. We have to do this song and dance as NavigationController | 110 // Navigate back. We have to do this song and dance as NavigationController |
| 110 // isn't happy if you navigate immediately while going back. | 111 // isn't happy if you navigate immediately while going back. |
| 111 controller().GoToIndex(index); | 112 controller().GoToIndex(index); |
| 112 WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 113 WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 void RecreateService() { | 116 void RecreateService() { |
| 116 // Must set service to null first so that it is destroyed before the new | 117 // Must set service to null first so that it is destroyed before the new |
| 117 // one is created. | 118 // one is created. |
| 118 service_->Shutdown(); | 119 service_->Shutdown(); |
| 120 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 119 service_.reset(); | 121 service_.reset(); |
| 120 service_.reset(new PersistentTabRestoreService(profile(), time_factory_)); | 122 service_.reset(new PersistentTabRestoreService(profile(), time_factory_)); |
| 121 SynchronousLoadTabsFromLastSession(); | 123 SynchronousLoadTabsFromLastSession(); |
| 122 } | 124 } |
| 123 | 125 |
| 124 // Adds a window with one tab and url to the profile's session service. | 126 // Adds a window with one tab and url to the profile's session service. |
| 125 // If |pinned| is true, the tab is marked as pinned in the session service. | 127 // If |pinned| is true, the tab is marked as pinned in the session service. |
| 126 void AddWindowWithOneTabToSessionService(bool pinned) { | 128 void AddWindowWithOneTabToSessionService(bool pinned) { |
| 127 SessionService* session_service = | 129 SessionService* session_service = |
| 128 SessionServiceFactory::GetForProfile(profile()); | 130 SessionServiceFactory::GetForProfile(profile()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 152 | 154 |
| 153 AddWindowWithOneTabToSessionService(pinned); | 155 AddWindowWithOneTabToSessionService(pinned); |
| 154 | 156 |
| 155 // Set this, otherwise previous session won't be loaded. | 157 // Set this, otherwise previous session won't be loaded. |
| 156 profile()->set_last_session_exited_cleanly(false); | 158 profile()->set_last_session_exited_cleanly(false); |
| 157 } | 159 } |
| 158 | 160 |
| 159 void SynchronousLoadTabsFromLastSession() { | 161 void SynchronousLoadTabsFromLastSession() { |
| 160 // Ensures that the load is complete before continuing. | 162 // Ensures that the load is complete before continuing. |
| 161 service_->LoadTabsFromLastSession(); | 163 service_->LoadTabsFromLastSession(); |
| 164 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 162 base::RunLoop().RunUntilIdle(); | 165 base::RunLoop().RunUntilIdle(); |
| 166 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 163 } | 167 } |
| 164 | 168 |
| 165 GURL url1_; | 169 GURL url1_; |
| 166 GURL url2_; | 170 GURL url2_; |
| 167 GURL url3_; | 171 GURL url3_; |
| 168 std::string user_agent_override_; | 172 std::string user_agent_override_; |
| 169 scoped_ptr<PersistentTabRestoreService> service_; | 173 scoped_ptr<PersistentTabRestoreService> service_; |
| 170 PersistentTabRestoreTimeFactory* time_factory_; | 174 PersistentTabRestoreTimeFactory* time_factory_; |
| 171 }; | 175 }; |
| 172 | 176 |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 | 746 |
| 743 EXPECT_FALSE(service_->IsLoaded()); | 747 EXPECT_FALSE(service_->IsLoaded()); |
| 744 TestTabRestoreServiceObserver observer; | 748 TestTabRestoreServiceObserver observer; |
| 745 service_->AddObserver(&observer); | 749 service_->AddObserver(&observer); |
| 746 EXPECT_EQ(max_entries, service_->entries().size()); | 750 EXPECT_EQ(max_entries, service_->entries().size()); |
| 747 SynchronousLoadTabsFromLastSession(); | 751 SynchronousLoadTabsFromLastSession(); |
| 748 EXPECT_TRUE(observer.got_loaded()); | 752 EXPECT_TRUE(observer.got_loaded()); |
| 749 EXPECT_TRUE(service_->IsLoaded()); | 753 EXPECT_TRUE(service_->IsLoaded()); |
| 750 service_->RemoveObserver(&observer); | 754 service_->RemoveObserver(&observer); |
| 751 } | 755 } |
| OLD | NEW |