Chromium Code Reviews| Index: third_party/WebKit/Source/modules/document_metadata/CopylessPasteExtractor.cpp |
| diff --git a/third_party/WebKit/Source/modules/document_metadata/CopylessPasteExtractor.cpp b/third_party/WebKit/Source/modules/document_metadata/CopylessPasteExtractor.cpp |
| index 2e7e51825a65afc3a65fcb75f48c750c0e42b40f..4b39632063f53badbd84443440d920b3dd527315 100644 |
| --- a/third_party/WebKit/Source/modules/document_metadata/CopylessPasteExtractor.cpp |
| +++ b/third_party/WebKit/Source/modules/document_metadata/CopylessPasteExtractor.cpp |
| @@ -247,14 +247,18 @@ void extractEntityFromTopLevelObject(const JSONObject& val, |
| extractTopLevelEntity(val, entities); |
| } |
| -bool extractMetadata(const Element& root, Vector<EntityPtr>& entities) { |
| +// kCount must be the last entry. |
| +enum ExtractionStatus { kOK, kEmpty, kParseFailure, kWrongType, kCount }; |
| + |
| +ExtractionStatus extractMetadata(const Element& root, |
| + Vector<EntityPtr>& entities) { |
| for (Element& element : ElementTraversal::DescendantsOf(root)) { |
| if (element.HasTagName(HTMLNames::scriptTag) && |
| element.getAttribute(HTMLNames::typeAttr) == "application/ld+json") { |
| std::unique_ptr<JSONValue> json = ParseJSON(element.textContent()); |
| if (!json) { |
| LOG(ERROR) << "Failed to parse json."; |
| - return false; |
| + return kParseFailure; |
| } |
| switch (json->GetType()) { |
| case JSONValue::ValueType::kTypeArray: |
| @@ -265,11 +269,14 @@ bool extractMetadata(const Element& root, Vector<EntityPtr>& entities) { |
| entities); |
| break; |
| default: |
| - return false; |
| + return kWrongType; |
| } |
| } |
| } |
| - return !entities.IsEmpty(); |
| + if (entities.IsEmpty()) { |
| + return kEmpty; |
| + } |
| + return kOK; |
| } |
| } // namespace |
| @@ -284,21 +291,30 @@ WebPagePtr CopylessPasteExtractor::extract(const Document& document) { |
| if (!html) |
| return nullptr; |
| - double start_time = MonotonicallyIncreasingTime(); |
| - |
| WebPagePtr page = WebPage::New(); |
| // Traverse the DOM tree and extract the metadata. |
| - if (!extractMetadata(*html, page->entities)) |
| - return nullptr; |
| - page->url = document.Url(); |
| - page->title = document.title(); |
| - |
| + double start_time = MonotonicallyIncreasingTime(); |
| + ExtractionStatus status = extractMetadata(*html, page->entities); |
| double elapsed_time = MonotonicallyIncreasingTime() - start_time; |
| + DEFINE_STATIC_LOCAL(EnumerationHistogram, status_histogram, |
| + ("CopylessPaste.ExtractionStatus", kCount)); |
| + status_histogram.Count(status); |
| + |
| + // Couldn't use SCOPED_BLINK_UMA_HISTOGRAM_TIMER() due to dynamic naming. |
|
haraken
2017/04/12 02:10:22
Drop this comment.
wychen
2017/04/12 02:18:12
Done.
|
| + if (status != kOK) { |
| + DEFINE_STATIC_LOCAL(CustomCountHistogram, extractionHistogram, |
| + ("CopylessPaste.ExtractionFailedUs", 1, 1000000, 50)); |
| + extractionHistogram.Count(1e6 * elapsed_time); |
|
haraken
2017/04/12 02:10:22
elapsed_time is in microseconds. So this should be
wychen
2017/04/12 02:18:11
MonotonicallyIncreasingTime() is in seconds.
|
| + return nullptr; |
| + } |
| DEFINE_STATIC_LOCAL(CustomCountHistogram, extractionHistogram, |
| ("CopylessPaste.ExtractionUs", 1, 1000000, 50)); |
| - extractionHistogram.Count(static_cast<int>(1e6 * elapsed_time)); |
| + extractionHistogram.Count(1e6 * elapsed_time); |
| + |
| + page->url = document.Url(); |
| + page->title = document.title(); |
| return page; |
| } |