| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h" | |
| 6 | |
| 7 #include "chrome/browser/profiles/profile.h" | |
| 8 #include "chrome/browser/profiles/profile_metrics.h" | |
| 9 #include "chrome/browser/signin/signin_manager.h" | |
| 10 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 11 #include "chrome/browser/sync/profile_sync_service.h" | |
| 12 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
| 13 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | |
| 14 #include "content/public/browser/navigation_controller.h" | |
| 15 #include "content/public/browser/site_instance.h" | |
| 16 #include "content/public/browser/web_contents.h" | |
| 17 #include "ui/app_list/signin_delegate_observer.h" | |
| 18 | |
| 19 #if defined(ENABLE_ONE_CLICK_SIGNIN) | |
| 20 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | |
| 21 #endif | |
| 22 | |
| 23 using content::WebContents; | |
| 24 | |
| 25 namespace { | |
| 26 | |
| 27 ProfileSyncService* GetSyncService(Profile* profile) { | |
| 28 return ProfileSyncServiceFactory::GetForProfile(profile); | |
| 29 } | |
| 30 | |
| 31 LoginUIService* GetLoginUIService(Profile* profile) { | |
| 32 return LoginUIServiceFactory::GetForProfile(profile); | |
| 33 } | |
| 34 | |
| 35 SigninManager* GetSigninManager(Profile* profile) { | |
| 36 return SigninManagerFactory::GetForProfile(profile); | |
| 37 } | |
| 38 | |
| 39 } // namespace | |
| 40 | |
| 41 ChromeSigninDelegate::ChromeSigninDelegate(Profile* profile) | |
| 42 : profile_(profile) {} | |
| 43 | |
| 44 bool ChromeSigninDelegate::NeedSignin() { | |
| 45 #if defined(USE_ASH) | |
| 46 return false; | |
| 47 #else | |
| 48 if (!profile_) | |
| 49 return false; | |
| 50 | |
| 51 return GetSigninManager(profile_)->GetAuthenticatedUsername().empty(); | |
| 52 #endif | |
| 53 } | |
| 54 | |
| 55 WebContents* ChromeSigninDelegate::PrepareForSignin() { | |
| 56 DCHECK(!IsActiveSignin()); | |
| 57 | |
| 58 if (!GetLoginUIService(profile_)) | |
| 59 return NULL; | |
| 60 | |
| 61 signin_tracker_.reset(new SigninTracker(profile_, this)); | |
| 62 | |
| 63 if (GetLoginUIService(profile_)->current_login_ui()) | |
| 64 GetLoginUIService(profile_)->current_login_ui()->CloseUI(); | |
| 65 | |
| 66 GetLoginUIService(profile_)->SetLoginUI(this); | |
| 67 | |
| 68 if (!GetSyncService(profile_)) | |
| 69 return NULL; | |
| 70 | |
| 71 GetSyncService(profile_)->UnsuppressAndStart(); | |
| 72 | |
| 73 #if defined(ENABLE_ONE_CLICK_SIGNIN) | |
| 74 GURL url("https://accounts.google.com/ServiceLogin?service=chromiumsync&" | |
| 75 "sarp=1&rm=hide&continue=https://www.google.com/intl/en-US/" | |
| 76 "chrome/blank.html?source=2"); | |
| 77 | |
| 78 WebContents::CreateParams params = WebContents::CreateParams( | |
| 79 profile_, content::SiteInstance::CreateForURL(profile_, url)); | |
| 80 WebContents* web_contents = WebContents::Create(params); | |
| 81 if (OneClickSigninHelper::CanOffer( | |
| 82 web_contents, OneClickSigninHelper::CAN_OFFER_FOR_ALL, "", NULL)) { | |
| 83 OneClickSigninHelper::CreateForWebContents(web_contents); | |
| 84 } | |
| 85 | |
| 86 web_contents->GetController().LoadURL( | |
| 87 url, content::Referrer(), content::PAGE_TRANSITION_LINK, | |
| 88 std::string()); | |
| 89 return web_contents; | |
| 90 #else | |
| 91 NOTREACHED(); | |
| 92 return NULL; | |
| 93 #endif | |
| 94 } | |
| 95 | |
| 96 ChromeSigninDelegate::~ChromeSigninDelegate() { | |
| 97 FinishSignin(); | |
| 98 } | |
| 99 | |
| 100 bool ChromeSigninDelegate::IsActiveSignin() { | |
| 101 if (!GetLoginUIService(profile_)) | |
| 102 return false; | |
| 103 | |
| 104 return GetLoginUIService(profile_)->current_login_ui() == this; | |
| 105 } | |
| 106 | |
| 107 void ChromeSigninDelegate::FinishSignin() { | |
| 108 if (!IsActiveSignin()) | |
| 109 return; | |
| 110 | |
| 111 GetLoginUIService(profile_)->LoginUIClosed(this); | |
| 112 } | |
| 113 | |
| 114 void ChromeSigninDelegate::FocusUI() { | |
| 115 // The launcher gets hidden if it is not focused, so if it is visible it | |
| 116 // is focused. Hence, nothing to do here. | |
| 117 } | |
| 118 | |
| 119 void ChromeSigninDelegate::CloseUI() { | |
| 120 // TODO: remove tab contents helper | |
| 121 // This can't happen, as the launcher keeps focus, but do something sensible | |
| 122 // nonetheless. | |
| 123 FinishSignin(); | |
| 124 } | |
| 125 | |
| 126 void ChromeSigninDelegate::GaiaCredentialsValid() { | |
| 127 } | |
| 128 | |
| 129 void ChromeSigninDelegate::SigninFailed(const GoogleServiceAuthError& error) { | |
| 130 } | |
| 131 | |
| 132 void ChromeSigninDelegate::SigninSuccess() { | |
| 133 if (!IsActiveSignin()) | |
| 134 return; | |
| 135 | |
| 136 FinishSignin(); | |
| 137 NotifySigninSuccess(); | |
| 138 } | |
| OLD | NEW |