| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/snippets_internals_message_handler.h" | 5 #include "chrome/browser/ui/webui/snippets_internals_message_handler.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 24 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 26 #include "base/values.h" | 26 #include "base/values.h" |
| 27 #include "chrome/browser/android/chrome_feature_list.h" | 27 #include "chrome/browser/android/chrome_feature_list.h" |
| 28 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" | 28 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" |
| 29 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 30 #include "chrome/common/chrome_features.h" | 30 #include "chrome/common/chrome_features.h" |
| 31 #include "components/ntp_snippets/category.h" | 31 #include "components/ntp_snippets/category.h" |
| 32 #include "components/ntp_snippets/category_info.h" | 32 #include "components/ntp_snippets/category_info.h" |
| 33 #include "components/ntp_snippets/category_rankers/category_ranker.h" |
| 33 #include "components/ntp_snippets/features.h" | 34 #include "components/ntp_snippets/features.h" |
| 34 #include "components/ntp_snippets/pref_names.h" | 35 #include "components/ntp_snippets/pref_names.h" |
| 35 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" | 36 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" |
| 36 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" | 37 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" |
| 37 #include "components/ntp_snippets/switches.h" | 38 #include "components/ntp_snippets/switches.h" |
| 38 #include "components/offline_pages/core/offline_page_feature.h" | 39 #include "components/offline_pages/core/offline_page_feature.h" |
| 39 #include "components/prefs/pref_service.h" | 40 #include "components/prefs/pref_service.h" |
| 40 #include "components/variations/variations_associated_data.h" | 41 #include "components/variations/variations_associated_data.h" |
| 41 #include "content/public/browser/web_ui.h" | 42 #include "content/public/browser/web_ui.h" |
| 42 | 43 |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 base::FeatureList::IsEnabled(ntp_snippets::kBookmarkSuggestionsFeature)); | 369 base::FeatureList::IsEnabled(ntp_snippets::kBookmarkSuggestionsFeature)); |
| 369 | 370 |
| 370 SendBoolean("flag-physical-web-page-suggestions", | 371 SendBoolean("flag-physical-web-page-suggestions", |
| 371 base::FeatureList::IsEnabled( | 372 base::FeatureList::IsEnabled( |
| 372 ntp_snippets::kPhysicalWebPageSuggestionsFeature)); | 373 ntp_snippets::kPhysicalWebPageSuggestionsFeature)); |
| 373 | 374 |
| 374 SendBoolean("flag-physical-web", base::FeatureList::IsEnabled( | 375 SendBoolean("flag-physical-web", base::FeatureList::IsEnabled( |
| 375 chrome::android::kPhysicalWebFeature)); | 376 chrome::android::kPhysicalWebFeature)); |
| 376 | 377 |
| 377 SendClassification(); | 378 SendClassification(); |
| 379 SendRankerDebugData(); |
| 378 SendLastRemoteSuggestionsBackgroundFetchTime(); | 380 SendLastRemoteSuggestionsBackgroundFetchTime(); |
| 379 | 381 |
| 380 if (remote_suggestions_provider_) { | 382 if (remote_suggestions_provider_) { |
| 381 const ntp_snippets::RemoteSuggestionsFetcher* fetcher = | 383 const ntp_snippets::RemoteSuggestionsFetcher* fetcher = |
| 382 remote_suggestions_provider_->suggestions_fetcher_for_debugging(); | 384 remote_suggestions_provider_->suggestions_fetcher_for_debugging(); |
| 383 SendString("switch-fetch-url", fetcher->fetch_url().spec()); | 385 SendString("switch-fetch-url", fetcher->fetch_url().spec()); |
| 384 web_ui()->CallJavascriptFunctionUnsafe( | 386 web_ui()->CallJavascriptFunctionUnsafe( |
| 385 "chrome.SnippetsInternals.receiveJson", | 387 "chrome.SnippetsInternals.receiveJson", |
| 386 base::Value(fetcher->last_json())); | 388 base::Value(fetcher->last_json())); |
| 387 } | 389 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 405 content_suggestions_service_->user_classifier()->GetEstimatedAvgTime( | 407 content_suggestions_service_->user_classifier()->GetEstimatedAvgTime( |
| 406 UserClassifier::Metric::NTP_OPENED)), | 408 UserClassifier::Metric::NTP_OPENED)), |
| 407 base::Value( | 409 base::Value( |
| 408 content_suggestions_service_->user_classifier()->GetEstimatedAvgTime( | 410 content_suggestions_service_->user_classifier()->GetEstimatedAvgTime( |
| 409 UserClassifier::Metric::SUGGESTIONS_SHOWN)), | 411 UserClassifier::Metric::SUGGESTIONS_SHOWN)), |
| 410 base::Value( | 412 base::Value( |
| 411 content_suggestions_service_->user_classifier()->GetEstimatedAvgTime( | 413 content_suggestions_service_->user_classifier()->GetEstimatedAvgTime( |
| 412 UserClassifier::Metric::SUGGESTIONS_USED))); | 414 UserClassifier::Metric::SUGGESTIONS_USED))); |
| 413 } | 415 } |
| 414 | 416 |
| 417 void SnippetsInternalsMessageHandler::SendRankerDebugData() { |
| 418 std::vector<ntp_snippets::CategoryRanker::DebugDataItem> data = |
| 419 content_suggestions_service_->category_ranker()->GetDebugData(); |
| 420 |
| 421 std::unique_ptr<base::ListValue> items_list(new base::ListValue); |
| 422 for (const auto& item : data) { |
| 423 auto entry = base::MakeUnique<base::DictionaryValue>(); |
| 424 entry->SetString("label", item.label); |
| 425 entry->SetString("content", item.content); |
| 426 items_list->Append(std::move(entry)); |
| 427 } |
| 428 |
| 429 base::DictionaryValue result; |
| 430 result.Set("list", std::move(items_list)); |
| 431 web_ui()->CallJavascriptFunctionUnsafe( |
| 432 "chrome.SnippetsInternals.receiveRankerDebugData", result); |
| 433 } |
| 434 |
| 415 void SnippetsInternalsMessageHandler:: | 435 void SnippetsInternalsMessageHandler:: |
| 416 SendLastRemoteSuggestionsBackgroundFetchTime() { | 436 SendLastRemoteSuggestionsBackgroundFetchTime() { |
| 417 base::Time time = base::Time::FromInternalValue(pref_service_->GetInt64( | 437 base::Time time = base::Time::FromInternalValue(pref_service_->GetInt64( |
| 418 ntp_snippets::prefs::kLastSuccessfulBackgroundFetchTime)); | 438 ntp_snippets::prefs::kLastSuccessfulBackgroundFetchTime)); |
| 419 web_ui()->CallJavascriptFunctionUnsafe( | 439 web_ui()->CallJavascriptFunctionUnsafe( |
| 420 "chrome.SnippetsInternals." | 440 "chrome.SnippetsInternals." |
| 421 "receiveLastRemoteSuggestionsBackgroundFetchTime", | 441 "receiveLastRemoteSuggestionsBackgroundFetchTime", |
| 422 base::Value(base::TimeFormatShortDateAndTime(time))); | 442 base::Value(base::TimeFormatShortDateAndTime(time))); |
| 423 } | 443 } |
| 424 | 444 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded( | 511 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded( |
| 492 Category category, | 512 Category category, |
| 493 std::vector<ContentSuggestion> dismissed_suggestions) { | 513 std::vector<ContentSuggestion> dismissed_suggestions) { |
| 494 if (dismissed_state_[category] == DismissedState::HIDDEN) { | 514 if (dismissed_state_[category] == DismissedState::HIDDEN) { |
| 495 return; | 515 return; |
| 496 } | 516 } |
| 497 dismissed_suggestions_[category] = std::move(dismissed_suggestions); | 517 dismissed_suggestions_[category] = std::move(dismissed_suggestions); |
| 498 dismissed_state_[category] = DismissedState::VISIBLE; | 518 dismissed_state_[category] = DismissedState::VISIBLE; |
| 499 SendContentSuggestions(); | 519 SendContentSuggestions(); |
| 500 } | 520 } |
| OLD | NEW |