Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Unified Diff: chrome/browser/ui/webui/signin/signin_dice_internals_handler.cc

Issue 2953253002: [DICE] Enable sync for an account that is already present in the token service. (Closed)
Patch Set: Address code review Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..48e1c14c1184fabed4a1c54b35e9b58b063f4743 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,36 @@ 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 is suicidal (it will kill itself once it finishes
+ // enabling sync).
+ OneClickSigninSyncStarter::Callback callback;
+ new OneClickSigninSyncStarter(
+ 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);
}
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_sync_starter.cc ('k') | components/browser_sync/profile_sync_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698