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 infobar_service_->RemoveObserver(this); | |
Peter Kasting
2015/04/23 22:54:48
Nit: Might want to comment: "This is safe even if
Michael van Ouwerkerk
2015/04/24 11:16:38
Done.
| |
21 } | |
22 | |
23 void InfoBarResponder::OnInfoBarAdded(infobars::InfoBar* infobar) { | |
24 infobar_service_->RemoveObserver(this); | |
25 ConfirmInfoBarDelegate* delegate = | |
26 infobar->delegate()->AsConfirmInfoBarDelegate(); | |
27 DCHECK(delegate); | |
28 | |
29 base::MessageLoop::current()->PostTask( | |
30 FROM_HERE, | |
31 base::Bind(&InfoBarResponder::Respond, base::Unretained(this), delegate)); | |
32 } | |
33 | |
34 void InfoBarResponder::Respond(ConfirmInfoBarDelegate* delegate) { | |
35 if (should_accept_) | |
36 delegate->Accept(); | |
37 else | |
38 delegate->Cancel(); | |
39 } | |
OLD | NEW |