Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: chrome/browser/signin/chrome_signin_helper.cc

Issue 2925083002: [signin] Move Mirror code to ChromeConnectedHeaderHelper (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/signin/core/browser/chrome_connected_header_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/signin/chrome_signin_helper.h" 5 #include "chrome/browser/signin/chrome_signin_helper.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "chrome/browser/prefs/incognito_mode_prefs.h" 9 #include "chrome/browser/prefs/incognito_mode_prefs.h"
10 #include "chrome/browser/profiles/profile_io_data.h" 10 #include "chrome/browser/profiles/profile_io_data.h"
11 #include "chrome/browser/signin/account_reconcilor_factory.h" 11 #include "chrome/browser/signin/account_reconcilor_factory.h"
12 #include "chrome/browser/signin/chrome_signin_client.h" 12 #include "chrome/browser/signin/chrome_signin_client.h"
13 #include "chrome/browser/tab_contents/tab_util.h" 13 #include "chrome/browser/tab_contents/tab_util.h"
14 #include "chrome/browser/ui/browser_window.h" 14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
16 #include "components/signin/core/browser/account_reconcilor.h" 16 #include "components/signin/core/browser/account_reconcilor.h"
17 #include "components/signin/core/browser/chrome_connected_header_helper.h"
17 #include "components/signin/core/browser/signin_header_helper.h" 18 #include "components/signin/core/browser/signin_header_helper.h"
19 #include "components/signin/core/common/profile_management_switches.h"
18 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/resource_request_info.h" 21 #include "content/public/browser/resource_request_info.h"
20 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
21 #include "google_apis/gaia/gaia_auth_util.h" 23 #include "google_apis/gaia/gaia_auth_util.h"
24 #include "net/http/http_response_headers.h"
22 #include "net/url_request/url_request.h" 25 #include "net/url_request/url_request.h"
23 26
24 #if defined(OS_ANDROID) 27 #if defined(OS_ANDROID)
25 #include "chrome/browser/android/signin/account_management_screen_helper.h" 28 #include "chrome/browser/android/signin/account_management_screen_helper.h"
26 #else 29 #else
27 #include "chrome/browser/ui/browser_commands.h" 30 #include "chrome/browser/ui/browser_commands.h"
28 #include "chrome/browser/ui/browser_finder.h" 31 #include "chrome/browser/ui/browser_finder.h"
29 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" 32 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
30 #endif // defined(OS_ANDROID) 33 #endif // defined(OS_ANDROID)
31 34
32 namespace signin { 35 namespace signin {
33 36
34 namespace { 37 namespace {
35 38
39 const char kChromeManageAccountsHeader[] = "X-Chrome-Manage-Accounts";
40
36 // Processes the mirror response header on the UI thread. Currently depending 41 // Processes the mirror response header on the UI thread. Currently depending
37 // on the value of |header_value|, it either shows the profile avatar menu, or 42 // on the value of |header_value|, it either shows the profile avatar menu, or
38 // opens an incognito window/tab. 43 // opens an incognito window/tab.
39 void ProcessMirrorHeaderUIThread(int child_id, 44 void ProcessMirrorHeaderUIThread(int child_id,
40 int route_id, 45 int route_id,
41 ManageAccountsParams manage_accounts_params) { 46 ManageAccountsParams manage_accounts_params) {
42 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 47 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
43 48
49 if (switches::GetAccountConsistencyMethod() !=
msarda 2017/06/12 12:21:14 I think we should not add this if - Gaia is not su
droger 2017/06/12 12:46:38 I agree that Gaia should not do it. The question
msarda 2017/06/12 14:08:57 The DCHECK also included the fact that it does not
50 switches::AccountConsistencyMethod::kMirror) {
51 return;
52 }
53
44 GAIAServiceType service_type = manage_accounts_params.service_type; 54 GAIAServiceType service_type = manage_accounts_params.service_type;
45 DCHECK_NE(GAIA_SERVICE_TYPE_NONE, service_type); 55 DCHECK_NE(GAIA_SERVICE_TYPE_NONE, service_type);
46 56
47 content::WebContents* web_contents = 57 content::WebContents* web_contents =
48 tab_util::GetWebContentsByID(child_id, route_id); 58 tab_util::GetWebContentsByID(child_id, route_id);
49 if (!web_contents) 59 if (!web_contents)
50 return; 60 return;
51 61
52 Profile* profile = 62 Profile* profile =
53 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 63 Profile::FromBrowserContext(web_contents->GetBrowserContext());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false)); 98 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false));
89 } else { 99 } else {
90 signin_metrics::LogAccountReconcilorStateOnGaiaResponse( 100 signin_metrics::LogAccountReconcilorStateOnGaiaResponse(
91 account_reconcilor->GetState()); 101 account_reconcilor->GetState());
92 AccountManagementScreenHelper::OpenAccountManagementScreen(profile, 102 AccountManagementScreenHelper::OpenAccountManagementScreen(profile,
93 service_type); 103 service_type);
94 } 104 }
95 #endif // !defined(OS_ANDROID) 105 #endif // !defined(OS_ANDROID)
96 } 106 }
97 107
98 // Returns the parameters contained in the X-Chrome-Manage-Accounts response
99 // header.
100 // If the request does not have a response header or if the header contains
101 // garbage, then |service_type| is set to |GAIA_SERVICE_TYPE_NONE|.
102 // Must be called on IO thread.
103 ManageAccountsParams BuildManageAccountsParamsHelper(net::URLRequest* request,
104 ProfileIOData* io_data) {
105 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
106
107 const content::ResourceRequestInfo* info =
108 content::ResourceRequestInfo::ForRequest(request);
109 if (!(info && info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME)) {
110 ManageAccountsParams empty_params;
111 empty_params.service_type = GAIA_SERVICE_TYPE_NONE;
112 return empty_params;
113 }
114
115 return BuildManageAccountsParamsIfExists(request, io_data->IsOffTheRecord());
116 }
117
118 } // namespace 108 } // namespace
119 109
120 void FixAccountConsistencyRequestHeader(net::URLRequest* request, 110 void FixAccountConsistencyRequestHeader(net::URLRequest* request,
121 const GURL& redirect_url, 111 const GURL& redirect_url,
122 ProfileIOData* io_data, 112 ProfileIOData* io_data,
123 int child_id, 113 int child_id,
124 int route_id) { 114 int route_id) {
125 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 115 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
126 116
127 if (io_data->IsOffTheRecord()) 117 if (io_data->IsOffTheRecord())
(...skipping 22 matching lines...) Expand all
150 // If new url is eligible to have the header, add it, otherwise remove it. 140 // If new url is eligible to have the header, add it, otherwise remove it.
151 AppendOrRemoveAccountConsistentyRequestHeader( 141 AppendOrRemoveAccountConsistentyRequestHeader(
152 request, redirect_url, io_data->google_services_account_id()->GetValue(), 142 request, redirect_url, io_data->google_services_account_id()->GetValue(),
153 io_data->GetCookieSettings(), profile_mode_mask); 143 io_data->GetCookieSettings(), profile_mode_mask);
154 } 144 }
155 145
156 void ProcessMirrorResponseHeaderIfExists(net::URLRequest* request, 146 void ProcessMirrorResponseHeaderIfExists(net::URLRequest* request,
157 ProfileIOData* io_data, 147 ProfileIOData* io_data,
158 int child_id, 148 int child_id,
159 int route_id) { 149 int route_id) {
160 ManageAccountsParams params = 150 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
161 BuildManageAccountsParamsHelper(request, io_data); 151
152 if (io_data->IsOffTheRecord())
msarda 2017/06/12 14:08:57 I think it would somehow make sense to have a NOTR
153 return;
154
155 const content::ResourceRequestInfo* info =
156 content::ResourceRequestInfo::ForRequest(request);
157 if (!(info && info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME))
158 return;
159
160 if (!gaia::IsGaiaSignonRealm(request->url().GetOrigin()))
161 return;
162
163 net::HttpResponseHeaders* response_headers = request->response_headers();
164 if (!response_headers)
165 return;
166
167 std::string header_value;
168 if (!response_headers->GetNormalizedHeader(kChromeManageAccountsHeader,
169 &header_value)) {
170 return;
171 }
172
173 ManageAccountsParams params = BuildManageAccountsParams(header_value);
174 // If the request does not have a response header or if the header contains
175 // garbage, then |service_type| is set to |GAIA_SERVICE_TYPE_NONE|.
162 if (params.service_type == GAIA_SERVICE_TYPE_NONE) 176 if (params.service_type == GAIA_SERVICE_TYPE_NONE)
163 return; 177 return;
164 178
165 params.child_id = child_id; 179 params.child_id = child_id;
166 params.route_id = route_id; 180 params.route_id = route_id;
167 content::BrowserThread::PostTask( 181 content::BrowserThread::PostTask(
168 content::BrowserThread::UI, FROM_HERE, 182 content::BrowserThread::UI, FROM_HERE,
169 base::Bind(ProcessMirrorHeaderUIThread, child_id, route_id, params)); 183 base::Bind(ProcessMirrorHeaderUIThread, child_id, route_id, params));
170 } 184 }
171 185
172 } // namespace signin 186 } // namespace signin
OLDNEW
« no previous file with comments | « no previous file | components/signin/core/browser/chrome_connected_header_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698