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

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

Issue 2431543003: WelcomeHandler sometimes has browser_ null in ctor (Closed)
Patch Set: Change to GetBrowser()->ShowModalSigninWindow 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
« no previous file with comments | « chrome/browser/ui/webui/welcome_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/welcome_handler.h" 5 #include "chrome/browser/ui/webui/welcome_handler.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 8 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
9 #include "chrome/browser/signin/signin_manager_factory.h" 9 #include "chrome/browser/signin/signin_manager_factory.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_finder.h" 11 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/browser_navigator.h" 12 #include "chrome/browser/ui/browser_navigator.h"
13 #include "chrome/browser/ui/profile_chooser_constants.h" 13 #include "chrome/browser/ui/profile_chooser_constants.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "components/signin/core/browser/signin_manager.h" 15 #include "components/signin/core/browser/signin_manager.h"
16 #include "components/signin/core/browser/signin_metrics.h" 16 #include "components/signin/core/browser/signin_metrics.h"
17 #include "ui/base/page_transition_types.h" 17 #include "ui/base/page_transition_types.h"
18 18
19 WelcomeHandler::WelcomeHandler(content::WebUI* web_ui) 19 WelcomeHandler::WelcomeHandler(content::WebUI* web_ui)
20 : profile_(Profile::FromWebUI(web_ui)), 20 : profile_(Profile::FromWebUI(web_ui)),
21 browser_(chrome::FindBrowserWithWebContents(web_ui->GetWebContents())),
22 oauth2_token_service_( 21 oauth2_token_service_(
23 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)), 22 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)),
24 result_(WelcomeResult::DEFAULT) { 23 result_(WelcomeResult::DEFAULT) {
25 oauth2_token_service_->AddObserver(this); 24 oauth2_token_service_->AddObserver(this);
26 } 25 }
27 26
28 WelcomeHandler::~WelcomeHandler() { 27 WelcomeHandler::~WelcomeHandler() {
29 oauth2_token_service_->RemoveObserver(this); 28 oauth2_token_service_->RemoveObserver(this);
30 // TODO(tmartino): Log to UMA according to WelcomeResult. 29 // TODO(tmartino): Log to UMA according to WelcomeResult.
31 } 30 }
32 31
33 // Override from OAuth2TokenService::Observer. Occurs when a new auth token is 32 // Override from OAuth2TokenService::Observer. Occurs when a new auth token is
34 // available. 33 // available.
35 void WelcomeHandler::OnRefreshTokenAvailable(const std::string& account_id) { 34 void WelcomeHandler::OnRefreshTokenAvailable(const std::string& account_id) {
36 result_ = WelcomeResult::SIGNED_IN; 35 result_ = WelcomeResult::SIGNED_IN;
37 GoToNewTabPage(); 36 GoToNewTabPage();
38 } 37 }
39 38
40 // Handles backend events necessary when user clicks "Sign in." 39 // Handles backend events necessary when user clicks "Sign in."
41 void WelcomeHandler::HandleActivateSignIn(const base::ListValue* args) { 40 void WelcomeHandler::HandleActivateSignIn(const base::ListValue* args) {
42 if (SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()) { 41 if (SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()) {
43 // In general, this page isn't shown to signed-in users; however, if one 42 // In general, this page isn't shown to signed-in users; however, if one
44 // should arrive here, then opening the sign-in dialog will likely lead 43 // should arrive here, then opening the sign-in dialog will likely lead
45 // to a crash. Thus, we just act like sign-in was "successful" and whisk 44 // to a crash. Thus, we just act like sign-in was "successful" and whisk
46 // them away to the NTP instead. 45 // them away to the NTP instead.
47 GoToNewTabPage(); 46 GoToNewTabPage();
48 } else { 47 } else {
49 browser_->ShowModalSigninWindow( 48 GetBrowser()->ShowModalSigninWindow(
50 profiles::BubbleViewMode::BUBBLE_VIEW_MODE_GAIA_SIGNIN, 49 profiles::BubbleViewMode::BUBBLE_VIEW_MODE_GAIA_SIGNIN,
51 signin_metrics::AccessPoint::ACCESS_POINT_START_PAGE); 50 signin_metrics::AccessPoint::ACCESS_POINT_START_PAGE);
52 } 51 }
53 } 52 }
54 53
55 // Handles backend events necessary when user clicks "No thanks." 54 // Handles backend events necessary when user clicks "No thanks."
56 void WelcomeHandler::HandleUserDecline(const base::ListValue* args) { 55 void WelcomeHandler::HandleUserDecline(const base::ListValue* args) {
57 result_ = WelcomeResult::DECLINED; 56 result_ = WelcomeResult::DECLINED;
58 GoToNewTabPage(); 57 GoToNewTabPage();
59 } 58 }
60 59
61 // Override from WebUIMessageHandler. 60 // Override from WebUIMessageHandler.
62 void WelcomeHandler::RegisterMessages() { 61 void WelcomeHandler::RegisterMessages() {
63 web_ui()->RegisterMessageCallback( 62 web_ui()->RegisterMessageCallback(
64 "handleActivateSignIn", base::Bind(&WelcomeHandler::HandleActivateSignIn, 63 "handleActivateSignIn", base::Bind(&WelcomeHandler::HandleActivateSignIn,
65 base::Unretained(this))); 64 base::Unretained(this)));
66 web_ui()->RegisterMessageCallback( 65 web_ui()->RegisterMessageCallback(
67 "handleUserDecline", 66 "handleUserDecline",
68 base::Bind(&WelcomeHandler::HandleUserDecline, base::Unretained(this))); 67 base::Bind(&WelcomeHandler::HandleUserDecline, base::Unretained(this)));
69 } 68 }
70 69
71 void WelcomeHandler::GoToNewTabPage() { 70 void WelcomeHandler::GoToNewTabPage() {
72 chrome::NavigateParams params(browser_, GURL(chrome::kChromeUINewTabURL), 71 chrome::NavigateParams params(GetBrowser(), GURL(chrome::kChromeUINewTabURL),
73 ui::PageTransition::PAGE_TRANSITION_LINK); 72 ui::PageTransition::PAGE_TRANSITION_LINK);
74 chrome::Navigate(&params); 73 chrome::Navigate(&params);
75 } 74 }
75
76 Browser* WelcomeHandler::GetBrowser() {
77 DCHECK(web_ui());
78 content::WebContents* contents = web_ui()->GetWebContents();
79 DCHECK(contents);
80 Browser* browser = chrome::FindBrowserWithWebContents(contents);
81 DCHECK(browser);
82 return browser;
83 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/welcome_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698