| 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 "components/ntp_snippets/remote/json_request.h" | 5 #include "components/ntp_snippets/remote/json_request.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "components/ntp_snippets/user_classifier.h" | 23 #include "components/ntp_snippets/user_classifier.h" |
| 24 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 24 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 25 #include "components/signin/core/browser/signin_manager.h" | 25 #include "components/signin/core/browser/signin_manager.h" |
| 26 #include "components/signin/core/browser/signin_manager_base.h" | 26 #include "components/signin/core/browser/signin_manager_base.h" |
| 27 #include "components/strings/grit/components_strings.h" | 27 #include "components/strings/grit/components_strings.h" |
| 28 #include "components/variations/net/variations_http_headers.h" | 28 #include "components/variations/net/variations_http_headers.h" |
| 29 #include "components/variations/variations_associated_data.h" | 29 #include "components/variations/variations_associated_data.h" |
| 30 #include "net/base/load_flags.h" | 30 #include "net/base/load_flags.h" |
| 31 #include "net/http/http_response_headers.h" | 31 #include "net/http/http_response_headers.h" |
| 32 #include "net/http/http_status_code.h" | 32 #include "net/http/http_status_code.h" |
| 33 #include "net/traffic_annotation/network_traffic_annotation.h" |
| 33 #include "net/url_request/url_fetcher.h" | 34 #include "net/url_request/url_fetcher.h" |
| 34 #include "net/url_request/url_request_context_getter.h" | 35 #include "net/url_request/url_request_context_getter.h" |
| 35 #include "third_party/icu/source/common/unicode/uloc.h" | 36 #include "third_party/icu/source/common/unicode/uloc.h" |
| 36 #include "third_party/icu/source/common/unicode/utypes.h" | 37 #include "third_party/icu/source/common/unicode/utypes.h" |
| 37 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
| 38 | 39 |
| 39 using net::URLFetcher; | 40 using net::URLFetcher; |
| 40 using net::URLRequestContextGetter; | 41 using net::URLRequestContextGetter; |
| 41 using net::HttpRequestHeaders; | 42 using net::HttpRequestHeaders; |
| 42 using net::URLRequestStatus; | 43 using net::URLRequestStatus; |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 bool success = base::JSONWriter::WriteWithOptions( | 425 bool success = base::JSONWriter::WriteWithOptions( |
| 425 *request, base::JSONWriter::OPTIONS_PRETTY_PRINT, &request_json); | 426 *request, base::JSONWriter::OPTIONS_PRETTY_PRINT, &request_json); |
| 426 DCHECK(success); | 427 DCHECK(success); |
| 427 return request_json; | 428 return request_json; |
| 428 } | 429 } |
| 429 | 430 |
| 430 std::unique_ptr<net::URLFetcher> JsonRequest::Builder::BuildURLFetcher( | 431 std::unique_ptr<net::URLFetcher> JsonRequest::Builder::BuildURLFetcher( |
| 431 net::URLFetcherDelegate* delegate, | 432 net::URLFetcherDelegate* delegate, |
| 432 const std::string& headers, | 433 const std::string& headers, |
| 433 const std::string& body) const { | 434 const std::string& body) const { |
| 434 std::unique_ptr<net::URLFetcher> url_fetcher = | 435 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 435 net::URLFetcher::Create(url_, net::URLFetcher::POST, delegate); | 436 net::DefineNetworkTrafficAnnotation("ntp_snippets_fetch", R"( |
| 437 semantics { |
| 438 sender: "New Tab Page Content Suggestions Fetch" |
| 439 description: |
| 440 "Chromium can show content suggestions (e.g. news articles) on the " |
| 441 "New Tab page. For signed-in users, these may be personalized " |
| 442 "based on the user's synced browsing history." |
| 443 trigger: |
| 444 "Triggered periodically in the background, or upon explicit user " |
| 445 "request." |
| 446 data: |
| 447 "The Chromium UI language, as well as a second language the user " |
| 448 "understands, based on translate::LanguageModel. For signed-in " |
| 449 "users, the requests is authenticated." |
| 450 destination: GOOGLE_OWNED_SERVICE |
| 451 } |
| 452 policy { |
| 453 cookies_allowed: false |
| 454 setting: |
| 455 "This feature cannot be disabled by settings now (but is requested " |
| 456 "to be implemented in crbug.com/695129)." |
| 457 policy { |
| 458 NTPContentSuggestionsEnabled { |
| 459 policy_options {mode: MANDATORY} |
| 460 value: false |
| 461 } |
| 462 } |
| 463 })"); |
| 464 std::unique_ptr<net::URLFetcher> url_fetcher = net::URLFetcher::Create( |
| 465 url_, net::URLFetcher::POST, delegate, traffic_annotation); |
| 436 url_fetcher->SetRequestContext(url_request_context_getter_.get()); | 466 url_fetcher->SetRequestContext(url_request_context_getter_.get()); |
| 437 url_fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 467 url_fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 438 net::LOAD_DO_NOT_SAVE_COOKIES); | 468 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 439 data_use_measurement::DataUseUserData::AttachToFetcher( | 469 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 440 url_fetcher.get(), | 470 url_fetcher.get(), |
| 441 data_use_measurement::DataUseUserData::NTP_SNIPPETS_SUGGESTIONS); | 471 data_use_measurement::DataUseUserData::NTP_SNIPPETS_SUGGESTIONS); |
| 442 | 472 |
| 443 url_fetcher->SetExtraRequestHeaders(headers); | 473 url_fetcher->SetExtraRequestHeaders(headers); |
| 444 url_fetcher->SetUploadData("application/json", body); | 474 url_fetcher->SetUploadData("application/json", body); |
| 445 | 475 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 "NewTabPage.Languages.UILanguageRatioInTwoTopLanguages", | 512 "NewTabPage.Languages.UILanguageRatioInTwoTopLanguages", |
| 483 ratio_ui_in_both_languages * 100); | 513 ratio_ui_in_both_languages * 100); |
| 484 break; | 514 break; |
| 485 } | 515 } |
| 486 } | 516 } |
| 487 } | 517 } |
| 488 | 518 |
| 489 } // namespace internal | 519 } // namespace internal |
| 490 | 520 |
| 491 } // namespace ntp_snippets | 521 } // namespace ntp_snippets |
| OLD | NEW |