Index: components/gcm_driver/instance_id/instance_id_impl.cc |
diff --git a/components/gcm_driver/instance_id/instance_id_impl.cc b/components/gcm_driver/instance_id/instance_id_impl.cc |
index 013ddbff354b17dbb939a99a5990cfd39a905bab..56a0cbed8d2c16e43743480ea3feea22dcd0710c 100644 |
--- a/components/gcm_driver/instance_id/instance_id_impl.cc |
+++ b/components/gcm_driver/instance_id/instance_id_impl.cc |
@@ -15,6 +15,7 @@ |
#include "base/memory/ptr_util.h" |
#include "base/message_loop/message_loop.h" |
#include "base/strings/string_number_conversions.h" |
+#include "base/threading/thread_task_runner_handle.h" |
#include "components/gcm_driver/gcm_driver.h" |
#include "crypto/random.h" |
@@ -67,15 +68,8 @@ InstanceIDImpl::~InstanceIDImpl() { |
} |
void InstanceIDImpl::GetID(const GetIDCallback& callback) { |
- if (!delayed_task_controller_.CanRunTaskWithoutDelay()) { |
- delayed_task_controller_.AddTask( |
- base::Bind(&InstanceIDImpl::DoGetID, |
- weak_ptr_factory_.GetWeakPtr(), |
- callback)); |
- return; |
- } |
- |
- DoGetID(callback); |
+ RunWhenReady(base::Bind(&InstanceIDImpl::DoGetID, |
+ weak_ptr_factory_.GetWeakPtr(), callback)); |
} |
void InstanceIDImpl::DoGetID(const GetIDCallback& callback) { |
@@ -84,15 +78,8 @@ void InstanceIDImpl::DoGetID(const GetIDCallback& callback) { |
} |
void InstanceIDImpl::GetCreationTime(const GetCreationTimeCallback& callback) { |
- if (!delayed_task_controller_.CanRunTaskWithoutDelay()) { |
- delayed_task_controller_.AddTask( |
- base::Bind(&InstanceIDImpl::DoGetCreationTime, |
- weak_ptr_factory_.GetWeakPtr(), |
- callback)); |
- return; |
- } |
- |
- DoGetCreationTime(callback); |
+ RunWhenReady(base::Bind(&InstanceIDImpl::DoGetCreationTime, |
+ weak_ptr_factory_.GetWeakPtr(), callback)); |
} |
void InstanceIDImpl::DoGetCreationTime( |
@@ -108,18 +95,9 @@ void InstanceIDImpl::GetToken( |
DCHECK(!authorized_entity.empty()); |
DCHECK(!scope.empty()); |
- if (!delayed_task_controller_.CanRunTaskWithoutDelay()) { |
- delayed_task_controller_.AddTask( |
- base::Bind(&InstanceIDImpl::DoGetToken, |
- weak_ptr_factory_.GetWeakPtr(), |
- authorized_entity, |
- scope, |
- options, |
- callback)); |
- return; |
- } |
- |
- DoGetToken(authorized_entity, scope, options, callback); |
+ RunWhenReady(base::Bind(&InstanceIDImpl::DoGetToken, |
+ weak_ptr_factory_.GetWeakPtr(), authorized_entity, |
+ scope, options, callback)); |
} |
void InstanceIDImpl::DoGetToken( |
@@ -142,14 +120,9 @@ void InstanceIDImpl::ValidateToken(const std::string& authorized_entity, |
DCHECK(!scope.empty()); |
DCHECK(!token.empty()); |
- if (!delayed_task_controller_.CanRunTaskWithoutDelay()) { |
- delayed_task_controller_.AddTask(base::Bind( |
- &InstanceIDImpl::DoValidateToken, weak_ptr_factory_.GetWeakPtr(), |
- authorized_entity, scope, token, callback)); |
- return; |
- } |
- |
- DoValidateToken(authorized_entity, scope, token, callback); |
+ RunWhenReady(base::Bind(&InstanceIDImpl::DoValidateToken, |
+ weak_ptr_factory_.GetWeakPtr(), authorized_entity, |
+ scope, token, callback)); |
} |
void InstanceIDImpl::DoValidateToken(const std::string& authorized_entity, |
@@ -170,17 +143,9 @@ void InstanceIDImpl::DeleteTokenImpl(const std::string& authorized_entity, |
DCHECK(!authorized_entity.empty()); |
DCHECK(!scope.empty()); |
- if (!delayed_task_controller_.CanRunTaskWithoutDelay()) { |
- delayed_task_controller_.AddTask( |
- base::Bind(&InstanceIDImpl::DoDeleteToken, |
- weak_ptr_factory_.GetWeakPtr(), |
- authorized_entity, |
- scope, |
- callback)); |
- return; |
- } |
- |
- DoDeleteToken(authorized_entity, scope, callback); |
+ RunWhenReady(base::Bind(&InstanceIDImpl::DoDeleteToken, |
+ weak_ptr_factory_.GetWeakPtr(), authorized_entity, |
+ scope, callback)); |
} |
void InstanceIDImpl::DoDeleteToken( |
@@ -199,15 +164,8 @@ void InstanceIDImpl::DoDeleteToken( |
} |
void InstanceIDImpl::DeleteIDImpl(const DeleteIDCallback& callback) { |
- if (!delayed_task_controller_.CanRunTaskWithoutDelay()) { |
- delayed_task_controller_.AddTask( |
- base::Bind(&InstanceIDImpl::DoDeleteID, |
- weak_ptr_factory_.GetWeakPtr(), |
- callback)); |
- return; |
- } |
- |
- DoDeleteID(callback); |
+ RunWhenReady(base::Bind(&InstanceIDImpl::DoDeleteID, |
+ weak_ptr_factory_.GetWeakPtr(), callback)); |
} |
void InstanceIDImpl::DoDeleteID(const DeleteIDCallback& callback) { |
@@ -305,4 +263,11 @@ gcm::InstanceIDHandler* InstanceIDImpl::Handler() { |
return handler; |
} |
+void InstanceIDImpl::RunWhenReady(base::Closure task) { |
+ if (!delayed_task_controller_.CanRunTaskWithoutDelay()) |
+ delayed_task_controller_.AddTask(task); |
+ else |
+ base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
Peter Beverloo
2017/04/03 17:45:01
It's a bit unfortunate that this makes things asyn
johnme
2017/04/03 17:50:43
Acknowledged :)
|
+} |
+ |
} // namespace instance_id |