Commit 04b63e7c authored by gab's avatar gab Committed by Commit Bot

Replace deprecated base::NonThreadSafe in chrome/service 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=scottbyer@chromium.org

Review-Url: https://codereview.chromium.org/2914573002
Cr-Commit-Position: refs/heads/master@{#476374}
parent a4b7c0e0
...@@ -33,19 +33,19 @@ CloudPrintProxy::CloudPrintProxy() ...@@ -33,19 +33,19 @@ CloudPrintProxy::CloudPrintProxy()
} }
CloudPrintProxy::~CloudPrintProxy() { CloudPrintProxy::~CloudPrintProxy() {
DCHECK(CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
ShutdownBackend(); ShutdownBackend();
} }
void CloudPrintProxy::Initialize(ServiceProcessPrefs* service_prefs, void CloudPrintProxy::Initialize(ServiceProcessPrefs* service_prefs,
Client* client) { Client* client) {
DCHECK(CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
service_prefs_ = service_prefs; service_prefs_ = service_prefs;
client_ = client; client_ = client;
} }
void CloudPrintProxy::EnableForUser() { void CloudPrintProxy::EnableForUser() {
DCHECK(CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!CreateBackend()) if (!CreateBackend())
return; return;
DCHECK(backend_.get()); DCHECK(backend_.get());
...@@ -78,7 +78,7 @@ void CloudPrintProxy::EnableForUserWithRobot( ...@@ -78,7 +78,7 @@ void CloudPrintProxy::EnableForUserWithRobot(
const std::string& robot_email, const std::string& robot_email,
const std::string& user_email, const std::string& user_email,
const base::DictionaryValue& user_settings) { const base::DictionaryValue& user_settings) {
DCHECK(CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
ShutdownBackend(); ShutdownBackend();
std::string proxy_id( std::string proxy_id(
...@@ -103,7 +103,7 @@ void CloudPrintProxy::EnableForUserWithRobot( ...@@ -103,7 +103,7 @@ void CloudPrintProxy::EnableForUserWithRobot(
} }
bool CloudPrintProxy::CreateBackend() { bool CloudPrintProxy::CreateBackend() {
DCHECK(CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (backend_.get()) if (backend_.get())
return false; return false;
...@@ -127,7 +127,7 @@ bool CloudPrintProxy::CreateBackend() { ...@@ -127,7 +127,7 @@ bool CloudPrintProxy::CreateBackend() {
} }
void CloudPrintProxy::UnregisterPrintersAndDisableForUser() { void CloudPrintProxy::UnregisterPrintersAndDisableForUser() {
DCHECK(CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (backend_.get()) { if (backend_.get()) {
// Try getting auth and printers info from the backend. // Try getting auth and printers info from the backend.
// We'll get notified in this case. // We'll get notified in this case.
...@@ -139,7 +139,7 @@ void CloudPrintProxy::UnregisterPrintersAndDisableForUser() { ...@@ -139,7 +139,7 @@ void CloudPrintProxy::UnregisterPrintersAndDisableForUser() {
} }
void CloudPrintProxy::DisableForUser() { void CloudPrintProxy::DisableForUser() {
DCHECK(CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
user_email_.clear(); user_email_.clear();
enabled_ = false; enabled_ = false;
if (client_) { if (client_) {
...@@ -178,7 +178,7 @@ void CloudPrintProxy::OnAuthenticated( ...@@ -178,7 +178,7 @@ void CloudPrintProxy::OnAuthenticated(
const std::string& robot_oauth_refresh_token, const std::string& robot_oauth_refresh_token,
const std::string& robot_email, const std::string& robot_email,
const std::string& user_email) { const std::string& user_email) {
DCHECK(CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
service_prefs_->SetString(prefs::kCloudPrintRobotRefreshToken, service_prefs_->SetString(prefs::kCloudPrintRobotRefreshToken,
robot_oauth_refresh_token); robot_oauth_refresh_token);
service_prefs_->SetString(prefs::kCloudPrintRobotEmail, service_prefs_->SetString(prefs::kCloudPrintRobotEmail,
...@@ -203,7 +203,7 @@ void CloudPrintProxy::OnAuthenticated( ...@@ -203,7 +203,7 @@ void CloudPrintProxy::OnAuthenticated(
} }
void CloudPrintProxy::OnAuthenticationFailed() { void CloudPrintProxy::OnAuthenticationFailed() {
DCHECK(CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Don't disable permanently. Could be just connection issue. // Don't disable permanently. Could be just connection issue.
ShutdownBackend(); ShutdownBackend();
if (client_) { if (client_) {
...@@ -233,7 +233,7 @@ void CloudPrintProxy::OnUnregisterPrinters( ...@@ -233,7 +233,7 @@ void CloudPrintProxy::OnUnregisterPrinters(
} }
void CloudPrintProxy::OnXmppPingUpdated(int ping_timeout) { void CloudPrintProxy::OnXmppPingUpdated(int ping_timeout) {
DCHECK(CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
service_prefs_->SetInt(prefs::kCloudPrintXmppPingTimeout, ping_timeout); service_prefs_->SetInt(prefs::kCloudPrintXmppPingTimeout, ping_timeout);
service_prefs_->WritePrefs(); service_prefs_->WritePrefs();
} }
...@@ -245,7 +245,7 @@ void CloudPrintProxy::OnUnregisterPrintersComplete() { ...@@ -245,7 +245,7 @@ void CloudPrintProxy::OnUnregisterPrintersComplete() {
} }
void CloudPrintProxy::ShutdownBackend() { void CloudPrintProxy::ShutdownBackend() {
DCHECK(CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (backend_.get()) if (backend_.get())
backend_->Shutdown(); backend_->Shutdown();
backend_.reset(); backend_.reset();
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "base/threading/non_thread_safe.h" #include "base/sequence_checker.h"
#include "chrome/service/cloud_print/cloud_print_proxy_backend.h" #include "chrome/service/cloud_print/cloud_print_proxy_backend.h"
#include "chrome/service/cloud_print/cloud_print_wipeout.h" #include "chrome/service/cloud_print/cloud_print_wipeout.h"
...@@ -24,8 +24,7 @@ struct CloudPrintProxyInfo; ...@@ -24,8 +24,7 @@ struct CloudPrintProxyInfo;
// CloudPrintProxy is the layer between the service process UI thread // CloudPrintProxy is the layer between the service process UI thread
// and the cloud print proxy backend. // and the cloud print proxy backend.
class CloudPrintProxy : public CloudPrintProxyFrontend, class CloudPrintProxy : public CloudPrintProxyFrontend,
public CloudPrintWipeout::Client, public CloudPrintWipeout::Client {
public base::NonThreadSafe {
public: public:
class Client { class Client {
public: public:
...@@ -99,6 +98,8 @@ class CloudPrintProxy : public CloudPrintProxyFrontend, ...@@ -99,6 +98,8 @@ class CloudPrintProxy : public CloudPrintProxyFrontend,
// This is a cleanup class for unregistering printers on proxy disable. // This is a cleanup class for unregistering printers on proxy disable.
std::unique_ptr<CloudPrintWipeout> wipeout_; std::unique_ptr<CloudPrintWipeout> wipeout_;
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(CloudPrintProxy); DISALLOW_COPY_AND_ASSIGN(CloudPrintProxy);
}; };
......
...@@ -24,11 +24,12 @@ CloudPrintTokenStore::CloudPrintTokenStore() { ...@@ -24,11 +24,12 @@ CloudPrintTokenStore::CloudPrintTokenStore() {
} }
CloudPrintTokenStore::~CloudPrintTokenStore() { CloudPrintTokenStore::~CloudPrintTokenStore() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
lazy_tls.Pointer()->Set(NULL); lazy_tls.Pointer()->Set(NULL);
} }
void CloudPrintTokenStore::SetToken(const std::string& token) { void CloudPrintTokenStore::SetToken(const std::string& token) {
DCHECK(CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
token_ = token; token_ = token;
} }
......
...@@ -8,14 +8,14 @@ ...@@ -8,14 +8,14 @@
#include <string> #include <string>
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/threading/non_thread_safe.h" #include "base/sequence_checker.h"
// This class serves as the single repository for cloud print auth tokens. This // This class serves as the single repository for cloud print auth tokens. This
// is only used within the CloudPrintProxyCoreThread. // is only used within the CloudPrintProxyCoreThread.
namespace cloud_print { namespace cloud_print {
class CloudPrintTokenStore : public base::NonThreadSafe { class CloudPrintTokenStore {
public: public:
// Returns the CloudPrintTokenStore instance for this thread. Will be NULL // Returns the CloudPrintTokenStore instance for this thread. Will be NULL
// if no instance was created in this thread before. // if no instance was created in this thread before.
...@@ -26,13 +26,15 @@ class CloudPrintTokenStore : public base::NonThreadSafe { ...@@ -26,13 +26,15 @@ class CloudPrintTokenStore : public base::NonThreadSafe {
void SetToken(const std::string& token); void SetToken(const std::string& token);
std::string token() const { std::string token() const {
DCHECK(CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return token_; return token_;
} }
private: private:
std::string token_; std::string token_;
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(CloudPrintTokenStore); DISALLOW_COPY_AND_ASSIGN(CloudPrintTokenStore);
}; };
......
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