Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6266)

Unified Diff: chrome/browser/infobars/infobar_responder.cc

Issue 1100953002: Move InfoBarResponder into its own file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..8c4fc2bd5024ca8ec855364a7b4bcd90879a5773
--- /dev/null
+++ b/chrome/browser/infobars/infobar_responder.cc
@@ -0,0 +1,39 @@
+// 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 should_accept)
+ : infobar_service_(infobar_service), should_accept_(should_accept) {
+ infobar_service_->AddObserver(this);
+}
+
+InfoBarResponder::~InfoBarResponder() {
+ 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.
+}
+
+void InfoBarResponder::OnInfoBarAdded(infobars::InfoBar* infobar) {
+ infobar_service_->RemoveObserver(this);
+ ConfirmInfoBarDelegate* delegate =
+ infobar->delegate()->AsConfirmInfoBarDelegate();
+ DCHECK(delegate);
+
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&InfoBarResponder::Respond, base::Unretained(this), delegate));
+}
+
+void InfoBarResponder::Respond(ConfirmInfoBarDelegate* delegate) {
+ if (should_accept_)
+ delegate->Accept();
+ else
+ delegate->Cancel();
+}
« no previous file with comments | « chrome/browser/infobars/infobar_responder.h ('k') | chrome/browser/notifications/platform_notification_service_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698