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.
5 #include "chrome/browser/infobars/infobar_responder.h"
8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "chrome/browser/infobars/infobar_service.h"
12 #include "components/infobars/core/confirm_infobar_delegate.h"
13 #include "components/infobars/core/infobar.h"
15 InfoBarResponder::InfoBarResponder(InfoBarService
* infobar_service
,
16 AutoResponseType response
)
17 : infobar_service_(infobar_service
), response_(response
) {
18 infobar_service_
->AddObserver(this);
21 InfoBarResponder::~InfoBarResponder() {
22 // This is safe even if we were already removed as an observer in
24 infobar_service_
->RemoveObserver(this);
27 void InfoBarResponder::OnInfoBarAdded(infobars::InfoBar
* infobar
) {
28 infobar_service_
->RemoveObserver(this);
29 ConfirmInfoBarDelegate
* delegate
=
30 infobar
->delegate()->AsConfirmInfoBarDelegate();
33 base::ThreadTaskRunnerHandle::Get()->PostTask(
35 base::Bind(&InfoBarResponder::Respond
, base::Unretained(this), delegate
));
38 void InfoBarResponder::OnInfoBarReplaced(infobars::InfoBar
* old_infobar
,
39 infobars::InfoBar
* new_infobar
) {
40 OnInfoBarAdded(new_infobar
);
43 void InfoBarResponder::Respond(ConfirmInfoBarDelegate
* delegate
) {
52 delegate
->InfoBarDismissed();