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

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: Add comment. 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..cddc89b343e129ef8852920dcc70474218748d98
--- /dev/null
+++ b/chrome/browser/infobars/infobar_responder.cc
@@ -0,0 +1,41 @@
+// 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() {
+ // This is safe even if we were already removed as an observer in
+ // OnInfoBarAdded().
+ infobar_service_->RemoveObserver(this);
+}
+
+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