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

Side by Side 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: Protect sync for DICE 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/signin/signin_dice_internals_handler.h" 5 #include "chrome/browser/ui/webui/signin/signin_dice_internals_handler.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/signin/account_tracker_service_factory.h"
10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
11 #include "chrome/browser/signin/signin_manager_factory.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_finder.h"
14 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h"
9 15
10 SigninDiceInternalsHandler::SigninDiceInternalsHandler(Profile* profile) 16 SigninDiceInternalsHandler::SigninDiceInternalsHandler(Profile* profile)
11 : profile_(profile) { 17 : profile_(profile) {
12 DCHECK(profile_); 18 DCHECK(profile_);
13 DCHECK(!profile_->IsOffTheRecord()); 19 DCHECK(!profile_->IsOffTheRecord());
14 } 20 }
15 21
16 SigninDiceInternalsHandler::~SigninDiceInternalsHandler() {} 22 SigninDiceInternalsHandler::~SigninDiceInternalsHandler() {}
17 23
18 void SigninDiceInternalsHandler::RegisterMessages() { 24 void SigninDiceInternalsHandler::RegisterMessages() {
19 web_ui()->RegisterMessageCallback( 25 web_ui()->RegisterMessageCallback(
20 "enableSync", base::Bind(&SigninDiceInternalsHandler::HandleEnableSync, 26 "enableSync", base::Bind(&SigninDiceInternalsHandler::HandleEnableSync,
21 base::Unretained(this))); 27 base::Unretained(this)));
22 } 28 }
23 29
24 void SigninDiceInternalsHandler::HandleEnableSync(const base::ListValue* args) { 30 void SigninDiceInternalsHandler::HandleEnableSync(const base::ListValue* args) {
25 // TODO(msarda): Implement start syncing. 31 if (SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()) {
26 VLOG(1) << "[Dice] Start syncing"; 32 VLOG(1) << "[Dice] Cannot enable sync as profile is already authenticated";
33 return;
34 }
35
36 AccountTrackerService* tracker =
37 AccountTrackerServiceFactory::GetForProfile(profile_);
38 ProfileOAuth2TokenService* token_service =
39 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
40 std::vector<std::string> account_ids = token_service->GetAccounts();
41 if (account_ids.empty()) {
42 VLOG(1) << "[Dice] No accounts available in the token service";
43 return;
44 }
45
46 Browser* browser = chrome::FindLastActiveWithProfile(profile_);
47 DCHECK(browser);
48 std::string account_id = account_ids[0];
49 std::string gaia_id = tracker->GetAccountInfo(account_id).gaia;
50 std::string email = tracker->GetAccountInfo(account_id).email;
51 VLOG(1) << "[Dice] Start syncing with account " << email;
52
53 OneClickSigninSyncStarter::Callback callback;
54 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.
55 profile_, browser, gaia_id, email, "" /* password */,
56 "" /* refresh_token */, OneClickSigninSyncStarter::CURRENT_PROFILE,
57 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST,
58 web_ui()->GetWebContents(),
59 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN,
60 GURL("") /* current_url */, GURL("") /* continue_url */, callback);
27 } 61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698