Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/webui/history_login_handler.h" | 5 #include "chrome/browser/ui/webui/history_login_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback_forward.h" | |
|
Dan Beam
2016/09/30 00:47:43
base/callback.h
lshang
2016/09/30 01:31:08
Done.
| |
| 9 #include "base/values.h" | 10 #include "base/values.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "chrome/browser/ui/webui/profile_info_watcher.h" | 15 #include "chrome/browser/ui/webui/profile_info_watcher.h" |
| 15 #include "components/signin/core/browser/signin_metrics.h" | 16 #include "components/signin/core/browser/signin_metrics.h" |
| 16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/browser/web_ui.h" | 18 #include "content/public/browser/web_ui.h" |
| 18 | 19 |
| 19 HistoryLoginHandler::HistoryLoginHandler() {} | 20 HistoryLoginHandler::HistoryLoginHandler( |
| 21 const base::Callback<void(bool)>& signin_callback) | |
| 22 : signin_callback_(signin_callback) {} | |
| 23 | |
| 20 HistoryLoginHandler::~HistoryLoginHandler() {} | 24 HistoryLoginHandler::~HistoryLoginHandler() {} |
| 21 | 25 |
| 22 void HistoryLoginHandler::RegisterMessages() { | 26 void HistoryLoginHandler::RegisterMessages() { |
| 23 profile_info_watcher_.reset(new ProfileInfoWatcher( | 27 profile_info_watcher_.reset(new ProfileInfoWatcher( |
| 24 Profile::FromWebUI(web_ui()), | 28 Profile::FromWebUI(web_ui()), |
| 25 base::Bind(&HistoryLoginHandler::ProfileInfoChanged, | 29 base::Bind(&HistoryLoginHandler::ProfileInfoChanged, |
| 26 base::Unretained(this)))); | 30 base::Unretained(this)))); |
| 27 | 31 |
| 28 web_ui()->RegisterMessageCallback("otherDevicesInitialized", | 32 web_ui()->RegisterMessageCallback("otherDevicesInitialized", |
| 29 base::Bind(&HistoryLoginHandler::HandleOtherDevicesInitialized, | 33 base::Bind(&HistoryLoginHandler::HandleOtherDevicesInitialized, |
| 30 base::Unretained(this))); | 34 base::Unretained(this))); |
| 31 | 35 |
| 32 web_ui()->RegisterMessageCallback("startSignInFlow", | 36 web_ui()->RegisterMessageCallback("startSignInFlow", |
| 33 base::Bind(&HistoryLoginHandler::HandleStartSignInFlow, | 37 base::Bind(&HistoryLoginHandler::HandleStartSignInFlow, |
| 34 base::Unretained(this))); | 38 base::Unretained(this))); |
| 35 } | 39 } |
| 36 | 40 |
| 37 void HistoryLoginHandler::HandleOtherDevicesInitialized( | 41 void HistoryLoginHandler::HandleOtherDevicesInitialized( |
| 38 const base::ListValue* /*args*/) { | 42 const base::ListValue* /*args*/) { |
| 43 AllowJavascript(); | |
| 39 ProfileInfoChanged(); | 44 ProfileInfoChanged(); |
| 40 } | 45 } |
| 41 | 46 |
| 42 void HistoryLoginHandler::ProfileInfoChanged() { | 47 void HistoryLoginHandler::ProfileInfoChanged() { |
| 43 bool signed_in = !profile_info_watcher_->GetAuthenticatedUsername().empty(); | 48 bool signed_in = !profile_info_watcher_->GetAuthenticatedUsername().empty(); |
| 44 web_ui()->CallJavascriptFunctionUnsafe("updateSignInState", | 49 if (!signin_callback_.is_null()) |
| 45 base::FundamentalValue(signed_in)); | 50 signin_callback_.Run(signed_in); |
| 51 | |
| 52 if (IsJavascriptAllowed()) { | |
| 53 CallJavascriptFunction("cr.webUIListenerCallback", | |
| 54 base::StringValue("sign-in-state-updated"), | |
| 55 base::FundamentalValue(signed_in)); | |
| 56 } | |
| 46 } | 57 } |
| 47 | 58 |
| 48 void HistoryLoginHandler::HandleStartSignInFlow( | 59 void HistoryLoginHandler::HandleStartSignInFlow( |
| 49 const base::ListValue* /*args*/) { | 60 const base::ListValue* /*args*/) { |
| 50 Browser* browser = | 61 Browser* browser = |
| 51 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); | 62 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); |
| 52 browser->window()->ShowAvatarBubbleFromAvatarButton( | 63 browser->window()->ShowAvatarBubbleFromAvatarButton( |
| 53 BrowserWindow::AVATAR_BUBBLE_MODE_SIGNIN, | 64 BrowserWindow::AVATAR_BUBBLE_MODE_SIGNIN, |
| 54 signin::ManageAccountsParams(), | 65 signin::ManageAccountsParams(), |
| 55 signin_metrics::AccessPoint::ACCESS_POINT_RECENT_TABS); | 66 signin_metrics::AccessPoint::ACCESS_POINT_RECENT_TABS); |
| 56 } | 67 } |
| OLD | NEW |