0

[GCM] Passing GCMClient::AccountTokenInfo list to GCMDriver

* Making sure GCMAccountTracker is only depenedent on the GCMDriver
* Replacing GCMDesktopDriver.SetAccountsForCheckin with
  virtual GCMDesktop.SetAccountTokens
* Producing a vector of AccountTokenInfo in GCMAccountTracker

BUG=374969
R=jianli@chromium.org

Review URL: https://codereview.chromium.org/594383003

Cr-Commit-Position: refs/heads/master@{#297190}
This commit is contained in:
fgorski
2014-09-29 09:46:18 -07:00
committed by Commit bot
parent 3e698a5483
commit 58b9dfcdec
19 changed files with 179 additions and 95 deletions

@ -152,7 +152,7 @@ void GCMAccountTracker::CompleteCollectingTokens() {
}
bool account_removed = false;
std::map<std::string, std::string> account_tokens;
std::vector<GCMClient::AccountTokenInfo> account_tokens;
for (AccountInfos::iterator iter = account_infos_.begin();
iter != account_infos_.end();) {
switch (iter->second.state) {
@ -165,10 +165,15 @@ void GCMAccountTracker::CompleteCollectingTokens() {
account_infos_.erase(iter++);
break;
case TOKEN_PRESENT:
account_tokens[iter->second.email] = iter->second.access_token;
case TOKEN_PRESENT: {
GCMClient::AccountTokenInfo token_info;
token_info.account_id = iter->first;
token_info.email = iter->second.email;
token_info.access_token = iter->second.access_token;
account_tokens.push_back(token_info);
++iter;
break;
}
case GETTING_TOKEN:
// This should not happen, as we are making a check that there are no

@ -9,6 +9,7 @@
#include <string>
#include "base/memory/scoped_vector.h"
#include "components/gcm_driver/gcm_client.h"
#include "google_apis/gaia/account_tracker.h"
#include "google_apis/gaia/oauth2_token_service.h"
@ -49,9 +50,9 @@ class GCMAccountTracker : public gaia::AccountTracker::Observer,
AccountState state;
};
// Callback for the GetAccountsForCheckin call. |account_tokens| maps email
// addresses to OAuth2 access tokens.
typedef base::Callback<void(const std::map<std::string, std::string>&
// Callback for the GetAccountsForCheckin call. |account_tokens|: list of
// email addresses, account ids and OAuth2 access tokens.
typedef base::Callback<void(const std::vector<GCMClient::AccountTokenInfo>&
account_tokens)> UpdateAccountsCallback;
// Creates an instance of GCMAccountTracker. |account_tracker| is used to

@ -37,6 +37,30 @@ std::string MakeAccessToken(const std::string& account_key) {
return "access_token-" + account_key;
}
GCMClient::AccountTokenInfo MakeAccountToken(const std::string& account_key) {
GCMClient::AccountTokenInfo token_info;
token_info.account_id = account_key;
token_info.email = account_key;
token_info.access_token = MakeAccessToken(account_key);
return token_info;
}
void VerifyAccountTokens(
const std::vector<GCMClient::AccountTokenInfo>& expected_tokens,
const std::vector<GCMClient::AccountTokenInfo>& actual_tokens) {
EXPECT_EQ(expected_tokens.size(), actual_tokens.size());
for (std::vector<GCMClient::AccountTokenInfo>::const_iterator
expected_iter = expected_tokens.begin(),
actual_iter = actual_tokens.begin();
expected_iter != expected_tokens.end() &&
actual_iter != actual_tokens.end();
++expected_iter, ++actual_iter) {
EXPECT_EQ(expected_iter->account_id, actual_iter->account_id);
EXPECT_EQ(expected_iter->email, actual_iter->email);
EXPECT_EQ(expected_iter->access_token, actual_iter->access_token);
}
}
} // namespace
class GCMAccountTrackerTest : public testing::Test {
@ -45,7 +69,7 @@ class GCMAccountTrackerTest : public testing::Test {
virtual ~GCMAccountTrackerTest();
// Callback for the account tracker.
void UpdateAccounts(const std::map<std::string, std::string>& accounts);
void UpdateAccounts(const std::vector<GCMClient::AccountTokenInfo>& accounts);
// Helpers to pass fake events to the tracker. Tests should have either a pair
// of Start/FinishAccountSignIn or SignInAccount per account. Don't mix.
@ -62,7 +86,7 @@ class GCMAccountTrackerTest : public testing::Test {
// Test results and helpers.
void ResetResults();
bool update_accounts_called() const { return update_accounts_called_; }
const std::map<std::string, std::string>& accounts() const {
const std::vector<GCMClient::AccountTokenInfo>& accounts() const {
return accounts_;
}
@ -70,7 +94,7 @@ class GCMAccountTrackerTest : public testing::Test {
GCMAccountTracker* tracker() { return tracker_.get(); }
private:
std::map<std::string, std::string> accounts_;
std::vector<GCMClient::AccountTokenInfo> accounts_;
bool update_accounts_called_;
base::MessageLoop message_loop_;
@ -104,7 +128,7 @@ GCMAccountTrackerTest::~GCMAccountTrackerTest() {
}
void GCMAccountTrackerTest::UpdateAccounts(
const std::map<std::string, std::string>& accounts) {
const std::vector<GCMClient::AccountTokenInfo>& accounts) {
update_accounts_called_ = true;
accounts_ = accounts;
}
@ -177,9 +201,9 @@ TEST_F(GCMAccountTrackerTest, SingleAccount) {
EXPECT_TRUE(update_accounts_called());
std::map<std::string, std::string> expected_accounts;
expected_accounts[kAccountId1] = MakeAccessToken(kAccountId1);
EXPECT_EQ(expected_accounts, accounts());
std::vector<GCMClient::AccountTokenInfo> expected_accounts;
expected_accounts.push_back(MakeAccountToken(kAccountId1));
VerifyAccountTokens(expected_accounts, accounts());
tracker()->Stop();
}
@ -198,10 +222,10 @@ TEST_F(GCMAccountTrackerTest, MultipleAccounts) {
IssueAccessToken(kAccountId2);
EXPECT_TRUE(update_accounts_called());
std::map<std::string, std::string> expected_accounts;
expected_accounts[kAccountId1] = MakeAccessToken(kAccountId1);
expected_accounts[kAccountId2] = MakeAccessToken(kAccountId2);
EXPECT_EQ(expected_accounts, accounts());
std::vector<GCMClient::AccountTokenInfo> expected_accounts;
expected_accounts.push_back(MakeAccountToken(kAccountId1));
expected_accounts.push_back(MakeAccountToken(kAccountId2));
VerifyAccountTokens(expected_accounts, accounts());
tracker()->Stop();
}
@ -216,9 +240,9 @@ TEST_F(GCMAccountTrackerTest, AccountAdded) {
IssueAccessToken(kAccountId1);
EXPECT_TRUE(update_accounts_called());
std::map<std::string, std::string> expected_accounts;
expected_accounts[kAccountId1] = MakeAccessToken(kAccountId1);
EXPECT_EQ(expected_accounts, accounts());
std::vector<GCMClient::AccountTokenInfo> expected_accounts;
expected_accounts.push_back(MakeAccountToken(kAccountId1));
VerifyAccountTokens(expected_accounts, accounts());
tracker()->Stop();
}
@ -238,9 +262,9 @@ TEST_F(GCMAccountTrackerTest, AccountRemoved) {
SignOutAccount(kAccountId2);
EXPECT_TRUE(update_accounts_called());
std::map<std::string, std::string> expected_accounts;
expected_accounts[kAccountId1] = MakeAccessToken(kAccountId1);
EXPECT_EQ(expected_accounts, accounts());
std::vector<GCMClient::AccountTokenInfo> expected_accounts;
expected_accounts.push_back(MakeAccountToken(kAccountId1));
VerifyAccountTokens(expected_accounts, accounts());
tracker()->Stop();
}
@ -256,9 +280,9 @@ TEST_F(GCMAccountTrackerTest, GetTokenFailed) {
IssueError(kAccountId2);
EXPECT_TRUE(update_accounts_called());
std::map<std::string, std::string> expected_accounts;
expected_accounts[kAccountId1] = MakeAccessToken(kAccountId1);
EXPECT_EQ(expected_accounts, accounts());
std::vector<GCMClient::AccountTokenInfo> expected_accounts;
expected_accounts.push_back(MakeAccountToken(kAccountId1));
VerifyAccountTokens(expected_accounts, accounts());
tracker()->Stop();
}
@ -275,9 +299,9 @@ TEST_F(GCMAccountTrackerTest, GetTokenFailedAccountRemoved) {
SignOutAccount(kAccountId2);
EXPECT_TRUE(update_accounts_called());
std::map<std::string, std::string> expected_accounts;
expected_accounts[kAccountId1] = MakeAccessToken(kAccountId1);
EXPECT_EQ(expected_accounts, accounts());
std::vector<GCMClient::AccountTokenInfo> expected_accounts;
expected_accounts.push_back(MakeAccountToken(kAccountId1));
VerifyAccountTokens(expected_accounts, accounts());
tracker()->Stop();
}
@ -294,9 +318,9 @@ TEST_F(GCMAccountTrackerTest, AccountRemovedWhileRequestsPending) {
IssueAccessToken(kAccountId2);
EXPECT_TRUE(update_accounts_called());
std::map<std::string, std::string> expected_accounts;
expected_accounts[kAccountId1] = MakeAccessToken(kAccountId1);
EXPECT_EQ(expected_accounts, accounts());
std::vector<GCMClient::AccountTokenInfo> expected_accounts;
expected_accounts.push_back(MakeAccountToken(kAccountId1));
VerifyAccountTokens(expected_accounts, accounts());
tracker()->Stop();
}

@ -4,7 +4,7 @@
#include "chrome/browser/services/gcm/gcm_profile_service.h"
#include <map>
#include <vector>
#include "base/logging.h"
#include "base/prefs/pref_service.h"
@ -43,7 +43,7 @@ namespace gcm {
// in. It ensures that account tracker is taking
class GCMProfileService::IdentityObserver : public IdentityProvider::Observer {
public:
IdentityObserver(Profile* profile, GCMDriverDesktop* driver);
IdentityObserver(Profile* profile, GCMDriver* driver);
virtual ~IdentityObserver();
// IdentityProvider::Observer:
@ -53,13 +53,14 @@ class GCMProfileService::IdentityObserver : public IdentityProvider::Observer {
std::string SignedInUserName() const;
// Called to inform IdentityObserver that a list of accounts was updated.
// |account_tokens| maps email addresses to OAuth2 access tokens.
// |account_tokens| is a list of email addresses, account IDs and OAuth2
// access tokens.
void AccountsUpdated(
const std::map<std::string, std::string>& account_tokens);
const std::vector<GCMClient::AccountTokenInfo>& account_tokens);
private:
Profile* profile_;
GCMDriverDesktop* driver_;
GCMDriver* driver_;
scoped_ptr<IdentityProvider> identity_provider_;
scoped_ptr<GCMAccountTracker> gcm_account_tracker_;
@ -73,7 +74,7 @@ class GCMProfileService::IdentityObserver : public IdentityProvider::Observer {
};
GCMProfileService::IdentityObserver::IdentityObserver(Profile* profile,
GCMDriverDesktop* driver)
GCMDriver* driver)
: profile_(profile), driver_(driver), weak_ptr_factory_(this) {
identity_provider_.reset(new ProfileIdentityProvider(
SigninManagerFactory::GetForProfile(profile),
@ -129,8 +130,8 @@ std::string GCMProfileService::IdentityObserver::SignedInUserName() const {
}
void GCMProfileService::IdentityObserver::AccountsUpdated(
const std::map<std::string, std::string>& account_tokens) {
driver_->SetAccountsForCheckin(account_tokens);
const std::vector<GCMClient::AccountTokenInfo>& account_tokens) {
driver_->SetAccountTokens(account_tokens);
}
#endif // !defined(OS_ANDROID)
@ -176,8 +177,7 @@ GCMProfileService::GCMProfileService(
driver_->AddConnectionObserver(chromeos_connection_observer_.get());
#endif
identity_observer_.reset(new IdentityObserver(
profile, static_cast<gcm::GCMDriverDesktop*>(driver_.get())));
identity_observer_.reset(new IdentityObserver(profile, driver_.get()));
}
#endif // defined(OS_ANDROID)

@ -116,8 +116,8 @@ GCMClient::GCMStatistics FakeGCMClient::GetStatistics() const {
return GCMClient::GCMStatistics();
}
void FakeGCMClient::SetAccountsForCheckin(
const std::map<std::string, std::string>& account_tokens) {
void FakeGCMClient::SetAccountTokens(
const std::vector<AccountTokenInfo>& account_tokens) {
}
void FakeGCMClient::UpdateAccountMapping(

@ -56,8 +56,8 @@ class FakeGCMClient : public GCMClient {
virtual void SetRecording(bool recording) OVERRIDE;
virtual void ClearActivityLogs() OVERRIDE;
virtual GCMStatistics GetStatistics() const OVERRIDE;
virtual void SetAccountsForCheckin(
const std::map<std::string, std::string>& account_tokens) OVERRIDE;
virtual void SetAccountTokens(
const std::vector<AccountTokenInfo>& account_tokens) OVERRIDE;
virtual void UpdateAccountMapping(
const AccountMapping& account_mapping) OVERRIDE;
virtual void RemoveAccountMapping(const std::string& account_id) OVERRIDE;

@ -76,6 +76,10 @@ void FakeGCMDriver::SendImpl(const std::string& app_id,
const GCMClient::OutgoingMessage& message) {
}
void FakeGCMDriver::SetAccountTokens(
const std::vector<GCMClient::AccountTokenInfo>& account_tokens) {
}
void FakeGCMDriver::UpdateAccountMapping(
const AccountMapping& account_mapping) {
}

@ -35,6 +35,8 @@ class FakeGCMDriver : public GCMDriver {
bool clear_logs) OVERRIDE;
virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback,
bool recording) OVERRIDE;
virtual void SetAccountTokens(
const std::vector<GCMClient::AccountTokenInfo>& account_tokens) OVERRIDE;
virtual void UpdateAccountMapping(
const AccountMapping& account_mapping) OVERRIDE;
virtual void RemoveAccountMapping(const std::string& account_id) OVERRIDE;

@ -56,7 +56,7 @@ void GCMAccountMapper::Initialize(
}
void GCMAccountMapper::SetAccountTokens(
const std::vector<GCMClient::AccountTokenInfo> account_tokens) {
const std::vector<GCMClient::AccountTokenInfo>& account_tokens) {
// If account mapper is not ready to handle tasks yet, save the latest
// account tokens and return.
if (!IsReady()) {

@ -37,7 +37,7 @@ class GCMAccountMapper : public GCMAppHandler {
// Called by AccountTracker, when a new list of account tokens is available.
// This will cause a refresh of account mappings and sending updates to GCM.
void SetAccountTokens(
const std::vector<GCMClient::AccountTokenInfo> account_tokens);
const std::vector<GCMClient::AccountTokenInfo>& account_tokens);
// Implementation of GCMAppHandler:
virtual void ShutdownHandler() OVERRIDE;

@ -284,9 +284,10 @@ class GCMClient {
virtual GCMStatistics GetStatistics() const = 0;
// Sets a list of accounts with OAuth2 tokens for the next checkin.
// |account_tokens| maps email addresses to OAuth2 access tokens.
virtual void SetAccountsForCheckin(
const std::map<std::string, std::string>& account_tokens) = 0;
// |account_tokens|: list of email addresses, account IDs and OAuth2 access
// tokens.
virtual void SetAccountTokens(
const std::vector<AccountTokenInfo>& account_tokens) = 0;
// Persists the |account_mapping| in the store.
virtual void UpdateAccountMapping(const AccountMapping& account_mapping) = 0;

@ -403,10 +403,17 @@ void GCMClientImpl::ResetState() {
// TODO(fgorski): reset all of the necessart objects and start over.
}
void GCMClientImpl::SetAccountsForCheckin(
const std::map<std::string, std::string>& account_tokens) {
void GCMClientImpl::SetAccountTokens(
const std::vector<AccountTokenInfo>& account_tokens) {
device_checkin_info_.account_tokens.clear();
for (std::vector<AccountTokenInfo>::const_iterator iter =
account_tokens.begin();
iter != account_tokens.end();
++iter) {
device_checkin_info_.account_tokens[iter->email] = iter->access_token;
}
bool accounts_set_before = device_checkin_info_.accounts_set;
device_checkin_info_.account_tokens = account_tokens;
device_checkin_info_.accounts_set = true;
DVLOG(1) << "Set account called with: " << account_tokens.size()
@ -420,8 +427,10 @@ void GCMClientImpl::SetAccountsForCheckin(
device_checkin_info_.last_checkin_accounts.begin();
iter != device_checkin_info_.last_checkin_accounts.end();
++iter) {
if (account_tokens.find(*iter) == account_tokens.end())
if (device_checkin_info_.account_tokens.find(*iter) ==
device_checkin_info_.account_tokens.end()) {
account_removed = true;
}
}
// Checkin will be forced when any of the accounts was removed during the

@ -103,8 +103,8 @@ class GCMClientImpl
virtual void SetRecording(bool recording) OVERRIDE;
virtual void ClearActivityLogs() OVERRIDE;
virtual GCMStatistics GetStatistics() const OVERRIDE;
virtual void SetAccountsForCheckin(
const std::map<std::string, std::string>& account_tokens) OVERRIDE;
virtual void SetAccountTokens(
const std::vector<AccountTokenInfo>& account_tokens) OVERRIDE;
virtual void UpdateAccountMapping(
const AccountMapping& account_mapping) OVERRIDE;
virtual void RemoveAccountMapping(const std::string& account_id) OVERRIDE;

@ -68,6 +68,24 @@ MCSMessage BuildDownstreamMessage(
return MCSMessage(kDataMessageStanzaTag, data_message);
}
GCMClient::AccountTokenInfo MakeAccountToken(const std::string& email,
const std::string& token) {
GCMClient::AccountTokenInfo account_token;
account_token.email = email;
account_token.access_token = token;
return account_token;
}
std::map<std::string, std::string> MakeEmailToTokenMap(
const std::vector<GCMClient::AccountTokenInfo>& account_tokens) {
std::map<std::string, std::string> email_token_map;
for (std::vector<GCMClient::AccountTokenInfo>::const_iterator iter =
account_tokens.begin(); iter != account_tokens.end(); ++iter) {
email_token_map[iter->email] = iter->access_token;
}
return email_token_map;
}
class FakeMCSClient : public MCSClient {
public:
FakeMCSClient(base::Clock* clock,
@ -843,14 +861,15 @@ TEST_F(GCMClientImplCheckinTest, CheckinWithAccounts) {
GServicesSettings::CalculateDigest(settings),
settings);
std::map<std::string, std::string> account_tokens;
account_tokens["test_user1@gmail.com"] = "token1";
account_tokens["test_user2@gmail.com"] = "token2";
gcm_client()->SetAccountsForCheckin(account_tokens);
std::vector<GCMClient::AccountTokenInfo> account_tokens;
account_tokens.push_back(MakeAccountToken("test_user1@gmail.com", "token1"));
account_tokens.push_back(MakeAccountToken("test_user2@gmail.com", "token2"));
gcm_client()->SetAccountTokens(account_tokens);
EXPECT_TRUE(device_checkin_info().last_checkin_accounts.empty());
EXPECT_TRUE(device_checkin_info().accounts_set);
EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
EXPECT_EQ(MakeEmailToTokenMap(account_tokens),
device_checkin_info().account_tokens);
PumpLoopUntilIdle();
CompleteCheckin(kDeviceAndroidId,
@ -863,7 +882,8 @@ TEST_F(GCMClientImplCheckinTest, CheckinWithAccounts) {
accounts.insert("test_user2@gmail.com");
EXPECT_EQ(accounts, device_checkin_info().last_checkin_accounts);
EXPECT_TRUE(device_checkin_info().accounts_set);
EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
EXPECT_EQ(MakeEmailToTokenMap(account_tokens),
device_checkin_info().account_tokens);
}
// This test only checks that periodic checkin happens.
@ -879,10 +899,10 @@ TEST_F(GCMClientImplCheckinTest, CheckinWhenAccountRemoved) {
GServicesSettings::CalculateDigest(settings),
settings);
std::map<std::string, std::string> account_tokens;
account_tokens["test_user1@gmail.com"] = "token1";
account_tokens["test_user2@gmail.com"] = "token2";
gcm_client()->SetAccountsForCheckin(account_tokens);
std::vector<GCMClient::AccountTokenInfo> account_tokens;
account_tokens.push_back(MakeAccountToken("test_user1@gmail.com", "token1"));
account_tokens.push_back(MakeAccountToken("test_user2@gmail.com", "token2"));
gcm_client()->SetAccountTokens(account_tokens);
PumpLoopUntilIdle();
CompleteCheckin(kDeviceAndroidId,
kDeviceSecurityToken,
@ -891,10 +911,11 @@ TEST_F(GCMClientImplCheckinTest, CheckinWhenAccountRemoved) {
EXPECT_EQ(2UL, device_checkin_info().last_checkin_accounts.size());
EXPECT_TRUE(device_checkin_info().accounts_set);
EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
EXPECT_EQ(MakeEmailToTokenMap(account_tokens),
device_checkin_info().account_tokens);
account_tokens.erase(account_tokens.find("test_user2@gmail.com"));
gcm_client()->SetAccountsForCheckin(account_tokens);
account_tokens.erase(account_tokens.begin() + 1);
gcm_client()->SetAccountTokens(account_tokens);
PumpLoopUntilIdle();
CompleteCheckin(kDeviceAndroidId,
@ -906,7 +927,8 @@ TEST_F(GCMClientImplCheckinTest, CheckinWhenAccountRemoved) {
accounts.insert("test_user1@gmail.com");
EXPECT_EQ(accounts, device_checkin_info().last_checkin_accounts);
EXPECT_TRUE(device_checkin_info().accounts_set);
EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
EXPECT_EQ(MakeEmailToTokenMap(account_tokens),
device_checkin_info().account_tokens);
}
// This test only checks that periodic checkin happens.
@ -922,9 +944,9 @@ TEST_F(GCMClientImplCheckinTest, CheckinWhenAccountReplaced) {
GServicesSettings::CalculateDigest(settings),
settings);
std::map<std::string, std::string> account_tokens;
account_tokens["test_user1@gmail.com"] = "token1";
gcm_client()->SetAccountsForCheckin(account_tokens);
std::vector<GCMClient::AccountTokenInfo> account_tokens;
account_tokens.push_back(MakeAccountToken("test_user1@gmail.com", "token1"));
gcm_client()->SetAccountTokens(account_tokens);
PumpLoopUntilIdle();
CompleteCheckin(kDeviceAndroidId,
@ -938,9 +960,9 @@ TEST_F(GCMClientImplCheckinTest, CheckinWhenAccountReplaced) {
// This should trigger another checkin, because the list of accounts is
// different.
account_tokens.erase(account_tokens.find("test_user1@gmail.com"));
account_tokens["test_user2@gmail.com"] = "token2";
gcm_client()->SetAccountsForCheckin(account_tokens);
account_tokens.clear();
account_tokens.push_back(MakeAccountToken("test_user2@gmail.com", "token2"));
gcm_client()->SetAccountTokens(account_tokens);
PumpLoopUntilIdle();
CompleteCheckin(kDeviceAndroidId,
@ -952,7 +974,8 @@ TEST_F(GCMClientImplCheckinTest, CheckinWhenAccountReplaced) {
accounts.insert("test_user2@gmail.com");
EXPECT_EQ(accounts, device_checkin_info().last_checkin_accounts);
EXPECT_TRUE(device_checkin_info().accounts_set);
EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
EXPECT_EQ(MakeEmailToTokenMap(account_tokens),
device_checkin_info().account_tokens);
}
class GCMClientImplStartAndStopTest : public GCMClientImplTest {

@ -118,6 +118,14 @@ class GCMDriver {
virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback,
bool recording) = 0;
// sets a list of signed in accounts with OAuth2 access tokens, when GCMDriver
// works in context of a signed in entity (e.g. browser profile where user is
// signed into sync).
// |account_tokens|: list of email addresses, account IDs and OAuth2 access
// tokens.
virtual void SetAccountTokens(
const std::vector<GCMClient::AccountTokenInfo>& account_tokens) = 0;
// Updates the |account_mapping| information in persistent store.
virtual void UpdateAccountMapping(const AccountMapping& account_mapping) = 0;

@ -136,11 +136,18 @@ void GCMDriverAndroid::SetGCMRecording(const GetGCMStatisticsCallback& callback,
NOTIMPLEMENTED();
}
void GCMDriverAndroid::SetAccountTokens(
const std::vector<GCMClient::AccountTokenInfo>& account_tokens) {
NOTIMPLEMENTED();
}
void GCMDriverAndroid::UpdateAccountMapping(
const AccountMapping& account_mapping) {
NOTIMPLEMENTED();
}
void GCMDriverAndroid::RemoveAccountMapping(const std::string& account_id) {
NOTIMPLEMENTED();
}
GCMClient::Result GCMDriverAndroid::EnsureStarted() {

@ -58,6 +58,8 @@ class GCMDriverAndroid : public GCMDriver {
bool clear_logs) OVERRIDE;
virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback,
bool recording) OVERRIDE;
virtual void SetAccountTokens(
const std::vector<GCMClient::AccountTokenInfo>& account_tokens) OVERRIDE;
virtual void UpdateAccountMapping(
const AccountMapping& account_mapping) OVERRIDE;
virtual void RemoveAccountMapping(const std::string& account_id) OVERRIDE;

@ -14,6 +14,7 @@
#include "base/metrics/histogram.h"
#include "base/sequenced_task_runner.h"
#include "base/threading/sequenced_worker_pool.h"
#include "components/gcm_driver/gcm_account_mapper.h"
#include "components/gcm_driver/gcm_app_handler.h"
#include "components/gcm_driver/gcm_channel_status_syncer.h"
#include "components/gcm_driver/gcm_client_factory.h"
@ -76,8 +77,8 @@ class GCMDriverDesktop::IOWorker : public GCMClient::Delegate {
void GetGCMStatistics(bool clear_logs);
void SetGCMRecording(bool recording);
void SetAccountsForCheckin(
const std::map<std::string, std::string>& account_tokens);
void SetAccountTokens(
const std::vector<GCMClient::AccountTokenInfo>& account_tokens);
void UpdateAccountMapping(const AccountMapping& account_mapping);
void RemoveAccountMapping(const std::string& account_id);
@ -307,12 +308,12 @@ void GCMDriverDesktop::IOWorker::SetGCMRecording(bool recording) {
base::Bind(&GCMDriverDesktop::GetGCMStatisticsFinished, service_, stats));
}
void GCMDriverDesktop::IOWorker::SetAccountsForCheckin(
const std::map<std::string, std::string>& account_tokens) {
void GCMDriverDesktop::IOWorker::SetAccountTokens(
const std::vector<GCMClient::AccountTokenInfo>& account_tokens) {
DCHECK(io_thread_->RunsTasksOnCurrentThread());
if (gcm_client_.get())
gcm_client_->SetAccountsForCheckin(account_tokens);
gcm_client_->SetAccountTokens(account_tokens);
}
void GCMDriverDesktop::IOWorker::UpdateAccountMapping(
@ -610,13 +611,13 @@ void GCMDriverDesktop::RemoveAccountMapping(const std::string& account_id) {
account_id));
}
void GCMDriverDesktop::SetAccountsForCheckin(
const std::map<std::string, std::string>& account_tokens) {
void GCMDriverDesktop::SetAccountTokens(
const std::vector<GCMClient::AccountTokenInfo>& account_tokens) {
DCHECK(ui_thread_->RunsTasksOnCurrentThread());
io_thread_->PostTask(
FROM_HERE,
base::Bind(&GCMDriverDesktop::IOWorker::SetAccountsForCheckin,
base::Bind(&GCMDriverDesktop::IOWorker::SetAccountTokens,
base::Unretained(io_worker_.get()),
account_tokens));
}

@ -37,6 +37,7 @@ class URLRequestContextGetter;
namespace gcm {
class GCMAccountMapper;
class GCMAppHandler;
class GCMClientFactory;
class GCMDelayedTaskController;
@ -74,19 +75,12 @@ class GCMDriverDesktop : public GCMDriver {
bool clear_logs) OVERRIDE;
virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback,
bool recording) OVERRIDE;
virtual void SetAccountTokens(
const std::vector<GCMClient::AccountTokenInfo>& account_tokens) OVERRIDE;
virtual void UpdateAccountMapping(
const AccountMapping& account_mapping) OVERRIDE;
virtual void RemoveAccountMapping(const std::string& account_id) OVERRIDE;
// GCMDriverDesktop specific implementation.
// Sets a list of accounts with OAuth2 tokens for the next checkin.
// |account_tokens| maps email addresses to OAuth2 access tokens.
// |account_removed| indicates that an account has been removed since the
// last time the callback was called, which triggers an immediate checkin,
// to ensure that association between device and account is removed.
void SetAccountsForCheckin(
const std::map<std::string, std::string>& account_tokens);
// Exposed for testing purpose.
bool gcm_enabled() const { return gcm_enabled_; }
GCMChannelStatusSyncer* gcm_channel_status_syncer_for_testing() {
@ -157,6 +151,9 @@ class GCMDriverDesktop : public GCMDriver {
// Makes sure list is empty on destruction.
ObserverList<GCMConnectionObserver, true> connection_observer_list_;
// Account mapper. Only works when user is signed in.
scoped_ptr<GCMAccountMapper> account_mapper_;
scoped_refptr<base::SequencedTaskRunner> ui_thread_;
scoped_refptr<base::SequencedTaskRunner> io_thread_;