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

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

Issue 2925083002: [signin] Move Mirror code to ChromeConnectedHeaderHelper (Closed)
Patch Set: fix comment 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/logging.h"
7 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
8 #include "build/build_config.h" 9 #include "build/build_config.h"
9 #include "chrome/browser/prefs/incognito_mode_prefs.h" 10 #include "chrome/browser/prefs/incognito_mode_prefs.h"
10 #include "chrome/browser/profiles/profile_io_data.h" 11 #include "chrome/browser/profiles/profile_io_data.h"
11 #include "chrome/browser/signin/account_reconcilor_factory.h" 12 #include "chrome/browser/signin/account_reconcilor_factory.h"
12 #include "chrome/browser/signin/chrome_signin_client.h" 13 #include "chrome/browser/signin/chrome_signin_client.h"
13 #include "chrome/browser/tab_contents/tab_util.h" 14 #include "chrome/browser/tab_contents/tab_util.h"
14 #include "chrome/browser/ui/browser_window.h" 15 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
16 #include "components/signin/core/browser/account_reconcilor.h" 17 #include "components/signin/core/browser/account_reconcilor.h"
18 #include "components/signin/core/browser/chrome_connected_header_helper.h"
17 #include "components/signin/core/browser/signin_header_helper.h" 19 #include "components/signin/core/browser/signin_header_helper.h"
20 #include "components/signin/core/common/profile_management_switches.h"
18 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/resource_request_info.h" 22 #include "content/public/browser/resource_request_info.h"
20 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
21 #include "google_apis/gaia/gaia_auth_util.h" 24 #include "google_apis/gaia/gaia_auth_util.h"
25 #include "net/http/http_response_headers.h"
22 #include "net/url_request/url_request.h" 26 #include "net/url_request/url_request.h"
23 27
24 #if defined(OS_ANDROID) 28 #if defined(OS_ANDROID)
25 #include "chrome/browser/android/signin/account_management_screen_helper.h" 29 #include "chrome/browser/android/signin/account_management_screen_helper.h"
26 #else 30 #else
27 #include "chrome/browser/ui/browser_commands.h" 31 #include "chrome/browser/ui/browser_commands.h"
28 #include "chrome/browser/ui/browser_finder.h" 32 #include "chrome/browser/ui/browser_finder.h"
29 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" 33 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
30 #endif // defined(OS_ANDROID) 34 #endif // defined(OS_ANDROID)
31 35
32 namespace signin { 36 namespace signin {
33 37
34 namespace { 38 namespace {
35 39
40 const char kChromeManageAccountsHeader[] = "X-Chrome-Manage-Accounts";
41
36 // Processes the mirror response header on the UI thread. Currently depending 42 // 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 43 // on the value of |header_value|, it either shows the profile avatar menu, or
38 // opens an incognito window/tab. 44 // opens an incognito window/tab.
39 void ProcessMirrorHeaderUIThread(int child_id, 45 void ProcessMirrorHeaderUIThread(int child_id,
40 int route_id, 46 int route_id,
41 ManageAccountsParams manage_accounts_params) { 47 ManageAccountsParams manage_accounts_params) {
42 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
49 DCHECK_EQ(switches::AccountConsistencyMethod::kMirror,
50 switches::GetAccountConsistencyMethod());
43 51
44 GAIAServiceType service_type = manage_accounts_params.service_type; 52 GAIAServiceType service_type = manage_accounts_params.service_type;
45 DCHECK_NE(GAIA_SERVICE_TYPE_NONE, service_type); 53 DCHECK_NE(GAIA_SERVICE_TYPE_NONE, service_type);
46 54
47 content::WebContents* web_contents = 55 content::WebContents* web_contents =
48 tab_util::GetWebContentsByID(child_id, route_id); 56 tab_util::GetWebContentsByID(child_id, route_id);
49 if (!web_contents) 57 if (!web_contents)
50 return; 58 return;
51 59
52 Profile* profile = 60 Profile* profile =
53 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 61 Profile::FromBrowserContext(web_contents->GetBrowserContext());
54 AccountReconcilor* account_reconcilor = 62 AccountReconcilor* account_reconcilor =
55 AccountReconcilorFactory::GetForProfile(profile); 63 AccountReconcilorFactory::GetForProfile(profile);
56 account_reconcilor->OnReceivedManageAccountsResponse( 64 account_reconcilor->OnReceivedManageAccountsResponse(service_type);
57 manage_accounts_params.service_type);
58 #if !defined(OS_ANDROID) 65 #if !defined(OS_ANDROID)
59 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 66 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
60 if (browser) { 67 if (browser) {
61 BrowserWindow::AvatarBubbleMode bubble_mode; 68 BrowserWindow::AvatarBubbleMode bubble_mode;
62 switch (service_type) { 69 switch (service_type) {
63 case GAIA_SERVICE_TYPE_INCOGNITO: 70 case GAIA_SERVICE_TYPE_INCOGNITO:
64 chrome::NewIncognitoWindow(browser); 71 chrome::NewIncognitoWindow(browser);
65 return; 72 return;
66 case GAIA_SERVICE_TYPE_ADDSESSION: 73 case GAIA_SERVICE_TYPE_ADDSESSION:
67 bubble_mode = BrowserWindow::AVATAR_BUBBLE_MODE_ADD_ACCOUNT; 74 bubble_mode = BrowserWindow::AVATAR_BUBBLE_MODE_ADD_ACCOUNT;
(...skipping 20 matching lines...) Expand all
88 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false)); 95 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false));
89 } else { 96 } else {
90 signin_metrics::LogAccountReconcilorStateOnGaiaResponse( 97 signin_metrics::LogAccountReconcilorStateOnGaiaResponse(
91 account_reconcilor->GetState()); 98 account_reconcilor->GetState());
92 AccountManagementScreenHelper::OpenAccountManagementScreen(profile, 99 AccountManagementScreenHelper::OpenAccountManagementScreen(profile,
93 service_type); 100 service_type);
94 } 101 }
95 #endif // !defined(OS_ANDROID) 102 #endif // !defined(OS_ANDROID)
96 } 103 }
97 104
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 105 } // namespace
119 106
120 void FixAccountConsistencyRequestHeader(net::URLRequest* request, 107 void FixAccountConsistencyRequestHeader(net::URLRequest* request,
121 const GURL& redirect_url, 108 const GURL& redirect_url,
122 ProfileIOData* io_data, 109 ProfileIOData* io_data,
123 int child_id, 110 int child_id,
124 int route_id) { 111 int route_id) {
125 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 112 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
126 113
127 if (io_data->IsOffTheRecord()) 114 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. 137 // If new url is eligible to have the header, add it, otherwise remove it.
151 AppendOrRemoveAccountConsistentyRequestHeader( 138 AppendOrRemoveAccountConsistentyRequestHeader(
152 request, redirect_url, io_data->google_services_account_id()->GetValue(), 139 request, redirect_url, io_data->google_services_account_id()->GetValue(),
153 io_data->GetCookieSettings(), profile_mode_mask); 140 io_data->GetCookieSettings(), profile_mode_mask);
154 } 141 }
155 142
156 void ProcessMirrorResponseHeaderIfExists(net::URLRequest* request, 143 void ProcessMirrorResponseHeaderIfExists(net::URLRequest* request,
157 ProfileIOData* io_data, 144 ProfileIOData* io_data,
158 int child_id, 145 int child_id,
159 int route_id) { 146 int route_id) {
160 ManageAccountsParams params = 147 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
161 BuildManageAccountsParamsHelper(request, io_data); 148
149 const content::ResourceRequestInfo* info =
150 content::ResourceRequestInfo::ForRequest(request);
151 if (!(info && info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME))
152 return;
153
154 if (!gaia::IsGaiaSignonRealm(request->url().GetOrigin()))
155 return;
156
157 net::HttpResponseHeaders* response_headers = request->response_headers();
158 if (!response_headers)
159 return;
160
161 std::string header_value;
162 if (!response_headers->GetNormalizedHeader(kChromeManageAccountsHeader,
163 &header_value)) {
164 return;
165 }
166
167 if (io_data->IsOffTheRecord()) {
168 NOTREACHED() << "Gaia should not send the X-Chrome-Manage-Accounts header "
169 << "in incognito.";
170 return;
171 }
172
173 if (switches::GetAccountConsistencyMethod() !=
174 switches::AccountConsistencyMethod::kMirror) {
175 NOTREACHED() << "Gaia should not send the X-Chrome-Manage-Accounts header "
176 << "when Mirror is disabled.";
177 return;
178 }
179
180 ManageAccountsParams params = BuildManageAccountsParams(header_value);
181 // If the request does not have a response header or if the header contains
182 // garbage, then |service_type| is set to |GAIA_SERVICE_TYPE_NONE|.
162 if (params.service_type == GAIA_SERVICE_TYPE_NONE) 183 if (params.service_type == GAIA_SERVICE_TYPE_NONE)
163 return; 184 return;
164 185
165 params.child_id = child_id; 186 params.child_id = child_id;
166 params.route_id = route_id; 187 params.route_id = route_id;
167 content::BrowserThread::PostTask( 188 content::BrowserThread::PostTask(
168 content::BrowserThread::UI, FROM_HERE, 189 content::BrowserThread::UI, FROM_HERE,
169 base::Bind(ProcessMirrorHeaderUIThread, child_id, route_id, params)); 190 base::Bind(ProcessMirrorHeaderUIThread, child_id, route_id, params));
170 } 191 }
171 192
172 } // namespace signin 193 } // 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