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

@ -108,17 +108,9 @@ ExtensionFunction::ResponseAction InstanceIDGetTokenFunction::DoWork() {
api::instance_id::GetToken::Params::Create(*args_);
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(
params->get_token_params.authorized_entity,
params->get_token_params.scope, /*time_to_live=*/base::TimeDelta(),
options,
/*flags=*/{},
base::BindOnce(&InstanceIDGetTokenFunction::GetTokenCompleted, this));

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

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

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

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

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

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

@ -245,7 +245,6 @@ void SyncTest::FakeInstanceID::GetToken(
const std::string& authorized_entity,
const std::string& scope,
base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags,
GetTokenCallback callback) {
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,
const std::string& scope,
base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags,
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."
},
"options": {
"deprecated": "options are deprecated and will be ignored.",
"type": "object",
"properties": {},
"additionalProperties": {

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

@ -947,7 +947,7 @@ void GCMClientImpl::Register(
instance_id_token_info->authorized_entity,
instance_id_token_info->scope,
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 + "/" +
instance_id_token_info->scope;
}

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

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

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

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

@ -4,8 +4,6 @@
package org.chromium.components.gcm_driver.instance_id;
import android.os.Bundle;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
@ -100,19 +98,15 @@ public class InstanceIDBridge {
}.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
* 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
private void getToken(final int requestId, final String authorizedEntity, final String scope,
String[] extrasStrings, 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]);
}
private void getToken(
final int requestId, final String authorizedEntity, final String scope, int flags) {
new BridgeAsyncTask<String>() {
@Override
protected String doBackgroundWork() {
@ -127,7 +121,7 @@ public class InstanceIDBridge {
SubscriptionFlagManager.buildSubscriptionUniqueId(
mSubtype, authorizedEntity),
flags);
return mInstanceID.getToken(authorizedEntity, scope, extras);
return mInstanceID.getToken(authorizedEntity, scope);
} catch (IOException ex) {
return "";
}

@ -97,11 +97,6 @@ public class InstanceIDWithSubtype {
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. */
@VisibleForTesting
public interface FakeFactory {

@ -4,7 +4,6 @@
package org.chromium.components.gcm_driver.instance_id;
import android.os.Bundle;
import android.os.Looper;
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
// 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).
if (Looper.getMainLooper() == Looper.myLooper())
if (Looper.getMainLooper() == Looper.myLooper()) {
throw new AssertionError(InstanceID.ERROR_MAIN_THREAD);
}
}
@Override
@ -112,8 +112,9 @@ public class FakeInstanceIDWithSubtype extends InstanceIDWithSubtype {
public String getId() {
// InstanceID.getId sometimes triggers a strict mode violation if it's called on the main
// thread, by reading from SharedPreferences.
if (Looper.getMainLooper() == Looper.myLooper())
if (Looper.getMainLooper() == Looper.myLooper()) {
throw new AssertionError(InstanceID.ERROR_MAIN_THREAD);
}
if (mId == null) {
mCreationTime = System.currentTimeMillis();
@ -126,20 +127,15 @@ public class FakeInstanceIDWithSubtype extends InstanceIDWithSubtype {
public long getCreationTime() {
// InstanceID.getCreationTime sometimes triggers a strict mode violation if it's called on
// the main thread, by reading from SharedPreferences.
if (Looper.getMainLooper() == Looper.myLooper())
if (Looper.getMainLooper() == Looper.myLooper()) {
throw new AssertionError(InstanceID.ERROR_MAIN_THREAD);
}
return mCreationTime;
}
@Override
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.
if (Looper.getMainLooper() == Looper.myLooper()) {
throw new IOException(InstanceID.ERROR_MAIN_THREAD);

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

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

@ -5,7 +5,6 @@
#ifndef COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_
#define COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_H_
#include <map>
#include <memory>
#include <set>
#include <string>
@ -108,15 +107,11 @@ class InstanceID {
// |scope|: identifies authorized actions that the authorized entity can take.
// E.g. for sending GCM messages, "GCM" scope should be used.
// |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.
// |callback|: to be called once the asynchronous operation is done.
virtual void GetToken(const std::string& authorized_entity,
const std::string& scope,
base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags,
GetTokenCallback callback) = 0;

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

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

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

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

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

@ -114,11 +114,6 @@ struct InstanceIDTokenInfo final : public RegistrationInfo {
// Not serialized/deserialized.
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:
~InstanceIDTokenInfo() override;
};

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

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

@ -64,11 +64,10 @@ class MockInstanceID : public InstanceID {
MOCK_METHOD1(GetID, void(GetIDCallback callback));
MOCK_METHOD1(GetCreationTime, void(GetCreationTimeCallback callback));
MOCK_METHOD6(GetToken,
MOCK_METHOD5(GetToken,
void(const std::string& authorized_entity,
const std::string& scope,
base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags,
GetTokenCallback callback));
MOCK_METHOD4(ValidateToken,
@ -207,8 +206,8 @@ class FCMNetworkHandlerTest : public testing::Test {
FCMSyncNetworkChannel::MessageCallback mock_on_message_callback) {
std::unique_ptr<FCMNetworkHandler> handler = MakeHandler();
handler->SetMessageReceiver(mock_on_message_callback);
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _))
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) {
EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS);
})));
handler->StartListening();
@ -266,8 +265,8 @@ TEST_F(FCMNetworkHandlerTest, ShouldPassTheTokenOnceRecieved) {
handler->SetTokenReceiver(mock_on_token_callback.Get());
// Check that the handler gets the token through GetToken.
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _))
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) {
EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS);
})));
EXPECT_CALL(mock_on_token_callback, Run("token")).Times(1);
@ -280,11 +279,11 @@ TEST_F(FCMNetworkHandlerTest, ShouldPassTheTokenOnceSubscribed) {
MockOnTokenCallback mock_on_token_callback;
// Check that the handler gets the token through GetToken.
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _))
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) {
EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
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();
base::RunLoop().RunUntilIdle();
EXPECT_CALL(mock_on_token_callback, Run("token")).Times(1);
@ -296,10 +295,10 @@ TEST_F(FCMNetworkHandlerTest, ShouldNotInvokeMessageCallbackOnEmptyMessage) {
gcm::IncomingMessage message;
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());
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _))
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) {
EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS);
})));
@ -341,7 +340,7 @@ TEST_F(FCMNetworkHandlerTest,
std::unique_ptr<FCMNetworkHandler> handler =
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);
EXPECT_THAT(
histogram_tester.GetAllSamples("FCMInvalidations.FCMMessageStatus"),
@ -360,7 +359,7 @@ TEST_F(FCMNetworkHandlerTest,
std::unique_ptr<FCMNetworkHandler> handler =
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);
EXPECT_THAT(
histogram_tester.GetAllSamples("FCMInvalidations.FCMMessageStatus"),
@ -379,7 +378,7 @@ TEST_F(FCMNetworkHandlerTest,
std::unique_ptr<FCMNetworkHandler> handler =
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);
EXPECT_THAT(
histogram_tester.GetAllSamples("FCMInvalidations.FCMMessageStatus"),
@ -397,8 +396,8 @@ TEST_F(FCMNetworkHandlerTest, ShouldRequestTokenImmediatellyEvenIfSaved) {
handler->SetTokenReceiver(mock_on_token_callback.Get());
// Check that after StartListening we receive the token and store it.
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _))
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) {
EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token", InstanceID::Result::SUCCESS);
})));
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
// saved token.
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _))
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) {
EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token_new", InstanceID::Result::SUCCESS);
})));
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
// and passed to the appropriate token receiver.
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _))
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) {
EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
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);
handler->StartListening();
testing::Mock::VerifyAndClearExpectations(mock_instance_id());
// 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);
task_runner->FastForwardBy(time_to_validation -
base::TimeDelta::FromSeconds(1));
// But when it is time, validation happens.
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _))
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) {
EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
std::move(callback).Run("token_new", InstanceID::Result::SUCCESS);
})));
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
// and passed to the appropriate token receiver
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _))
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) {
EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
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);
handler->StartListening();
testing::Mock::VerifyAndClearExpectations(mock_instance_id());
// 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);
task_runner->FastForwardBy(time_to_validation -
base::TimeDelta::FromSeconds(1));
// But when it is time, validation happens.
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, _, _, _, _))
.WillOnce(WithArg<5>(Invoke([](InstanceID::GetTokenCallback callback) {
EXPECT_CALL(*mock_instance_id(), GetToken)
.WillOnce(WithArg<4>(Invoke([](InstanceID::GetTokenCallback callback) {
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));
}
@ -492,7 +491,7 @@ TEST_F(FCMNetworkHandlerTestWithTTL, ShouldProvideTTLWithSyncSenderID) {
EXPECT_CALL(
*mock_instance_id(),
GetToken(_, _, Eq(base::TimeDelta::FromSeconds(kTimeToLiveInSeconds)), _,
_, _));
_));
MakeHandler(/*sender_id=*/"8181035976")->StartListening();
}
@ -500,13 +499,12 @@ TEST_F(FCMNetworkHandlerTestWithTTL, ShouldProvideTTLWithPolicySenderID) {
EXPECT_CALL(
*mock_instance_id(),
GetToken(_, _, Eq(base::TimeDelta::FromSeconds(kTimeToLiveInSeconds)), _,
_, _));
_));
MakeHandler(/*sender_id=*/"1013309121859")->StartListening();
}
TEST_F(FCMNetworkHandlerTestWithTTL, ShouldNotProvideTTLWithFakeSenderID) {
EXPECT_CALL(*mock_instance_id(),
GetToken(_, _, Eq(base::TimeDelta()), _, _, _));
EXPECT_CALL(*mock_instance_id(), GetToken(_, _, Eq(base::TimeDelta()), _, _));
MakeHandler(/*sender_id=*/"fake_sender_id")->StartListening();
}

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

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

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

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

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

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

@ -2294,7 +2294,10 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</histogram>
<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>knollr@chromium.org</owner>
<summary>

@ -7252,7 +7252,10 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</histogram>
<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>knollr@chromium.org</owner>
<summary>