| 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" |
| 7 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 9 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 9 #include "chrome/browser/signin/signin_manager_factory.h" | 10 #include "chrome/browser/signin/signin_manager_factory.h" |
| 10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_finder.h" | 12 #include "chrome/browser/ui/browser_finder.h" |
| 12 #include "chrome/browser/ui/browser_navigator.h" | 13 #include "chrome/browser/ui/browser_navigator.h" |
| 13 #include "chrome/browser/ui/profile_chooser_constants.h" | 14 #include "chrome/browser/ui/profile_chooser_constants.h" |
| 14 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 15 #include "components/signin/core/browser/signin_manager.h" | 16 #include "components/signin/core/browser/signin_manager.h" |
| 16 #include "components/signin/core/browser/signin_metrics.h" | 17 #include "components/signin/core/browser/signin_metrics.h" |
| 17 #include "ui/base/page_transition_types.h" | 18 #include "ui/base/page_transition_types.h" |
| 18 | 19 |
| 19 WelcomeHandler::WelcomeHandler(content::WebUI* web_ui) | 20 WelcomeHandler::WelcomeHandler(content::WebUI* web_ui) |
| 20 : profile_(Profile::FromWebUI(web_ui)), | 21 : profile_(Profile::FromWebUI(web_ui)), |
| 21 oauth2_token_service_( | 22 oauth2_token_service_( |
| 22 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)), | 23 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)), |
| 23 result_(WelcomeResult::DEFAULT) { | 24 result_(WelcomeResult::DEFAULT) { |
| 24 oauth2_token_service_->AddObserver(this); | 25 oauth2_token_service_->AddObserver(this); |
| 25 } | 26 } |
| 26 | 27 |
| 27 WelcomeHandler::~WelcomeHandler() { | 28 WelcomeHandler::~WelcomeHandler() { |
| 28 oauth2_token_service_->RemoveObserver(this); | 29 oauth2_token_service_->RemoveObserver(this); |
| 29 // TODO(tmartino): Log to UMA according to WelcomeResult. | 30 UMA_HISTOGRAM_ENUMERATION("Welcome.SignInPromptResult", result_, |
| 31 WelcomeResult::WELCOME_RESULT_MAX); |
| 30 } | 32 } |
| 31 | 33 |
| 32 // Override from OAuth2TokenService::Observer. Occurs when a new auth token is | 34 // Override from OAuth2TokenService::Observer. Occurs when a new auth token is |
| 33 // available. | 35 // available. |
| 34 void WelcomeHandler::OnRefreshTokenAvailable(const std::string& account_id) { | 36 void WelcomeHandler::OnRefreshTokenAvailable(const std::string& account_id) { |
| 35 result_ = WelcomeResult::SIGNED_IN; | 37 result_ = WelcomeResult::SIGNED_IN; |
| 36 GoToNewTabPage(); | 38 GoToNewTabPage(); |
| 37 } | 39 } |
| 38 | 40 |
| 39 // Handles backend events necessary when user clicks "Sign in." | 41 // Handles backend events necessary when user clicks "Sign in." |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 76 } |
| 75 | 77 |
| 76 Browser* WelcomeHandler::GetBrowser() { | 78 Browser* WelcomeHandler::GetBrowser() { |
| 77 DCHECK(web_ui()); | 79 DCHECK(web_ui()); |
| 78 content::WebContents* contents = web_ui()->GetWebContents(); | 80 content::WebContents* contents = web_ui()->GetWebContents(); |
| 79 DCHECK(contents); | 81 DCHECK(contents); |
| 80 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 82 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
| 81 DCHECK(browser); | 83 DCHECK(browser); |
| 82 return browser; | 84 return browser; |
| 83 } | 85 } |
| OLD | NEW |