OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "google_apis/gaia/gaia_auth_fetcher.h" | 5 #include "google_apis/gaia/gaia_auth_fetcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 namespace { | 30 namespace { |
31 const int kLoadFlagsIgnoreCookies = net::LOAD_DO_NOT_SEND_COOKIES | | 31 const int kLoadFlagsIgnoreCookies = net::LOAD_DO_NOT_SEND_COOKIES | |
32 net::LOAD_DO_NOT_SAVE_COOKIES; | 32 net::LOAD_DO_NOT_SAVE_COOKIES; |
33 | 33 |
34 static bool CookiePartsContains(const std::vector<std::string>& parts, | 34 static bool CookiePartsContains(const std::vector<std::string>& parts, |
35 const char* part) { | 35 const char* part) { |
36 return std::find(parts.begin(), parts.end(), part) != parts.end(); | 36 return std::find(parts.begin(), parts.end(), part) != parts.end(); |
37 } | 37 } |
38 | 38 |
39 bool ExtractOAuth2TokenPairResponse(DictionaryValue* dict, | 39 bool ExtractOAuth2TokenPairResponse(base::DictionaryValue* dict, |
40 std::string* refresh_token, | 40 std::string* refresh_token, |
41 std::string* access_token, | 41 std::string* access_token, |
42 int* expires_in_secs) { | 42 int* expires_in_secs) { |
43 DCHECK(refresh_token); | 43 DCHECK(refresh_token); |
44 DCHECK(access_token); | 44 DCHECK(access_token); |
45 DCHECK(expires_in_secs); | 45 DCHECK(expires_in_secs); |
46 | 46 |
47 if (!dict->GetStringWithoutPathExpansion("refresh_token", refresh_token) || | 47 if (!dict->GetStringWithoutPathExpansion("refresh_token", refresh_token) || |
48 !dict->GetStringWithoutPathExpansion("access_token", access_token) || | 48 !dict->GetStringWithoutPathExpansion("access_token", access_token) || |
49 !dict->GetIntegerWithoutPathExpansion("expires_in", expires_in_secs)) { | 49 !dict->GetIntegerWithoutPathExpansion("expires_in", expires_in_secs)) { |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 const net::URLRequestStatus& status, | 813 const net::URLRequestStatus& status, |
814 int response_code) { | 814 int response_code) { |
815 std::string refresh_token; | 815 std::string refresh_token; |
816 std::string access_token; | 816 std::string access_token; |
817 int expires_in_secs = 0; | 817 int expires_in_secs = 0; |
818 | 818 |
819 bool success = false; | 819 bool success = false; |
820 if (status.is_success() && response_code == net::HTTP_OK) { | 820 if (status.is_success() && response_code == net::HTTP_OK) { |
821 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); | 821 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); |
822 if (value.get() && value->GetType() == base::Value::TYPE_DICTIONARY) { | 822 if (value.get() && value->GetType() == base::Value::TYPE_DICTIONARY) { |
823 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | 823 base::DictionaryValue* dict = |
| 824 static_cast<base::DictionaryValue*>(value.get()); |
824 success = ExtractOAuth2TokenPairResponse(dict, &refresh_token, | 825 success = ExtractOAuth2TokenPairResponse(dict, &refresh_token, |
825 &access_token, &expires_in_secs); | 826 &access_token, &expires_in_secs); |
826 } | 827 } |
827 } | 828 } |
828 | 829 |
829 if (success) { | 830 if (success) { |
830 consumer_->OnClientOAuthSuccess( | 831 consumer_->OnClientOAuthSuccess( |
831 GaiaAuthConsumer::ClientOAuthResult(refresh_token, access_token, | 832 GaiaAuthConsumer::ClientOAuthResult(refresh_token, access_token, |
832 expires_in_secs)); | 833 expires_in_secs)); |
833 } else { | 834 } else { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 NOTREACHED(); | 940 NOTREACHED(); |
940 } | 941 } |
941 } | 942 } |
942 | 943 |
943 // static | 944 // static |
944 bool GaiaAuthFetcher::IsSecondFactorSuccess( | 945 bool GaiaAuthFetcher::IsSecondFactorSuccess( |
945 const std::string& alleged_error) { | 946 const std::string& alleged_error) { |
946 return alleged_error.find(kSecondFactor) != | 947 return alleged_error.find(kSecondFactor) != |
947 std::string::npos; | 948 std::string::npos; |
948 } | 949 } |
OLD | NEW |