| OLD | NEW |
| 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 "base/metrics/histogram_macros.h" |
| 8 #include "base/metrics/user_metrics.h" |
| 7 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 9 #include "chrome/browser/signin/signin_manager_factory.h" | 11 #include "chrome/browser/signin/signin_manager_factory.h" |
| 10 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
| 12 #include "chrome/browser/ui/browser_navigator.h" | 14 #include "chrome/browser/ui/browser_navigator.h" |
| 13 #include "chrome/browser/ui/profile_chooser_constants.h" | 15 #include "chrome/browser/ui/profile_chooser_constants.h" |
| 14 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 15 #include "components/signin/core/browser/signin_manager.h" | 17 #include "components/signin/core/browser/signin_manager.h" |
| 16 #include "components/signin/core/browser/signin_metrics.h" | 18 #include "components/signin/core/browser/signin_metrics.h" |
| 17 #include "ui/base/page_transition_types.h" | 19 #include "ui/base/page_transition_types.h" |
| 18 | 20 |
| 19 WelcomeHandler::WelcomeHandler(content::WebUI* web_ui) | 21 WelcomeHandler::WelcomeHandler(content::WebUI* web_ui) |
| 20 : profile_(Profile::FromWebUI(web_ui)), | 22 : profile_(Profile::FromWebUI(web_ui)), |
| 21 oauth2_token_service_( | 23 oauth2_token_service_( |
| 22 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)), | 24 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)), |
| 23 result_(WelcomeResult::DEFAULT) { | 25 result_(WelcomeResult::DEFAULT) { |
| 24 oauth2_token_service_->AddObserver(this); | 26 oauth2_token_service_->AddObserver(this); |
| 25 } | 27 } |
| 26 | 28 |
| 27 WelcomeHandler::~WelcomeHandler() { | 29 WelcomeHandler::~WelcomeHandler() { |
| 28 oauth2_token_service_->RemoveObserver(this); | 30 oauth2_token_service_->RemoveObserver(this); |
| 29 // TODO(tmartino): Log to UMA according to WelcomeResult. | 31 UMA_HISTOGRAM_ENUMERATION("Welcome.SignInPromptResult", result_, |
| 32 WelcomeResult::WELCOME_RESULT_MAX); |
| 30 } | 33 } |
| 31 | 34 |
| 32 // Override from OAuth2TokenService::Observer. Occurs when a new auth token is | 35 // Override from OAuth2TokenService::Observer. Occurs when a new auth token is |
| 33 // available. | 36 // available. |
| 34 void WelcomeHandler::OnRefreshTokenAvailable(const std::string& account_id) { | 37 void WelcomeHandler::OnRefreshTokenAvailable(const std::string& account_id) { |
| 35 result_ = WelcomeResult::SIGNED_IN; | 38 result_ = WelcomeResult::SIGNED_IN; |
| 36 GoToNewTabPage(); | 39 GoToNewTabPage(); |
| 37 } | 40 } |
| 38 | 41 |
| 39 // Handles backend events necessary when user clicks "Sign in." | 42 // Handles backend events necessary when user clicks "Sign in." |
| 40 void WelcomeHandler::HandleActivateSignIn(const base::ListValue* args) { | 43 void WelcomeHandler::HandleActivateSignIn(const base::ListValue* args) { |
| 41 if (SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()) { | 44 if (SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()) { |
| 42 // In general, this page isn't shown to signed-in users; however, if one | 45 // In general, this page isn't shown to signed-in users; however, if one |
| 43 // should arrive here, then opening the sign-in dialog will likely lead | 46 // should arrive here, then opening the sign-in dialog will likely lead |
| 44 // to a crash. Thus, we just act like sign-in was "successful" and whisk | 47 // to a crash. Thus, we just act like sign-in was "successful" and whisk |
| 45 // them away to the NTP instead. | 48 // them away to the NTP instead. |
| 46 GoToNewTabPage(); | 49 GoToNewTabPage(); |
| 47 } else { | 50 } else { |
| 51 base::RecordAction( |
| 52 base::UserMetricsAction("Signin_Impression_FromStartPage")); |
| 48 GetBrowser()->ShowModalSigninWindow( | 53 GetBrowser()->ShowModalSigninWindow( |
| 49 profiles::BubbleViewMode::BUBBLE_VIEW_MODE_GAIA_SIGNIN, | 54 profiles::BubbleViewMode::BUBBLE_VIEW_MODE_GAIA_SIGNIN, |
| 50 signin_metrics::AccessPoint::ACCESS_POINT_START_PAGE); | 55 signin_metrics::AccessPoint::ACCESS_POINT_START_PAGE); |
| 51 } | 56 } |
| 52 } | 57 } |
| 53 | 58 |
| 54 // Handles backend events necessary when user clicks "No thanks." | 59 // Handles backend events necessary when user clicks "No thanks." |
| 55 void WelcomeHandler::HandleUserDecline(const base::ListValue* args) { | 60 void WelcomeHandler::HandleUserDecline(const base::ListValue* args) { |
| 56 result_ = WelcomeResult::DECLINED; | 61 result_ = WelcomeResult::DECLINED; |
| 57 GoToNewTabPage(); | 62 GoToNewTabPage(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 74 } | 79 } |
| 75 | 80 |
| 76 Browser* WelcomeHandler::GetBrowser() { | 81 Browser* WelcomeHandler::GetBrowser() { |
| 77 DCHECK(web_ui()); | 82 DCHECK(web_ui()); |
| 78 content::WebContents* contents = web_ui()->GetWebContents(); | 83 content::WebContents* contents = web_ui()->GetWebContents(); |
| 79 DCHECK(contents); | 84 DCHECK(contents); |
| 80 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 85 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
| 81 DCHECK(browser); | 86 DCHECK(browser); |
| 82 return browser; | 87 return browser; |
| 83 } | 88 } |
| OLD | NEW |