BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / infobars / infobar_responder.cc
blob8f8cca5169432e8360cb94a077d1e1357861bc84
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"
7 #include "base/bind.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
23 // OnInfoBarAdded().
24 infobar_service_->RemoveObserver(this);
27 void InfoBarResponder::OnInfoBarAdded(infobars::InfoBar* infobar) {
28 infobar_service_->RemoveObserver(this);
29 ConfirmInfoBarDelegate* delegate =
30 infobar->delegate()->AsConfirmInfoBarDelegate();
31 DCHECK(delegate);
33 base::ThreadTaskRunnerHandle::Get()->PostTask(
34 FROM_HERE,
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) {
44 switch (response_) {
45 case ACCEPT:
46 delegate->Accept();
47 break;
48 case DENY:
49 delegate->Cancel();
50 break;
51 case DISMISS:
52 delegate->InfoBarDismissed();
53 break;