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

Side by Side Diff: chrome/browser/ui/search/instant_unload_handler.cc

Issue 14307023: chrome: Use base::MessageLoop. (Part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/ui/search/instant_unload_handler.h" 5 #include "chrome/browser/ui/search/instant_unload_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "chrome/browser/ui/browser_navigator.h" 10 #include "chrome/browser/ui/browser_navigator.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 scoped_ptr<content::WebContents> contents, 65 scoped_ptr<content::WebContents> contents,
66 int index) { 66 int index) {
67 DCHECK(!contents->GetDelegate()); 67 DCHECK(!contents->GetDelegate());
68 68
69 if (!contents->NeedToFireBeforeUnload()) { 69 if (!contents->NeedToFireBeforeUnload()) {
70 // Tab doesn't have any beforeunload listeners and can be safely deleted. 70 // Tab doesn't have any beforeunload listeners and can be safely deleted.
71 // However, the tab object should not be deleted immediately because when we 71 // However, the tab object should not be deleted immediately because when we
72 // get here from BrowserInstantController::TabDeactivated, other tab 72 // get here from BrowserInstantController::TabDeactivated, other tab
73 // observers may still expect to interact with the tab before the event has 73 // observers may still expect to interact with the tab before the event has
74 // finished propagating. 74 // finished propagating.
75 MessageLoop::current()->DeleteSoon(FROM_HERE, contents.release()); 75 base::MessageLoop::current()->DeleteSoon(FROM_HERE, contents.release());
76 return; 76 return;
77 } 77 }
78 78
79 // Tab has beforeunload listeners. Install a delegate to run them. 79 // Tab has beforeunload listeners. Install a delegate to run them.
80 delegates_.push_back( 80 delegates_.push_back(
81 new WebContentsDelegateImpl(this, contents.Pass(), index)); 81 new WebContentsDelegateImpl(this, contents.Pass(), index));
82 } 82 }
83 83
84 void InstantUnloadHandler::Activate(WebContentsDelegateImpl* delegate, 84 void InstantUnloadHandler::Activate(WebContentsDelegateImpl* delegate,
85 scoped_ptr<content::WebContents> contents, 85 scoped_ptr<content::WebContents> contents,
86 int index) { 86 int index) {
87 // Remove (and delete) the delegate. 87 // Remove (and delete) the delegate.
88 Destroy(delegate); 88 Destroy(delegate);
89 89
90 // Add the tab back in. 90 // Add the tab back in.
91 chrome::NavigateParams params(browser_, contents.release()); 91 chrome::NavigateParams params(browser_, contents.release());
92 params.disposition = NEW_FOREGROUND_TAB; 92 params.disposition = NEW_FOREGROUND_TAB;
93 params.tabstrip_index = index; 93 params.tabstrip_index = index;
94 chrome::Navigate(&params); 94 chrome::Navigate(&params);
95 } 95 }
96 96
97 void InstantUnloadHandler::Destroy(WebContentsDelegateImpl* delegate) { 97 void InstantUnloadHandler::Destroy(WebContentsDelegateImpl* delegate) {
98 ScopedVector<WebContentsDelegateImpl>::iterator i = 98 ScopedVector<WebContentsDelegateImpl>::iterator i =
99 std::find(delegates_.begin(), delegates_.end(), delegate); 99 std::find(delegates_.begin(), delegates_.end(), delegate);
100 DCHECK(i != delegates_.end()); 100 DCHECK(i != delegates_.end());
101 101
102 // The delegate's method is a caller on the stack, so schedule the deletion 102 // The delegate's method is a caller on the stack, so schedule the deletion
103 // for later. 103 // for later.
104 delegates_.weak_erase(i); 104 delegates_.weak_erase(i);
105 MessageLoop::current()->DeleteSoon(FROM_HERE, delegate); 105 base::MessageLoop::current()->DeleteSoon(FROM_HERE, delegate);
106 } 106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698