OLD | NEW |
---|---|
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 Loading... | |
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("...", R"( | |
sfiera
2017/05/22 12:48:17
one_google_bar_service
Ramin Halavati
2017/05/22 13:11:48
Done.
| |
274 semantics { | |
275 sender: "..." | |
sfiera
2017/05/22 12:48:17
One Google Bar Service
Ramin Halavati
2017/05/22 13:11:48
Done.
| |
276 description: "..." | |
sfiera
2017/05/22 12:48:16
Downloads the "One Google" bar if Google is the co
sfiera
2017/05/22 12:51:37
Ah, with another look, I see we reference an API k
Ramin Halavati
2017/05/22 13:11:48
I am confused, could you please rephrase?
| |
277 trigger: "..." | |
sfiera
2017/05/22 12:48:17
Displaying the new tab page on Desktop
Ramin Halavati
2017/05/22 13:11:48
Done.
| |
278 data: "..." | |
sfiera
2017/05/22 12:48:17
Credentials of signed-in user
Ramin Halavati
2017/05/22 13:11:48
Done.
| |
279 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER/LOCAL | |
280 } | |
281 policy { | |
282 cookies_allowed: false | |
283 setting: "..." | |
sfiera
2017/05/22 12:48:16
Signing out of Chrome or choosing a non-Google sea
Ramin Halavati
2017/05/22 13:11:48
Done.
| |
284 chrome_policy { | |
285 [POLICY_NAME] { | |
286 policy_options {mode: MANDATORY/RECOMMENDED/UNSET} | |
287 [POLICY_NAME]: ... //(value to disable it) | |
288 } | |
sfiera
2017/05/22 12:48:17
DefaultSearchProviderEnabled {
policy_options {m
Ramin Halavati
2017/05/22 13:11:49
Done.
| |
289 } | |
290 policy_exception_justification: "..." | |
291 })"); | |
292 url_fetcher_ = net::URLFetcher::Create(0, url, net::URLFetcher::POST, this, | |
293 traffic_annotation); | |
272 url_fetcher_->SetRequestContext(request_context_); | 294 url_fetcher_->SetRequestContext(request_context_); |
273 | 295 |
274 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_AUTH_DATA | | 296 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_AUTH_DATA | |
275 net::LOAD_DO_NOT_SEND_COOKIES | | 297 net::LOAD_DO_NOT_SEND_COOKIES | |
276 net::LOAD_DO_NOT_SAVE_COOKIES); | 298 net::LOAD_DO_NOT_SAVE_COOKIES); |
277 url_fetcher_->SetUploadData("application/json", GetRequestBody()); | 299 url_fetcher_->SetUploadData("application/json", GetRequestBody()); |
278 url_fetcher_->SetExtraRequestHeaders( | 300 url_fetcher_->SetExtraRequestHeaders( |
279 GetExtraRequestHeaders(url, access_token)); | 301 GetExtraRequestHeaders(url, access_token)); |
280 | 302 |
281 url_fetcher_->Start(); | 303 url_fetcher_->Start(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 Respond(base::nullopt); | 391 Respond(base::nullopt); |
370 } | 392 } |
371 | 393 |
372 void OneGoogleBarFetcherImpl::Respond( | 394 void OneGoogleBarFetcherImpl::Respond( |
373 const base::Optional<OneGoogleBarData>& data) { | 395 const base::Optional<OneGoogleBarData>& data) { |
374 for (auto& callback : callbacks_) { | 396 for (auto& callback : callbacks_) { |
375 std::move(callback).Run(data); | 397 std::move(callback).Run(data); |
376 } | 398 } |
377 callbacks_.clear(); | 399 callbacks_.clear(); |
378 } | 400 } |
OLD | NEW |