Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / views / frame / web_contents_close_handler.cc
blob1fc1a38ccb6c21a6d5bc521696bf0c9499536ad1
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/frame/web_contents_close_handler.h"
7 #include "chrome/browser/ui/views/frame/web_contents_close_handler_delegate.h"
9 WebContentsCloseHandler::WebContentsCloseHandler(
10 WebContentsCloseHandlerDelegate* delegate)
11 : delegate_(delegate),
12 in_close_(false),
13 tab_changed_after_clone_(false) {
16 WebContentsCloseHandler::~WebContentsCloseHandler() {
19 void WebContentsCloseHandler::TabInserted() {
20 // Tests may end up reviving a TabStrip that is empty.
21 if (!in_close_)
22 return;
23 in_close_ = false;
24 delegate_->DestroyClonedLayer();
27 void WebContentsCloseHandler::ActiveTabChanged() {
28 if (in_close_)
29 tab_changed_after_clone_ = true;
30 else
31 delegate_->DestroyClonedLayer();
34 void WebContentsCloseHandler::WillCloseAllTabs() {
35 DCHECK(!in_close_);
36 in_close_ = true;
37 tab_changed_after_clone_ = false;
38 delegate_->CloneWebContentsLayer();
39 timer_.Stop();
42 void WebContentsCloseHandler::CloseAllTabsCanceled() {
43 DCHECK(in_close_);
44 in_close_ = false;
45 if (tab_changed_after_clone_) {
46 // If the tab changed, destroy immediately. That way we make sure we aren't
47 // showing the wrong thing.
48 delegate_->DestroyClonedLayer();
49 } else {
50 // The most common reason for a close to be canceled is a before unload
51 // handler. Often times the tab still ends up closing, but only after we get
52 // back a response from the renderer. Assume this is going to happen and
53 // keep around the cloned layer for a bit more time.
54 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(500),
55 this, &WebContentsCloseHandler::OnStillHaventClosed);
59 void WebContentsCloseHandler::OnStillHaventClosed() {
60 delegate_->DestroyClonedLayer();