OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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. |
| 4 |
| 5 #include "chrome/browser/infobars/infobar_responder.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 11 #include "components/infobars/core/infobar.h" |
| 12 |
| 13 InfoBarResponder::InfoBarResponder(InfoBarService* infobar_service, |
| 14 bool should_accept) |
| 15 : infobar_service_(infobar_service), should_accept_(should_accept) { |
| 16 infobar_service_->AddObserver(this); |
| 17 } |
| 18 |
| 19 InfoBarResponder::~InfoBarResponder() { |
| 20 // This is safe even if we were already removed as an observer in |
| 21 // OnInfoBarAdded(). |
| 22 infobar_service_->RemoveObserver(this); |
| 23 } |
| 24 |
| 25 void InfoBarResponder::OnInfoBarAdded(infobars::InfoBar* infobar) { |
| 26 infobar_service_->RemoveObserver(this); |
| 27 ConfirmInfoBarDelegate* delegate = |
| 28 infobar->delegate()->AsConfirmInfoBarDelegate(); |
| 29 DCHECK(delegate); |
| 30 |
| 31 base::MessageLoop::current()->PostTask( |
| 32 FROM_HERE, |
| 33 base::Bind(&InfoBarResponder::Respond, base::Unretained(this), delegate)); |
| 34 } |
| 35 |
| 36 void InfoBarResponder::Respond(ConfirmInfoBarDelegate* delegate) { |
| 37 if (should_accept_) |
| 38 delegate->Accept(); |
| 39 else |
| 40 delegate->Cancel(); |
| 41 } |
OLD | NEW |