| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/child_accounts/family_info_fetcher.h" | 5 #include "chrome/browser/supervised_user/child_accounts/family_info_fetcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 13 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 14 #include "net/http/http_status_code.h" | 15 #include "net/http/http_status_code.h" |
| 15 #include "net/url_request/url_request_status.h" | 16 #include "net/url_request/url_request_status.h" |
| 16 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 17 | 18 |
| 18 const char kFamilyApiUrl[] = "https://www.googleapis.com/kidsmanagement/v1/"; | 19 const char kFamilyApiUrl[] = "https://www.googleapis.com/kidsmanagement/v1/"; |
| 19 const char kGetFamilyProfileApiSuffix[] = "families/mine?alt=json"; | 20 const char kGetFamilyProfileApiSuffix[] = "families/mine?alt=json"; |
| 20 const char kGetFamilyMembersApiSuffix[] = "families/mine/members?alt=json"; | 21 const char kGetFamilyMembersApiSuffix[] = "families/mine/members?alt=json"; |
| 21 const char kScope[] = "https://www.googleapis.com/auth/kid.family.readonly"; | 22 const char kScope[] = "https://www.googleapis.com/auth/kid.family.readonly"; |
| 22 const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s"; | 23 const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s"; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 const OAuth2TokenService::Request* request, | 169 const OAuth2TokenService::Request* request, |
| 169 const std::string& access_token, | 170 const std::string& access_token, |
| 170 const base::Time& expiration_time) { | 171 const base::Time& expiration_time) { |
| 171 DCHECK_EQ(access_token_request_.get(), request); | 172 DCHECK_EQ(access_token_request_.get(), request); |
| 172 access_token_ = access_token; | 173 access_token_ = access_token; |
| 173 | 174 |
| 174 GURL url(kFamilyApiUrl + request_suffix_); | 175 GURL url(kFamilyApiUrl + request_suffix_); |
| 175 const int id = 0; | 176 const int id = 0; |
| 176 url_fetcher_ = net::URLFetcher::Create(id, url, request_type_, this); | 177 url_fetcher_ = net::URLFetcher::Create(id, url, request_type_, this); |
| 177 | 178 |
| 179 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 180 url_fetcher_.get(), |
| 181 data_use_measurement::DataUseUserData::SUPERVISED_USER); |
| 178 url_fetcher_->SetRequestContext(request_context_); | 182 url_fetcher_->SetRequestContext(request_context_); |
| 179 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 183 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 180 net::LOAD_DO_NOT_SAVE_COOKIES); | 184 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 181 url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumRetries); | 185 url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumRetries); |
| 182 url_fetcher_->AddExtraRequestHeader( | 186 url_fetcher_->AddExtraRequestHeader( |
| 183 base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str())); | 187 base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str())); |
| 184 | 188 |
| 185 url_fetcher_->Start(); | 189 url_fetcher_->Start(); |
| 186 } | 190 } |
| 187 | 191 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 consumer_->OnFailure(SERVICE_ERROR); | 320 consumer_->OnFailure(SERVICE_ERROR); |
| 317 return; | 321 return; |
| 318 } | 322 } |
| 319 std::vector<FamilyMember> members; | 323 std::vector<FamilyMember> members; |
| 320 if (!ParseMembers(members_list, &members)){ | 324 if (!ParseMembers(members_list, &members)){ |
| 321 consumer_->OnFailure(SERVICE_ERROR); | 325 consumer_->OnFailure(SERVICE_ERROR); |
| 322 return; | 326 return; |
| 323 } | 327 } |
| 324 consumer_->OnGetFamilyMembersSuccess(members); | 328 consumer_->OnGetFamilyMembersSuccess(members); |
| 325 } | 329 } |
| OLD | NEW |