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

Side by Side Diff: chrome/browser/ui/webui/history_login_handler.cc

Issue 2361513003: MD History: Update sign in state in data source (Closed)
Patch Set: try another approach Created 4 years, 2 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
OLDNEW
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/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h" 12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_window.h" 13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/webui/profile_info_watcher.h" 14 #include "chrome/browser/ui/webui/profile_info_watcher.h"
15 #include "components/signin/core/browser/signin_metrics.h" 15 #include "components/signin/core/browser/signin_metrics.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_ui.h" 17 #include "content/public/browser/web_ui.h"
18 #include "content/public/browser/web_ui_data_source.h"
18 19
19 HistoryLoginHandler::HistoryLoginHandler() {} 20 HistoryLoginHandler::HistoryLoginHandler(content::WebUIDataSource* data_source)
Dan Beam 2016/09/28 03:56:49 could we just pass a base::Callback instead of a W
lshang 2016/09/29 08:06:47 Done.
21 : data_source_(data_source) {}
22
20 HistoryLoginHandler::~HistoryLoginHandler() {} 23 HistoryLoginHandler::~HistoryLoginHandler() {}
21 24
22 void HistoryLoginHandler::RegisterMessages() { 25 void HistoryLoginHandler::RegisterMessages() {
23 profile_info_watcher_.reset(new ProfileInfoWatcher( 26 profile_info_watcher_.reset(new ProfileInfoWatcher(
24 Profile::FromWebUI(web_ui()), 27 Profile::FromWebUI(web_ui()),
25 base::Bind(&HistoryLoginHandler::ProfileInfoChanged, 28 base::Bind(&HistoryLoginHandler::ProfileInfoChanged,
26 base::Unretained(this)))); 29 base::Unretained(this))));
27 30
28 web_ui()->RegisterMessageCallback("otherDevicesInitialized", 31 web_ui()->RegisterMessageCallback("otherDevicesInitialized",
29 base::Bind(&HistoryLoginHandler::HandleOtherDevicesInitialized, 32 base::Bind(&HistoryLoginHandler::HandleOtherDevicesInitialized,
30 base::Unretained(this))); 33 base::Unretained(this)));
31 34
32 web_ui()->RegisterMessageCallback("startSignInFlow", 35 web_ui()->RegisterMessageCallback("startSignInFlow",
33 base::Bind(&HistoryLoginHandler::HandleStartSignInFlow, 36 base::Bind(&HistoryLoginHandler::HandleStartSignInFlow,
34 base::Unretained(this))); 37 base::Unretained(this)));
35 } 38 }
36 39
37 void HistoryLoginHandler::HandleOtherDevicesInitialized( 40 void HistoryLoginHandler::HandleOtherDevicesInitialized(
38 const base::ListValue* /*args*/) { 41 const base::ListValue* /*args*/) {
39 ProfileInfoChanged(); 42 ProfileInfoChanged();
40 } 43 }
41 44
42 void HistoryLoginHandler::ProfileInfoChanged() { 45 void HistoryLoginHandler::ProfileInfoChanged() {
43 bool signed_in = !profile_info_watcher_->GetAuthenticatedUsername().empty(); 46 bool signed_in = !profile_info_watcher_->GetAuthenticatedUsername().empty();
44 web_ui()->CallJavascriptFunctionUnsafe("updateSignInState", 47 data_source_->AddBoolean("isUserSignedIn", signed_in);
Dan Beam 2016/09/28 03:56:49 this also duplicates the name of this key (not so
lshang 2016/09/29 08:06:47 NaN after we re-create the data source here and th
45 base::FundamentalValue(signed_in)); 48 AllowJavascript();
Dan Beam 2016/09/27 23:16:23 you only want to call AllowJavascript() when the p
calamity 2016/09/28 02:54:23 Hmm, the other handlers in history don't have init
49 CallJavascriptFunction("cr.webUIListenerCallback",
50 base::StringValue("sign-in-state-updated"),
51 base::FundamentalValue(signed_in));
46 } 52 }
47 53
48 void HistoryLoginHandler::HandleStartSignInFlow( 54 void HistoryLoginHandler::HandleStartSignInFlow(
49 const base::ListValue* /*args*/) { 55 const base::ListValue* /*args*/) {
50 Browser* browser = 56 Browser* browser =
51 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); 57 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents());
52 browser->window()->ShowAvatarBubbleFromAvatarButton( 58 browser->window()->ShowAvatarBubbleFromAvatarButton(
53 BrowserWindow::AVATAR_BUBBLE_MODE_SIGNIN, 59 BrowserWindow::AVATAR_BUBBLE_MODE_SIGNIN,
54 signin::ManageAccountsParams(), 60 signin::ManageAccountsParams(),
55 signin_metrics::AccessPoint::ACCESS_POINT_RECENT_TABS); 61 signin_metrics::AccessPoint::ACCESS_POINT_RECENT_TABS);
56 } 62 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698