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

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

Issue 1160073004: chrome/browser/ui: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments. Created 5 years, 6 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/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/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/location.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 13
12 HoverTabSelector::HoverTabSelector( 14 HoverTabSelector::HoverTabSelector(
13 TabStripModel* tab_strip_model) 15 TabStripModel* tab_strip_model)
14 : tab_strip_model_(tab_strip_model), 16 : tab_strip_model_(tab_strip_model),
15 tab_transition_tab_index_(-1), 17 tab_transition_tab_index_(-1),
16 weak_factory_(this) { 18 weak_factory_(this) {
17 DCHECK(tab_strip_model_); 19 DCHECK(tab_strip_model_);
18 } 20 }
19 21
20 HoverTabSelector::~HoverTabSelector() { 22 HoverTabSelector::~HoverTabSelector() {
21 } 23 }
22 24
23 void HoverTabSelector::StartTabTransition(int index) { 25 void HoverTabSelector::StartTabTransition(int index) {
24 // If there is a transition underway already, only start a new 26 // If there is a transition underway already, only start a new
25 // transition (canceling the old one) if the target tab differs. 27 // transition (canceling the old one) if the target tab differs.
26 if (weak_factory_.HasWeakPtrs()) { 28 if (weak_factory_.HasWeakPtrs()) {
27 if (index == tab_transition_tab_index_) 29 if (index == tab_transition_tab_index_)
28 return; 30 return;
29 CancelTabTransition(); 31 CancelTabTransition();
30 } 32 }
31 // Start a new transition if the target isn't active already. 33 // Start a new transition if the target isn't active already.
32 if (index != tab_strip_model_->active_index()) { 34 if (index != tab_strip_model_->active_index()) {
33 // The delay between beginning to hover over a tab and the transition 35 // The delay between beginning to hover over a tab and the transition
34 // to that tab taking place. 36 // to that tab taking place.
35 const base::TimeDelta kHoverTransitionDelay = 37 const base::TimeDelta kHoverTransitionDelay =
36 base::TimeDelta::FromMilliseconds(500); 38 base::TimeDelta::FromMilliseconds(500);
37 tab_transition_tab_index_ = index; 39 tab_transition_tab_index_ = index;
38 base::MessageLoop::current()->PostDelayedTask( 40 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
39 FROM_HERE, 41 FROM_HERE, base::Bind(&HoverTabSelector::PerformTabTransition,
40 base::Bind(&HoverTabSelector::PerformTabTransition, 42 weak_factory_.GetWeakPtr()),
41 weak_factory_.GetWeakPtr()),
42 kHoverTransitionDelay); 43 kHoverTransitionDelay);
43 } 44 }
44 } 45 }
45 46
46 void HoverTabSelector::CancelTabTransition() { 47 void HoverTabSelector::CancelTabTransition() {
47 weak_factory_.InvalidateWeakPtrs(); 48 weak_factory_.InvalidateWeakPtrs();
48 } 49 }
49 50
50 void HoverTabSelector::PerformTabTransition() { 51 void HoverTabSelector::PerformTabTransition() {
51 DCHECK(tab_transition_tab_index_ >= 0 && 52 DCHECK(tab_transition_tab_index_ >= 0 &&
52 tab_transition_tab_index_ < tab_strip_model_->count()); 53 tab_transition_tab_index_ < tab_strip_model_->count());
53 tab_strip_model_->ActivateTabAt(tab_transition_tab_index_, true); 54 tab_strip_model_->ActivateTabAt(tab_transition_tab_index_, true);
54 } 55 }
55 56
OLDNEW
« no previous file with comments | « chrome/browser/ui/tab_modal_confirm_dialog_browsertest.cc ('k') | chrome/browser/ui/toolbar/toolbar_actions_bar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698