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

Unified Diff: components/rappor/rappor_message_filter.cc

Issue 1014543003: Add an IPC method for Blink to call RapporService::RecordSample() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments and cleanup Created 5 years, 9 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: components/rappor/rappor_message_filter.cc
diff --git a/components/rappor/rappor_message_filter.cc b/components/rappor/rappor_message_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..077cc57d6ad4c6b4d2c68cb85c5513f8dd3e5f68
--- /dev/null
+++ b/components/rappor/rappor_message_filter.cc
@@ -0,0 +1,51 @@
+// Copyright (c) 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 "components/rappor/rappor_message_filter.h"
+
+#include "components/rappor/rappor_messages.h"
+#include "components/rappor/rappor_service.h"
+#include "components/rappor/rappor_utils.h"
+#include "ipc/ipc_message_macros.h"
+
+using content::BrowserThread;
+
+namespace rappor {
+
+RapporMessageFilter::RapporMessageFilter(RapporService* rapporService)
+ : BrowserMessageFilter(RapporMsgStart),
+ m_rapporService(rapporService) {
+ DCHECK(rapporService);
+}
+
+RapporMessageFilter::~RapporMessageFilter() {}
+
+void RapporMessageFilter::OverrideThreadForMessage(
+ const IPC::Message& message, BrowserThread::ID* thread) {
+ switch (message.type()) {
+ case RapporHostMsg_RecordSample::ID:
+ *thread = BrowserThread::UI;
+ break;
+ }
+}
+
+bool RapporMessageFilter::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(RapporMessageFilter, message)
+ IPC_MESSAGE_HANDLER(RapporHostMsg_RecordSample, OnRecordSample)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void RapporMessageFilter::OnRecordSample(
+ const std::string& metric,
+ const std::string& sample) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ m_rapporService->RecordSample(metric,
+ rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
+ sample);
+}
+
+} // namespace rappor

Powered by Google App Engine
This is Rietveld 408576698