| 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 "chrome/browser/supervised_user/child_accounts/kids_management_api.h" | 13 #include "chrome/browser/supervised_user/child_accounts/kids_management_api.h" | 
| 14 #include "components/data_use_measurement/core/data_use_user_data.h" | 14 #include "components/data_use_measurement/core/data_use_user_data.h" | 
| 15 #include "net/base/load_flags.h" | 15 #include "net/base/load_flags.h" | 
| 16 #include "net/http/http_status_code.h" | 16 #include "net/http/http_status_code.h" | 
|  | 17 #include "net/traffic_annotation/network_traffic_annotation.h" | 
| 17 #include "net/url_request/url_request_status.h" | 18 #include "net/url_request/url_request_status.h" | 
| 18 #include "url/gurl.h" | 19 #include "url/gurl.h" | 
| 19 | 20 | 
| 20 const char kGetFamilyProfileApiPath[] = "families/mine?alt=json"; | 21 const char kGetFamilyProfileApiPath[] = "families/mine?alt=json"; | 
| 21 const char kGetFamilyMembersApiPath[] = "families/mine/members?alt=json"; | 22 const char kGetFamilyMembersApiPath[] = "families/mine/members?alt=json"; | 
| 22 const char kScope[] = "https://www.googleapis.com/auth/kid.family.readonly"; | 23 const char kScope[] = "https://www.googleapis.com/auth/kid.family.readonly"; | 
| 23 const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s"; | 24 const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s"; | 
| 24 const int kNumRetries = 1; | 25 const int kNumRetries = 1; | 
| 25 | 26 | 
| 26 const char kIdFamily[] = "family"; | 27 const char kIdFamily[] = "family"; | 
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 164 | 165 | 
| 165 void FamilyInfoFetcher::OnGetTokenSuccess( | 166 void FamilyInfoFetcher::OnGetTokenSuccess( | 
| 166     const OAuth2TokenService::Request* request, | 167     const OAuth2TokenService::Request* request, | 
| 167     const std::string& access_token, | 168     const std::string& access_token, | 
| 168     const base::Time& expiration_time) { | 169     const base::Time& expiration_time) { | 
| 169   DCHECK_EQ(access_token_request_.get(), request); | 170   DCHECK_EQ(access_token_request_.get(), request); | 
| 170   access_token_ = access_token; | 171   access_token_ = access_token; | 
| 171 | 172 | 
| 172   GURL url = kids_management_api::GetURL(request_path_); | 173   GURL url = kids_management_api::GetURL(request_path_); | 
| 173   const int id = 0; | 174   const int id = 0; | 
| 174   url_fetcher_ = net::URLFetcher::Create(id, url, net::URLFetcher::GET, this); | 175   net::NetworkTrafficAnnotationTag traffic_annotation = | 
|  | 176       net::DefineNetworkTrafficAnnotation("family_info", R"( | 
|  | 177         semantics { | 
|  | 178           sender: "Supervised Users" | 
|  | 179           description: | 
|  | 180             "Fetches information about the user's family group from the Google " | 
|  | 181             "Family API." | 
|  | 182           trigger: | 
|  | 183             "Triggered in regular intervals to update profile information." | 
|  | 184           data: | 
|  | 185             "The request is authenticated with an OAuth2 access token " | 
|  | 186             "identifying the Google account. No other information is sent." | 
|  | 187           destination: GOOGLE_OWNED_SERVICE | 
|  | 188         } | 
|  | 189         policy { | 
|  | 190           cookies_allowed: false | 
|  | 191           setting: | 
|  | 192             "This feature cannot be disabled in settings and is only enabled " | 
|  | 193             "for child accounts. If sign-in is restricted to accounts from a " | 
|  | 194             "managed domain, those accounts are not going to be child accounts." | 
|  | 195           chrome_policy { | 
|  | 196             RestrictSigninToPattern { | 
|  | 197               policy_options {mode: MANDATORY} | 
|  | 198               RestrictSigninToPattern: "*@manageddomain.com" | 
|  | 199             } | 
|  | 200           } | 
|  | 201         })"); | 
|  | 202   url_fetcher_ = net::URLFetcher::Create(id, url, net::URLFetcher::GET, this, | 
|  | 203                                          traffic_annotation); | 
| 175 | 204 | 
| 176   data_use_measurement::DataUseUserData::AttachToFetcher( | 205   data_use_measurement::DataUseUserData::AttachToFetcher( | 
| 177       url_fetcher_.get(), | 206       url_fetcher_.get(), | 
| 178       data_use_measurement::DataUseUserData::SUPERVISED_USER); | 207       data_use_measurement::DataUseUserData::SUPERVISED_USER); | 
| 179   url_fetcher_->SetRequestContext(request_context_); | 208   url_fetcher_->SetRequestContext(request_context_); | 
| 180   url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 209   url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 
| 181                              net::LOAD_DO_NOT_SAVE_COOKIES); | 210                              net::LOAD_DO_NOT_SAVE_COOKIES); | 
| 182   url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumRetries); | 211   url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumRetries); | 
| 183   url_fetcher_->AddExtraRequestHeader( | 212   url_fetcher_->AddExtraRequestHeader( | 
| 184       base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str())); | 213       base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str())); | 
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 317     consumer_->OnFailure(SERVICE_ERROR); | 346     consumer_->OnFailure(SERVICE_ERROR); | 
| 318     return; | 347     return; | 
| 319   } | 348   } | 
| 320   std::vector<FamilyMember> members; | 349   std::vector<FamilyMember> members; | 
| 321   if (!ParseMembers(members_list, &members)){ | 350   if (!ParseMembers(members_list, &members)){ | 
| 322     consumer_->OnFailure(SERVICE_ERROR); | 351     consumer_->OnFailure(SERVICE_ERROR); | 
| 323     return; | 352     return; | 
| 324   } | 353   } | 
| 325   consumer_->OnGetFamilyMembersSuccess(members); | 354   consumer_->OnGetFamilyMembersSuccess(members); | 
| 326 } | 355 } | 
| OLD | NEW | 
|---|