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

Side by Side Diff: chrome/browser/sync/test/integration/sessions_helper.cc

Issue 2750163003: Prevent tabs sync during browser shutdown.
Patch Set: Created 3 years, 9 months 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
OLDNEW
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/sync/test/integration/sessions_helper.h" 5 #include "chrome/browser/sync/test/integration/sessions_helper.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 Browser* browser = test()->GetBrowser(index); 108 Browser* browser = test()->GetBrowser(index);
109 for (std::vector<GURL>::const_iterator it = urls.begin(); 109 for (std::vector<GURL>::const_iterator it = urls.begin();
110 it != urls.end(); ++it) { 110 it != urls.end(); ++it) {
111 DVLOG(1) << "Opening tab: " << it->spec() << " using browser " << index 111 DVLOG(1) << "Opening tab: " << it->spec() << " using browser " << index
112 << "."; 112 << ".";
113 chrome::ShowSingletonTab(browser, *it); 113 chrome::ShowSingletonTab(browser, *it);
114 } 114 }
115 return WaitForTabsToLoad(index, urls); 115 return WaitForTabsToLoad(index, urls);
116 } 116 }
117 117
118 bool CloseTabAtIndex(int index, int tab_index, const GURL& url) {
119 auto* tab_strip = test()->GetBrowser(index)->tab_strip_model();
120 tab_strip->CloseWebContentsAt(tab_index, TabStripModel::CLOSE_NONE);
121
122 return WaitForTabsToClose(index, {url});
123 }
124
118 void MoveTab(int from_index, int to_index, int tab_index) { 125 void MoveTab(int from_index, int to_index, int tab_index) {
119 content::WebContents* detached_contents = 126 content::WebContents* detached_contents =
120 test() 127 test()
121 ->GetBrowser(from_index) 128 ->GetBrowser(from_index)
122 ->tab_strip_model() 129 ->tab_strip_model()
123 ->DetachWebContentsAt(tab_index); 130 ->DetachWebContentsAt(tab_index);
124 131
125 TabStripModel* target_strip = test()->GetBrowser(to_index)->tab_strip_model(); 132 TabStripModel* target_strip = test()->GetBrowser(to_index)->tab_strip_model();
126 target_strip->InsertWebContentsAt(target_strip->count(), detached_contents, 133 target_strip->InsertWebContentsAt(target_strip->count(), detached_contents,
127 TabStripModel::ADD_ACTIVE); 134 TabStripModel::ADD_ACTIVE);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 181 }
175 182
176 void OnFaviconsChanged(const std::set<GURL>& /* page_urls */, 183 void OnFaviconsChanged(const std::set<GURL>& /* page_urls */,
177 const GURL& /* icon_url */) override { 184 const GURL& /* icon_url */) override {
178 // Unwind to ensure SessionsSyncManager has processed the event. 185 // Unwind to ensure SessionsSyncManager has processed the event.
179 base::ThreadTaskRunnerHandle::Get()->PostTask( 186 base::ThreadTaskRunnerHandle::Get()->PostTask(
180 FROM_HERE, 187 FROM_HERE,
181 base::Bind(&TabEventHandler::QuitLoop, weak_factory_.GetWeakPtr())); 188 base::Bind(&TabEventHandler::QuitLoop, weak_factory_.GetWeakPtr()));
182 } 189 }
183 190
191 void SetAllBrowsersClosing(bool /*browsers_closing*/) override {}
192
184 private: 193 private:
185 void QuitLoop() { base::MessageLoop::current()->QuitWhenIdle(); } 194 void QuitLoop() { base::MessageLoop::current()->QuitWhenIdle(); }
186 195
187 base::WeakPtrFactory<TabEventHandler> weak_factory_; 196 base::WeakPtrFactory<TabEventHandler> weak_factory_;
188 }; 197 };
189 198
190 } // namespace 199 bool WaitForTabsToLoadOrClose(int index,
191 200 const std::vector<GURL>& urls,
192 bool WaitForTabsToLoad(int index, const std::vector<GURL>& urls) { 201 bool wait_load) {
193 DVLOG(1) << "Waiting for session to propagate to associator."; 202 DVLOG(1) << "Waiting for session to propagate to associator.";
194 base::TimeTicks start_time = base::TimeTicks::Now(); 203 base::TimeTicks start_time = base::TimeTicks::Now();
195 base::TimeTicks end_time = start_time + TestTimeouts::action_max_timeout(); 204 base::TimeTicks end_time = start_time + TestTimeouts::action_max_timeout();
196 bool found; 205 bool found;
197 for (std::vector<GURL>::const_iterator it = urls.begin(); 206 for (std::vector<GURL>::const_iterator it = urls.begin(); it != urls.end();
198 it != urls.end(); ++it) { 207 ++it) {
199 found = false; 208 found = !wait_load;
200 while (!found) { 209 while (found != wait_load) {
201 found = ModelAssociatorHasTabWithUrl(index, *it); 210 found = ModelAssociatorHasTabWithUrl(index, *it);
202 if (base::TimeTicks::Now() >= end_time) { 211 if (base::TimeTicks::Now() >= end_time) {
203 LOG(ERROR) << "Failed to find all tabs after " 212 LOG(ERROR) << "Failed to find all tabs after "
204 << TestTimeouts::action_max_timeout().InSecondsF() 213 << TestTimeouts::action_max_timeout().InSecondsF()
205 << " seconds."; 214 << " seconds.";
206 return false; 215 return false;
207 } 216 }
208 if (!found) { 217 if (found != wait_load) {
209 TabEventHandler handler; 218 TabEventHandler handler;
210 sync_sessions::NotificationServiceSessionsRouter router( 219 sync_sessions::NotificationServiceSessionsRouter router(
211 test()->GetProfile(index), 220 test()->GetProfile(index),
212 ProfileSyncServiceFactory::GetInstance() 221 ProfileSyncServiceFactory::GetInstance()
213 ->GetForProfile(test()->GetProfile(index)) 222 ->GetForProfile(test()->GetProfile(index))
214 ->GetSyncClient() 223 ->GetSyncClient()
215 ->GetSyncSessionsClient(), 224 ->GetSyncSessionsClient(),
216 syncer::SyncableService::StartSyncFlare()); 225 syncer::SyncableService::StartSyncFlare());
217 router.StartRoutingTo(&handler); 226 router.StartRoutingTo(&handler);
218 content::RunMessageLoop(); 227 content::RunMessageLoop();
219 } 228 }
220 } 229 }
221 } 230 }
222 return true; 231 return true;
223 } 232 }
224 233
234 } // namespace
235
236 bool WaitForTabsToLoad(int index, const std::vector<GURL>& urls) {
237 return WaitForTabsToLoadOrClose(index, urls, true);
238 }
239
240 bool WaitForTabsToClose(int index, const std::vector<GURL>& urls) {
241 return WaitForTabsToLoadOrClose(index, urls, false);
242 }
243
225 bool GetLocalWindows(int index, ScopedWindowMap* local_windows) { 244 bool GetLocalWindows(int index, ScopedWindowMap* local_windows) {
226 // The local session provided by GetLocalSession is owned, and has lifetime 245 // The local session provided by GetLocalSession is owned, and has lifetime
227 // controlled, by the model associator, so we must make our own copy. 246 // controlled, by the model associator, so we must make our own copy.
228 const sync_sessions::SyncedSession* local_session; 247 const sync_sessions::SyncedSession* local_session;
229 if (!GetLocalSession(index, &local_session)) { 248 if (!GetLocalSession(index, &local_session)) {
230 return false; 249 return false;
231 } 250 }
232 for (auto w = local_session->windows.begin(); 251 for (auto w = local_session->windows.begin();
233 w != local_session->windows.end(); ++w) { 252 w != local_session->windows.end(); ++w) {
234 const sessions::SessionWindow& window = *(w->second); 253 const sessions::SessionWindow& window = *(w->second);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 index_(index), 455 index_(index),
437 windows_(windows) {} 456 windows_(windows) {}
438 457
439 bool ForeignSessionsMatchChecker::IsExitConditionSatisfied() { 458 bool ForeignSessionsMatchChecker::IsExitConditionSatisfied() {
440 return sessions_helper::CheckForeignSessionsAgainst(index_, windows_); 459 return sessions_helper::CheckForeignSessionsAgainst(index_, windows_);
441 } 460 }
442 461
443 std::string ForeignSessionsMatchChecker::GetDebugMessage() const { 462 std::string ForeignSessionsMatchChecker::GetDebugMessage() const {
444 return "Waiting for matching foreign sessions"; 463 return "Waiting for matching foreign sessions";
445 } 464 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698