Commit b9dae93e authored by tzik's avatar tzik Committed by Commit bot

Simplify SequencedTaskRunner::{Delete,Releaose}Soon impl

This CL removes SequencedTaskRunner-like type support from DeleteHelper.
There no longer exists such a class, and the removal simplify the
implementation.

TBR=kinuko@chromium.org, shess@chromium.org, asvitkine@chromium.org
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_site_isolation

Review-Url: https://codereview.chromium.org/2686033002
Cr-Commit-Position: refs/heads/master@{#449544}
parent 033d9e89
......@@ -14,20 +14,13 @@ bool SequencedTaskRunner::PostNonNestableTask(
return PostNonNestableDelayedTask(from_here, task, base::TimeDelta());
}
bool SequencedTaskRunner::DeleteSoonInternal(
bool SequencedTaskRunner::DeleteOrReleaseSoonInternal(
const tracked_objects::Location& from_here,
void(*deleter)(const void*),
void (*deleter)(const void*),
const void* object) {
return PostNonNestableTask(from_here, Bind(deleter, object));
}
bool SequencedTaskRunner::ReleaseSoonInternal(
const tracked_objects::Location& from_here,
void(*releaser)(const void*),
const void* object) {
return PostNonNestableTask(from_here, Bind(releaser, object));
}
OnTaskRunnerDeleter::OnTaskRunnerDeleter(
scoped_refptr<SequencedTaskRunner> task_runner)
: task_runner_(std::move(task_runner)) {
......
......@@ -122,9 +122,8 @@ class BASE_EXPORT SequencedTaskRunner : public TaskRunner {
template <class T>
bool DeleteSoon(const tracked_objects::Location& from_here,
const T* object) {
return
subtle::DeleteHelperInternal<T, bool>::DeleteViaSequencedTaskRunner(
this, from_here, object);
return DeleteOrReleaseSoonInternal(from_here, &DeleteHelper<T>::DoDelete,
object);
}
// Submits a non-nestable task to release the given object. Returns
......@@ -132,26 +131,18 @@ class BASE_EXPORT SequencedTaskRunner : public TaskRunner {
// and false if the object definitely will not be released.
template <class T>
bool ReleaseSoon(const tracked_objects::Location& from_here,
T* object) {
return
subtle::ReleaseHelperInternal<T, bool>::ReleaseViaSequencedTaskRunner(
this, from_here, object);
const T* object) {
return DeleteOrReleaseSoonInternal(from_here, &ReleaseHelper<T>::DoRelease,
object);
}
protected:
~SequencedTaskRunner() override {}
private:
template <class T, class R> friend class subtle::DeleteHelperInternal;
template <class T, class R> friend class subtle::ReleaseHelperInternal;
bool DeleteSoonInternal(const tracked_objects::Location& from_here,
void(*deleter)(const void*),
const void* object);
bool ReleaseSoonInternal(const tracked_objects::Location& from_here,
void(*releaser)(const void*),
const void* object);
bool DeleteOrReleaseSoonInternal(const tracked_objects::Location& from_here,
void (*deleter)(const void*),
const void* object);
};
struct BASE_EXPORT OnTaskRunnerDeleter {
......
......@@ -5,23 +5,9 @@
#ifndef BASE_SEQUENCED_TASK_RUNNER_HELPERS_H_
#define BASE_SEQUENCED_TASK_RUNNER_HELPERS_H_
#include "base/debug/alias.h"
#include "base/macros.h"
// TODO(akalin): Investigate whether it's possible to just have
// SequencedTaskRunner use these helpers (instead of MessageLoop).
// Then we can just move these to sequenced_task_runner.h.
namespace tracked_objects {
class Location;
}
namespace base {
namespace subtle {
template <class T, class R> class DeleteHelperInternal;
template <class T, class R> class ReleaseHelperInternal;
}
class SequencedTaskRunner;
// Template helpers which use function indirection to erase T from the
// function signature while still remembering it so we can call the
......@@ -34,80 +20,23 @@ template <class T, class R> class ReleaseHelperInternal;
template <class T>
class DeleteHelper {
private:
template <class T2, class R> friend class subtle::DeleteHelperInternal;
static void DoDelete(const void* object) {
delete reinterpret_cast<const T*>(object);
delete static_cast<const T*>(object);
}
DISALLOW_COPY_AND_ASSIGN(DeleteHelper);
friend class SequencedTaskRunner;
};
template <class T>
class ReleaseHelper {
private:
template <class T2, class R> friend class subtle::ReleaseHelperInternal;
static void DoRelease(const void* object) {
reinterpret_cast<const T*>(object)->Release();
static_cast<const T*>(object)->Release();
}
DISALLOW_COPY_AND_ASSIGN(ReleaseHelper);
friend class SequencedTaskRunner;
};
namespace subtle {
// An internal SequencedTaskRunner-like class helper for DeleteHelper
// and ReleaseHelper. We don't want to expose the Do*() functions
// directly directly since the void* argument makes it possible to
// pass/ an object of the wrong type to delete. Instead, we force
// callers to go through these internal helpers for type
// safety. SequencedTaskRunner-like classes which expose DeleteSoon or
// ReleaseSoon methods should friend the appropriate helper and
// implement a corresponding *Internal method with the following
// signature:
//
// bool(const tracked_objects::Location&,
// void(*function)(const void*),
// void* object)
//
// An implementation of this function should simply create a
// base::Closure from (function, object) and return the result of
// posting the task.
template <class T, class ReturnType>
class DeleteHelperInternal {
public:
template <class SequencedTaskRunnerType>
static ReturnType DeleteViaSequencedTaskRunner(
SequencedTaskRunnerType* sequenced_task_runner,
const tracked_objects::Location& from_here,
const T* object) {
return sequenced_task_runner->DeleteSoonInternal(
from_here, &DeleteHelper<T>::DoDelete, object);
}
private:
DISALLOW_COPY_AND_ASSIGN(DeleteHelperInternal);
};
template <class T, class ReturnType>
class ReleaseHelperInternal {
public:
template <class SequencedTaskRunnerType>
static ReturnType ReleaseViaSequencedTaskRunner(
SequencedTaskRunnerType* sequenced_task_runner,
const tracked_objects::Location& from_here,
const T* object) {
return sequenced_task_runner->ReleaseSoonInternal(
from_here, &ReleaseHelper<T>::DoRelease, object);
}
private:
DISALLOW_COPY_AND_ASSIGN(ReleaseHelperInternal);
};
} // namespace subtle
} // namespace base
#endif // BASE_SEQUENCED_TASK_RUNNER_HELPERS_H_
......@@ -7,6 +7,7 @@
#include "base/base_switches.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/debug/alias.h"
#include "base/debug/dump_without_crashing.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
......
......@@ -5,6 +5,7 @@
#include "content/browser/frame_host/render_frame_message_filter.h"
#include "base/command_line.h"
#include "base/debug/alias.h"
#include "base/macros.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
......
......@@ -18,6 +18,7 @@
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/command_line.h"
#include "base/debug/alias.h"
#include "base/debug/crash_logging.h"
#include "base/debug/dump_without_crashing.h"
#include "base/feature_list.h"
......
......@@ -12,6 +12,7 @@
#include <utility>
#include "base/bind.h"
#include "base/debug/alias.h"
#include "base/debug/dump_without_crashing.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
......
......@@ -5,6 +5,7 @@
#include "ui/gfx/win/direct_write.h"
#include "base/command_line.h"
#include "base/debug/alias.h"
#include "base/metrics/field_trial.h"
#include "base/win/registry.h"
#include "base/win/scoped_comptr.h"
......
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