Chromium Code Reviews| Index: chrome/browser/ui/webui/signin/signin_dice_internals_handler.cc |
| diff --git a/chrome/browser/ui/webui/signin/signin_dice_internals_handler.cc b/chrome/browser/ui/webui/signin/signin_dice_internals_handler.cc |
| index 77e3d4942ceee4a103abeb3e73215776a18676a4..2e0d7672a2253fc548b7bcc72bfc947c9d90107a 100644 |
| --- a/chrome/browser/ui/webui/signin/signin_dice_internals_handler.cc |
| +++ b/chrome/browser/ui/webui/signin/signin_dice_internals_handler.cc |
| @@ -6,6 +6,12 @@ |
| #include "base/values.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/signin/account_tracker_service_factory.h" |
| +#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| +#include "chrome/browser/signin/signin_manager_factory.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_finder.h" |
| +#include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
| SigninDiceInternalsHandler::SigninDiceInternalsHandler(Profile* profile) |
| : profile_(profile) { |
| @@ -22,6 +28,34 @@ void SigninDiceInternalsHandler::RegisterMessages() { |
| } |
| void SigninDiceInternalsHandler::HandleEnableSync(const base::ListValue* args) { |
| - // TODO(msarda): Implement start syncing. |
| - VLOG(1) << "[Dice] Start syncing"; |
| + if (SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()) { |
| + VLOG(1) << "[Dice] Cannot enable sync as profile is already authenticated"; |
| + return; |
| + } |
| + |
| + AccountTrackerService* tracker = |
| + AccountTrackerServiceFactory::GetForProfile(profile_); |
| + ProfileOAuth2TokenService* token_service = |
| + ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| + std::vector<std::string> account_ids = token_service->GetAccounts(); |
| + if (account_ids.empty()) { |
| + VLOG(1) << "[Dice] No accounts available in the token service"; |
| + return; |
| + } |
| + |
| + Browser* browser = chrome::FindLastActiveWithProfile(profile_); |
| + DCHECK(browser); |
| + std::string account_id = account_ids[0]; |
| + std::string gaia_id = tracker->GetAccountInfo(account_id).gaia; |
| + std::string email = tracker->GetAccountInfo(account_id).email; |
| + VLOG(1) << "[Dice] Start syncing with account " << email; |
| + |
| + OneClickSigninSyncStarter::Callback callback; |
| + new OneClickSigninSyncStarter( |
|
pastarmovj
2017/07/05 13:56:21
nit: Please add a comment above that this class is
msarda
2017/07/05 15:53:59
Done.
|
| + profile_, browser, gaia_id, email, "" /* password */, |
| + "" /* refresh_token */, OneClickSigninSyncStarter::CURRENT_PROFILE, |
| + OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST, |
| + web_ui()->GetWebContents(), |
| + OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN, |
| + GURL("") /* current_url */, GURL("") /* continue_url */, callback); |
| } |