| Index: components/signin/core/browser/signin_header_helper.cc
|
| diff --git a/components/signin/core/browser/signin_header_helper.cc b/components/signin/core/browser/signin_header_helper.cc
|
| index 28dd54e16f7519ca2b001a3b95bf0b24358152e1..282e06aca5ae497b76694aea599acea01d4fa17a 100644
|
| --- a/components/signin/core/browser/signin_header_helper.cc
|
| +++ b/components/signin/core/browser/signin_header_helper.cc
|
| @@ -5,12 +5,10 @@
|
| #include "components/signin/core/browser/signin_header_helper.h"
|
|
|
| #include <stddef.h>
|
| -#include <map>
|
|
|
| #include "base/logging.h"
|
| #include "base/macros.h"
|
| #include "base/strings/string_split.h"
|
| -#include "build/build_config.h"
|
| #include "components/content_settings/core/browser/cookie_settings.h"
|
| #include "components/google/core/browser/google_util.h"
|
| #include "components/signin/core/browser/chrome_connected_header_helper.h"
|
| @@ -18,7 +16,6 @@
|
| #include "google_apis/gaia/gaia_auth_util.h"
|
| #include "google_apis/gaia/gaia_urls.h"
|
| #include "net/base/escape.h"
|
| -#include "net/http/http_response_headers.h"
|
| #include "net/url_request/url_request.h"
|
| #include "url/gurl.h"
|
|
|
| @@ -28,59 +25,6 @@
|
|
|
| namespace signin {
|
|
|
| -namespace {
|
| -
|
| -// Dictionary of fields in a mirror response header.
|
| -typedef std::map<std::string, std::string> MirrorResponseHeaderDictionary;
|
| -
|
| -const char kChromeManageAccountsHeader[] = "X-Chrome-Manage-Accounts";
|
| -const char kContinueUrlAttrName[] = "continue_url";
|
| -const char kEmailAttrName[] = "email";
|
| -const char kIsSameTabAttrName[] = "is_same_tab";
|
| -const char kIsSamlAttrName[] = "is_saml";
|
| -const char kServiceTypeAttrName[] = "action";
|
| -
|
| -// Determines the service type that has been passed from Gaia in the header.
|
| -GAIAServiceType GetGAIAServiceTypeFromHeader(const std::string& header_value) {
|
| - if (header_value == "SIGNOUT")
|
| - return GAIA_SERVICE_TYPE_SIGNOUT;
|
| - else if (header_value == "INCOGNITO")
|
| - return GAIA_SERVICE_TYPE_INCOGNITO;
|
| - else if (header_value == "ADDSESSION")
|
| - return GAIA_SERVICE_TYPE_ADDSESSION;
|
| - else if (header_value == "REAUTH")
|
| - return GAIA_SERVICE_TYPE_REAUTH;
|
| - else if (header_value == "SIGNUP")
|
| - return GAIA_SERVICE_TYPE_SIGNUP;
|
| - else if (header_value == "DEFAULT")
|
| - return GAIA_SERVICE_TYPE_DEFAULT;
|
| - else
|
| - return GAIA_SERVICE_TYPE_NONE;
|
| -}
|
| -
|
| -// Parses the mirror response header. Its expected format is
|
| -// "key1=value1,key2=value2,...".
|
| -MirrorResponseHeaderDictionary ParseMirrorResponseHeader(
|
| - const std::string& header_value) {
|
| - MirrorResponseHeaderDictionary dictionary;
|
| - for (const base::StringPiece& field :
|
| - base::SplitStringPiece(header_value, ",", base::KEEP_WHITESPACE,
|
| - base::SPLIT_WANT_NONEMPTY)) {
|
| - size_t delim = field.find_first_of('=');
|
| - if (delim == std::string::npos) {
|
| - DLOG(WARNING) << "Unexpected Gaia header field '" << field << "'.";
|
| - continue;
|
| - }
|
| - dictionary[field.substr(0, delim).as_string()] = net::UnescapeURLComponent(
|
| - field.substr(delim + 1).as_string(),
|
| - net::UnescapeRule::PATH_SEPARATORS |
|
| - net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS);
|
| - }
|
| - return dictionary;
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| extern const char kChromeConnectedHeader[] = "X-Chrome-Connected";
|
| extern const char kDiceRequestHeader[] = "X-Chrome-ID-Consistency-Request";
|
|
|
| @@ -145,6 +89,27 @@ bool SigninHeaderHelper::AppendOrRemoveRequestHeader(
|
| return true;
|
| }
|
|
|
| +// static
|
| +SigninHeaderHelper::ResponseHeaderDictionary
|
| +SigninHeaderHelper::ParseAccountConsistencyResponseHeader(
|
| + const std::string& header_value) {
|
| + ResponseHeaderDictionary dictionary;
|
| + for (const base::StringPiece& field :
|
| + base::SplitStringPiece(header_value, ",", base::KEEP_WHITESPACE,
|
| + base::SPLIT_WANT_NONEMPTY)) {
|
| + size_t delim = field.find_first_of('=');
|
| + if (delim == std::string::npos) {
|
| + DLOG(WARNING) << "Unexpected Gaia header field '" << field << "'.";
|
| + continue;
|
| + }
|
| + dictionary[field.substr(0, delim).as_string()] = net::UnescapeURLComponent(
|
| + field.substr(delim + 1).as_string(),
|
| + net::UnescapeRule::PATH_SEPARATORS |
|
| + net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS);
|
| + }
|
| + return dictionary;
|
| +}
|
| +
|
| std::string SigninHeaderHelper::BuildRequestHeaderIfPossible(
|
| bool is_header_request,
|
| const GURL& url,
|
| @@ -185,47 +150,7 @@ void AppendOrRemoveAccountConsistentyRequestHeader(
|
|
|
| ManageAccountsParams BuildManageAccountsParams(
|
| const std::string& header_value) {
|
| - ManageAccountsParams params;
|
| - MirrorResponseHeaderDictionary header_dictionary =
|
| - ParseMirrorResponseHeader(header_value);
|
| - MirrorResponseHeaderDictionary::const_iterator it = header_dictionary.begin();
|
| - for (; it != header_dictionary.end(); ++it) {
|
| - const std::string key_name(it->first);
|
| - if (key_name == kServiceTypeAttrName) {
|
| - params.service_type =
|
| - GetGAIAServiceTypeFromHeader(header_dictionary[kServiceTypeAttrName]);
|
| - } else if (key_name == kEmailAttrName) {
|
| - params.email = header_dictionary[kEmailAttrName];
|
| - } else if (key_name == kIsSamlAttrName) {
|
| - params.is_saml = header_dictionary[kIsSamlAttrName] == "true";
|
| - } else if (key_name == kContinueUrlAttrName) {
|
| - params.continue_url = header_dictionary[kContinueUrlAttrName];
|
| - } else if (key_name == kIsSameTabAttrName) {
|
| - params.is_same_tab = header_dictionary[kIsSameTabAttrName] == "true";
|
| - } else {
|
| - DLOG(WARNING) << "Unexpected Gaia header attribute '" << key_name << "'.";
|
| - }
|
| - }
|
| - return params;
|
| -}
|
| -
|
| -ManageAccountsParams BuildManageAccountsParamsIfExists(net::URLRequest* request,
|
| - bool is_off_the_record) {
|
| - ManageAccountsParams empty_params;
|
| - empty_params.service_type = GAIA_SERVICE_TYPE_NONE;
|
| - if (!gaia::IsGaiaSignonRealm(request->url().GetOrigin()))
|
| - return empty_params;
|
| -
|
| - std::string header_value;
|
| - net::HttpResponseHeaders* response_headers = request->response_headers();
|
| - if (!response_headers ||
|
| - !response_headers->GetNormalizedHeader(
|
| - kChromeManageAccountsHeader, &header_value)) {
|
| - return empty_params;
|
| - }
|
| -
|
| - DCHECK(switches::IsAccountConsistencyMirrorEnabled() && !is_off_the_record);
|
| - return BuildManageAccountsParams(header_value);
|
| + return ChromeConnectedHeaderHelper::BuildManageAccountsParams(header_value);
|
| }
|
|
|
| } // namespace signin
|
|
|