Skip to content

Commit

Permalink
Reverting 27389.
Browse files Browse the repository at this point in the history
Review URL: http://codereview.chromium.org/246027

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27594 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
darin@chromium.org committed Sep 30, 2009
1 parent 5924fb6 commit 39fe32a
Show file tree
Hide file tree
Showing 27 changed files with 106 additions and 122 deletions.
4 changes: 2 additions & 2 deletions base/message_pump_glib_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ class MessagePumpGLibTest : public testing::Test {
// This lets us call NewRunnableMethod on EventInjector instances.
template<>
struct RunnableMethodTraits<EventInjector> {
static void RetainCallee(EventInjector* obj) { }
static void ReleaseCallee(EventInjector* obj) { }
void RetainCallee(EventInjector* obj) { }
void ReleaseCallee(EventInjector* obj) { }
};

TEST_F(MessagePumpGLibTest, TestQuit) {
Expand Down
4 changes: 4 additions & 0 deletions base/ref_counted.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace subtle {

class RefCountedBase {
public:
static bool ImplementsThreadSafeReferenceCounting() { return false; }

bool HasOneRef() const { return ref_count_ == 1; }

protected:
Expand All @@ -38,6 +40,8 @@ class RefCountedBase {

class RefCountedThreadSafeBase {
public:
static bool ImplementsThreadSafeReferenceCounting() { return true; }

bool HasOneRef() const;

protected:
Expand Down
34 changes: 28 additions & 6 deletions base/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,33 @@ class ReleaseTask : public CancelableTask {

template <class T>
struct RunnableMethodTraits {
static void RetainCallee(T* obj) {
RunnableMethodTraits() {
#ifndef NDEBUG
origin_thread_id_ = PlatformThread::CurrentId();
#endif
}

~RunnableMethodTraits() {
#ifndef NDEBUG
// If destroyed on a separate thread, then we had better have been using
// thread-safe reference counting!
if (origin_thread_id_ != PlatformThread::CurrentId())
DCHECK(T::ImplementsThreadSafeReferenceCounting());
#endif
}

void RetainCallee(T* obj) {
obj->AddRef();
}
static void ReleaseCallee(T* obj) {

void ReleaseCallee(T* obj) {
obj->Release();
}

private:
#ifndef NDEBUG
PlatformThreadId origin_thread_id_;
#endif
};

// RunnableMethod and RunnableFunction -----------------------------------------
Expand Down Expand Up @@ -240,13 +261,13 @@ struct RunnableMethodTraits {
// RunnableMethod and NewRunnableMethod implementation -------------------------

template <class T, class Method, class Params>
class RunnableMethod : public CancelableTask,
public RunnableMethodTraits<T> {
class RunnableMethod : public CancelableTask {
public:
RunnableMethod(T* obj, Method meth, const Params& params)
: obj_(obj), meth_(meth), params_(params) {
RetainCallee(obj_);
traits_.RetainCallee(obj_);
}

~RunnableMethod() {
ReleaseCallee();
}
Expand All @@ -263,14 +284,15 @@ class RunnableMethod : public CancelableTask,
private:
void ReleaseCallee() {
if (obj_) {
RunnableMethodTraits<T>::ReleaseCallee(obj_);
traits_.ReleaseCallee(obj_);
obj_ = NULL;
}
}

T* obj_;
Method meth_;
Params params_;
RunnableMethodTraits<T> traits_;
};

template <class T, class Method>
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ void BrowserProcessImpl::CreateGoogleURLTracker() {
// which don't do any management.
template <>
struct RunnableMethodTraits<BrowserProcessImpl> {
static void RetainCallee(BrowserProcessImpl*) {}
static void ReleaseCallee(BrowserProcessImpl*) {}
void RetainCallee(BrowserProcessImpl*) {}
void ReleaseCallee(BrowserProcessImpl*) {}
};

void BrowserProcessImpl::CheckForInspectorFiles() {
Expand Down
15 changes: 6 additions & 9 deletions chrome/browser/browsing_data_remover.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@
#include "net/url_request/url_request_context.h"
#include "webkit/glue/password_form.h"

// Done so that we can use invokeLater on BrowsingDataRemovers and not have
// Done so that we can use PostTask on BrowsingDataRemovers and not have
// BrowsingDataRemover implement RefCounted.
template<>
void RunnableMethodTraits<BrowsingDataRemover>::RetainCallee(
BrowsingDataRemover* remover) {
}
template<>
void RunnableMethodTraits<BrowsingDataRemover>::ReleaseCallee(
BrowsingDataRemover* remover) {
}
template <>
struct RunnableMethodTraits<BrowsingDataRemover> {
void RetainCallee(BrowsingDataRemover*) {}
void ReleaseCallee(BrowsingDataRemover*) {}
};

bool BrowsingDataRemover::removing_ = false;

Expand Down
13 changes: 5 additions & 8 deletions chrome/browser/chrome_plugin_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,11 @@ class ModelessHtmlDialogDelegate : public HtmlDialogUIDelegate {

// Allows InvokeLater without adding refcounting. The object is only deleted
// when its last InvokeLater is run anyway.
template<>
void RunnableMethodTraits<ModelessHtmlDialogDelegate>::RetainCallee(
ModelessHtmlDialogDelegate* remover) {
}
template<>
void RunnableMethodTraits<ModelessHtmlDialogDelegate>::ReleaseCallee(
ModelessHtmlDialogDelegate* remover) {
}
template <>
struct RunnableMethodTraits<ModelessHtmlDialogDelegate> {
void RetainCallee(ModelessHtmlDialogDelegate*) {}
void ReleaseCallee(ModelessHtmlDialogDelegate*) {}
};

namespace {

Expand Down
13 changes: 5 additions & 8 deletions chrome/browser/chromeos/touchpad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@

// Allows InvokeLater without adding refcounting. The object is only deleted
// when its last InvokeLater is run anyway.
template<>
void RunnableMethodTraits<Touchpad>::RetainCallee(
Touchpad* remover) {
}
template<>
void RunnableMethodTraits<Touchpad>::ReleaseCallee(
Touchpad* remover) {
}
template <>
struct RunnableMethodTraits<Touchpad> {
void RetainCallee(Touchpad*) {}
void ReleaseCallee(Touchpad*) {}
};

// static
void Touchpad::RegisterUserPrefs(PrefService* prefs) {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/dom_ui/chrome_url_data_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ class ChromeURLDataManager {
// Since we have a single global ChromeURLDataManager, we don't need to
// grab a reference to it when creating Tasks involving it.
template <> struct RunnableMethodTraits<ChromeURLDataManager> {
static void RetainCallee(ChromeURLDataManager*) {}
static void ReleaseCallee(ChromeURLDataManager*) {}
void RetainCallee(ChromeURLDataManager*) {}
void ReleaseCallee(ChromeURLDataManager*) {}
};

// The single global instance of ChromeURLDataManager.
Expand Down
26 changes: 10 additions & 16 deletions chrome/browser/gears_integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,11 @@ class CreateShortcutCommand : public CPCommandInterface {

// Allows InvokeLater without adding refcounting. The object is only deleted
// when its last InvokeLater is run anyway.
template<>
void RunnableMethodTraits<CreateShortcutCommand>::RetainCallee(
CreateShortcutCommand* remover) {
}
template<>
void RunnableMethodTraits<CreateShortcutCommand>::ReleaseCallee(
CreateShortcutCommand* remover) {
}
template <>
struct RunnableMethodTraits<CreateShortcutCommand> {
void RetainCallee(CreateShortcutCommand*) {}
void ReleaseCallee(CreateShortcutCommand*) {}
};

void GearsCreateShortcut(
const webkit_glue::WebApplicationInfo& app_info,
Expand Down Expand Up @@ -299,14 +296,11 @@ class QueryShortcutsCommand : public CPCommandInterface {

// Allows InvokeLater without adding refcounting. The object is only deleted
// when its last InvokeLater is run anyway.
template<>
void RunnableMethodTraits<QueryShortcutsCommand>::RetainCallee(
QueryShortcutsCommand* remover) {
}
template<>
void RunnableMethodTraits<QueryShortcutsCommand>::ReleaseCallee(
QueryShortcutsCommand* remover) {
}
template <>
struct RunnableMethodTraits<QueryShortcutsCommand> {
void RetainCallee(QueryShortcutsCommand*) {}
void ReleaseCallee(QueryShortcutsCommand*) {}
};

void GearsQueryShortcuts(GearsQueryShortcutsCallback* callback) {
CPHandleCommand(GEARSPLUGINCOMMAND_GET_SHORTCUT_LIST,
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/history/history_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class HistoryTest;
// the HistoryTest object.
template <>
struct RunnableMethodTraits<history::HistoryTest> {
static void RetainCallee(history::HistoryTest* obj) { }
static void ReleaseCallee(history::HistoryTest* obj) { }
void RetainCallee(history::HistoryTest* obj) { }
void ReleaseCallee(history::HistoryTest* obj) { }
};

namespace history {
Expand Down
11 changes: 1 addition & 10 deletions chrome/browser/printing/print_job.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "base/basictypes.h"
#include "base/gfx/native_widget_types.h"
#include "base/message_loop.h"
#include "base/ref_counted.h"
#include "chrome/browser/printing/print_job_worker_owner.h"
#include "chrome/common/notification_registrar.h"

Expand All @@ -32,9 +31,8 @@ class PrinterQuery;
// any state change. While printing, the PrintJobManager instance keeps a
// reference to the job to be sure it is kept alive. All the code in this class
// runs in the UI thread.
class PrintJob : public base::RefCountedThreadSafe<PrintJob>,
class PrintJob : public PrintJobWorkerOwner,
public NotificationObserver,
public PrintJobWorkerOwner,
public MessageLoop::DestructionObserver {
public:
// Create a empty PrintJob. When initializing with this constructor,
Expand All @@ -52,13 +50,6 @@ class PrintJob : public base::RefCountedThreadSafe<PrintJob>,
const NotificationDetails& details);

// PrintJobWorkerOwner
virtual void AddRef() {
return base::RefCountedThreadSafe<PrintJob>::AddRef();
}
virtual void Release() {
return base::RefCountedThreadSafe<PrintJob>::Release();
}

virtual void GetSettingsDone(const PrintSettings& new_settings,
PrintingContext::Result result);
virtual PrintJobWorker* DetachWorker(PrintJobWorkerOwner* new_owner);
Expand Down
10 changes: 2 additions & 8 deletions chrome/browser/printing/print_job_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ class TestPrintJobWorker : public printing::PrintJobWorker {

class TestOwner : public printing::PrintJobWorkerOwner {
public:
virtual void AddRef() {
EXPECT_FALSE(true);
}
virtual void Release() {
EXPECT_FALSE(true);
}
virtual void GetSettingsDone(const printing::PrintSettings& new_settings,
printing::PrintingContext::Result result) {
EXPECT_FALSE(true);
Expand Down Expand Up @@ -104,9 +98,9 @@ TEST(PrintJobTest, SimplePrint) {
volatile bool check = false;
scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check));
EXPECT_EQ(MessageLoop::current(), job->message_loop());
TestOwner owner;
scoped_refptr<TestOwner> owner(new TestOwner);
TestSource source;
job->Initialize(&owner, &source);
job->Initialize(owner, &source);
job->Stop();
job = NULL;
EXPECT_TRUE(check);
Expand Down
3 changes: 0 additions & 3 deletions chrome/browser/printing/print_job_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,6 @@ void PrintJobWorker::OnFailure() {

} // namespace printing

RunnableMethodTraits<printing::PrintJobWorker>::RunnableMethodTraits() {
}

void RunnableMethodTraits<printing::PrintJobWorker>::RetainCallee(
printing::PrintJobWorker* obj) {
DCHECK(!owner_.get());
Expand Down
1 change: 0 additions & 1 deletion chrome/browser/printing/print_job_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ class PrintJobWorker : public base::Thread {

template <>
struct RunnableMethodTraits<printing::PrintJobWorker> {
RunnableMethodTraits();
void RetainCallee(printing::PrintJobWorker* obj);
void ReleaseCallee(printing::PrintJobWorker* obj);
private:
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/printing/print_job_worker_owner.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_OWNER_H__
#define CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_OWNER_H__

#include "base/ref_counted.h"
#include "printing/printing_context.h"

class MessageLoop;
Expand All @@ -14,12 +15,11 @@ namespace printing {
class PrintJobWorker;
class PrintSettings;

class PrintJobWorkerOwner {
class PrintJobWorkerOwner :
public base::RefCountedThreadSafe<PrintJobWorkerOwner> {
public:
virtual ~PrintJobWorkerOwner() {
}
virtual void AddRef() = 0;
virtual void Release() = 0;

// Finishes the initialization began by PrintJobWorker::Init(). Creates a
// new PrintedDocument if necessary. Solely meant to be called by
Expand Down
10 changes: 1 addition & 9 deletions chrome/browser/printing/printer_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define CHROME_BROWSER_PRINTING_PRINTER_QUERY_H_

#include "base/scoped_ptr.h"
#include "base/ref_counted.h"
#include "chrome/browser/printing/print_job_worker_owner.h"

class CancelableTask;
Expand All @@ -21,8 +20,7 @@ namespace printing {
class PrintJobWorker;

// Query the printer for settings.
class PrinterQuery : public base::RefCountedThreadSafe<PrinterQuery>,
public PrintJobWorkerOwner {
class PrinterQuery : public PrintJobWorkerOwner {
public:
// GetSettings() UI parameter.
enum GetSettingsAskParam {
Expand All @@ -34,12 +32,6 @@ class PrinterQuery : public base::RefCountedThreadSafe<PrinterQuery>,
virtual ~PrinterQuery();

// PrintJobWorkerOwner
virtual void AddRef() {
return base::RefCountedThreadSafe<PrinterQuery>::AddRef();
}
virtual void Release() {
return base::RefCountedThreadSafe<PrinterQuery>::Release();
}
virtual void GetSettingsDone(const PrintSettings& new_settings,
PrintingContext::Result result);
virtual PrintJobWorker* DetachWorker(PrintJobWorkerOwner* new_owner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ static bool FindProcessHoldingSocket(pid_t* pid_out, uint64_t socket_inode) {
// end of the processes lifetime, which is greater in span then the lifetime of
// the IO message loop.
template<> struct RunnableMethodTraits<RenderCrashHandlerHostLinux> {
static void RetainCallee(RenderCrashHandlerHostLinux*) { }
static void ReleaseCallee(RenderCrashHandlerHostLinux*) { }
void RetainCallee(RenderCrashHandlerHostLinux*) { }
void ReleaseCallee(RenderCrashHandlerHostLinux*) { }
};

RenderCrashHandlerHostLinux::RenderCrashHandlerHostLinux()
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/visitedlink_master.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ class AsyncCloseHandle : public Task {
// Sometimes, the master will be deleted before the rebuild is complete, in
// which case it notifies the builder via DisownMaster(). The builder will
// delete itself once rebuilding is complete, and not execute any callback.
class VisitedLinkMaster::TableBuilder : public HistoryService::URLEnumerator,
public base::RefCounted<TableBuilder> {
class VisitedLinkMaster::TableBuilder :
public HistoryService::URLEnumerator,
public base::RefCountedThreadSafe<TableBuilder> {
public:
TableBuilder(VisitedLinkMaster* master,
const uint8 salt[LINK_SALT_LENGTH]);
Expand Down
4 changes: 2 additions & 2 deletions chrome/common/extensions/extension_error_reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
// This is okay since the ExtensionErrorReporter is a singleton that lives until
// the end of the process.
template <> struct RunnableMethodTraits<ExtensionErrorReporter> {
static void RetainCallee(ExtensionErrorReporter*) {}
static void ReleaseCallee(ExtensionErrorReporter*) {}
void RetainCallee(ExtensionErrorReporter*) {}
void ReleaseCallee(ExtensionErrorReporter*) {}
};

ExtensionErrorReporter* ExtensionErrorReporter::instance_ = NULL;
Expand Down
Loading

0 comments on commit 39fe32a

Please sign in to comment.