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

Side by Side Diff: chrome/browser/search/one_google_bar/one_google_bar_fetcher_impl.cc

Issue 2900673002: Network traffic annotation added to one_google_bar. (Closed)
Patch Set: Annotation updated. Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/search/one_google_bar/one_google_bar_fetcher_impl.h" 5 #include "chrome/browser/search/one_google_bar/one_google_bar_fetcher_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/metrics/field_trial_params.h" 13 #include "base/metrics/field_trial_params.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/search/one_google_bar/one_google_bar_data.h" 18 #include "chrome/browser/search/one_google_bar/one_google_bar_data.h"
19 #include "chrome/common/chrome_content_client.h" 19 #include "chrome/common/chrome_content_client.h"
20 #include "chrome/common/chrome_features.h" 20 #include "chrome/common/chrome_features.h"
21 #include "components/google/core/browser/google_url_tracker.h" 21 #include "components/google/core/browser/google_url_tracker.h"
22 #include "components/safe_json/safe_json_parser.h" 22 #include "components/safe_json/safe_json_parser.h"
23 #include "components/signin/core/browser/access_token_fetcher.h" 23 #include "components/signin/core/browser/access_token_fetcher.h"
24 #include "components/signin/core/browser/signin_manager.h" 24 #include "components/signin/core/browser/signin_manager.h"
25 #include "components/variations/net/variations_http_headers.h" 25 #include "components/variations/net/variations_http_headers.h"
26 #include "google_apis/gaia/oauth2_token_service.h" 26 #include "google_apis/gaia/oauth2_token_service.h"
27 #include "google_apis/google_api_keys.h" 27 #include "google_apis/google_api_keys.h"
28 #include "net/base/load_flags.h" 28 #include "net/base/load_flags.h"
29 #include "net/http/http_status_code.h" 29 #include "net/http/http_status_code.h"
30 #include "net/traffic_annotation/network_traffic_annotation.h"
30 #include "net/url_request/url_fetcher.h" 31 #include "net/url_request/url_fetcher.h"
31 #include "net/url_request/url_fetcher_delegate.h" 32 #include "net/url_request/url_fetcher_delegate.h"
32 33
33 namespace { 34 namespace {
34 35
35 const char kApiUrl[] = "https://onegoogle-pa.googleapis.com/v1/getbar"; 36 const char kApiUrl[] = "https://onegoogle-pa.googleapis.com/v1/getbar";
36 37
37 const char kApiKeyFormat[] = "?key=%s"; 38 const char kApiKeyFormat[] = "?key=%s";
38 39
39 const char kApiScope[] = "https://www.googleapis.com/auth/onegoogle.api"; 40 const char kApiScope[] = "https://www.googleapis.com/auth/onegoogle.api";
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 262 }
262 263
263 void OneGoogleBarFetcherImpl::AuthenticatedURLFetcher::GotAccessToken( 264 void OneGoogleBarFetcherImpl::AuthenticatedURLFetcher::GotAccessToken(
264 const GoogleServiceAuthError& error, 265 const GoogleServiceAuthError& error,
265 const std::string& access_token) { 266 const std::string& access_token) {
266 // Delete the token fetcher after we leave this method. 267 // Delete the token fetcher after we leave this method.
267 std::unique_ptr<AccessTokenFetcher> deleter(std::move(token_fetcher_)); 268 std::unique_ptr<AccessTokenFetcher> deleter(std::move(token_fetcher_));
268 269
269 bool use_oauth = !access_token.empty(); 270 bool use_oauth = !access_token.empty();
270 GURL url = GetApiUrl(use_oauth); 271 GURL url = GetApiUrl(use_oauth);
271 url_fetcher_ = net::URLFetcher::Create(0, url, net::URLFetcher::POST, this); 272 net::NetworkTrafficAnnotationTag traffic_annotation =
273 net::DefineNetworkTrafficAnnotation("one_google_bar_service", R"(
274 semantics {
275 sender: "One Google Bar Service"
276 description: "Downloads the 'One Google' bar."
277 trigger:
278 "Displaying the new tab page on Desktop, if Google is the "
279 "configured search provider."
280 data: "Credentials if user has signed-in."
msramek 2017/05/22 16:51:16 nit: AFAIU "signed-in" (with the dash) is an adjec
Ramin Halavati 2017/05/23 04:54:57 Done.
281 destination: GOOGLE_OWNED_SERVICE
282 }
283 policy {
284 cookies_allowed: false
285 setting:
286 "Users can control this feature via selecting a non-Google default "
287 "search engine in Chrome settings under 'Search Engine'."
288 chrome_policy {
289 DefaultSearchProviderEnabled {
290 policy_options {mode: MANDATORY}
291 DefaultSearchProviderEnabled: false
292 }
293 }
294 })");
295 url_fetcher_ = net::URLFetcher::Create(0, url, net::URLFetcher::POST, this,
296 traffic_annotation);
272 url_fetcher_->SetRequestContext(request_context_); 297 url_fetcher_->SetRequestContext(request_context_);
273 298
274 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_AUTH_DATA | 299 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_AUTH_DATA |
275 net::LOAD_DO_NOT_SEND_COOKIES | 300 net::LOAD_DO_NOT_SEND_COOKIES |
276 net::LOAD_DO_NOT_SAVE_COOKIES); 301 net::LOAD_DO_NOT_SAVE_COOKIES);
277 url_fetcher_->SetUploadData("application/json", GetRequestBody()); 302 url_fetcher_->SetUploadData("application/json", GetRequestBody());
278 url_fetcher_->SetExtraRequestHeaders( 303 url_fetcher_->SetExtraRequestHeaders(
279 GetExtraRequestHeaders(url, access_token)); 304 GetExtraRequestHeaders(url, access_token));
280 305
281 url_fetcher_->Start(); 306 url_fetcher_->Start();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 Respond(base::nullopt); 394 Respond(base::nullopt);
370 } 395 }
371 396
372 void OneGoogleBarFetcherImpl::Respond( 397 void OneGoogleBarFetcherImpl::Respond(
373 const base::Optional<OneGoogleBarData>& data) { 398 const base::Optional<OneGoogleBarData>& data) {
374 for (auto& callback : callbacks_) { 399 for (auto& callback : callbacks_) {
375 std::move(callback).Run(data); 400 std::move(callback).Run(data);
376 } 401 }
377 callbacks_.clear(); 402 callbacks_.clear();
378 } 403 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698