Skip to content

Commit

Permalink
Replace DISALLOW_COPY_AND_ASSIGN in base/
Browse files Browse the repository at this point in the history
This replaces DISALLOW_COPY_AND_ASSIGN with explicit constructor deletes
where a local script is able to detect its insertion place (~Foo() is
public => insert before this line).

This logic is wrong if ~Foo() has comments above it, as it should be
inserted before that.

This is incomplete as not all classes have a public ~Foo() declared, so
not all DISALLOW_COPY_AND_ASSIGN occurrences are replaced.

IWYU cleanup is left as a separate pass that is easier when these macros
go away.

Bug: 1010217
Change-Id: Ia83e0ea9132ef47450b22a6b4331a242e7519e66
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3163384
Reviewed-by: Lei Zhang <thestig@chromium.org>
Owners-Override: Lei Zhang <thestig@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/main@{#921905}
  • Loading branch information
pbos authored and Chromium LUCI CQ committed Sep 15, 2021
1 parent 226bed5 commit 7319bbd
Show file tree
Hide file tree
Showing 216 changed files with 1,078 additions and 563 deletions.
7 changes: 4 additions & 3 deletions base/android/application_status_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class BASE_EXPORT ApplicationStatusListener {
using ApplicationStateChangeCallback =
base::RepeatingCallback<void(ApplicationState)>;

ApplicationStatusListener(const ApplicationStatusListener&) = delete;
ApplicationStatusListener& operator=(const ApplicationStatusListener&) =
delete;

virtual ~ApplicationStatusListener();

// Sets the callback to call when application state changes.
Expand All @@ -87,9 +91,6 @@ class BASE_EXPORT ApplicationStatusListener {

protected:
ApplicationStatusListener();

private:
DISALLOW_COPY_AND_ASSIGN(ApplicationStatusListener);
};

} // namespace android
Expand Down
5 changes: 3 additions & 2 deletions base/android/build_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ enum SdkVersion {
// primarily in crash reporting.
class BASE_EXPORT BuildInfo {
public:
BuildInfo(const BuildInfo&) = delete;
BuildInfo& operator=(const BuildInfo&) = delete;

~BuildInfo() {}

// Static factory method for getting the singleton BuildInfo instance.
Expand Down Expand Up @@ -171,8 +174,6 @@ class BASE_EXPORT BuildInfo {
const bool is_debug_android_;
const bool is_tv_;
const char* const version_incremental_;

DISALLOW_COPY_AND_ASSIGN(BuildInfo);
};

} // namespace android
Expand Down
5 changes: 3 additions & 2 deletions base/android/java_handler_thread_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class DummyTaskObserver : public TaskObserver {
num_tasks_processed_(0),
num_tasks_(num_tasks) {}

DummyTaskObserver(const DummyTaskObserver&) = delete;
DummyTaskObserver& operator=(const DummyTaskObserver&) = delete;

~DummyTaskObserver() override = default;

void WillProcessTask(const PendingTask& /* pending_task */,
Expand All @@ -57,8 +60,6 @@ class DummyTaskObserver : public TaskObserver {
int num_tasks_started_;
int num_tasks_processed_;
const int num_tasks_;

DISALLOW_COPY_AND_ASSIGN(DummyTaskObserver);
};

void PostNTasks(int posts_remaining) {
Expand Down
6 changes: 4 additions & 2 deletions base/android/jni_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,15 @@ BASE_EXPORT std::string GetJavaExceptionInfo(JNIEnv* env,
class BASE_EXPORT JNIStackFrameSaver {
public:
JNIStackFrameSaver(void* current_fp);

JNIStackFrameSaver(const JNIStackFrameSaver&) = delete;
JNIStackFrameSaver& operator=(const JNIStackFrameSaver&) = delete;

~JNIStackFrameSaver();
static void* SavedFrame();

private:
void* previous_fp_;

DISALLOW_COPY_AND_ASSIGN(JNIStackFrameSaver);
};

#endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
Expand Down
6 changes: 4 additions & 2 deletions base/android/jni_generator/sample_for_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ namespace android {
class CPPClass {
public:
CPPClass();

CPPClass(const CPPClass&) = delete;
CPPClass& operator=(const CPPClass&) = delete;

~CPPClass();

// Java @CalledByNative methods implicitly available to C++ via the _jni.h
Expand Down Expand Up @@ -103,8 +107,6 @@ class CPPClass {

private:
std::map<long, std::string> map_;

DISALLOW_COPY_AND_ASSIGN(CPPClass);
};

} // namespace android
Expand Down
6 changes: 4 additions & 2 deletions base/android/scoped_hardware_buffer_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class BASE_EXPORT ScopedHardwareBufferHandle {
// Takes ownership of |other|'s buffer reference. Does NOT acquire a new one.
ScopedHardwareBufferHandle(ScopedHardwareBufferHandle&& other);

ScopedHardwareBufferHandle(const ScopedHardwareBufferHandle&) = delete;
ScopedHardwareBufferHandle& operator=(const ScopedHardwareBufferHandle&) =
delete;

// Releases this handle's reference to the underlying buffer object if still
// valid.
~ScopedHardwareBufferHandle();
Expand Down Expand Up @@ -80,8 +84,6 @@ class BASE_EXPORT ScopedHardwareBufferHandle {
explicit ScopedHardwareBufferHandle(AHardwareBuffer* buffer);

AHardwareBuffer* buffer_ = nullptr;

DISALLOW_COPY_AND_ASSIGN(ScopedHardwareBufferHandle);
};

} // namespace android
Expand Down
24 changes: 14 additions & 10 deletions base/android/scoped_java_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ class BASE_EXPORT ScopedJavaLocalFrame {
public:
explicit ScopedJavaLocalFrame(JNIEnv* env);
ScopedJavaLocalFrame(JNIEnv* env, int capacity);

ScopedJavaLocalFrame(const ScopedJavaLocalFrame&) = delete;
ScopedJavaLocalFrame& operator=(const ScopedJavaLocalFrame&) = delete;

~ScopedJavaLocalFrame();

private:
// This class is only good for use on the thread it was created on so
// it's safe to cache the non-threadsafe JNIEnv* inside this object.
JNIEnv* env_;

DISALLOW_COPY_AND_ASSIGN(ScopedJavaLocalFrame);
};

// Forward declare the generic java reference template class.
Expand All @@ -53,6 +55,9 @@ class BASE_EXPORT JavaRef<jobject> {
// Java "null" equivalent.
constexpr JavaRef(std::nullptr_t) {}

JavaRef(const JavaRef&) = delete;
JavaRef& operator=(const JavaRef&) = delete;

// Public to allow destruction of null JavaRef objects.
~JavaRef() {}

Expand Down Expand Up @@ -92,8 +97,6 @@ class BASE_EXPORT JavaRef<jobject> {

private:
jobject obj_ = nullptr;

DISALLOW_COPY_AND_ASSIGN(JavaRef);
};

// Forward declare the object array reader for the convenience function.
Expand All @@ -108,6 +111,10 @@ class JavaRef : public JavaRef<jobject> {
public:
constexpr JavaRef() {}
constexpr JavaRef(std::nullptr_t) {}

JavaRef(const JavaRef&) = delete;
JavaRef& operator=(const JavaRef&) = delete;

~JavaRef() {}

T obj() const { return static_cast<T>(JavaRef<jobject>::obj()); }
Expand All @@ -125,9 +132,6 @@ class JavaRef : public JavaRef<jobject> {

protected:
JavaRef(JNIEnv* env, T obj) : JavaRef<jobject>(env, obj) {}

private:
DISALLOW_COPY_AND_ASSIGN(JavaRef);
};

// Holds a local reference to a JNI method parameter.
Expand All @@ -147,14 +151,14 @@ class JavaParamRef : public JavaRef<T> {
// working.
JavaParamRef(std::nullptr_t) {}

JavaParamRef(const JavaParamRef&) = delete;
JavaParamRef& operator=(const JavaParamRef&) = delete;

~JavaParamRef() {}

// TODO(torne): remove this cast once we're using JavaRef consistently.
// http://crbug.com/506850
operator T() const { return JavaRef<T>::obj(); }

private:
DISALLOW_COPY_AND_ASSIGN(JavaParamRef);
};

// Holds a local reference to a Java object. The local reference is scoped
Expand Down
6 changes: 4 additions & 2 deletions base/android/task_scheduler/task_runner_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class TaskRunnerAndroid {
public:
explicit TaskRunnerAndroid(scoped_refptr<TaskRunner> task_runner,
TaskRunnerType type);

TaskRunnerAndroid(const TaskRunnerAndroid&) = delete;
TaskRunnerAndroid& operator=(const TaskRunnerAndroid&) = delete;

~TaskRunnerAndroid();

void Destroy(JNIEnv* env);
Expand All @@ -33,8 +37,6 @@ class TaskRunnerAndroid {
private:
const scoped_refptr<TaskRunner> task_runner_;
const TaskRunnerType type_;

DISALLOW_COPY_AND_ASSIGN(TaskRunnerAndroid);
};

} // namespace base
Expand Down
6 changes: 4 additions & 2 deletions base/android/trace_event_binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class TraceEventDataConverter {
: name_(ConvertJavaStringToUTF8(env, jname)),
has_arg_(jarg != nullptr),
arg_(jarg ? ConvertJavaStringToUTF8(env, jarg) : "") {}

TraceEventDataConverter(const TraceEventDataConverter&) = delete;
TraceEventDataConverter& operator=(const TraceEventDataConverter&) = delete;

~TraceEventDataConverter() = default;

// Return saved values to pass to TRACE_EVENT macros.
Expand All @@ -105,8 +109,6 @@ class TraceEventDataConverter {
std::string name_;
bool has_arg_;
std::string arg_;

DISALLOW_COPY_AND_ASSIGN(TraceEventDataConverter);
};

} // namespace
Expand Down
5 changes: 3 additions & 2 deletions base/debug/activity_analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ class BASE_EXPORT GlobalActivityAnalyzer {
explicit GlobalActivityAnalyzer(
std::unique_ptr<PersistentMemoryAllocator> allocator);

GlobalActivityAnalyzer(const GlobalActivityAnalyzer&) = delete;
GlobalActivityAnalyzer& operator=(const GlobalActivityAnalyzer&) = delete;

~GlobalActivityAnalyzer();

// Creates a global analyzer using a given persistent-memory |allocator|.
Expand Down Expand Up @@ -247,8 +250,6 @@ class BASE_EXPORT GlobalActivityAnalyzer {
// first/next iteration.
AnalyzerMap::iterator analyzers_iterator_;
int64_t analyzers_iterator_pid_;

DISALLOW_COPY_AND_ASSIGN(GlobalActivityAnalyzer);
};

} // namespace debug
Expand Down
5 changes: 3 additions & 2 deletions base/debug/activity_analyzer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ class SimpleActivityThread : public SimpleThread {
exit_(false),
exit_condition_(&lock_) {}

SimpleActivityThread(const SimpleActivityThread&) = delete;
SimpleActivityThread& operator=(const SimpleActivityThread&) = delete;

~SimpleActivityThread() override = default;

void Run() override {
Expand Down Expand Up @@ -158,8 +161,6 @@ class SimpleActivityThread : public SimpleThread {
std::atomic<bool> exit_;
Lock lock_;
ConditionVariable exit_condition_;

DISALLOW_COPY_AND_ASSIGN(SimpleActivityThread);
};

} // namespace
Expand Down
39 changes: 25 additions & 14 deletions base/debug/activity_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ class BASE_EXPORT ActivityTrackerMemoryAllocator {
size_t object_size,
size_t cache_size,
bool make_iterable);

ActivityTrackerMemoryAllocator(const ActivityTrackerMemoryAllocator&) =
delete;
ActivityTrackerMemoryAllocator& operator=(
const ActivityTrackerMemoryAllocator&) = delete;

~ActivityTrackerMemoryAllocator();

// Gets a reference to an object of the configured type. This can return
Expand Down Expand Up @@ -231,8 +237,6 @@ class BASE_EXPORT ActivityTrackerMemoryAllocator {
// The cache of released object memories.
std::unique_ptr<Reference[]> cache_values_;
size_t cache_used_;

DISALLOW_COPY_AND_ASSIGN(ActivityTrackerMemoryAllocator);
};


Expand Down Expand Up @@ -632,6 +636,10 @@ class BASE_EXPORT ThreadActivityTracker {
const void* origin,
Activity::Type type,
const ActivityData& data);

ScopedActivity(const ScopedActivity&) = delete;
ScopedActivity& operator=(const ScopedActivity&) = delete;

~ScopedActivity();

// Indicates if this activity is actually being recorded. It may not be if
Expand All @@ -649,9 +657,6 @@ class BASE_EXPORT ThreadActivityTracker {

// An identifier that indicates a specific activity on the stack.
ActivityId activity_id_;

private:
DISALLOW_COPY_AND_ASSIGN(ScopedActivity);
};

// A ThreadActivityTracker runs on top of memory that is managed externally.
Expand Down Expand Up @@ -859,6 +864,10 @@ class BASE_EXPORT GlobalActivityTracker {
Activity::Type type,
const ActivityData& data,
bool lock_allowed);

ScopedThreadActivity(const ScopedThreadActivity&) = delete;
ScopedThreadActivity& operator=(const ScopedThreadActivity&) = delete;

~ScopedThreadActivity();

// Returns an object for manipulating user data.
Expand All @@ -883,8 +892,6 @@ class BASE_EXPORT GlobalActivityTracker {

// An object that manages additional user data, created only upon request.
std::unique_ptr<ActivityUserData> user_data_;

DISALLOW_COPY_AND_ASSIGN(ScopedThreadActivity);
};

~GlobalActivityTracker();
Expand Down Expand Up @@ -1077,6 +1084,10 @@ class BASE_EXPORT GlobalActivityTracker {
class ThreadSafeUserData : public ActivityUserData {
public:
ThreadSafeUserData(void* memory, size_t size, int64_t pid = 0);

ThreadSafeUserData(const ThreadSafeUserData&) = delete;
ThreadSafeUserData& operator=(const ThreadSafeUserData&) = delete;

~ThreadSafeUserData() override;

private:
Expand All @@ -1086,8 +1097,6 @@ class BASE_EXPORT GlobalActivityTracker {
size_t size) override;

Lock data_lock_;

DISALLOW_COPY_AND_ASSIGN(ThreadSafeUserData);
};

// State of a module as stored in persistent memory. This supports a single
Expand Down Expand Up @@ -1142,6 +1151,10 @@ class BASE_EXPORT GlobalActivityTracker {
ManagedActivityTracker(PersistentMemoryAllocator::Reference mem_reference,
void* base,
size_t size);

ManagedActivityTracker(const ManagedActivityTracker&) = delete;
ManagedActivityTracker& operator=(const ManagedActivityTracker&) = delete;

~ManagedActivityTracker() override;

// The reference into persistent memory from which the thread-tracker's
Expand All @@ -1150,9 +1163,6 @@ class BASE_EXPORT GlobalActivityTracker {

// The physical address used for the thread-tracker's memory.
void* const mem_base_;

private:
DISALLOW_COPY_AND_ASSIGN(ManagedActivityTracker);
};

// Creates a global tracker using a given persistent-memory |allocator| and
Expand Down Expand Up @@ -1266,6 +1276,9 @@ class BASE_EXPORT ScopedActivity
: ScopedActivity(from_here.program_counter(), action, id, info) {}
ScopedActivity() : ScopedActivity(0, 0, 0) {}

ScopedActivity(const ScopedActivity&) = delete;
ScopedActivity& operator=(const ScopedActivity&) = delete;

// Changes the |action| and/or |info| of this activity on the stack. This
// is useful for tracking progress through a function, updating the action
// to indicate "milestones" in the block (max 16 milestones: 0-15) or the
Expand All @@ -1285,8 +1298,6 @@ class BASE_EXPORT ScopedActivity
// A copy of the ID code so it doesn't have to be passed by the caller when
// changing the |info| field.
uint32_t id_;

DISALLOW_COPY_AND_ASSIGN(ScopedActivity);
};


Expand Down
Loading

0 comments on commit 7319bbd

Please sign in to comment.