Chromium Code Reviews| Index: chrome/browser/infobars/infobar_responder.cc |
| diff --git a/chrome/browser/infobars/infobar_responder.cc b/chrome/browser/infobars/infobar_responder.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f1658f5501f3d3c10d35cb406c81c77b08e08eea |
| --- /dev/null |
| +++ b/chrome/browser/infobars/infobar_responder.cc |
| @@ -0,0 +1,42 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/infobars/infobar_responder.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "chrome/browser/infobars/infobar_service.h" |
| +#include "components/infobars/core/confirm_infobar_delegate.h" |
| +#include "components/infobars/core/infobar.h" |
| + |
| +InfoBarResponder::InfoBarResponder(InfoBarService* infobar_service, bool accept) |
| + : infobar_service_(infobar_service), accept_(accept), has_observed_(false) { |
| + infobar_service_->AddObserver(this); |
| +} |
| + |
| +InfoBarResponder::~InfoBarResponder() { |
| + infobar_service_->RemoveObserver(this); |
| +} |
| + |
| +void InfoBarResponder::OnInfoBarAdded(infobars::InfoBar* infobar) { |
| + if (has_observed_) |
| + return; |
| + has_observed_ = true; |
|
Peter Kasting
2015/04/23 00:14:08
Seems like you could also just do "infobar_service
Michael van Ouwerkerk
2015/04/23 13:36:09
I thought I tried that when I originally wrote thi
|
| + ConfirmInfoBarDelegate* delegate = |
| + infobar->delegate()->AsConfirmInfoBarDelegate(); |
| + DCHECK(delegate); |
| + |
| + // Respond to the infobar asynchronously, like a person. |
|
Peter Kasting
2015/04/23 00:14:08
Nit: I don't think this comment adds anything
Michael van Ouwerkerk
2015/04/23 13:36:09
Done.
|
| + base::MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&InfoBarResponder::Respond, base::Unretained(this), delegate)); |
| +} |
| + |
| +void InfoBarResponder::Respond(ConfirmInfoBarDelegate* delegate) { |
| + if (accept_) { |
|
Peter Kasting
2015/04/23 00:14:08
Nit: No {}
Michael van Ouwerkerk
2015/04/23 13:36:09
Done.
|
| + delegate->Accept(); |
| + } else { |
| + delegate->Cancel(); |
| + } |
| +} |