Commit 261f3da0 authored by Sébastien Séguin-Gagnon's avatar Sébastien Séguin-Gagnon Committed by Commit Bot

[SH] Record metrics from JS response.

Bug: 1099268
Change-Id: I2a0de73ed846b100a549429888dabeb8ffe2db6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2461217
Commit-Queue: sebsg <sebsg@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarSebastien Lalancette <seblalancette@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817023}
parent 0a5a93ce
include_rules = [ include_rules = [
"+components/url_formatter", "+components/url_formatter",
"+components/leveldb_proto/public", "+components/leveldb_proto/public",
"+components/shared_highlighting/core/common",
"+crypto", "+crypto",
"+ios/net", "+ios/net",
"+ios/web", "+ios/web",
......
...@@ -17,6 +17,7 @@ source_set("navigation") { ...@@ -17,6 +17,7 @@ source_set("navigation") {
":core", ":core",
":navigation_manager_util", ":navigation_manager_util",
"//base", "//base",
"//components/shared_highlighting/core/common",
"//ios/net", "//ios/net",
"//ios/web:core", "//ios/web:core",
"//ios/web/common", "//ios/web/common",
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#import "base/json/json_writer.h" #import "base/json/json_writer.h"
#import "base/strings/string_util.h" #import "base/strings/string_util.h"
#import "base/strings/utf_string_conversions.h" #import "base/strings/utf_string_conversions.h"
#import "components/shared_highlighting/core/common/shared_highlighting_metrics.h"
#import "ios/web/common/features.h" #import "ios/web/common/features.h"
#import "ios/web/navigation/text_fragments_utils.h" #import "ios/web/navigation/text_fragments_utils.h"
#import "ios/web/public/js_messaging/web_frame.h" #import "ios/web/public/js_messaging/web_frame.h"
...@@ -24,6 +25,9 @@ namespace { ...@@ -24,6 +25,9 @@ namespace {
const char kScriptCommandPrefix[] = "textFragments"; const char kScriptCommandPrefix[] = "textFragments";
const char kScriptResponseCommand[] = "textFragments.response"; const char kScriptResponseCommand[] = "textFragments.response";
const double kMinSelectorCount = 0.0;
const double kMaxSelectorCount = 200.0;
} // namespace } // namespace
@interface CRWTextFragmentsHandler () { @interface CRWTextFragmentsHandler () {
...@@ -72,10 +76,14 @@ const char kScriptResponseCommand[] = "textFragments.response"; ...@@ -72,10 +76,14 @@ const char kScriptResponseCommand[] = "textFragments.response";
base::Value parsedFragments = base::Value parsedFragments =
web::ParseTextFragments(self.webStateImpl->GetLastCommittedURL()); web::ParseTextFragments(self.webStateImpl->GetLastCommittedURL());
if (parsedFragments.type() == base::Value::Type::NONE) if (parsedFragments.type() == base::Value::Type::NONE) {
return; return;
}
shared_highlighting::LogTextFragmentSelectorCount(
parsedFragments.GetList().size());
shared_highlighting::LogTextFragmentLinkOpenSource(referrer.url);
// TODO (crbug.com/1099268): Log the origin and number of fragments metrics.
std::string fragmentParam; std::string fragmentParam;
base::JSONWriter::Write(parsedFragments, &fragmentParam); base::JSONWriter::Write(parsedFragments, &fragmentParam);
...@@ -91,8 +99,9 @@ const char kScriptResponseCommand[] = "textFragments.response"; ...@@ -91,8 +99,9 @@ const char kScriptResponseCommand[] = "textFragments.response";
// Returns NO if fragments highlighting is not allowed in the current |context|. // Returns NO if fragments highlighting is not allowed in the current |context|.
- (BOOL)areTextFragmentsAllowedInContext:(web::NavigationContext*)context { - (BOOL)areTextFragmentsAllowedInContext:(web::NavigationContext*)context {
if (!base::FeatureList::IsEnabled(web::features::kScrollToTextIOS)) if (!base::FeatureList::IsEnabled(web::features::kScrollToTextIOS)) {
return NO; return NO;
}
if (self.isBeingDestroyed) { if (self.isBeingDestroyed) {
return NO; return NO;
...@@ -121,7 +130,34 @@ const char kScriptResponseCommand[] = "textFragments.response"; ...@@ -121,7 +130,34 @@ const char kScriptResponseCommand[] = "textFragments.response";
return; return;
} }
// TODO (crbug.com/1099268): Log the success/failure metric. // Log success metrics.
base::Optional<double> optionalFragmentCount =
response.FindDoublePath("result.fragmentsCount");
base::Optional<double> optionalSuccessCount =
response.FindDoublePath("result.successCount");
// Since the response can't be trusted, don't log metrics if the results look
// invalid.
if (!optionalFragmentCount ||
optionalFragmentCount.value() > kMaxSelectorCount ||
optionalFragmentCount.value() <= kMinSelectorCount) {
return;
}
if (!optionalSuccessCount ||
optionalSuccessCount.value() > kMaxSelectorCount ||
optionalSuccessCount.value() < kMinSelectorCount) {
return;
}
if (optionalSuccessCount.value() > optionalFragmentCount.value()) {
return;
}
int fragmentCount = static_cast<int>(optionalFragmentCount.value());
int successCount = static_cast<int>(optionalSuccessCount.value());
shared_highlighting::LogTextFragmentMatchRate(successCount, fragmentCount);
shared_highlighting::LogTextFragmentAmbiguousMatch(
/*ambiguous_match=*/successCount != fragmentCount);
} }
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment