Commit d19cd77f authored by gab's avatar gab Committed by Commit Bot

Replace deprecated base::NonThreadSafe in google_apis/gaia in favor of SequenceChecker.

Note to crash team: This CL is a refactor and has no intended behavior change.

This change was scripted by https://crbug.com/676387#c8.

Note-worthy for the reviewer:
 * SequenceChecker enforces thread-safety but not thread-affinity!
   If the classes that were updated are thread-affine (use thread local
   storage or a third-party API that does) they should be migrated to
   ThreadChecker instead.
 * ~NonThreadSafe() used to implcitly check in its destructor
   ~Sequence/ThreadChecker() doesn't by design. To keep this CL a
   no-op, an explicit check was added to the destructor of migrated
   classes.
 * NonThreadSafe used to provide access to subclasses, as such
   the |sequence_checker_| member was made protected rather than
   private where necessary.

BUG=676387
This CL was uploaded by git cl split.

R=rogerta@chromium.org

Review-Url: https://codereview.chromium.org/2910983003
Cr-Commit-Position: refs/heads/master@{#476406}
parent 882f2fb8
......@@ -66,7 +66,7 @@ OAuth2TokenService::RequestImpl::RequestImpl(
}
OAuth2TokenService::RequestImpl::~RequestImpl() {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
std::string OAuth2TokenService::RequestImpl::GetAccountId() const {
......@@ -81,7 +81,7 @@ void OAuth2TokenService::RequestImpl::InformConsumer(
const GoogleServiceAuthError& error,
const std::string& access_token,
const base::Time& expiration_date) {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (error.state() == GoogleServiceAuthError::NONE)
consumer_->OnGetTokenSuccess(this, access_token, expiration_date);
else
......@@ -395,6 +395,7 @@ OAuth2TokenService::OAuth2TokenService(
}
OAuth2TokenService::~OAuth2TokenService() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Release all the pending fetchers.
pending_fetchers_.clear();
}
......@@ -480,7 +481,7 @@ OAuth2TokenService::StartRequestForClientWithContext(
const std::string& client_secret,
const ScopeSet& scopes,
Consumer* consumer) {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
// fixed.
......@@ -631,7 +632,7 @@ void OAuth2TokenService::InvalidateAccessTokenImpl(
const std::string& client_id,
const ScopeSet& scopes,
const std::string& access_token) {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
RemoveCacheEntry(
RequestParameters(client_id,
account_id,
......@@ -641,7 +642,7 @@ void OAuth2TokenService::InvalidateAccessTokenImpl(
}
void OAuth2TokenService::OnFetchComplete(Fetcher* fetcher) {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Update the auth error state so auth errors are appropriately communicated
// to the user.
......@@ -708,7 +709,7 @@ bool OAuth2TokenService::HasCacheEntry(
const OAuth2TokenService::CacheEntry* OAuth2TokenService::GetCacheEntry(
const RequestParameters& request_parameters) {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
TokenCache::iterator token_iterator = token_cache_.find(request_parameters);
if (token_iterator == token_cache_.end())
return NULL;
......@@ -722,7 +723,7 @@ const OAuth2TokenService::CacheEntry* OAuth2TokenService::GetCacheEntry(
bool OAuth2TokenService::RemoveCacheEntry(
const RequestParameters& request_parameters,
const std::string& token_to_remove) {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
TokenCache::iterator token_iterator = token_cache_.find(request_parameters);
if (token_iterator != token_cache_.end() &&
token_iterator->second.access_token == token_to_remove) {
......@@ -746,7 +747,7 @@ void OAuth2TokenService::RegisterCacheEntry(
const OAuth2TokenService::ScopeSet& scopes,
const std::string& access_token,
const base::Time& expiration_date) {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
CacheEntry& token = token_cache_[RequestParameters(client_id,
account_id,
......@@ -756,7 +757,7 @@ void OAuth2TokenService::RegisterCacheEntry(
}
void OAuth2TokenService::ClearCache() {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (TokenCache::iterator iter = token_cache_.begin();
iter != token_cache_.end(); ++iter) {
for (auto& observer : diagnostics_observer_list_)
......@@ -767,7 +768,7 @@ void OAuth2TokenService::ClearCache() {
}
void OAuth2TokenService::ClearCacheForAccount(const std::string& account_id) {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (TokenCache::iterator iter = token_cache_.begin();
iter != token_cache_.end();
/* iter incremented in body */) {
......@@ -811,7 +812,7 @@ void OAuth2TokenService::CancelFetchers(
void OAuth2TokenService::set_max_authorization_token_fetch_retries_for_testing(
int max_retries) {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
max_fetch_retry_num_ = max_retries;
}
......
......@@ -16,7 +16,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/threading/non_thread_safe.h"
#include "base/sequence_checker.h"
#include "base/time/time.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "google_apis/gaia/oauth2_access_token_consumer.h"
......@@ -53,7 +53,7 @@ class OAuth2TokenServiceDelegate;
//
// The caller of StartRequest() owns the returned request and is responsible to
// delete the request even once the callback has been invoked.
class OAuth2TokenService : public base::NonThreadSafe {
class OAuth2TokenService {
public:
// A set of scopes in OAuth2 authentication.
typedef std::set<std::string> ScopeSet;
......@@ -221,7 +221,6 @@ class OAuth2TokenService : public base::NonThreadSafe {
// operated on the UI thread.
// TODO(davidroche): move this out of header file.
class RequestImpl : public base::SupportsWeakPtr<RequestImpl>,
public base::NonThreadSafe,
public Request {
public:
// |consumer| is required to outlive this.
......@@ -242,6 +241,8 @@ class OAuth2TokenService : public base::NonThreadSafe {
// |consumer_| to call back when this request completes.
const std::string account_id_;
Consumer* const consumer_;
SEQUENCE_CHECKER(sequence_checker_);
};
// Implement it in delegates if they want to report errors to the user.
......@@ -388,6 +389,8 @@ class OAuth2TokenService : public base::NonThreadSafe {
SameScopesRequestedForDifferentClients);
FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, UpdateClearsCache);
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(OAuth2TokenService);
};
......
......@@ -38,8 +38,7 @@ OAuth2TokenServiceRequest::TokenServiceProvider::~TokenServiceProvider() {
//
// 5. Core is destroyed on owner thread.
class OAuth2TokenServiceRequest::Core
: public base::NonThreadSafe,
public base::RefCountedThreadSafe<OAuth2TokenServiceRequest::Core> {
: public base::RefCountedThreadSafe<OAuth2TokenServiceRequest::Core> {
public:
// Note the thread where an instance of Core is constructed is referred to as
// the "owner thread" here.
......@@ -72,6 +71,8 @@ class OAuth2TokenServiceRequest::Core
OAuth2TokenService* token_service();
OAuth2TokenServiceRequest* owner();
SEQUENCE_CHECKER(sequence_checker_);
private:
friend class base::RefCountedThreadSafe<OAuth2TokenServiceRequest::Core>;
......@@ -102,7 +103,7 @@ OAuth2TokenServiceRequest::Core::~Core() {
}
void OAuth2TokenServiceRequest::Core::Start() {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
token_service_task_runner_->PostTask(
FROM_HERE,
base::Bind(&OAuth2TokenServiceRequest::Core::StartOnTokenServiceThread,
......@@ -110,7 +111,7 @@ void OAuth2TokenServiceRequest::Core::Start() {
}
void OAuth2TokenServiceRequest::Core::Stop() {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!IsStopped());
// Detaches |owner_| from this instance so |owner_| will be called back only
......@@ -129,7 +130,7 @@ void OAuth2TokenServiceRequest::Core::Stop() {
}
bool OAuth2TokenServiceRequest::Core::IsStopped() const {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return owner_ == NULL;
}
......@@ -144,12 +145,12 @@ OAuth2TokenService* OAuth2TokenServiceRequest::Core::token_service() {
}
OAuth2TokenServiceRequest* OAuth2TokenServiceRequest::Core::owner() {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return owner_;
}
void OAuth2TokenServiceRequest::Core::DoNothing() {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
namespace {
......@@ -255,14 +256,14 @@ void RequestCore::OnGetTokenFailure(const OAuth2TokenService::Request* request,
void RequestCore::InformOwnerOnGetTokenSuccess(std::string access_token,
base::Time expiration_time) {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!IsStopped()) {
consumer_->OnGetTokenSuccess(owner(), access_token, expiration_time);
}
}
void RequestCore::InformOwnerOnGetTokenFailure(GoogleServiceAuthError error) {
DCHECK(CalledOnValidThread());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!IsStopped()) {
consumer_->OnGetTokenFailure(owner(), error);
}
......@@ -355,6 +356,7 @@ void OAuth2TokenServiceRequest::InvalidateToken(
}
OAuth2TokenServiceRequest::~OAuth2TokenServiceRequest() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
core_->Stop();
}
......
......@@ -11,16 +11,15 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/sequence_checker.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/non_thread_safe.h"
#include "google_apis/gaia/oauth2_token_service.h"
// OAuth2TokenServiceRequest represents an asynchronous request to an
// OAuth2TokenService that may live in another thread.
//
// An OAuth2TokenServiceRequest can be created and started from any thread.
class OAuth2TokenServiceRequest : public OAuth2TokenService::Request,
public base::NonThreadSafe {
class OAuth2TokenServiceRequest : public OAuth2TokenService::Request {
public:
class Core;
......@@ -101,6 +100,8 @@ class OAuth2TokenServiceRequest : public OAuth2TokenService::Request,
const std::string account_id_;
scoped_refptr<Core> core_;
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(OAuth2TokenServiceRequest);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment