0

Remove InstanceID.GetToken options argument

Reactivated UMA still shows zero usage of this and the extensions API
was the only user. Remove it as this won't be supported in the upcoming
FCM API migration anyway.

Bug: 1148321
Change-Id: I6382efeba8d98353d46da8915613015c745c2b4a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2549929
Commit-Queue: Richard Knoll <knollr@chromium.org>
Reviewed-by: Martin Kreichgauer <martinkr@google.com>
Reviewed-by: Marc Treib <treib@chromium.org>
Reviewed-by: Karan Bhatia <karandeepb@chromium.org>
Reviewed-by: Peter Beverloo <peter@chromium.org>
Reviewed-by: Caitlin Fischer <caitlinfischer@google.com>
Cr-Commit-Position: refs/heads/master@{#835625}
This commit is contained in:
Richard Knoll
2020-12-10 12:07:28 +00:00
committed by Chromium LUCI CQ
parent 6c526f4421
commit 943b81ad5f
40 changed files with 134 additions and 262 deletions

@ -4,7 +4,6 @@
#include "chrome/browser/chromeos/cryptauth/client_app_metadata_provider_service.h" #include "chrome/browser/chromeos/cryptauth/client_app_metadata_provider_service.h"
#include <map>
#include <string> #include <string>
#include "ash/public/cpp/ash_pref_names.h" #include "ash/public/cpp/ash_pref_names.h"
@ -250,7 +249,7 @@ void ClientAppMetadataProviderService::OnInstanceIdFetched(
device_sync:: device_sync::
kCryptAuthV2EnrollmentAuthorizedEntity /* authorized_entity */, kCryptAuthV2EnrollmentAuthorizedEntity /* authorized_entity */,
kInstanceIdScope /* scope */, base::TimeDelta() /* time_to_live */, kInstanceIdScope /* scope */, base::TimeDelta() /* time_to_live */,
std::map<std::string, std::string>() /* options */, {} /* flags */, {} /* flags */,
base::BindOnce( base::BindOnce(
&ClientAppMetadataProviderService::OnInstanceIdTokenFetched, &ClientAppMetadataProviderService::OnInstanceIdTokenFetched,
weak_ptr_factory_.GetWeakPtr(), bluetooth_adapter, hardware_info, weak_ptr_factory_.GetWeakPtr(), bluetooth_adapter, hardware_info,

@ -108,17 +108,9 @@ ExtensionFunction::ResponseAction InstanceIDGetTokenFunction::DoWork() {
api::instance_id::GetToken::Params::Create(*args_); api::instance_id::GetToken::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params.get()); EXTENSION_FUNCTION_VALIDATE(params.get());
std::map<std::string, std::string> options;
if (params->get_token_params.options.get())
options = params->get_token_params.options->additional_properties;
UMA_HISTOGRAM_COUNTS_100("Extensions.InstanceID.GetToken.OptionsCount",
options.size());
GetInstanceID()->GetToken( GetInstanceID()->GetToken(
params->get_token_params.authorized_entity, params->get_token_params.authorized_entity,
params->get_token_params.scope, /*time_to_live=*/base::TimeDelta(), params->get_token_params.scope, /*time_to_live=*/base::TimeDelta(),
options,
/*flags=*/{}, /*flags=*/{},
base::BindOnce(&InstanceIDGetTokenFunction::GetTokenCompleted, this)); base::BindOnce(&InstanceIDGetTokenFunction::GetTokenCompleted, this));

@ -49,7 +49,7 @@ void GetGCMToken(content::BrowserContext* context,
} }
instance_id->GetToken(kProdSenderId, kScopeGCM, instance_id->GetToken(kProdSenderId, kScopeGCM,
/*time_to_live=*/base::TimeDelta(), /*options=*/{}, /*time_to_live=*/base::TimeDelta(),
/*flags=*/{}, std::move(callback)); /*flags=*/{}, std::move(callback));
} }

@ -844,8 +844,7 @@ void PushMessagingServiceImpl::DoSubscribe(
->GetInstanceID(app_identifier.app_id()) ->GetInstanceID(app_identifier.app_id())
->GetToken( ->GetToken(
push_messaging::NormalizeSenderInfo(application_server_key_string), push_messaging::NormalizeSenderInfo(application_server_key_string),
kGCMScope, ttl, std::map<std::string, std::string>() /* options */, kGCMScope, ttl, {} /* flags */,
{} /* flags */,
base::BindOnce(&PushMessagingServiceImpl::DidSubscribe, base::BindOnce(&PushMessagingServiceImpl::DidSubscribe,
weak_factory_.GetWeakPtr(), app_identifier, weak_factory_.GetWeakPtr(), app_identifier,
application_server_key_string, application_server_key_string,

@ -87,7 +87,6 @@ void BinaryFCMService::GetInstanceID(GetInstanceIDCallback callback) {
->GetToken( ->GetToken(
kBinaryFCMServiceSenderId, instance_id::kGCMScope, kBinaryFCMServiceSenderId, instance_id::kGCMScope,
/*time_to_live=*/base::TimeDelta(), /*time_to_live=*/base::TimeDelta(),
/*options=*/{},
/*flags=*/{}, /*flags=*/{},
base::BindOnce(&BinaryFCMService::OnGetInstanceID, base::BindOnce(&BinaryFCMService::OnGetInstanceID,
weakptr_factory_.GetWeakPtr(), std::move(callback))); weakptr_factory_.GetWeakPtr(), std::move(callback)));

@ -27,7 +27,6 @@
namespace safe_browsing { namespace safe_browsing {
using ::testing::_;
using ::testing::Invoke; using ::testing::Invoke;
using ::testing::Return; using ::testing::Return;
@ -55,11 +54,10 @@ class MockInstanceID : public instance_id::InstanceID {
MockInstanceID() : InstanceID("", nullptr) {} MockInstanceID() : InstanceID("", nullptr) {}
~MockInstanceID() override = default; ~MockInstanceID() override = default;
MOCK_METHOD6(GetToken, MOCK_METHOD5(GetToken,
void(const std::string& authorized_entity, void(const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags, std::set<Flags> flags,
GetTokenCallback callback)); GetTokenCallback callback));
@ -331,17 +329,16 @@ TEST_F(BinaryFCMServiceTest, UnregistersTokensOnShutdown) {
TEST_F(BinaryFCMServiceTest, UnregisterOneTokensOneCall) { TEST_F(BinaryFCMServiceTest, UnregisterOneTokensOneCall) {
MockInstanceIDDriver driver; MockInstanceIDDriver driver;
MockInstanceID instance_id; MockInstanceID instance_id;
ON_CALL(driver, GetInstanceID(_)).WillByDefault(Return(&instance_id)); ON_CALL(driver, GetInstanceID).WillByDefault(Return(&instance_id));
binary_fcm_service_.reset(); binary_fcm_service_.reset();
binary_fcm_service_ = std::make_unique<BinaryFCMService>( binary_fcm_service_ = std::make_unique<BinaryFCMService>(
gcm::GCMProfileServiceFactory::GetForProfile(&profile_)->driver(), gcm::GCMProfileServiceFactory::GetForProfile(&profile_)->driver(),
&driver); &driver);
EXPECT_CALL(instance_id, GetToken(_, _, _, _, _, _)) EXPECT_CALL(instance_id, GetToken)
.Times(2) .Times(2)
.WillRepeatedly( .WillRepeatedly(
Invoke([](const std::string&, const std::string&, base::TimeDelta, Invoke([](const std::string&, const std::string&, base::TimeDelta,
const std::map<std::string, std::string>&,
std::set<instance_id::InstanceID::Flags>, std::set<instance_id::InstanceID::Flags>,
instance_id::InstanceID::GetTokenCallback callback) { instance_id::InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", std::move(callback).Run("token",
@ -364,7 +361,7 @@ TEST_F(BinaryFCMServiceTest, UnregisterOneTokensOneCall) {
content::RunAllTasksUntilIdle(); content::RunAllTasksUntilIdle();
EXPECT_CALL(instance_id, DeleteToken(_, _, _)) EXPECT_CALL(instance_id, DeleteToken)
.WillOnce( .WillOnce(
Invoke([](const std::string&, const std::string&, Invoke([](const std::string&, const std::string&,
instance_id::InstanceID::DeleteTokenCallback callback) { instance_id::InstanceID::DeleteTokenCallback callback) {
@ -380,16 +377,15 @@ TEST_F(BinaryFCMServiceTest, UnregisterOneTokensOneCall) {
TEST_F(BinaryFCMServiceTest, UnregisterTwoTokensTwoCalls) { TEST_F(BinaryFCMServiceTest, UnregisterTwoTokensTwoCalls) {
MockInstanceIDDriver driver; MockInstanceIDDriver driver;
MockInstanceID instance_id; MockInstanceID instance_id;
ON_CALL(driver, GetInstanceID(_)).WillByDefault(Return(&instance_id)); ON_CALL(driver, GetInstanceID).WillByDefault(Return(&instance_id));
binary_fcm_service_.reset(); binary_fcm_service_.reset();
binary_fcm_service_ = std::make_unique<BinaryFCMService>( binary_fcm_service_ = std::make_unique<BinaryFCMService>(
gcm::GCMProfileServiceFactory::GetForProfile(&profile_)->driver(), gcm::GCMProfileServiceFactory::GetForProfile(&profile_)->driver(),
&driver); &driver);
EXPECT_CALL(instance_id, GetToken(_, _, _, _, _, _)) EXPECT_CALL(instance_id, GetToken)
.WillOnce( .WillOnce(
Invoke([](const std::string&, const std::string&, base::TimeDelta, Invoke([](const std::string&, const std::string&, base::TimeDelta,
const std::map<std::string, std::string>&,
std::set<instance_id::InstanceID::Flags>, std::set<instance_id::InstanceID::Flags>,
instance_id::InstanceID::GetTokenCallback callback) { instance_id::InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", std::move(callback).Run("token",
@ -397,7 +393,6 @@ TEST_F(BinaryFCMServiceTest, UnregisterTwoTokensTwoCalls) {
})) }))
.WillOnce( .WillOnce(
Invoke([](const std::string&, const std::string&, base::TimeDelta, Invoke([](const std::string&, const std::string&, base::TimeDelta,
const std::map<std::string, std::string>&,
std::set<instance_id::InstanceID::Flags>, std::set<instance_id::InstanceID::Flags>,
instance_id::InstanceID::GetTokenCallback callback) { instance_id::InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token 2", std::move(callback).Run("token 2",
@ -420,7 +415,7 @@ TEST_F(BinaryFCMServiceTest, UnregisterTwoTokensTwoCalls) {
content::RunAllTasksUntilIdle(); content::RunAllTasksUntilIdle();
EXPECT_CALL(instance_id, DeleteToken(_, _, _)) EXPECT_CALL(instance_id, DeleteToken)
.Times(2) .Times(2)
.WillOnce( .WillOnce(
Invoke([](const std::string&, const std::string&, Invoke([](const std::string&, const std::string&,
@ -437,7 +432,7 @@ TEST_F(BinaryFCMServiceTest, UnregisterTwoTokensTwoCalls) {
TEST_F(BinaryFCMServiceTest, UnregisterTwoTokenConflict) { TEST_F(BinaryFCMServiceTest, UnregisterTwoTokenConflict) {
MockInstanceIDDriver driver; MockInstanceIDDriver driver;
MockInstanceID instance_id; MockInstanceID instance_id;
ON_CALL(driver, GetInstanceID(_)).WillByDefault(Return(&instance_id)); ON_CALL(driver, GetInstanceID).WillByDefault(Return(&instance_id));
binary_fcm_service_.reset(); binary_fcm_service_.reset();
binary_fcm_service_ = std::make_unique<BinaryFCMService>( binary_fcm_service_ = std::make_unique<BinaryFCMService>(
gcm::GCMProfileServiceFactory::GetForProfile(&profile_)->driver(), gcm::GCMProfileServiceFactory::GetForProfile(&profile_)->driver(),
@ -448,18 +443,17 @@ TEST_F(BinaryFCMServiceTest, UnregisterTwoTokenConflict) {
// Both calls to GetToken return the same value since we mock a case where the // Both calls to GetToken return the same value since we mock a case where the
// second GetToken call happens before the first DeleteToken call resolves. // second GetToken call happens before the first DeleteToken call resolves.
EXPECT_CALL(instance_id, GetToken(_, _, _, _, _, _)) EXPECT_CALL(instance_id, GetToken)
.Times(2) .Times(2)
.WillRepeatedly( .WillRepeatedly(
Invoke([](const std::string&, const std::string&, base::TimeDelta, Invoke([](const std::string&, const std::string&, base::TimeDelta,
const std::map<std::string, std::string>&,
std::set<instance_id::InstanceID::Flags>, std::set<instance_id::InstanceID::Flags>,
instance_id::InstanceID::GetTokenCallback callback) { instance_id::InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", std::move(callback).Run("token",
instance_id::InstanceID::Result::SUCCESS); instance_id::InstanceID::Result::SUCCESS);
})); }));
EXPECT_CALL(instance_id, DeleteToken(_, _, _)) EXPECT_CALL(instance_id, DeleteToken)
.WillOnce( .WillOnce(
Invoke([this, &second_id]( Invoke([this, &second_id](
const std::string&, const std::string&, const std::string&, const std::string&,
@ -484,7 +478,7 @@ TEST_F(BinaryFCMServiceTest, UnregisterTwoTokenConflict) {
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
// Unregister the second token. // Unregister the second token.
EXPECT_CALL(instance_id, DeleteToken(_, _, _)) EXPECT_CALL(instance_id, DeleteToken)
.WillOnce( .WillOnce(
Invoke([](const std::string&, const std::string&, Invoke([](const std::string&, const std::string&,
instance_id::InstanceID::DeleteTokenCallback callback) { instance_id::InstanceID::DeleteTokenCallback callback) {
@ -499,16 +493,15 @@ TEST_F(BinaryFCMServiceTest, UnregisterTwoTokenConflict) {
TEST_F(BinaryFCMServiceTest, QueuesGetInstanceIDOnRetriableError) { TEST_F(BinaryFCMServiceTest, QueuesGetInstanceIDOnRetriableError) {
MockInstanceIDDriver driver; MockInstanceIDDriver driver;
MockInstanceID instance_id; MockInstanceID instance_id;
ON_CALL(driver, GetInstanceID(_)).WillByDefault(Return(&instance_id)); ON_CALL(driver, GetInstanceID).WillByDefault(Return(&instance_id));
binary_fcm_service_.reset(); binary_fcm_service_.reset();
binary_fcm_service_ = std::make_unique<BinaryFCMService>( binary_fcm_service_ = std::make_unique<BinaryFCMService>(
gcm::GCMProfileServiceFactory::GetForProfile(&profile_)->driver(), gcm::GCMProfileServiceFactory::GetForProfile(&profile_)->driver(),
&driver); &driver);
EXPECT_CALL(instance_id, GetToken(_, _, _, _, _, _)) EXPECT_CALL(instance_id, GetToken)
.WillOnce( .WillOnce(
Invoke([](const std::string&, const std::string&, base::TimeDelta, Invoke([](const std::string&, const std::string&, base::TimeDelta,
const std::map<std::string, std::string>&,
std::set<instance_id::InstanceID::Flags>, std::set<instance_id::InstanceID::Flags>,
instance_id::InstanceID::GetTokenCallback callback) { instance_id::InstanceID::GetTokenCallback callback) {
std::move(callback).Run( std::move(callback).Run(
@ -516,7 +509,6 @@ TEST_F(BinaryFCMServiceTest, QueuesGetInstanceIDOnRetriableError) {
})) }))
.WillOnce( .WillOnce(
Invoke([](const std::string&, const std::string&, base::TimeDelta, Invoke([](const std::string&, const std::string&, base::TimeDelta,
const std::map<std::string, std::string>&,
std::set<instance_id::InstanceID::Flags>, std::set<instance_id::InstanceID::Flags>,
instance_id::InstanceID::GetTokenCallback callback) { instance_id::InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", std::move(callback).Run("token",

@ -73,7 +73,6 @@ void SharingDeviceRegistration::RetrieveTargetInfo(
instance_id_driver_->GetInstanceID(kSharingFCMAppID) instance_id_driver_->GetInstanceID(kSharingFCMAppID)
->GetToken(authorized_entity, instance_id::kGCMScope, ->GetToken(authorized_entity, instance_id::kGCMScope,
/*time_to_live=*/base::TimeDelta(), /*time_to_live=*/base::TimeDelta(),
/*options=*/{},
/*flags=*/{InstanceID::Flags::kBypassScheduler}, /*flags=*/{InstanceID::Flags::kBypassScheduler},
base::BindOnce(&SharingDeviceRegistration::OnFCMTokenReceived, base::BindOnce(&SharingDeviceRegistration::OnFCMTokenReceived,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),

@ -73,7 +73,6 @@ class FakeInstanceID : public instance_id::InstanceID {
void GetToken(const std::string& authorized_entity, void GetToken(const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags, std::set<Flags> flags,
GetTokenCallback callback) override { GetTokenCallback callback) override {
if (authorized_entity == kSharingSenderID) if (authorized_entity == kSharingSenderID)

@ -245,7 +245,6 @@ void SyncTest::FakeInstanceID::GetToken(
const std::string& authorized_entity, const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags, std::set<Flags> flags,
GetTokenCallback callback) { GetTokenCallback callback) {
std::move(callback).Run(token_, instance_id::InstanceID::Result::SUCCESS); std::move(callback).Run(token_, instance_id::InstanceID::Result::SUCCESS);

@ -117,7 +117,6 @@ class SyncTest : public PlatformBrowserTest {
void GetToken(const std::string& authorized_entity, void GetToken(const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags, std::set<Flags> flags,
GetTokenCallback callback) override; GetTokenCallback callback) override;

@ -66,6 +66,7 @@
"description": "Identifies authorized actions that the authorized entity can take. E.g. for sending GCM messages, <code>GCM</code> scope should be used." "description": "Identifies authorized actions that the authorized entity can take. E.g. for sending GCM messages, <code>GCM</code> scope should be used."
}, },
"options": { "options": {
"deprecated": "options are deprecated and will be ignored.",
"type": "object", "type": "object",
"properties": {}, "properties": {},
"additionalProperties": { "additionalProperties": {

@ -63,7 +63,6 @@ class FakeGCMProfileService::CustomFakeGCMDriver
const std::string& authorized_entity, const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
GetTokenCallback callback) override; GetTokenCallback callback) override;
void DeleteToken(const std::string& app_id, void DeleteToken(const std::string& app_id,
const std::string& authorized_entity, const std::string& authorized_entity,
@ -189,14 +188,12 @@ void FakeGCMProfileService::CustomFakeGCMDriver::GetToken(
const std::string& authorized_entity, const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
GetTokenCallback callback) { GetTokenCallback callback) {
if (service_->is_offline_) if (service_->is_offline_)
return; // Drop request. return; // Drop request.
instance_id::FakeGCMDriverForInstanceID::GetToken( instance_id::FakeGCMDriverForInstanceID::GetToken(
app_id, authorized_entity, scope, time_to_live, options, app_id, authorized_entity, scope, time_to_live, std::move(callback));
std::move(callback));
} }
void FakeGCMProfileService::CustomFakeGCMDriver::DeleteToken( void FakeGCMProfileService::CustomFakeGCMDriver::DeleteToken(

@ -947,7 +947,7 @@ void GCMClientImpl::Register(
instance_id_token_info->authorized_entity, instance_id_token_info->authorized_entity,
instance_id_token_info->scope, instance_id_token_info->scope,
ConstructGCMVersion(chrome_build_info_.version), ConstructGCMVersion(chrome_build_info_.version),
instance_id_token_info->time_to_live, instance_id_token_info->options)); instance_id_token_info->time_to_live));
source_to_record = instance_id_token_info->authorized_entity + "/" + source_to_record = instance_id_token_info->authorized_entity + "/" +
instance_id_token_info->scope; instance_id_token_info->scope;
} }

@ -52,7 +52,6 @@ class InstanceIDHandler {
const std::string& authorized_entity, const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
GetTokenCallback callback) = 0; GetTokenCallback callback) = 0;
virtual void ValidateToken(const std::string& app_id, virtual void ValidateToken(const std::string& app_id,
const std::string& authorized_entity, const std::string& authorized_entity,

@ -110,8 +110,7 @@ class GCMDriverDesktop::IOWorker : public GCMClient::Delegate {
void GetToken(const std::string& app_id, void GetToken(const std::string& app_id,
const std::string& authorized_entity, const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live);
const std::map<std::string, std::string>& options);
bool ValidateRegistration(scoped_refptr<RegistrationInfo> registration_info, bool ValidateRegistration(scoped_refptr<RegistrationInfo> registration_info,
const std::string& registration_id); const std::string& registration_id);
void DeleteToken(const std::string& app_id, void DeleteToken(const std::string& app_id,
@ -455,12 +454,10 @@ void GCMDriverDesktop::IOWorker::GetInstanceIDData(
service_, app_id, instance_id, extra_data)); service_, app_id, instance_id, extra_data));
} }
void GCMDriverDesktop::IOWorker::GetToken( void GCMDriverDesktop::IOWorker::GetToken(const std::string& app_id,
const std::string& app_id, const std::string& authorized_entity,
const std::string& authorized_entity, const std::string& scope,
const std::string& scope, base::TimeDelta time_to_live) {
base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options) {
DCHECK(io_thread_->RunsTasksInCurrentSequence()); DCHECK(io_thread_->RunsTasksInCurrentSequence());
auto instance_id_token_info = base::MakeRefCounted<InstanceIDTokenInfo>(); auto instance_id_token_info = base::MakeRefCounted<InstanceIDTokenInfo>();
@ -468,7 +465,6 @@ void GCMDriverDesktop::IOWorker::GetToken(
instance_id_token_info->authorized_entity = authorized_entity; instance_id_token_info->authorized_entity = authorized_entity;
instance_id_token_info->scope = scope; instance_id_token_info->scope = scope;
instance_id_token_info->time_to_live = time_to_live; instance_id_token_info->time_to_live = time_to_live;
instance_id_token_info->options = options;
gcm_client_->Register(std::move(instance_id_token_info)); gcm_client_->Register(std::move(instance_id_token_info));
} }
@ -842,7 +838,6 @@ void GCMDriverDesktop::GetToken(
const std::string& authorized_entity, const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
GetTokenCallback callback) { GetTokenCallback callback) {
DCHECK(!app_id.empty()); DCHECK(!app_id.empty());
DCHECK(!authorized_entity.empty()); DCHECK(!authorized_entity.empty());
@ -872,19 +867,17 @@ void GCMDriverDesktop::GetToken(
if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
delayed_task_controller_->AddTask(base::BindOnce( delayed_task_controller_->AddTask(base::BindOnce(
&GCMDriverDesktop::DoGetToken, weak_ptr_factory_.GetWeakPtr(), app_id, &GCMDriverDesktop::DoGetToken, weak_ptr_factory_.GetWeakPtr(), app_id,
authorized_entity, scope, time_to_live, options)); authorized_entity, scope, time_to_live));
return; return;
} }
DoGetToken(app_id, authorized_entity, scope, time_to_live, options); DoGetToken(app_id, authorized_entity, scope, time_to_live);
} }
void GCMDriverDesktop::DoGetToken( void GCMDriverDesktop::DoGetToken(const std::string& app_id,
const std::string& app_id, const std::string& authorized_entity,
const std::string& authorized_entity, const std::string& scope,
const std::string& scope, base::TimeDelta time_to_live) {
base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options) {
DCHECK(ui_thread_->RunsTasksInCurrentSequence()); DCHECK(ui_thread_->RunsTasksInCurrentSequence());
TokenTuple tuple_key(app_id, authorized_entity, scope); TokenTuple tuple_key(app_id, authorized_entity, scope);
@ -895,10 +888,9 @@ void GCMDriverDesktop::DoGetToken(
} }
io_thread_->PostTask( io_thread_->PostTask(
FROM_HERE, FROM_HERE, base::BindOnce(&GCMDriverDesktop::IOWorker::GetToken,
base::BindOnce(&GCMDriverDesktop::IOWorker::GetToken, base::Unretained(io_worker_.get()), app_id,
base::Unretained(io_worker_.get()), app_id, authorized_entity, scope, time_to_live));
authorized_entity, scope, time_to_live, options));
} }
void GCMDriverDesktop::ValidateToken(const std::string& app_id, void GCMDriverDesktop::ValidateToken(const std::string& app_id,

@ -116,7 +116,6 @@ class GCMDriverDesktop : public GCMDriver,
const std::string& authorized_entity, const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
GetTokenCallback callback) override; GetTokenCallback callback) override;
void ValidateToken(const std::string& app_id, void ValidateToken(const std::string& app_id,
const std::string& authorized_entity, const std::string& authorized_entity,
@ -166,8 +165,7 @@ class GCMDriverDesktop : public GCMDriver,
void DoGetToken(const std::string& app_id, void DoGetToken(const std::string& app_id,
const std::string& authorized_entity, const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live);
const std::map<std::string, std::string>& options);
void DoDeleteToken(const std::string& app_id, void DoDeleteToken(const std::string& app_id,
const std::string& authorized_entity, const std::string& authorized_entity,
const std::string& scope); const std::string& scope);

@ -738,7 +738,7 @@ TEST_F(GCMDriverFunctionalTest, DISABLED_RegisterAfterUnfinishedUnregister) {
// Start unregistration without waiting for it to complete. // Start unregistration without waiting for it to complete.
Unregister(kTestAppID1, GCMDriverTest::DO_NOT_WAIT); Unregister(kTestAppID1, GCMDriverTest::DO_NOT_WAIT);
// Register immeidately after unregistration is not completed. // Register immediately after unregistration is not completed.
sender_ids.push_back("sender2"); sender_ids.push_back("sender2");
Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT);
@ -947,10 +947,8 @@ void GCMDriverInstanceIDTest::GetToken(const std::string& app_id,
WaitToFinish wait_to_finish) { WaitToFinish wait_to_finish) {
base::RunLoop run_loop; base::RunLoop run_loop;
set_async_operation_completed_callback(run_loop.QuitClosure()); set_async_operation_completed_callback(run_loop.QuitClosure());
std::map<std::string, std::string> options;
driver()->GetInstanceIDHandlerInternal()->GetToken( driver()->GetInstanceIDHandlerInternal()->GetToken(
app_id, authorized_entity, scope, /*time_to_live=*/base::TimeDelta(), app_id, authorized_entity, scope, /*time_to_live=*/base::TimeDelta(),
options,
base::BindOnce(&GCMDriverTest::RegisterCompleted, base::BindOnce(&GCMDriverTest::RegisterCompleted,
base::Unretained(this))); base::Unretained(this)));
if (wait_to_finish == WAIT) if (wait_to_finish == WAIT)

@ -4,8 +4,6 @@
package org.chromium.components.gcm_driver.instance_id; package org.chromium.components.gcm_driver.instance_id;
import android.os.Bundle;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
@ -100,19 +98,15 @@ public class InstanceIDBridge {
}.execute(); }.execute();
} }
/** Async wrapper for {@link InstanceID#getToken(String, String, Bundle)}. /**
* Async wrapper for {@link InstanceID#getToken(String, String)}.
* |isLazy| isn't part of the InstanceID.getToken() call and not sent to the * |isLazy| isn't part of the InstanceID.getToken() call and not sent to the
* FCM server. It's used to mark the subscription as lazy such that incoming * FCM server. It's used to mark the subscription as lazy such that incoming
* messages are deferred until there are visible activities.*/ * messages are deferred until there are visible activities.
*/
@CalledByNative @CalledByNative
private void getToken(final int requestId, final String authorizedEntity, final String scope, private void getToken(
String[] extrasStrings, int flags) { final int requestId, final String authorizedEntity, final String scope, int flags) {
final Bundle extras = new Bundle();
assert extrasStrings.length % 2 == 0;
for (int i = 0; i < extrasStrings.length; i += 2) {
extras.putString(extrasStrings[i], extrasStrings[i + 1]);
}
new BridgeAsyncTask<String>() { new BridgeAsyncTask<String>() {
@Override @Override
protected String doBackgroundWork() { protected String doBackgroundWork() {
@ -127,7 +121,7 @@ public class InstanceIDBridge {
SubscriptionFlagManager.buildSubscriptionUniqueId( SubscriptionFlagManager.buildSubscriptionUniqueId(
mSubtype, authorizedEntity), mSubtype, authorizedEntity),
flags); flags);
return mInstanceID.getToken(authorizedEntity, scope, extras); return mInstanceID.getToken(authorizedEntity, scope);
} catch (IOException ex) { } catch (IOException ex) {
return ""; return "";
} }

@ -97,11 +97,6 @@ public class InstanceIDWithSubtype {
return mInstanceID.getToken(authorizedEntity, scope); return mInstanceID.getToken(authorizedEntity, scope);
} }
public String getToken(String authorizedEntity, String scope, Bundle extras)
throws IOException {
return mInstanceID.getToken(authorizedEntity, scope, extras);
}
/** Fake subclasses can set {@link #sFakeFactoryForTesting} to an implementation of this. */ /** Fake subclasses can set {@link #sFakeFactoryForTesting} to an implementation of this. */
@VisibleForTesting @VisibleForTesting
public interface FakeFactory { public interface FakeFactory {

@ -4,7 +4,6 @@
package org.chromium.components.gcm_driver.instance_id; package org.chromium.components.gcm_driver.instance_id;
import android.os.Bundle;
import android.os.Looper; import android.os.Looper;
import android.util.Pair; import android.util.Pair;
@ -99,8 +98,9 @@ public class FakeInstanceIDWithSubtype extends InstanceIDWithSubtype {
// triggers a strict mode violation if it's called on the main thread, by reading from // triggers a strict mode violation if it's called on the main thread, by reading from
// SharedPreferences. Since we can't override those static methods to simulate the strict // SharedPreferences. Since we can't override those static methods to simulate the strict
// mode violation in tests, check the thread here (which is only called from getInstance). // mode violation in tests, check the thread here (which is only called from getInstance).
if (Looper.getMainLooper() == Looper.myLooper()) if (Looper.getMainLooper() == Looper.myLooper()) {
throw new AssertionError(InstanceID.ERROR_MAIN_THREAD); throw new AssertionError(InstanceID.ERROR_MAIN_THREAD);
}
} }
@Override @Override
@ -112,8 +112,9 @@ public class FakeInstanceIDWithSubtype extends InstanceIDWithSubtype {
public String getId() { public String getId() {
// InstanceID.getId sometimes triggers a strict mode violation if it's called on the main // InstanceID.getId sometimes triggers a strict mode violation if it's called on the main
// thread, by reading from SharedPreferences. // thread, by reading from SharedPreferences.
if (Looper.getMainLooper() == Looper.myLooper()) if (Looper.getMainLooper() == Looper.myLooper()) {
throw new AssertionError(InstanceID.ERROR_MAIN_THREAD); throw new AssertionError(InstanceID.ERROR_MAIN_THREAD);
}
if (mId == null) { if (mId == null) {
mCreationTime = System.currentTimeMillis(); mCreationTime = System.currentTimeMillis();
@ -126,20 +127,15 @@ public class FakeInstanceIDWithSubtype extends InstanceIDWithSubtype {
public long getCreationTime() { public long getCreationTime() {
// InstanceID.getCreationTime sometimes triggers a strict mode violation if it's called on // InstanceID.getCreationTime sometimes triggers a strict mode violation if it's called on
// the main thread, by reading from SharedPreferences. // the main thread, by reading from SharedPreferences.
if (Looper.getMainLooper() == Looper.myLooper()) if (Looper.getMainLooper() == Looper.myLooper()) {
throw new AssertionError(InstanceID.ERROR_MAIN_THREAD); throw new AssertionError(InstanceID.ERROR_MAIN_THREAD);
}
return mCreationTime; return mCreationTime;
} }
@Override @Override
public String getToken(String authorizedEntity, String scope) throws IOException { public String getToken(String authorizedEntity, String scope) throws IOException {
return getToken(authorizedEntity, scope, null);
}
@Override
public String getToken(String authorizedEntity, String scope, Bundle extras)
throws IOException {
// InstanceID.getToken enforces this. // InstanceID.getToken enforces this.
if (Looper.getMainLooper() == Looper.myLooper()) { if (Looper.getMainLooper() == Looper.myLooper()) {
throw new IOException(InstanceID.ERROR_MAIN_THREAD); throw new IOException(InstanceID.ERROR_MAIN_THREAD);

@ -61,7 +61,6 @@ void FakeGCMDriverForInstanceID::GetToken(
const std::string& authorized_entity, const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
GetTokenCallback callback) { GetTokenCallback callback) {
std::string key = app_id + authorized_entity + scope; std::string key = app_id + authorized_entity + scope;
auto iter = tokens_.find(key); auto iter = tokens_.find(key);

@ -46,7 +46,6 @@ class FakeGCMDriverForInstanceID : public gcm::FakeGCMDriver,
const std::string& authorized_entity, const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
GetTokenCallback callback) override; GetTokenCallback callback) override;
void ValidateToken(const std::string& app_id, void ValidateToken(const std::string& app_id,
const std::string& authorized_entity, const std::string& authorized_entity,

@ -5,7 +5,6 @@
#ifndef COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_ #ifndef COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_
#define COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_ #define COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_
#include <map>
#include <memory> #include <memory>
#include <set> #include <set>
#include <string> #include <string>
@ -108,15 +107,11 @@ class InstanceID {
// |scope|: identifies authorized actions that the authorized entity can take. // |scope|: identifies authorized actions that the authorized entity can take.
// E.g. for sending GCM messages, "GCM" scope should be used. // E.g. for sending GCM messages, "GCM" scope should be used.
// |time_to_live|: TTL of retrieved token, unlimited if zero value passed. // |time_to_live|: TTL of retrieved token, unlimited if zero value passed.
// |options|: allows including a small number of string key/value pairs that
// will be associated with the token and may be used in processing
// the request.
// |flags|: Flags used to create this token. // |flags|: Flags used to create this token.
// |callback|: to be called once the asynchronous operation is done. // |callback|: to be called once the asynchronous operation is done.
virtual void GetToken(const std::string& authorized_entity, virtual void GetToken(const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags, std::set<Flags> flags,
GetTokenCallback callback) = 0; GetTokenCallback callback) = 0;

@ -9,12 +9,10 @@
#include <numeric> #include <numeric>
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/android/jni_array.h"
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/location.h" #include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
@ -94,13 +92,10 @@ void InstanceIDAndroid::GetToken(
const std::string& authorized_entity, const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags, std::set<Flags> flags,
GetTokenCallback callback) { GetTokenCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
UMA_HISTOGRAM_COUNTS_100("InstanceID.GetToken.OptionsCount", options.size());
if (!time_to_live.is_zero()) { if (!time_to_live.is_zero()) {
LOG(WARNING) << "Non-zero TTL requested for InstanceID token, while TTLs" LOG(WARNING) << "Non-zero TTL requested for InstanceID token, while TTLs"
" are not supported by Android Firebase IID API."; " are not supported by Android Firebase IID API.";
@ -109,12 +104,6 @@ void InstanceIDAndroid::GetToken(
int32_t request_id = get_token_callbacks_.Add( int32_t request_id = get_token_callbacks_.Add(
std::make_unique<GetTokenCallback>(std::move(callback))); std::make_unique<GetTokenCallback>(std::move(callback)));
std::vector<std::string> options_strings;
for (const auto& entry : options) {
options_strings.push_back(entry.first);
options_strings.push_back(entry.second);
}
int java_flags = std::accumulate( int java_flags = std::accumulate(
flags.begin(), flags.end(), 0, flags.begin(), flags.end(), 0,
[](int sum, Flags flag) { return sum + static_cast<int>(flag); }); [](int sum, Flags flag) { return sum + static_cast<int>(flag); });
@ -123,8 +112,7 @@ void InstanceIDAndroid::GetToken(
Java_InstanceIDBridge_getToken( Java_InstanceIDBridge_getToken(
env, java_ref_, request_id, env, java_ref_, request_id,
ConvertUTF8ToJavaString(env, authorized_entity), ConvertUTF8ToJavaString(env, authorized_entity),
ConvertUTF8ToJavaString(env, scope), ConvertUTF8ToJavaString(env, scope), java_flags);
base::android::ToJavaArrayOfStrings(env, options_strings), java_flags);
} }
void InstanceIDAndroid::ValidateToken(const std::string& authorized_entity, void InstanceIDAndroid::ValidateToken(const std::string& authorized_entity,

@ -7,7 +7,6 @@
#include <jni.h> #include <jni.h>
#include <map>
#include <string> #include <string>
#include "base/android/scoped_java_ref.h" #include "base/android/scoped_java_ref.h"
@ -46,7 +45,6 @@ class InstanceIDAndroid : public InstanceID {
void GetToken(const std::string& audience, void GetToken(const std::string& audience,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags, std::set<Flags> flags,
GetTokenCallback callback) override; GetTokenCallback callback) override;
void ValidateToken(const std::string& authorized_entity, void ValidateToken(const std::string& authorized_entity,

@ -69,11 +69,9 @@ class InstanceIDDriverTest : public testing::Test {
std::string GetID(InstanceID* instance_id); std::string GetID(InstanceID* instance_id);
base::Time GetCreationTime(InstanceID* instance_id); base::Time GetCreationTime(InstanceID* instance_id);
InstanceID::Result DeleteID(InstanceID* instance_id); InstanceID::Result DeleteID(InstanceID* instance_id);
std::string GetToken( std::string GetToken(InstanceID* instance_id,
InstanceID* instance_id, const std::string& authorized_entity,
const std::string& authorized_entity, const std::string& scope);
const std::string& scope,
const std::map<std::string, std::string>& options);
InstanceID::Result DeleteToken( InstanceID::Result DeleteToken(
InstanceID* instance_id, InstanceID* instance_id,
const std::string& authorized_entity, const std::string& authorized_entity,
@ -170,16 +168,14 @@ InstanceID::Result InstanceIDDriverTest::DeleteID(InstanceID* instance_id) {
return result_; return result_;
} }
std::string InstanceIDDriverTest::GetToken( std::string InstanceIDDriverTest::GetToken(InstanceID* instance_id,
InstanceID* instance_id, const std::string& authorized_entity,
const std::string& authorized_entity, const std::string& scope) {
const std::string& scope,
const std::map<std::string, std::string>& options) {
async_operation_completed_ = false; async_operation_completed_ = false;
token_.clear(); token_.clear();
result_ = InstanceID::UNKNOWN_ERROR; result_ = InstanceID::UNKNOWN_ERROR;
instance_id->GetToken( instance_id->GetToken(
authorized_entity, scope, /*time_to_live=*/base::TimeDelta(), options, authorized_entity, scope, /*time_to_live=*/base::TimeDelta(),
/*flags=*/{}, /*flags=*/{},
base::BindRepeating(&InstanceIDDriverTest::GetTokenCompleted, base::BindRepeating(&InstanceIDDriverTest::GetTokenCompleted,
base::Unretained(this))); base::Unretained(this)));
@ -326,23 +322,18 @@ TEST_F(InstanceIDDriverTest, DeleteID) {
TEST_F(InstanceIDDriverTest, GetToken) { TEST_F(InstanceIDDriverTest, GetToken) {
InstanceID* instance_id = driver()->GetInstanceID(kTestAppID1); InstanceID* instance_id = driver()->GetInstanceID(kTestAppID1);
std::map<std::string, std::string> options; std::string token1 = GetToken(instance_id, kAuthorizedEntity1, kScope1);
std::string token1 =
GetToken(instance_id, kAuthorizedEntity1, kScope1, options);
EXPECT_FALSE(token1.empty()); EXPECT_FALSE(token1.empty());
// Same token is returned for same authorized entity and scope. // Same token is returned for same authorized entity and scope.
EXPECT_EQ(token1, EXPECT_EQ(token1, GetToken(instance_id, kAuthorizedEntity1, kScope1));
GetToken(instance_id, kAuthorizedEntity1, kScope1, options));
// Different token is returned for different authorized entity or scope. // Different token is returned for different authorized entity or scope.
std::string token2 = std::string token2 = GetToken(instance_id, kAuthorizedEntity1, kScope2);
GetToken(instance_id, kAuthorizedEntity1, kScope2, options);
EXPECT_FALSE(token2.empty()); EXPECT_FALSE(token2.empty());
EXPECT_NE(token1, token2); EXPECT_NE(token1, token2);
std::string token3 = std::string token3 = GetToken(instance_id, kAuthorizedEntity2, kScope1);
GetToken(instance_id, kAuthorizedEntity2, kScope1, options);
EXPECT_FALSE(token3.empty()); EXPECT_FALSE(token3.empty());
EXPECT_NE(token1, token3); EXPECT_NE(token1, token3);
EXPECT_NE(token2, token3); EXPECT_NE(token2, token3);
@ -350,14 +341,11 @@ TEST_F(InstanceIDDriverTest, GetToken) {
TEST_F(InstanceIDDriverTest, DeleteToken) { TEST_F(InstanceIDDriverTest, DeleteToken) {
InstanceID* instance_id = driver()->GetInstanceID(kTestAppID1); InstanceID* instance_id = driver()->GetInstanceID(kTestAppID1);
std::map<std::string, std::string> options;
// Gets 2 tokens. // Gets 2 tokens.
std::string token1 = std::string token1 = GetToken(instance_id, kAuthorizedEntity1, kScope1);
GetToken(instance_id, kAuthorizedEntity1, kScope1, options);
EXPECT_FALSE(token1.empty()); EXPECT_FALSE(token1.empty());
std::string token2 = std::string token2 = GetToken(instance_id, kAuthorizedEntity2, kScope1);
GetToken(instance_id, kAuthorizedEntity2, kScope1, options);
EXPECT_FALSE(token1.empty()); EXPECT_FALSE(token1.empty());
EXPECT_NE(token1, token2); EXPECT_NE(token1, token2);
@ -365,14 +353,12 @@ TEST_F(InstanceIDDriverTest, DeleteToken) {
// deletion. // deletion.
EXPECT_EQ(InstanceID::SUCCESS, EXPECT_EQ(InstanceID::SUCCESS,
DeleteToken(instance_id, kAuthorizedEntity1, kScope1)); DeleteToken(instance_id, kAuthorizedEntity1, kScope1));
std::string new_token1 = std::string new_token1 = GetToken(instance_id, kAuthorizedEntity1, kScope2);
GetToken(instance_id, kAuthorizedEntity1, kScope2, options);
EXPECT_FALSE(new_token1.empty()); EXPECT_FALSE(new_token1.empty());
EXPECT_NE(token1, new_token1); EXPECT_NE(token1, new_token1);
// The other token is not affected by the deletion. // The other token is not affected by the deletion.
EXPECT_EQ(token2, EXPECT_EQ(token2, GetToken(instance_id, kAuthorizedEntity2, kScope1));
GetToken(instance_id, kAuthorizedEntity2, kScope1, options));
} }
} // namespace instance_id } // namespace instance_id

@ -12,7 +12,6 @@
#include "base/base64.h" #include "base/base64.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
@ -91,29 +90,25 @@ void InstanceIDImpl::DoGetCreationTime(GetCreationTimeCallback callback) {
void InstanceIDImpl::GetToken(const std::string& authorized_entity, void InstanceIDImpl::GetToken(const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags, std::set<Flags> flags,
GetTokenCallback callback) { GetTokenCallback callback) {
DCHECK(!authorized_entity.empty()); DCHECK(!authorized_entity.empty());
DCHECK(!scope.empty()); DCHECK(!scope.empty());
UMA_HISTOGRAM_COUNTS_100("InstanceID.GetToken.OptionsCount", options.size()); RunWhenReady(base::BindOnce(&InstanceIDImpl::DoGetToken,
weak_ptr_factory_.GetWeakPtr(), authorized_entity,
RunWhenReady(base::BindOnce( scope, time_to_live, std::move(callback)));
&InstanceIDImpl::DoGetToken, weak_ptr_factory_.GetWeakPtr(),
authorized_entity, scope, time_to_live, options, std::move(callback)));
} }
void InstanceIDImpl::DoGetToken( void InstanceIDImpl::DoGetToken(
const std::string& authorized_entity, const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
GetTokenCallback callback) { GetTokenCallback callback) {
EnsureIDGenerated(); EnsureIDGenerated();
Handler()->GetToken( Handler()->GetToken(
app_id(), authorized_entity, scope, time_to_live, options, app_id(), authorized_entity, scope, time_to_live,
base::BindOnce(&InstanceIDImpl::OnGetTokenCompleted, base::BindOnce(&InstanceIDImpl::OnGetTokenCompleted,
weak_ptr_factory_.GetWeakPtr(), std::move(callback))); weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
} }

@ -5,7 +5,6 @@
#ifndef COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_IMPL_H_ #ifndef COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_IMPL_H_
#define COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_IMPL_H_ #define COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_IMPL_H_
#include <map>
#include <memory> #include <memory>
#include <string> #include <string>
@ -36,7 +35,6 @@ class InstanceIDImpl : public InstanceID {
void GetToken(const std::string& authorized_entity, void GetToken(const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags, std::set<Flags> flags,
GetTokenCallback callback) override; GetTokenCallback callback) override;
void ValidateToken(const std::string& authorized_entity, void ValidateToken(const std::string& authorized_entity,
@ -66,7 +64,6 @@ class InstanceIDImpl : public InstanceID {
void DoGetToken(const std::string& authorized_entity, void DoGetToken(const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
GetTokenCallback callback); GetTokenCallback callback);
void DoValidateToken(const std::string& authorized_entity, void DoValidateToken(const std::string& authorized_entity,
const std::string& scope, const std::string& scope,

@ -114,11 +114,6 @@ struct InstanceIDTokenInfo final : public RegistrationInfo {
// Not serialized/deserialized. // Not serialized/deserialized.
base::TimeDelta time_to_live; base::TimeDelta time_to_live;
// Allows including a small number of string key/value pairs that will be
// associated with the token and may be used in processing the request. These
// are not serialized/deserialized.
std::map<std::string, std::string> options;
private: private:
~InstanceIDTokenInfo() override; ~InstanceIDTokenInfo() override;
}; };

@ -83,11 +83,10 @@ class MockInstanceID : public InstanceID {
MOCK_METHOD1(GetID, void(GetIDCallback callback)); MOCK_METHOD1(GetID, void(GetIDCallback callback));
MOCK_METHOD1(GetCreationTime, void(GetCreationTimeCallback callback)); MOCK_METHOD1(GetCreationTime, void(GetCreationTimeCallback callback));
MOCK_METHOD6(GetToken, MOCK_METHOD5(GetToken,
void(const std::string& authorized_entity, void(const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags, std::set<Flags> flags,
GetTokenCallback callback)); GetTokenCallback callback));
MOCK_METHOD4(ValidateToken, MOCK_METHOD4(ValidateToken,

@ -192,7 +192,6 @@ void FCMNetworkHandler::StartListening() {
diagnostic_info_.instance_id_token_requested = base::Time::Now(); diagnostic_info_.instance_id_token_requested = base::Time::Now();
instance_id_driver_->GetInstanceID(app_id_)->GetToken( instance_id_driver_->GetInstanceID(app_id_)->GetToken(
sender_id_, kGCMScope, GetTimeToLive(sender_id_), sender_id_, kGCMScope, GetTimeToLive(sender_id_),
/*options=*/std::map<std::string, std::string>(),
/*flags=*/{InstanceID::Flags::kIsLazy}, /*flags=*/{InstanceID::Flags::kIsLazy},
base::BindRepeating(&FCMNetworkHandler::DidRetrieveToken, base::BindRepeating(&FCMNetworkHandler::DidRetrieveToken,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
@ -253,7 +252,6 @@ void FCMNetworkHandler::StartTokenValidation() {
diagnostic_info_.token_validation_requested_num++; diagnostic_info_.token_validation_requested_num++;
instance_id_driver_->GetInstanceID(app_id_)->GetToken( instance_id_driver_->GetInstanceID(app_id_)->GetToken(
sender_id_, kGCMScope, GetTimeToLive(sender_id_), sender_id_, kGCMScope, GetTimeToLive(sender_id_),
std::map<std::string, std::string>(),
/*flags=*/{InstanceID::Flags::kIsLazy}, /*flags=*/{InstanceID::Flags::kIsLazy},
base::BindOnce(&FCMNetworkHandler::DidReceiveTokenForValidation, base::BindOnce(&FCMNetworkHandler::DidReceiveTokenForValidation,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));

@ -64,11 +64,10 @@ class MockInstanceID : public InstanceID {
MOCK_METHOD1(GetID, void(GetIDCallback callback)); MOCK_METHOD1(GetID, void(GetIDCallback callback));
MOCK_METHOD1(GetCreationTime, void(GetCreationTimeCallback callback)); MOCK_METHOD1(GetCreationTime, void(GetCreationTimeCallback callback));
MOCK_METHOD6(GetToken, MOCK_METHOD5(GetToken,
void(const std::string& authorized_entity, void(const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags, std::set<Flags> flags,
GetTokenCallback callback)); GetTokenCallback callback));
MOCK_METHOD4(ValidateToken, MOCK_METHOD4(ValidateToken,
@ -207,8 +206,8 @@ class FCMNetworkHandlerTest : public testing::Test {
FCMSyncNetworkChannel::MessageCallback mock_on_message_callback) { FCMSyncNetworkChannel::MessageCallback mock_on_message_callback) {
std::unique_ptr<FCMNetworkHandler> handler = MakeHandler(); std::unique_ptr<FCMNetworkHandler> handler = MakeHandler();
handler->SetMessageReceiver(mock_on_message_callback); handler->SetMessageReceiver(mock_on_message_callback);
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _)) EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { .WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS); std::move(callback).Run("token", InstanceID::Result::SUCCESS);
}))); })));
handler->StartListening(); handler->StartListening();
@ -266,8 +265,8 @@ TEST_F(FCMNetworkHandlerTest, ShouldPassTheTokenOnceRecieved) {
handler->SetTokenReceiver(mock_on_token_callback.Get()); handler->SetTokenReceiver(mock_on_token_callback.Get());
// Check that the handler gets the token through GetToken. // Check that the handler gets the token through GetToken.
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _)) EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { .WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS); std::move(callback).Run("token", InstanceID::Result::SUCCESS);
}))); })));
EXPECT_CALL(mock_on_token_callback, Run("token")).Times(1); EXPECT_CALL(mock_on_token_callback, Run("token")).Times(1);
@ -280,11 +279,11 @@ TEST_F(FCMNetworkHandlerTest, ShouldPassTheTokenOnceSubscribed) {
MockOnTokenCallback mock_on_token_callback; MockOnTokenCallback mock_on_token_callback;
// Check that the handler gets the token through GetToken. // Check that the handler gets the token through GetToken.
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _)) EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { .WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS); std::move(callback).Run("token", InstanceID::Result::SUCCESS);
}))); })));
EXPECT_CALL(mock_on_token_callback, Run(_)).Times(0); EXPECT_CALL(mock_on_token_callback, Run).Times(0);
handler->StartListening(); handler->StartListening();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_CALL(mock_on_token_callback, Run("token")).Times(1); EXPECT_CALL(mock_on_token_callback, Run("token")).Times(1);
@ -296,10 +295,10 @@ TEST_F(FCMNetworkHandlerTest, ShouldNotInvokeMessageCallbackOnEmptyMessage) {
gcm::IncomingMessage message; gcm::IncomingMessage message;
std::unique_ptr<FCMNetworkHandler> handler = MakeHandler(); std::unique_ptr<FCMNetworkHandler> handler = MakeHandler();
EXPECT_CALL(mock_on_message_callback, Run(_, _, _, _)).Times(0); EXPECT_CALL(mock_on_message_callback, Run).Times(0);
handler->SetMessageReceiver(mock_on_message_callback.Get()); handler->SetMessageReceiver(mock_on_message_callback.Get());
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _)) EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { .WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS); std::move(callback).Run("token", InstanceID::Result::SUCCESS);
}))); })));
@ -341,7 +340,7 @@ TEST_F(FCMNetworkHandlerTest,
std::unique_ptr<FCMNetworkHandler> handler = std::unique_ptr<FCMNetworkHandler> handler =
MakeHandlerReadyForMessage(mock_on_message_callback.Get()); MakeHandlerReadyForMessage(mock_on_message_callback.Get());
EXPECT_CALL(mock_on_message_callback, Run(_, _, _, _)).Times(0); EXPECT_CALL(mock_on_message_callback, Run).Times(0);
handler->OnMessage(kInvalidationsAppId, message); handler->OnMessage(kInvalidationsAppId, message);
EXPECT_THAT( EXPECT_THAT(
histogram_tester.GetAllSamples("FCMInvalidations.FCMMessageStatus"), histogram_tester.GetAllSamples("FCMInvalidations.FCMMessageStatus"),
@ -360,7 +359,7 @@ TEST_F(FCMNetworkHandlerTest,
std::unique_ptr<FCMNetworkHandler> handler = std::unique_ptr<FCMNetworkHandler> handler =
MakeHandlerReadyForMessage(mock_on_message_callback.Get()); MakeHandlerReadyForMessage(mock_on_message_callback.Get());
EXPECT_CALL(mock_on_message_callback, Run(_, _, _, _)).Times(0); EXPECT_CALL(mock_on_message_callback, Run).Times(0);
handler->OnMessage(kInvalidationsAppId, message); handler->OnMessage(kInvalidationsAppId, message);
EXPECT_THAT( EXPECT_THAT(
histogram_tester.GetAllSamples("FCMInvalidations.FCMMessageStatus"), histogram_tester.GetAllSamples("FCMInvalidations.FCMMessageStatus"),
@ -379,7 +378,7 @@ TEST_F(FCMNetworkHandlerTest,
std::unique_ptr<FCMNetworkHandler> handler = std::unique_ptr<FCMNetworkHandler> handler =
MakeHandlerReadyForMessage(mock_on_message_callback.Get()); MakeHandlerReadyForMessage(mock_on_message_callback.Get());
EXPECT_CALL(mock_on_message_callback, Run(_, _, _, _)).Times(0); EXPECT_CALL(mock_on_message_callback, Run).Times(0);
handler->OnMessage(kInvalidationsAppId, message); handler->OnMessage(kInvalidationsAppId, message);
EXPECT_THAT( EXPECT_THAT(
histogram_tester.GetAllSamples("FCMInvalidations.FCMMessageStatus"), histogram_tester.GetAllSamples("FCMInvalidations.FCMMessageStatus"),
@ -397,8 +396,8 @@ TEST_F(FCMNetworkHandlerTest, ShouldRequestTokenImmediatellyEvenIfSaved) {
handler->SetTokenReceiver(mock_on_token_callback.Get()); handler->SetTokenReceiver(mock_on_token_callback.Get());
// Check that after StartListening we receive the token and store it. // Check that after StartListening we receive the token and store it.
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _)) EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { .WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS); std::move(callback).Run("token", InstanceID::Result::SUCCESS);
}))); })));
EXPECT_CALL(mock_on_token_callback, Run("token")).Times(1); EXPECT_CALL(mock_on_token_callback, Run("token")).Times(1);
@ -413,8 +412,8 @@ TEST_F(FCMNetworkHandlerTest, ShouldRequestTokenImmediatellyEvenIfSaved) {
// Check that after StartListening the token will be requested, depite we have // Check that after StartListening the token will be requested, depite we have
// saved token. // saved token.
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _)) EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { .WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token_new", InstanceID::Result::SUCCESS); std::move(callback).Run("token_new", InstanceID::Result::SUCCESS);
}))); })));
EXPECT_CALL(mock_on_token_callback, Run("token_new")).Times(1); EXPECT_CALL(mock_on_token_callback, Run("token_new")).Times(1);
@ -431,23 +430,23 @@ TEST_F(FCMNetworkHandlerTest, ShouldScheduleTokenValidationAndActOnNewToken) {
// Checking that after start listening the token will be requested // Checking that after start listening the token will be requested
// and passed to the appropriate token receiver. // and passed to the appropriate token receiver.
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _)) EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { .WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS); std::move(callback).Run("token", InstanceID::Result::SUCCESS);
}))); })));
EXPECT_CALL(*mock_instance_id(), ValidateToken(_, _, _, _)).Times(0); EXPECT_CALL(*mock_instance_id(), ValidateToken).Times(0);
EXPECT_CALL(mock_on_token_callback, Run("token")).Times(1); EXPECT_CALL(mock_on_token_callback, Run("token")).Times(1);
handler->StartListening(); handler->StartListening();
testing::Mock::VerifyAndClearExpectations(mock_instance_id()); testing::Mock::VerifyAndClearExpectations(mock_instance_id());
// Adjust timers and check that validation will happen in time. // Adjust timers and check that validation will happen in time.
// The old token was invalid, so token listener shold be informed. // The old token was invalid, so token listener should be informed.
const base::TimeDelta time_to_validation = base::TimeDelta::FromHours(24); const base::TimeDelta time_to_validation = base::TimeDelta::FromHours(24);
task_runner->FastForwardBy(time_to_validation - task_runner->FastForwardBy(time_to_validation -
base::TimeDelta::FromSeconds(1)); base::TimeDelta::FromSeconds(1));
// But when it is time, validation happens. // But when it is time, validation happens.
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _)) EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { .WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token_new", InstanceID::Result::SUCCESS); std::move(callback).Run("token_new", InstanceID::Result::SUCCESS);
}))); })));
EXPECT_CALL(mock_on_token_callback, Run("token_new")).Times(1); EXPECT_CALL(mock_on_token_callback, Run("token_new")).Times(1);
@ -464,27 +463,27 @@ TEST_F(FCMNetworkHandlerTest,
// Checking that after start listening the token will be requested // Checking that after start listening the token will be requested
// and passed to the appropriate token receiver // and passed to the appropriate token receiver
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _)) EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { .WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS); std::move(callback).Run("token", InstanceID::Result::SUCCESS);
}))); })));
EXPECT_CALL(*mock_instance_id(), ValidateToken(_, _, _, _)).Times(0); EXPECT_CALL(*mock_instance_id(), ValidateToken).Times(0);
EXPECT_CALL(mock_on_token_callback, Run("token")).Times(1); EXPECT_CALL(mock_on_token_callback, Run("token")).Times(1);
handler->StartListening(); handler->StartListening();
testing::Mock::VerifyAndClearExpectations(mock_instance_id()); testing::Mock::VerifyAndClearExpectations(mock_instance_id());
// Adjust timers and check that validation will happen in time. // Adjust timers and check that validation will happen in time.
// The old token is valid, so no token listener shold be informed. // The old token is valid, so no token listener should be informed.
const base::TimeDelta time_to_validation = base::TimeDelta::FromHours(24); const base::TimeDelta time_to_validation = base::TimeDelta::FromHours(24);
task_runner->FastForwardBy(time_to_validation - task_runner->FastForwardBy(time_to_validation -
base::TimeDelta::FromSeconds(1)); base::TimeDelta::FromSeconds(1));
// But when it is time, validation happens. // But when it is time, validation happens.
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _)) EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { .WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS); std::move(callback).Run("token", InstanceID::Result::SUCCESS);
}))); })));
EXPECT_CALL(mock_on_token_callback, Run(_)).Times(0); EXPECT_CALL(mock_on_token_callback, Run).Times(0);
task_runner->FastForwardBy(base::TimeDelta::FromSeconds(1)); task_runner->FastForwardBy(base::TimeDelta::FromSeconds(1));
} }
@ -492,7 +491,7 @@ TEST_F(FCMNetworkHandlerTestWithTTL, ShouldProvideTTLWithSyncSenderID) {
EXPECT_CALL( EXPECT_CALL(
*mock_instance_id(), *mock_instance_id(),
GetToken(_, _, Eq(base::TimeDelta::FromSeconds(kTimeToLiveInSeconds)), _, GetToken(_, _, Eq(base::TimeDelta::FromSeconds(kTimeToLiveInSeconds)), _,
_, _)); _));
MakeHandler(/*sender_id=*/"8181035976")->StartListening(); MakeHandler(/*sender_id=*/"8181035976")->StartListening();
} }
@ -500,13 +499,12 @@ TEST_F(FCMNetworkHandlerTestWithTTL, ShouldProvideTTLWithPolicySenderID) {
EXPECT_CALL( EXPECT_CALL(
*mock_instance_id(), *mock_instance_id(),
GetToken(_, _, Eq(base::TimeDelta::FromSeconds(kTimeToLiveInSeconds)), _, GetToken(_, _, Eq(base::TimeDelta::FromSeconds(kTimeToLiveInSeconds)), _,
_, _)); _));
MakeHandler(/*sender_id=*/"1013309121859")->StartListening(); MakeHandler(/*sender_id=*/"1013309121859")->StartListening();
} }
TEST_F(FCMNetworkHandlerTestWithTTL, ShouldNotProvideTTLWithFakeSenderID) { TEST_F(FCMNetworkHandlerTestWithTTL, ShouldNotProvideTTLWithFakeSenderID) {
EXPECT_CALL(*mock_instance_id(), EXPECT_CALL(*mock_instance_id(), GetToken(_, _, Eq(base::TimeDelta()), _, _));
GetToken(_, _, Eq(base::TimeDelta()), _, _, _));
MakeHandler(/*sender_id=*/"fake_sender_id")->StartListening(); MakeHandler(/*sender_id=*/"fake_sender_id")->StartListening();
} }

@ -204,7 +204,6 @@ void FCMHandler::StartTokenFetch(
instance_id_driver_->GetInstanceID(app_id_)->GetToken( instance_id_driver_->GetInstanceID(app_id_)->GetToken(
sender_id_, instance_id::kGCMScope, sender_id_, instance_id::kGCMScope,
/*time_to_live=*/base::TimeDelta::FromSeconds(kInstanceIDTokenTTLSeconds), /*time_to_live=*/base::TimeDelta::FromSeconds(kInstanceIDTokenTTLSeconds),
/*options=*/std::map<std::string, std::string>(),
/*flags=*/{instance_id::InstanceID::Flags::kIsLazy}, std::move(callback)); /*flags=*/{instance_id::InstanceID::Flags::kIsLazy}, std::move(callback));
} }

@ -4,7 +4,6 @@
#include "components/sync/invalidations/fcm_handler.h" #include "components/sync/invalidations/fcm_handler.h"
#include <map>
#include <set> #include <set>
#include <string> #include <string>
#include <utility> #include <utility>
@ -53,7 +52,6 @@ class MockInstanceID : public InstanceID {
(const std::string& authorized_entity, (const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live,
(const std::map<std::string, std::string>& options),
std::set<Flags> flags, std::set<Flags> flags,
GetTokenCallback callback), GetTokenCallback callback),
(override)); (override));
@ -134,7 +132,7 @@ class FCMHandlerTest : public testing::Test {
TEST_F(FCMHandlerTest, ShouldReturnValidToken) { TEST_F(FCMHandlerTest, ShouldReturnValidToken) {
// Check that the handler gets the token through GetToken. // Check that the handler gets the token through GetToken.
EXPECT_CALL(mock_instance_id_, GetToken) EXPECT_CALL(mock_instance_id_, GetToken)
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { .WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS); std::move(callback).Run("token", InstanceID::Result::SUCCESS);
}))); })));
@ -163,7 +161,7 @@ TEST_F(FCMHandlerTest, ShouldNotifyOnTokenChange) {
// Check that the handler gets the token through GetToken. // Check that the handler gets the token through GetToken.
ON_CALL(mock_instance_id_, GetToken) ON_CALL(mock_instance_id_, GetToken)
.WillByDefault( .WillByDefault(
WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS); std::move(callback).Run("token", InstanceID::Result::SUCCESS);
}))); })));
@ -180,7 +178,7 @@ TEST_F(FCMHandlerTest, ShouldScheduleTokenValidationAndActOnNewToken) {
// Check that the handler gets the token through GetToken and notifies the // Check that the handler gets the token through GetToken and notifies the
// observer. // observer.
EXPECT_CALL(mock_instance_id_, GetToken) EXPECT_CALL(mock_instance_id_, GetToken)
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { .WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS); std::move(callback).Run("token", InstanceID::Result::SUCCESS);
}))); })));
EXPECT_CALL(mock_token_observer, OnFCMRegistrationTokenChanged()).Times(1); EXPECT_CALL(mock_token_observer, OnFCMRegistrationTokenChanged()).Times(1);
@ -193,7 +191,7 @@ TEST_F(FCMHandlerTest, ShouldScheduleTokenValidationAndActOnNewToken) {
base::TimeDelta::FromSeconds(1)); base::TimeDelta::FromSeconds(1));
// When it is time, validation happens. // When it is time, validation happens.
EXPECT_CALL(mock_instance_id_, GetToken) EXPECT_CALL(mock_instance_id_, GetToken)
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { .WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("new token", InstanceID::Result::SUCCESS); std::move(callback).Run("new token", InstanceID::Result::SUCCESS);
}))); })));
EXPECT_CALL(mock_token_observer, OnFCMRegistrationTokenChanged()).Times(1); EXPECT_CALL(mock_token_observer, OnFCMRegistrationTokenChanged()).Times(1);
@ -209,7 +207,7 @@ TEST_F(FCMHandlerTest, ShouldScheduleTokenValidationAndNotActOnSameToken) {
// Check that the handler gets the token through GetToken and notifies the // Check that the handler gets the token through GetToken and notifies the
// observer. // observer.
EXPECT_CALL(mock_instance_id_, GetToken) EXPECT_CALL(mock_instance_id_, GetToken)
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { .WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS); std::move(callback).Run("token", InstanceID::Result::SUCCESS);
}))); })));
EXPECT_CALL(mock_token_observer, OnFCMRegistrationTokenChanged()).Times(1); EXPECT_CALL(mock_token_observer, OnFCMRegistrationTokenChanged()).Times(1);
@ -222,7 +220,7 @@ TEST_F(FCMHandlerTest, ShouldScheduleTokenValidationAndNotActOnSameToken) {
base::TimeDelta::FromSeconds(1)); base::TimeDelta::FromSeconds(1));
// When it is time, validation happens. // When it is time, validation happens.
EXPECT_CALL(mock_instance_id_, GetToken) EXPECT_CALL(mock_instance_id_, GetToken)
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { .WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS); std::move(callback).Run("token", InstanceID::Result::SUCCESS);
}))); })));
EXPECT_CALL(mock_token_observer, OnFCMRegistrationTokenChanged()).Times(0); EXPECT_CALL(mock_token_observer, OnFCMRegistrationTokenChanged()).Times(0);
@ -234,7 +232,7 @@ TEST_F(FCMHandlerTest, ShouldScheduleTokenValidationAndNotActOnSameToken) {
TEST_F(FCMHandlerTest, ShouldClearTokenOnStopListeningPermanently) { TEST_F(FCMHandlerTest, ShouldClearTokenOnStopListeningPermanently) {
// Check that the handler gets the token through GetToken. // Check that the handler gets the token through GetToken.
EXPECT_CALL(mock_instance_id_, GetToken) EXPECT_CALL(mock_instance_id_, GetToken)
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) { .WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS); std::move(callback).Run("token", InstanceID::Result::SUCCESS);
}))); })));
fcm_handler_.StartListening(); fcm_handler_.StartListening();

@ -59,7 +59,7 @@ class FCMHandler : public gcm::GCMAppHandler, public Registration {
instance_id_->GetToken( instance_id_->GetToken(
kFCMSenderId, instance_id::kGCMScope, kFCMSenderId, instance_id::kGCMScope,
/*time_to_live=*/base::TimeDelta(), /*options=*/{}, /*time_to_live=*/base::TimeDelta(),
/*flags=*/{}, /*flags=*/{},
base::BindOnce(&FCMHandler::GetTokenComplete, base::Unretained(this))); base::BindOnce(&FCMHandler::GetTokenComplete, base::Unretained(this)));
} }

@ -21,8 +21,6 @@ const char kInstanceIDKey[] = "appid";
const char kScopeKey[] = "scope"; const char kScopeKey[] = "scope";
const char kExtraScopeKey[] = "X-scope"; const char kExtraScopeKey[] = "X-scope";
const char kTimeToLiveSecondsKey[] = "ttl"; const char kTimeToLiveSecondsKey[] = "ttl";
// Prefix that needs to be added for each option key.
const char kOptionKeyPrefix[] = "X-";
} // namespace } // namespace
@ -31,14 +29,12 @@ InstanceIDGetTokenRequestHandler::InstanceIDGetTokenRequestHandler(
const std::string& authorized_entity, const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
int gcm_version, int gcm_version,
base::TimeDelta time_to_live, base::TimeDelta time_to_live)
const std::map<std::string, std::string>& options)
: instance_id_(instance_id), : instance_id_(instance_id),
authorized_entity_(authorized_entity), authorized_entity_(authorized_entity),
scope_(scope), scope_(scope),
gcm_version_(gcm_version), gcm_version_(gcm_version),
time_to_live_(time_to_live), time_to_live_(time_to_live) {
options_(options) {
DCHECK(!instance_id.empty()); DCHECK(!instance_id.empty());
DCHECK(!authorized_entity.empty()); DCHECK(!authorized_entity.empty());
DCHECK(!scope.empty()); DCHECK(!scope.empty());
@ -49,8 +45,6 @@ InstanceIDGetTokenRequestHandler::~InstanceIDGetTokenRequestHandler() {}
void InstanceIDGetTokenRequestHandler::BuildRequestBody(std::string* body) { void InstanceIDGetTokenRequestHandler::BuildRequestBody(std::string* body) {
BuildFormEncoding(kScopeKey, scope_, body); BuildFormEncoding(kScopeKey, scope_, body);
BuildFormEncoding(kExtraScopeKey, scope_, body); BuildFormEncoding(kExtraScopeKey, scope_, body);
for (auto iter = options_.begin(); iter != options_.end(); ++iter)
BuildFormEncoding(kOptionKeyPrefix + iter->first, iter->second, body);
BuildFormEncoding(kGMSVersionKey, base::NumberToString(gcm_version_), body); BuildFormEncoding(kGMSVersionKey, base::NumberToString(gcm_version_), body);
BuildFormEncoding(kInstanceIDKey, instance_id_, body); BuildFormEncoding(kInstanceIDKey, instance_id_, body);
BuildFormEncoding(kAuthorizedEntityKey, authorized_entity_, body); BuildFormEncoding(kAuthorizedEntityKey, authorized_entity_, body);

@ -5,7 +5,6 @@
#ifndef GOOGLE_APIS_GCM_ENGINE_INSTANCE_ID_GET_TOKEN_REQUEST_HANDLER_H_ #ifndef GOOGLE_APIS_GCM_ENGINE_INSTANCE_ID_GET_TOKEN_REQUEST_HANDLER_H_
#define GOOGLE_APIS_GCM_ENGINE_INSTANCE_ID_GET_TOKEN_REQUEST_HANDLER_H_ #define GOOGLE_APIS_GCM_ENGINE_INSTANCE_ID_GET_TOKEN_REQUEST_HANDLER_H_
#include <map>
#include <string> #include <string>
#include "base/macros.h" #include "base/macros.h"
@ -18,13 +17,11 @@ namespace gcm {
class GCM_EXPORT InstanceIDGetTokenRequestHandler class GCM_EXPORT InstanceIDGetTokenRequestHandler
: public RegistrationRequest::CustomRequestHandler { : public RegistrationRequest::CustomRequestHandler {
public: public:
InstanceIDGetTokenRequestHandler( InstanceIDGetTokenRequestHandler(const std::string& instance_id,
const std::string& instance_id, const std::string& authorized_entity,
const std::string& authorized_entity, const std::string& scope,
const std::string& scope, int gcm_version,
int gcm_version, base::TimeDelta time_to_live);
base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options);
~InstanceIDGetTokenRequestHandler() override; ~InstanceIDGetTokenRequestHandler() override;
// RegistrationRequest overrides: // RegistrationRequest overrides:
@ -38,7 +35,6 @@ class GCM_EXPORT InstanceIDGetTokenRequestHandler
std::string scope_; std::string scope_;
int gcm_version_; int gcm_version_;
base::TimeDelta time_to_live_; base::TimeDelta time_to_live_;
std::map<std::string, std::string> options_;
DISALLOW_COPY_AND_ASSIGN(InstanceIDGetTokenRequestHandler); DISALLOW_COPY_AND_ASSIGN(InstanceIDGetTokenRequestHandler);
}; };

@ -56,7 +56,6 @@ class RegistrationRequestTest : public GCMRequestTestBase {
RegistrationRequest::Status status_; RegistrationRequest::Status status_;
std::string registration_id_; std::string registration_id_;
bool callback_called_; bool callback_called_;
std::map<std::string, std::string> extras_;
std::unique_ptr<RegistrationRequest> request_; std::unique_ptr<RegistrationRequest> request_;
FakeGCMStatsRecorder recorder_; FakeGCMStatsRecorder recorder_;
}; };
@ -404,8 +403,7 @@ class InstanceIDGetTokenRequestTest : public RegistrationRequestTest {
const std::string& instance_id, const std::string& instance_id,
const std::string& authorized_entity, const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live);
const std::map<std::string, std::string>& options);
}; };
InstanceIDGetTokenRequestTest::InstanceIDGetTokenRequestTest() { InstanceIDGetTokenRequestTest::InstanceIDGetTokenRequestTest() {
@ -419,16 +417,14 @@ void InstanceIDGetTokenRequestTest::CreateRequest(
const std::string& instance_id, const std::string& instance_id,
const std::string& authorized_entity, const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
base::TimeDelta time_to_live, base::TimeDelta time_to_live) {
const std::map<std::string, std::string>& options) {
std::string category = use_subtype ? kProductCategoryForSubtypes : kAppId; std::string category = use_subtype ? kProductCategoryForSubtypes : kAppId;
std::string subtype = use_subtype ? kAppId : std::string(); std::string subtype = use_subtype ? kAppId : std::string();
RegistrationRequest::RequestInfo request_info(kAndroidId, kSecurityToken, RegistrationRequest::RequestInfo request_info(kAndroidId, kSecurityToken,
category, subtype); category, subtype);
std::unique_ptr<InstanceIDGetTokenRequestHandler> request_handler( std::unique_ptr<InstanceIDGetTokenRequestHandler> request_handler(
new InstanceIDGetTokenRequestHandler(instance_id, authorized_entity, new InstanceIDGetTokenRequestHandler(instance_id, authorized_entity,
scope, kGCMVersion, time_to_live, scope, kGCMVersion, time_to_live));
options));
request_.reset(new RegistrationRequest( request_.reset(new RegistrationRequest(
GURL(kRegistrationURL), request_info, std::move(request_handler), GURL(kRegistrationURL), request_info, std::move(request_handler),
GetBackoffPolicy(), GetBackoffPolicy(),
@ -439,12 +435,9 @@ void InstanceIDGetTokenRequestTest::CreateRequest(
} }
TEST_F(InstanceIDGetTokenRequestTest, RequestSuccessful) { TEST_F(InstanceIDGetTokenRequestTest, RequestSuccessful) {
std::map<std::string, std::string> options;
options["Foo"] = "Bar";
set_max_retry_count(0); set_max_retry_count(0);
CreateRequest(false /* use_subtype */, kInstanceId, kDeveloperId, kScope, CreateRequest(false /* use_subtype */, kInstanceId, kDeveloperId, kScope,
/*time_to_live=*/base::TimeDelta(), options); /*time_to_live=*/base::TimeDelta());
request_->Start(); request_->Start();
SetResponseForURLAndComplete(kRegistrationURL, net::HTTP_OK, "token=2501"); SetResponseForURLAndComplete(kRegistrationURL, net::HTTP_OK, "token=2501");
@ -454,10 +447,8 @@ TEST_F(InstanceIDGetTokenRequestTest, RequestSuccessful) {
} }
TEST_F(InstanceIDGetTokenRequestTest, RequestDataAndURL) { TEST_F(InstanceIDGetTokenRequestTest, RequestDataAndURL) {
std::map<std::string, std::string> options;
options["Foo"] = "Bar";
CreateRequest(false /* use_subtype */, kInstanceId, kDeveloperId, kScope, CreateRequest(false /* use_subtype */, kInstanceId, kDeveloperId, kScope,
/*time_to_live=*/base::TimeDelta(), options); /*time_to_live=*/base::TimeDelta());
request_->Start(); request_->Start();
// Verify that the no-cookie flag is set. // Verify that the no-cookie flag is set.
@ -489,7 +480,6 @@ TEST_F(InstanceIDGetTokenRequestTest, RequestDataAndURL) {
expected_pairs["appid"] = kInstanceId; expected_pairs["appid"] = kInstanceId;
expected_pairs["scope"] = kScope; expected_pairs["scope"] = kScope;
expected_pairs["X-scope"] = kScope; expected_pairs["X-scope"] = kScope;
expected_pairs["X-Foo"] = "Bar";
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(
VerifyFetcherUploadDataForURL(kRegistrationURL, &expected_pairs)); VerifyFetcherUploadDataForURL(kRegistrationURL, &expected_pairs));
@ -497,8 +487,7 @@ TEST_F(InstanceIDGetTokenRequestTest, RequestDataAndURL) {
TEST_F(InstanceIDGetTokenRequestTest, RequestDataWithTTL) { TEST_F(InstanceIDGetTokenRequestTest, RequestDataWithTTL) {
CreateRequest(false, kInstanceId, kDeveloperId, kScope, CreateRequest(false, kInstanceId, kDeveloperId, kScope,
/*time_to_live=*/base::TimeDelta::FromSeconds(100), /*time_to_live=*/base::TimeDelta::FromSeconds(100));
/*options=*/{});
request_->Start(); request_->Start();
// Same as RequestDataAndURL except "ttl" and "X-Foo". // Same as RequestDataAndURL except "ttl" and "X-Foo".
@ -517,10 +506,8 @@ TEST_F(InstanceIDGetTokenRequestTest, RequestDataWithTTL) {
} }
TEST_F(InstanceIDGetTokenRequestTest, RequestDataWithSubtype) { TEST_F(InstanceIDGetTokenRequestTest, RequestDataWithSubtype) {
std::map<std::string, std::string> options;
options["Foo"] = "Bar";
CreateRequest(true /* use_subtype */, kInstanceId, kDeveloperId, kScope, CreateRequest(true /* use_subtype */, kInstanceId, kDeveloperId, kScope,
/*time_to_live=*/base::TimeDelta(), options); /*time_to_live=*/base::TimeDelta());
request_->Start(); request_->Start();
// Same as RequestDataAndURL except "app" and "X-subtype". // Same as RequestDataAndURL except "app" and "X-subtype".
@ -533,7 +520,6 @@ TEST_F(InstanceIDGetTokenRequestTest, RequestDataWithSubtype) {
expected_pairs["appid"] = kInstanceId; expected_pairs["appid"] = kInstanceId;
expected_pairs["scope"] = kScope; expected_pairs["scope"] = kScope;
expected_pairs["X-scope"] = kScope; expected_pairs["X-scope"] = kScope;
expected_pairs["X-Foo"] = "Bar";
// Verify data was formatted properly. // Verify data was formatted properly.
std::string upload_data; std::string upload_data;
@ -552,9 +538,8 @@ TEST_F(InstanceIDGetTokenRequestTest, RequestDataWithSubtype) {
} }
TEST_F(InstanceIDGetTokenRequestTest, ResponseHttpStatusNotOK) { TEST_F(InstanceIDGetTokenRequestTest, ResponseHttpStatusNotOK) {
std::map<std::string, std::string> options;
CreateRequest(false /* use_subtype */, kInstanceId, kDeveloperId, kScope, CreateRequest(false /* use_subtype */, kInstanceId, kDeveloperId, kScope,
/*time_to_live=*/base::TimeDelta(), options); /*time_to_live=*/base::TimeDelta());
request_->Start(); request_->Start();
SetResponseForURLAndComplete(kRegistrationURL, net::HTTP_UNAUTHORIZED, SetResponseForURLAndComplete(kRegistrationURL, net::HTTP_UNAUTHORIZED,

@ -2294,7 +2294,10 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</histogram> </histogram>
<histogram name="Extensions.InstanceID.GetToken.OptionsCount" units="options" <histogram name="Extensions.InstanceID.GetToken.OptionsCount" units="options"
expires_after="M91"> expires_after="M89">
<obsolete>
Deprecated as of 11/2020
</obsolete>
<owner>peter@chromium.org</owner> <owner>peter@chromium.org</owner>
<owner>knollr@chromium.org</owner> <owner>knollr@chromium.org</owner>
<summary> <summary>

@ -7252,7 +7252,10 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</histogram> </histogram>
<histogram name="InstanceID.GetToken.OptionsCount" units="options" <histogram name="InstanceID.GetToken.OptionsCount" units="options"
expires_after="M91"> expires_after="M89">
<obsolete>
Deprecated as of 11/2020
</obsolete>
<owner>peter@chromium.org</owner> <owner>peter@chromium.org</owner>
<owner>knollr@chromium.org</owner> <owner>knollr@chromium.org</owner>
<summary> <summary>