| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sync/one_click_signin_sync_starter.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "components/prefs/pref_service.h" | |
| 13 | |
| 14 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 15 #include "chrome/browser/policy/cloud/user_policy_signin_service.h" | 12 #include "chrome/browser/policy/cloud/user_policy_signin_service.h" |
| 16 #include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h" | 13 #include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h" |
| 17 #endif | |
| 18 | |
| 19 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/profiles/profile_attributes_storage.h" | 15 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 21 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 16 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 22 #include "chrome/browser/profiles/profile_io_data.h" | 17 #include "chrome/browser/profiles/profile_io_data.h" |
| 23 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
| 24 #include "chrome/browser/profiles/profile_window.h" | 19 #include "chrome/browser/profiles/profile_window.h" |
| 25 #include "chrome/browser/signin/signin_manager_factory.h" | 20 #include "chrome/browser/signin/signin_manager_factory.h" |
| 26 #include "chrome/browser/signin/signin_tracker_factory.h" | 21 #include "chrome/browser/signin/signin_tracker_factory.h" |
| 27 #include "chrome/browser/sync/profile_sync_service_factory.h" | 22 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 28 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 29 #include "chrome/browser/ui/browser_finder.h" | 24 #include "chrome/browser/ui/browser_finder.h" |
| 30 #include "chrome/browser/ui/browser_list.h" | 25 #include "chrome/browser/ui/browser_list.h" |
| 31 #include "chrome/browser/ui/browser_tabstrip.h" | 26 #include "chrome/browser/ui/browser_tabstrip.h" |
| 32 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
| 33 #include "chrome/browser/ui/chrome_pages.h" | 28 #include "chrome/browser/ui/chrome_pages.h" |
| 34 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h" | 29 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h" |
| 35 #include "chrome/browser/ui/tab_dialogs.h" | 30 #include "chrome/browser/ui/tab_dialogs.h" |
| 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 31 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 37 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 32 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 38 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
| 39 #include "chrome/grit/chromium_strings.h" | 34 #include "chrome/grit/chromium_strings.h" |
| 40 #include "chrome/grit/generated_resources.h" | 35 #include "chrome/grit/generated_resources.h" |
| 41 #include "components/browser_sync/browser/profile_sync_service.h" | 36 #include "components/browser_sync/browser/profile_sync_service.h" |
| 37 #include "components/prefs/pref_service.h" |
| 42 #include "components/signin/core/browser/signin_manager.h" | 38 #include "components/signin/core/browser/signin_manager.h" |
| 43 #include "components/signin/core/browser/signin_metrics.h" | 39 #include "components/signin/core/browser/signin_metrics.h" |
| 44 #include "components/signin/core/common/profile_management_switches.h" | 40 #include "components/signin/core/common/profile_management_switches.h" |
| 45 #include "components/sync_driver/sync_prefs.h" | 41 #include "components/sync_driver/sync_prefs.h" |
| 46 #include "content/public/browser/user_metrics.h" | 42 #include "content/public/browser/user_metrics.h" |
| 47 #include "net/base/url_util.h" | 43 #include "net/base/url_util.h" |
| 48 #include "net/url_request/url_request_context_getter.h" | 44 #include "net/url_request/url_request_context_getter.h" |
| 49 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
| 50 | 46 |
| 51 namespace { | 47 namespace { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); | 139 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); |
| 144 sync_prefs.SetSyncRequested(true); | 140 sync_prefs.SetSyncRequested(true); |
| 145 } | 141 } |
| 146 | 142 |
| 147 void OneClickSigninSyncStarter::ConfirmSignin(const std::string& oauth_token) { | 143 void OneClickSigninSyncStarter::ConfirmSignin(const std::string& oauth_token) { |
| 148 DCHECK(!oauth_token.empty()); | 144 DCHECK(!oauth_token.empty()); |
| 149 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 145 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
| 150 // If this is a new signin (no account authenticated yet) try loading | 146 // If this is a new signin (no account authenticated yet) try loading |
| 151 // policy for this user now, before any signed in services are initialized. | 147 // policy for this user now, before any signed in services are initialized. |
| 152 if (!signin->IsAuthenticated()) { | 148 if (!signin->IsAuthenticated()) { |
| 153 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 154 policy::UserPolicySigninService* policy_service = | 149 policy::UserPolicySigninService* policy_service = |
| 155 policy::UserPolicySigninServiceFactory::GetForProfile(profile_); | 150 policy::UserPolicySigninServiceFactory::GetForProfile(profile_); |
| 156 policy_service->RegisterForPolicy( | 151 policy_service->RegisterForPolicy( |
| 157 signin->GetUsernameForAuthInProgress(), | 152 signin->GetUsernameForAuthInProgress(), |
| 158 oauth_token, | 153 oauth_token, |
| 159 base::Bind(&OneClickSigninSyncStarter::OnRegisteredForPolicy, | 154 base::Bind(&OneClickSigninSyncStarter::OnRegisteredForPolicy, |
| 160 weak_pointer_factory_.GetWeakPtr())); | 155 weak_pointer_factory_.GetWeakPtr())); |
| 161 return; | 156 return; |
| 162 #else | |
| 163 ConfirmAndSignin(); | |
| 164 #endif | |
| 165 } else { | 157 } else { |
| 166 // The user is already signed in - just tell SigninManager to continue | 158 // The user is already signed in - just tell SigninManager to continue |
| 167 // with its re-auth flow. | 159 // with its re-auth flow. |
| 168 signin->CompletePendingSignin(); | 160 signin->CompletePendingSignin(); |
| 169 } | 161 } |
| 170 } | 162 } |
| 171 | 163 |
| 172 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 173 OneClickSigninSyncStarter::SigninDialogDelegate::SigninDialogDelegate( | 164 OneClickSigninSyncStarter::SigninDialogDelegate::SigninDialogDelegate( |
| 174 base::WeakPtr<OneClickSigninSyncStarter> sync_starter) | 165 base::WeakPtr<OneClickSigninSyncStarter> sync_starter) |
| 175 : sync_starter_(sync_starter) { | 166 : sync_starter_(sync_starter) { |
| 176 } | 167 } |
| 177 | 168 |
| 178 OneClickSigninSyncStarter::SigninDialogDelegate::~SigninDialogDelegate() { | 169 OneClickSigninSyncStarter::SigninDialogDelegate::~SigninDialogDelegate() { |
| 179 } | 170 } |
| 180 | 171 |
| 181 void OneClickSigninSyncStarter::SigninDialogDelegate::OnCancelSignin() { | 172 void OneClickSigninSyncStarter::SigninDialogDelegate::OnCancelSignin() { |
| 182 SetUserChoiceHistogram(SIGNIN_CHOICE_CANCEL); | 173 SetUserChoiceHistogram(SIGNIN_CHOICE_CANCEL); |
| 183 content::RecordAction( | 174 content::RecordAction( |
| 184 base::UserMetricsAction("Signin_EnterpriseAccountPrompt_Cancel")); | 175 base::UserMetricsAction("Signin_EnterpriseAccountPrompt_Cancel")); |
| 185 if (sync_starter_ != NULL) | 176 if (sync_starter_ != NULL) |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 } | 329 } |
| 339 case Profile::CREATE_STATUS_REMOTE_FAIL: | 330 case Profile::CREATE_STATUS_REMOTE_FAIL: |
| 340 case Profile::CREATE_STATUS_CANCELED: | 331 case Profile::CREATE_STATUS_CANCELED: |
| 341 case Profile::MAX_CREATE_STATUS: { | 332 case Profile::MAX_CREATE_STATUS: { |
| 342 NOTREACHED() << "Invalid profile creation status"; | 333 NOTREACHED() << "Invalid profile creation status"; |
| 343 CancelSigninAndDelete(); | 334 CancelSigninAndDelete(); |
| 344 return; | 335 return; |
| 345 } | 336 } |
| 346 } | 337 } |
| 347 } | 338 } |
| 348 #endif | |
| 349 | 339 |
| 350 void OneClickSigninSyncStarter::CancelSigninAndDelete() { | 340 void OneClickSigninSyncStarter::CancelSigninAndDelete() { |
| 351 SigninManagerFactory::GetForProfile(profile_) | 341 SigninManagerFactory::GetForProfile(profile_) |
| 352 ->SignOut(signin_metrics::ABORT_SIGNIN, | 342 ->SignOut(signin_metrics::ABORT_SIGNIN, |
| 353 signin_metrics::SignoutDelete::IGNORE_METRIC); | 343 signin_metrics::SignoutDelete::IGNORE_METRIC); |
| 354 // The statement above results in a call to SigninFailed() which will free | 344 // The statement above results in a call to SigninFailed() which will free |
| 355 // this object, so do not refer to the OneClickSigninSyncStarter object | 345 // this object, so do not refer to the OneClickSigninSyncStarter object |
| 356 // after this point. | 346 // after this point. |
| 357 } | 347 } |
| 358 | 348 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 false /* user_gesture */); | 631 false /* user_gesture */); |
| 642 } | 632 } |
| 643 | 633 |
| 644 void OneClickSigninSyncStarter::LoadContinueUrl() { | 634 void OneClickSigninSyncStarter::LoadContinueUrl() { |
| 645 web_contents()->GetController().LoadURL( | 635 web_contents()->GetController().LoadURL( |
| 646 continue_url_, | 636 continue_url_, |
| 647 content::Referrer(), | 637 content::Referrer(), |
| 648 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 638 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 649 std::string()); | 639 std::string()); |
| 650 } | 640 } |
| OLD | NEW |