Chromium Code Reviews| Index: chrome/browser/safe_browsing/incident_reporting/omnibox_watcher.cc |
| diff --git a/chrome/browser/safe_browsing/incident_reporting/omnibox_watcher.cc b/chrome/browser/safe_browsing/incident_reporting/omnibox_watcher.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c847b545cb073192f979681989ad7b2cdba74112 |
| --- /dev/null |
| +++ b/chrome/browser/safe_browsing/incident_reporting/omnibox_watcher.cc |
| @@ -0,0 +1,44 @@ |
| +// Copyright 2014 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/safe_browsing/incident_reporting/omnibox_watcher.h" |
| + |
| +#include "base/callback.h" |
| +#include "chrome/browser/chrome_notification_types.h" |
| +#include "chrome/browser/omnibox/omnibox_log.h" |
| +#include "chrome/common/safe_browsing/csd.pb.h" |
| +#include "components/omnibox/autocomplete_result.h" |
| +#include "content/public/browser/notification_details.h" |
| +#include "content/public/browser/notification_service.h" |
| + |
| +namespace safe_browsing { |
| + |
| +OmniboxWatcher::OmniboxWatcher(const AddIncidentCallback& callback): |
| + incident_callback_(callback) { |
| + registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, |
| + content::NotificationService::AllSources()); |
| +} |
| + |
| +OmniboxWatcher::~OmniboxWatcher() { |
| +} |
| + |
| +void OmniboxWatcher::Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + DCHECK_EQ(chrome::NOTIFICATION_OMNIBOX_OPENED_URL, type); |
| + const OmniboxLog log(*content::Details<OmniboxLog>(details).ptr()); |
|
grt (UTC plus 2)
2014/11/15 17:56:15
do you need to copy the log here? how about:
con
Mark P
2014/11/18 00:54:44
Done.
|
| + // Users tend not to type very long strings explicitly (especially without |
| + // using the paste-and-go option); it's suspicious when they do so. |
| + if (!log.is_paste_and_go && (log.text.length() > 200)) { |
| + scoped_ptr<ClientIncidentReport_IncidentData> incident_data( |
| + new ClientIncidentReport_IncidentData()); |
| + ClientIncidentReport_IncidentData_OmniboxIncident* |
| + omnibox_interaction = incident_data->mutable_omnibox_interaction(); |
| + omnibox_interaction->set_destination_url( |
| + log.result.match_at(log.selected_index).destination_url.spec()); |
| + incident_callback_.Run(incident_data.Pass()); |
| + } |
| +} |
| + |
| +} // namespace safe_browsing |