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

Side by Side Diff: chrome/browser/ui/webui/snippets_internals_message_handler.cc

Issue 2664753002: Remove base::StringValue (Closed)
Patch Set: Rebase Created 3 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 unified diff | Download patch
OLDNEW
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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 310
311 SendClassification(); 311 SendClassification();
312 SendLastRemoteSuggestionsBackgroundFetchTime(); 312 SendLastRemoteSuggestionsBackgroundFetchTime();
313 313
314 if (remote_suggestions_provider_) { 314 if (remote_suggestions_provider_) {
315 const ntp_snippets::RemoteSuggestionsFetcher* fetcher = 315 const ntp_snippets::RemoteSuggestionsFetcher* fetcher =
316 remote_suggestions_provider_->suggestions_fetcher_for_debugging(); 316 remote_suggestions_provider_->suggestions_fetcher_for_debugging();
317 SendString("switch-fetch-url", fetcher->fetch_url().spec()); 317 SendString("switch-fetch-url", fetcher->fetch_url().spec());
318 web_ui()->CallJavascriptFunctionUnsafe( 318 web_ui()->CallJavascriptFunctionUnsafe(
319 "chrome.SnippetsInternals.receiveJson", 319 "chrome.SnippetsInternals.receiveJson",
320 base::StringValue(fetcher->last_json())); 320 base::Value(fetcher->last_json()));
321 } 321 }
322 322
323 SendContentSuggestions(); 323 SendContentSuggestions();
324 } 324 }
325 325
326 void SnippetsInternalsMessageHandler::SendClassification() { 326 void SnippetsInternalsMessageHandler::SendClassification() {
327 web_ui()->CallJavascriptFunctionUnsafe( 327 web_ui()->CallJavascriptFunctionUnsafe(
328 "chrome.SnippetsInternals.receiveClassification", 328 "chrome.SnippetsInternals.receiveClassification",
329 base::StringValue(content_suggestions_service_->user_classifier() 329 base::Value(content_suggestions_service_->user_classifier()
330 ->GetUserClassDescriptionForDebugging()), 330 ->GetUserClassDescriptionForDebugging()),
331 base::Value( 331 base::Value(
332 content_suggestions_service_->user_classifier()->GetEstimatedAvgTime( 332 content_suggestions_service_->user_classifier()->GetEstimatedAvgTime(
333 UserClassifier::Metric::NTP_OPENED)), 333 UserClassifier::Metric::NTP_OPENED)),
334 base::Value( 334 base::Value(
335 content_suggestions_service_->user_classifier()->GetEstimatedAvgTime( 335 content_suggestions_service_->user_classifier()->GetEstimatedAvgTime(
336 UserClassifier::Metric::SUGGESTIONS_SHOWN)), 336 UserClassifier::Metric::SUGGESTIONS_SHOWN)),
337 base::Value( 337 base::Value(
338 content_suggestions_service_->user_classifier()->GetEstimatedAvgTime( 338 content_suggestions_service_->user_classifier()->GetEstimatedAvgTime(
339 UserClassifier::Metric::SUGGESTIONS_USED))); 339 UserClassifier::Metric::SUGGESTIONS_USED)));
340 } 340 }
341 341
342 void SnippetsInternalsMessageHandler:: 342 void SnippetsInternalsMessageHandler::
343 SendLastRemoteSuggestionsBackgroundFetchTime() { 343 SendLastRemoteSuggestionsBackgroundFetchTime() {
344 base::Time time = base::Time::FromInternalValue(pref_service_->GetInt64( 344 base::Time time = base::Time::FromInternalValue(pref_service_->GetInt64(
345 ntp_snippets::prefs::kLastSuccessfulBackgroundFetchTime)); 345 ntp_snippets::prefs::kLastSuccessfulBackgroundFetchTime));
346 web_ui()->CallJavascriptFunctionUnsafe( 346 web_ui()->CallJavascriptFunctionUnsafe(
347 "chrome.SnippetsInternals." 347 "chrome.SnippetsInternals."
348 "receiveLastRemoteSuggestionsBackgroundFetchTime", 348 "receiveLastRemoteSuggestionsBackgroundFetchTime",
349 base::StringValue(base::TimeFormatShortDateAndTime(time))); 349 base::Value(base::TimeFormatShortDateAndTime(time)));
350 } 350 }
351 351
352 void SnippetsInternalsMessageHandler::SendContentSuggestions() { 352 void SnippetsInternalsMessageHandler::SendContentSuggestions() {
353 std::unique_ptr<base::ListValue> categories_list(new base::ListValue); 353 std::unique_ptr<base::ListValue> categories_list(new base::ListValue);
354 354
355 int index = 0; 355 int index = 0;
356 for (Category category : content_suggestions_service_->GetCategories()) { 356 for (Category category : content_suggestions_service_->GetCategories()) {
357 CategoryStatus status = 357 CategoryStatus status =
358 content_suggestions_service_->GetCategoryStatus(category); 358 content_suggestions_service_->GetCategoryStatus(category);
359 base::Optional<CategoryInfo> info = 359 base::Optional<CategoryInfo> info =
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 "chrome.SnippetsInternals.receiveContentSuggestions", result); 401 "chrome.SnippetsInternals.receiveContentSuggestions", result);
402 } 402 }
403 403
404 void SnippetsInternalsMessageHandler::SendBoolean(const std::string& name, 404 void SnippetsInternalsMessageHandler::SendBoolean(const std::string& name,
405 bool value) { 405 bool value) {
406 SendString(name, value ? "True" : "False"); 406 SendString(name, value ? "True" : "False");
407 } 407 }
408 408
409 void SnippetsInternalsMessageHandler::SendString(const std::string& name, 409 void SnippetsInternalsMessageHandler::SendString(const std::string& name,
410 const std::string& value) { 410 const std::string& value) {
411 base::StringValue string_name(name); 411 base::Value string_name(name);
412 base::StringValue string_value(value); 412 base::Value string_value(value);
413 413
414 web_ui()->CallJavascriptFunctionUnsafe( 414 web_ui()->CallJavascriptFunctionUnsafe(
415 "chrome.SnippetsInternals.receiveProperty", string_name, string_value); 415 "chrome.SnippetsInternals.receiveProperty", string_name, string_value);
416 } 416 }
417 417
418 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded( 418 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded(
419 Category category, 419 Category category,
420 std::vector<ContentSuggestion> dismissed_suggestions) { 420 std::vector<ContentSuggestion> dismissed_suggestions) {
421 if (dismissed_state_[category] == DismissedState::HIDDEN) { 421 if (dismissed_state_[category] == DismissedState::HIDDEN) {
422 return; 422 return;
423 } 423 }
424 dismissed_suggestions_[category] = std::move(dismissed_suggestions); 424 dismissed_suggestions_[category] = std::move(dismissed_suggestions);
425 dismissed_state_[category] = DismissedState::VISIBLE; 425 dismissed_state_[category] = DismissedState::VISIBLE;
426 SendContentSuggestions(); 426 SendContentSuggestions();
427 } 427 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698