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

Side by Side Diff: chrome/browser/ui/tabs/hover_tab_selector.cc

Issue 8590012: base::Bind migrations in chrome/browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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
« no previous file with comments | « chrome/browser/ui/tabs/hover_tab_selector.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/tabs/hover_tab_selector.h" 5 #include "chrome/browser/ui/tabs/hover_tab_selector.h"
6 6
7 #include "base/bind.h"
7 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
8 #include "base/message_loop.h" 9 #include "base/message_loop.h"
9 #include "chrome/browser/tabs/tab_strip_model.h" 10 #include "chrome/browser/tabs/tab_strip_model.h"
10 11
11 HoverTabSelector::HoverTabSelector( 12 HoverTabSelector::HoverTabSelector(
12 TabStripModel* tab_strip_model) 13 TabStripModel* tab_strip_model)
13 : tab_strip_model_(tab_strip_model), 14 : tab_strip_model_(tab_strip_model),
14 tab_transition_tab_index_(-1), 15 tab_transition_tab_index_(-1),
15 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { 16 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
16 DCHECK(tab_strip_model_); 17 DCHECK(tab_strip_model_);
17 } 18 }
18 19
19 HoverTabSelector::~HoverTabSelector() { 20 HoverTabSelector::~HoverTabSelector() {
20 } 21 }
21 22
22 void HoverTabSelector::StartTabTransition(int index) { 23 void HoverTabSelector::StartTabTransition(int index) {
23 // If there is a transition underway already, only start a new 24 // If there is a transition underway already, only start a new
24 // transition (canceling the old one) if the target tab differs. 25 // transition (canceling the old one) if the target tab differs.
25 if (!task_factory_.empty()) { 26 if (weak_factory_.HasWeakPtrs()) {
26 if (index == tab_transition_tab_index_) 27 if (index == tab_transition_tab_index_)
27 return; 28 return;
28 CancelTabTransition(); 29 CancelTabTransition();
29 } 30 }
30 // Start a new transition if the target isn't active already. 31 // Start a new transition if the target isn't active already.
31 if (index != tab_strip_model_->active_index()) { 32 if (index != tab_strip_model_->active_index()) {
32 // The delay between beginning to hover over a tab and the transition 33 // The delay between beginning to hover over a tab and the transition
33 // to that tab taking place. 34 // to that tab taking place.
34 const int64 kHoverTransitionDelayInMillis = 500; 35 const int64 kHoverTransitionDelayInMillis = 500;
35 tab_transition_tab_index_ = index; 36 tab_transition_tab_index_ = index;
36 CancelableTask* task = task_factory_.NewRunnableMethod( 37 MessageLoop::current()->PostDelayedTask(
37 &HoverTabSelector::PerformTabTransition); 38 FROM_HERE, base::Bind(&HoverTabSelector::PerformTabTransition,
38 MessageLoop::current()->PostDelayedTask(FROM_HERE, 39 weak_factory_.GetWeakPtr()),
39 task, 40 kHoverTransitionDelayInMillis);
40 kHoverTransitionDelayInMillis);
41 } 41 }
42 } 42 }
43 43
44 void HoverTabSelector::CancelTabTransition() { 44 void HoverTabSelector::CancelTabTransition() {
45 task_factory_.RevokeAll(); 45 weak_factory_.InvalidateWeakPtrs();
46 } 46 }
47 47
48 void HoverTabSelector::PerformTabTransition() { 48 void HoverTabSelector::PerformTabTransition() {
49 DCHECK(tab_transition_tab_index_ >= 0 && 49 DCHECK(tab_transition_tab_index_ >= 0 &&
50 tab_transition_tab_index_ < tab_strip_model_->count()); 50 tab_transition_tab_index_ < tab_strip_model_->count());
51 tab_strip_model_->ActivateTabAt(tab_transition_tab_index_, true); 51 tab_strip_model_->ActivateTabAt(tab_transition_tab_index_, true);
52 } 52 }
53 53
OLDNEW
« no previous file with comments | « chrome/browser/ui/tabs/hover_tab_selector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698