| 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/supervised_user/experimental/safe_search_url_reporter.h
" | 5 #include "chrome/browser/supervised_user/experimental/safe_search_url_reporter.h
" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 13 #include "chrome/browser/signin/signin_manager_factory.h" | 13 #include "chrome/browser/signin/signin_manager_factory.h" |
| 14 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 14 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 15 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 15 #include "components/signin/core/browser/signin_manager.h" | 16 #include "components/signin/core/browser/signin_manager.h" |
| 16 #include "components/signin/core/browser/signin_manager_base.h" | 17 #include "components/signin/core/browser/signin_manager_base.h" |
| 17 #include "google_apis/gaia/google_service_auth_error.h" | 18 #include "google_apis/gaia/google_service_auth_error.h" |
| 18 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
| 19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 20 #include "net/http/http_status_code.h" | 21 #include "net/http/http_status_code.h" |
| 21 #include "net/url_request/url_fetcher.h" | 22 #include "net/url_request/url_fetcher.h" |
| 22 #include "net/url_request/url_request_status.h" | 23 #include "net/url_request/url_request_status.h" |
| 23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 break; | 104 break; |
| 104 it++; | 105 it++; |
| 105 } | 106 } |
| 106 DCHECK(it != reports_.end()); | 107 DCHECK(it != reports_.end()); |
| 107 | 108 |
| 108 (*it)->access_token = access_token; | 109 (*it)->access_token = access_token; |
| 109 | 110 |
| 110 (*it)->url_fetcher = URLFetcher::Create((*it)->url_fetcher_id, GURL(kApiUrl), | 111 (*it)->url_fetcher = URLFetcher::Create((*it)->url_fetcher_id, GURL(kApiUrl), |
| 111 URLFetcher::POST, this); | 112 URLFetcher::POST, this); |
| 112 | 113 |
| 114 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 115 (*it)->url_fetcher.get(), |
| 116 data_use_measurement::DataUseUserData::SUPERVISED_USER); |
| 113 (*it)->url_fetcher->SetRequestContext(context_); | 117 (*it)->url_fetcher->SetRequestContext(context_); |
| 114 (*it)->url_fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 118 (*it)->url_fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 115 net::LOAD_DO_NOT_SAVE_COOKIES); | 119 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 116 (*it)->url_fetcher->SetAutomaticallyRetryOnNetworkChanges(kNumRetries); | 120 (*it)->url_fetcher->SetAutomaticallyRetryOnNetworkChanges(kNumRetries); |
| 117 (*it)->url_fetcher->AddExtraRequestHeader( | 121 (*it)->url_fetcher->AddExtraRequestHeader( |
| 118 base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str())); | 122 base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str())); |
| 119 | 123 |
| 120 base::DictionaryValue dict; | 124 base::DictionaryValue dict; |
| 121 dict.SetStringWithoutPathExpansion(kUrlKey, (*it)->url.spec().c_str()); | 125 dict.SetStringWithoutPathExpansion(kUrlKey, (*it)->url.spec().c_str()); |
| 122 | 126 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 return; | 178 return; |
| 175 } | 179 } |
| 176 | 180 |
| 177 DispatchResult(it, true); | 181 DispatchResult(it, true); |
| 178 } | 182 } |
| 179 | 183 |
| 180 void SafeSearchURLReporter::DispatchResult(ReportIterator it, bool success) { | 184 void SafeSearchURLReporter::DispatchResult(ReportIterator it, bool success) { |
| 181 (*it)->callback.Run(success); | 185 (*it)->callback.Run(success); |
| 182 reports_.erase(it); | 186 reports_.erase(it); |
| 183 } | 187 } |
| OLD | NEW |