diff options
17 files changed, 228 insertions, 65 deletions
diff --git a/chrome/browser/sync/engine/model_changing_syncer_command.cc b/chrome/browser/sync/engine/model_changing_syncer_command.cc index 797f795..407c299 100644 --- a/chrome/browser/sync/engine/model_changing_syncer_command.cc +++ b/chrome/browser/sync/engine/model_changing_syncer_command.cc @@ -4,10 +4,12 @@ #include "chrome/browser/sync/engine/model_changing_syncer_command.h" +#include "base/basictypes.h" #include "base/callback_old.h" #include "chrome/browser/sync/engine/model_safe_worker.h" #include "chrome/browser/sync/sessions/status_controller.h" #include "chrome/browser/sync/sessions/sync_session.h" +#include "chrome/browser/sync/util/unrecoverable_error_info.h" namespace browser_sync { @@ -45,9 +47,15 @@ void ModelChangingSyncerCommand::ExecuteImpl(sessions::SyncSession* session) { sessions::StatusController* status = work_session_->status_controller(); sessions::ScopedModelSafeGroupRestriction r(status, group); - scoped_ptr<Callback0::Type> c(NewCallback(this, - &ModelChangingSyncerCommand::StartChangingModel)); - worker->DoWorkAndWaitUntilDone(c.get()); + WorkCallback c = base::Bind( + &ModelChangingSyncerCommand::StartChangingModel, + // We wait until the callback is executed. So it is safe to use + // unretained. + base::Unretained(this)); + + // TODO(lipalani): Check the return value for an unrecoverable error. + ignore_result(worker->DoWorkAndWaitUntilDone(c)); + } } diff --git a/chrome/browser/sync/engine/model_changing_syncer_command.h b/chrome/browser/sync/engine/model_changing_syncer_command.h index f6d6a43..36172e7 100644 --- a/chrome/browser/sync/engine/model_changing_syncer_command.h +++ b/chrome/browser/sync/engine/model_changing_syncer_command.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,6 +7,7 @@ #pragma once #include "chrome/browser/sync/engine/syncer_command.h" +#include "chrome/browser/sync/util/unrecoverable_error_info.h" namespace browser_sync { namespace sessions { @@ -32,8 +33,11 @@ class ModelChangingSyncerCommand : public SyncerCommand { virtual void ExecuteImpl(sessions::SyncSession* session); // wrapper so implementations don't worry about storing work_session - void StartChangingModel() { + UnrecoverableErrorInfo StartChangingModel() { + // TODO(lipalani): |ModelChangingExecuteImpl| should return an + // UnrecoverableErrorInfo struct. ModelChangingExecuteImpl(work_session_); + return UnrecoverableErrorInfo(); } // Sometimes, a command has work to do that needs to touch global state diff --git a/chrome/browser/sync/engine/model_safe_worker.cc b/chrome/browser/sync/engine/model_safe_worker.cc index ae94b26..907d75e 100644 --- a/chrome/browser/sync/engine/model_safe_worker.cc +++ b/chrome/browser/sync/engine/model_safe_worker.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "chrome/browser/sync/engine/model_safe_worker.h" +#include "chrome/browser/sync/util/unrecoverable_error_info.h" #include "base/json/json_writer.h" #include "base/memory/scoped_ptr.h" @@ -74,8 +75,10 @@ ModelSafeWorker::ModelSafeWorker() {} ModelSafeWorker::~ModelSafeWorker() {} -void ModelSafeWorker::DoWorkAndWaitUntilDone(Callback0::Type* work) { - work->Run(); // For GROUP_PASSIVE, we do the work on the current thread. +UnrecoverableErrorInfo ModelSafeWorker::DoWorkAndWaitUntilDone( + const WorkCallback& work) { + // For GROUP_PASSIVE, we do the work on the current thread. + return work.Run(); } ModelSafeGroup ModelSafeWorker::GetModelSafeGroup() { diff --git a/chrome/browser/sync/engine/model_safe_worker.h b/chrome/browser/sync/engine/model_safe_worker.h index f4829ec..3a707db 100644 --- a/chrome/browser/sync/engine/model_safe_worker.h +++ b/chrome/browser/sync/engine/model_safe_worker.h @@ -10,9 +10,11 @@ #include <string> #include <vector> +#include "base/callback.h" #include "base/callback_old.h" #include "base/memory/ref_counted.h" #include "chrome/browser/sync/syncable/model_type.h" +#include "chrome/browser/sync/util/unrecoverable_error_info.h" namespace base { class DictionaryValue; @@ -20,6 +22,8 @@ class DictionaryValue; namespace browser_sync { +typedef base::Callback<UnrecoverableErrorInfo(void)> WorkCallback; + enum ModelSafeGroup { GROUP_PASSIVE = 0, // Models that are just "passively" being synced; e.g. // changes to these models don't need to be pushed to a @@ -52,7 +56,8 @@ class ModelSafeWorker : public base::RefCountedThreadSafe<ModelSafeWorker> { // Any time the Syncer performs model modifications (e.g employing a // WriteTransaction), it should be done by this method to ensure it is done // from a model-safe thread. - virtual void DoWorkAndWaitUntilDone(Callback0::Type* work); + virtual UnrecoverableErrorInfo DoWorkAndWaitUntilDone( + const WorkCallback& work); virtual ModelSafeGroup GetModelSafeGroup(); diff --git a/chrome/browser/sync/glue/browser_thread_model_worker.cc b/chrome/browser/sync/glue/browser_thread_model_worker.cc index de2ae424..9c1abdf 100644 --- a/chrome/browser/sync/glue/browser_thread_model_worker.cc +++ b/chrome/browser/sync/glue/browser_thread_model_worker.cc @@ -17,11 +17,12 @@ BrowserThreadModelWorker::BrowserThreadModelWorker( BrowserThreadModelWorker::~BrowserThreadModelWorker() {} -void BrowserThreadModelWorker::DoWorkAndWaitUntilDone(Callback0::Type* work) { +UnrecoverableErrorInfo BrowserThreadModelWorker::DoWorkAndWaitUntilDone( + const WorkCallback& work) { + UnrecoverableErrorInfo error_info; if (BrowserThread::CurrentlyOn(thread_)) { DLOG(WARNING) << "Already on thread " << thread_; - work->Run(); - return; + return work.Run(); } WaitableEvent done(false, false); if (!BrowserThread::PostTask( @@ -31,17 +32,21 @@ void BrowserThreadModelWorker::DoWorkAndWaitUntilDone(Callback0::Type* work) { this, &BrowserThreadModelWorker::CallDoWorkAndSignalTask, work, - &done))) { + &done, + &error_info))) { NOTREACHED() << "Failed to post task to thread " << thread_; - return; + return error_info; } done.Wait(); + return error_info; } void BrowserThreadModelWorker::CallDoWorkAndSignalTask( - Callback0::Type* work, WaitableEvent* done) { + const WorkCallback& work, + WaitableEvent* done, + UnrecoverableErrorInfo* error_info) { DCHECK(BrowserThread::CurrentlyOn(thread_)); - work->Run(); + *error_info = work.Run(); done->Signal(); } @@ -55,8 +60,10 @@ DatabaseModelWorker::DatabaseModelWorker() DatabaseModelWorker::~DatabaseModelWorker() {} void DatabaseModelWorker::CallDoWorkAndSignalTask( - Callback0::Type* work, WaitableEvent* done) { - BrowserThreadModelWorker::CallDoWorkAndSignalTask(work, done); + const WorkCallback& work, + WaitableEvent* done, + UnrecoverableErrorInfo* error_info) { + BrowserThreadModelWorker::CallDoWorkAndSignalTask(work, done, error_info); } FileModelWorker::FileModelWorker() @@ -65,8 +72,10 @@ FileModelWorker::FileModelWorker() FileModelWorker::~FileModelWorker() {} void FileModelWorker::CallDoWorkAndSignalTask( - Callback0::Type* work, WaitableEvent* done) { - BrowserThreadModelWorker::CallDoWorkAndSignalTask(work, done); + const WorkCallback& work, + WaitableEvent* done, + UnrecoverableErrorInfo* error_info) { + BrowserThreadModelWorker::CallDoWorkAndSignalTask(work, done, error_info); } } // namespace browser_sync diff --git a/chrome/browser/sync/glue/browser_thread_model_worker.h b/chrome/browser/sync/glue/browser_thread_model_worker.h index c1c0730..487e56c 100644 --- a/chrome/browser/sync/glue/browser_thread_model_worker.h +++ b/chrome/browser/sync/glue/browser_thread_model_worker.h @@ -10,6 +10,7 @@ #include "base/callback.h" #include "base/compiler_specific.h" #include "chrome/browser/sync/engine/model_safe_worker.h" +#include "chrome/browser/sync/util/unrecoverable_error_info.h" #include "content/browser/browser_thread.h" namespace base { @@ -27,15 +28,18 @@ class BrowserThreadModelWorker : public browser_sync::ModelSafeWorker { virtual ~BrowserThreadModelWorker(); // ModelSafeWorker implementation. Called on the sync thread. - virtual void DoWorkAndWaitUntilDone(Callback0::Type* work); - virtual ModelSafeGroup GetModelSafeGroup(); + virtual UnrecoverableErrorInfo DoWorkAndWaitUntilDone( + const WorkCallback& work) OVERRIDE; + virtual ModelSafeGroup GetModelSafeGroup() OVERRIDE; protected: // Marked pure virtual so subclasses have to override, but there is // an implementation that subclasses should use. This is so that // (subclass)::CallDoWorkAndSignalTask shows up in callstacks. virtual void CallDoWorkAndSignalTask( - Callback0::Type* work, base::WaitableEvent* done) = 0; + const WorkCallback& work, + base::WaitableEvent* done, + UnrecoverableErrorInfo* error_info) = 0; private: BrowserThread::ID thread_; @@ -54,7 +58,9 @@ class DatabaseModelWorker : public BrowserThreadModelWorker { protected: virtual void CallDoWorkAndSignalTask( - Callback0::Type* work, base::WaitableEvent* done) OVERRIDE; + const WorkCallback& work, + base::WaitableEvent* done, + UnrecoverableErrorInfo* error_info) OVERRIDE; }; class FileModelWorker : public BrowserThreadModelWorker { @@ -64,7 +70,9 @@ class FileModelWorker : public BrowserThreadModelWorker { protected: virtual void CallDoWorkAndSignalTask( - Callback0::Type* work, base::WaitableEvent* done) OVERRIDE; + const WorkCallback& work, + base::WaitableEvent* done, + UnrecoverableErrorInfo* error_info) OVERRIDE; }; } // namespace browser_sync diff --git a/chrome/browser/sync/glue/browser_thread_model_worker_unittest.cc b/chrome/browser/sync/glue/browser_thread_model_worker_unittest.cc index 63e6322..dd8f613 100644 --- a/chrome/browser/sync/glue/browser_thread_model_worker_unittest.cc +++ b/chrome/browser/sync/glue/browser_thread_model_worker_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/bind.h" #include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" @@ -9,6 +10,7 @@ #include "base/test/test_timeouts.h" #include "base/timer.h" #include "chrome/browser/sync/glue/browser_thread_model_worker.h" +#include "chrome/browser/sync/util/unrecoverable_error_info.h" #include "content/browser/browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" @@ -38,23 +40,25 @@ class BrowserThreadModelWorkerTest : public testing::Test { // Schedule DoWork to be executed on the DB thread and have the test fail if // DoWork hasn't executed within action_timeout_ms() ms. void ScheduleWork() { - scoped_ptr<Callback0::Type> c(NewCallback(this, - &BrowserThreadModelWorkerTest::DoWork)); + // We wait until the callback is done. So it is safe to use unretained. + WorkCallback c = base::Bind(&BrowserThreadModelWorkerTest::DoWork, + base::Unretained(this)); timer()->Start( FROM_HERE, TimeDelta::FromMilliseconds(TestTimeouts::action_timeout_ms()), this, &BrowserThreadModelWorkerTest::Timeout); - worker()->DoWorkAndWaitUntilDone(c.get()); + worker()->DoWorkAndWaitUntilDone(c); } // This is the work that will be scheduled to be done on the DB thread. - void DoWork() { + UnrecoverableErrorInfo DoWork() { EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); timer_.Stop(); // Stop the failure timer so the test succeeds. BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, new MessageLoop::QuitTask()); did_do_work_ = true; + return UnrecoverableErrorInfo(); } // This will be called by the OneShotTimer and make the test fail unless diff --git a/chrome/browser/sync/glue/history_model_worker.cc b/chrome/browser/sync/glue/history_model_worker.cc index 5ad8664..84200ac 100644 --- a/chrome/browser/sync/glue/history_model_worker.cc +++ b/chrome/browser/sync/glue/history_model_worker.cc @@ -16,12 +16,15 @@ namespace browser_sync { class WorkerTask : public HistoryDBTask { public: - WorkerTask(Callback0::Type* work, WaitableEvent* done) - : work_(work), done_(done) {} + WorkerTask( + const WorkCallback& work, + WaitableEvent* done, + UnrecoverableErrorInfo* error_info) + : work_(work), done_(done), error_info_(error_info) {} virtual bool RunOnDBThread(history::HistoryBackend* backend, history::HistoryDatabase* db) { - work_->Run(); + *error_info_ = work_.Run(); done_->Signal(); return true; } @@ -31,8 +34,9 @@ class WorkerTask : public HistoryDBTask { virtual void DoneRunOnMainThread() {} protected: - Callback0::Type* work_; + WorkCallback work_; WaitableEvent* done_; + UnrecoverableErrorInfo* error_info_; }; @@ -44,11 +48,14 @@ HistoryModelWorker::HistoryModelWorker(HistoryService* history_service) HistoryModelWorker::~HistoryModelWorker() { } -void HistoryModelWorker::DoWorkAndWaitUntilDone(Callback0::Type* work) { +UnrecoverableErrorInfo HistoryModelWorker::DoWorkAndWaitUntilDone( + const WorkCallback& work) { WaitableEvent done(false, false); - scoped_refptr<WorkerTask> task(new WorkerTask(work, &done)); + UnrecoverableErrorInfo error_info; + scoped_refptr<WorkerTask> task(new WorkerTask(work, &done, &error_info)); history_service_->ScheduleDBTask(task.get(), &cancelable_consumer_); done.Wait(); + return error_info; } ModelSafeGroup HistoryModelWorker::GetModelSafeGroup() { diff --git a/chrome/browser/sync/glue/history_model_worker.h b/chrome/browser/sync/glue/history_model_worker.h index ccf1b04..86586b0 100644 --- a/chrome/browser/sync/glue/history_model_worker.h +++ b/chrome/browser/sync/glue/history_model_worker.h @@ -7,6 +7,7 @@ #pragma once #include "chrome/browser/sync/engine/model_safe_worker.h" +#include "chrome/browser/sync/util/unrecoverable_error_info.h" #include "base/basictypes.h" #include "base/callback.h" @@ -29,8 +30,9 @@ class HistoryModelWorker : public browser_sync::ModelSafeWorker { virtual ~HistoryModelWorker(); // ModelSafeWorker implementation. Called on syncapi SyncerThread. - virtual void DoWorkAndWaitUntilDone(Callback0::Type* work); - virtual ModelSafeGroup GetModelSafeGroup(); + virtual UnrecoverableErrorInfo DoWorkAndWaitUntilDone( + const WorkCallback& work) OVERRIDE; + virtual ModelSafeGroup GetModelSafeGroup() OVERRIDE; private: scoped_refptr<HistoryService> history_service_; diff --git a/chrome/browser/sync/glue/password_model_worker.cc b/chrome/browser/sync/glue/password_model_worker.cc index 1b4ad83..2024f3b 100644 --- a/chrome/browser/sync/glue/password_model_worker.cc +++ b/chrome/browser/sync/glue/password_model_worker.cc @@ -21,17 +21,22 @@ PasswordModelWorker::PasswordModelWorker(PasswordStore* password_store) PasswordModelWorker::~PasswordModelWorker() {} -void PasswordModelWorker::DoWorkAndWaitUntilDone(Callback0::Type* work) { +UnrecoverableErrorInfo PasswordModelWorker::DoWorkAndWaitUntilDone( + const WorkCallback& work) { WaitableEvent done(false, false); + UnrecoverableErrorInfo error_info; password_store_->ScheduleTask( NewRunnableMethod(this, &PasswordModelWorker::CallDoWorkAndSignalTask, - work, &done)); + work, &done, &error_info)); done.Wait(); + return error_info; } -void PasswordModelWorker::CallDoWorkAndSignalTask(Callback0::Type* work, - WaitableEvent* done) { - work->Run(); +void PasswordModelWorker::CallDoWorkAndSignalTask( + const WorkCallback& work, + WaitableEvent* done, + UnrecoverableErrorInfo* error_info) { + *error_info = work.Run(); done->Signal(); } diff --git a/chrome/browser/sync/glue/password_model_worker.h b/chrome/browser/sync/glue/password_model_worker.h index 8aa4956..53f6c7c 100644 --- a/chrome/browser/sync/glue/password_model_worker.h +++ b/chrome/browser/sync/glue/password_model_worker.h @@ -7,9 +7,11 @@ #pragma once #include "chrome/browser/sync/engine/model_safe_worker.h" +#include "chrome/browser/sync/util/unrecoverable_error_info.h" #include "base/basictypes.h" #include "base/callback.h" +#include "base/compiler_specific.h" #include "base/memory/ref_counted.h" class PasswordStore; @@ -29,12 +31,15 @@ class PasswordModelWorker : public browser_sync::ModelSafeWorker { virtual ~PasswordModelWorker(); // ModelSafeWorker implementation. Called on syncapi SyncerThread. - virtual void DoWorkAndWaitUntilDone(Callback0::Type* work); - virtual ModelSafeGroup GetModelSafeGroup(); + virtual UnrecoverableErrorInfo DoWorkAndWaitUntilDone( + const WorkCallback& work) OVERRIDE; + virtual ModelSafeGroup GetModelSafeGroup() OVERRIDE; private: - void CallDoWorkAndSignalTask(Callback0::Type* work, - base::WaitableEvent* done); + void CallDoWorkAndSignalTask( + const WorkCallback& work, + base::WaitableEvent* done, + UnrecoverableErrorInfo* error_info); scoped_refptr<PasswordStore> password_store_; DISALLOW_COPY_AND_ASSIGN(PasswordModelWorker); diff --git a/chrome/browser/sync/glue/ui_model_worker.cc b/chrome/browser/sync/glue/ui_model_worker.cc index 020e3c9..3139929 100644 --- a/chrome/browser/sync/glue/ui_model_worker.cc +++ b/chrome/browser/sync/glue/ui_model_worker.cc @@ -11,7 +11,8 @@ namespace browser_sync { -void UIModelWorker::DoWorkAndWaitUntilDone(Callback0::Type* work) { +UnrecoverableErrorInfo UIModelWorker::DoWorkAndWaitUntilDone( + const WorkCallback& work) { // In most cases, this method is called in WORKING state. It is possible this // gets called when we are in the RUNNING_MANUAL_SHUTDOWN_PUMP state, because // the UI loop has initiated shutdown but the syncer hasn't got the memo yet. @@ -19,12 +20,11 @@ void UIModelWorker::DoWorkAndWaitUntilDone(Callback0::Type* work) { // code handling this case in Stop(). Note there _no_ way we can be in here // with state_ = STOPPED, so it is safe to read / compare in this case. CHECK_NE(ANNOTATE_UNPROTECTED_READ(state_), STOPPED); - + UnrecoverableErrorInfo error_info; if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { DLOG(WARNING) << "DoWorkAndWaitUntilDone called from " << "ui_loop_. Probably a nested invocation?"; - work->Run(); - return; + return work.Run(); } // Create an unsignaled event to wait on. @@ -35,16 +35,19 @@ void UIModelWorker::DoWorkAndWaitUntilDone(Callback0::Type* work) { // The task is owned by the message loop as per usual. base::AutoLock lock(lock_); DCHECK(!pending_work_); - pending_work_ = new CallDoWorkAndSignalTask(work, &work_done, this); + UnrecoverableErrorInfo error_info; + pending_work_ = new CallDoWorkAndSignalTask(work, &work_done, this, + &error_info); if (!BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, pending_work_)) { LOG(WARNING) << "Could not post work to UI loop."; pending_work_ = NULL; syncapi_event_.Signal(); - return; + return error_info; } } syncapi_event_.Signal(); // Notify that the syncapi produced work for us. work_done.Wait(); + return error_info; } UIModelWorker::UIModelWorker() @@ -99,7 +102,7 @@ ModelSafeGroup UIModelWorker::GetModelSafeGroup() { } void UIModelWorker::CallDoWorkAndSignalTask::Run() { - if (!work_) { + if (work_.is_null()) { // This can happen during tests or cases where there are more than just the // default UIModelWorker in existence and it gets destroyed before // the main UI loop has terminated. There is no easy way to assert the @@ -110,11 +113,11 @@ void UIModelWorker::CallDoWorkAndSignalTask::Run() { // actually gets destroyed. return; } - work_->Run(); + *error_info_ = work_.Run(); // Sever ties with work_ to allow the sanity-checking above that we don't // get run twice. - work_ = NULL; + work_.Reset(); // Notify the UIModelWorker that scheduled us that we have run // successfully. diff --git a/chrome/browser/sync/glue/ui_model_worker.h b/chrome/browser/sync/glue/ui_model_worker.h index a9d35bd..6008f6d 100644 --- a/chrome/browser/sync/glue/ui_model_worker.h +++ b/chrome/browser/sync/glue/ui_model_worker.h @@ -7,10 +7,12 @@ #pragma once #include "base/callback.h" +#include "base/compiler_specific.h" #include "base/synchronization/condition_variable.h" #include "base/synchronization/lock.h" #include "base/task.h" #include "chrome/browser/sync/engine/model_safe_worker.h" +#include "chrome/browser/sync/util/unrecoverable_error_info.h" namespace base { class WaitableEvent; @@ -36,10 +38,13 @@ class UIModelWorker : public browser_sync::ModelSafeWorker { // A simple task to signal a waitable event after Run()ning a Closure. class CallDoWorkAndSignalTask : public Task { public: - CallDoWorkAndSignalTask(Callback0::Type* work, - base::WaitableEvent* work_done, - UIModelWorker* scheduler) - : work_(work), work_done_(work_done), scheduler_(scheduler) { + CallDoWorkAndSignalTask( + const WorkCallback& work, + base::WaitableEvent* work_done, + UIModelWorker* scheduler, + UnrecoverableErrorInfo* error_info) + : work_(work), work_done_(work_done), scheduler_(scheduler), + error_info_(error_info) { } virtual ~CallDoWorkAndSignalTask() { } @@ -49,12 +54,14 @@ class UIModelWorker : public browser_sync::ModelSafeWorker { private: // Task data - a closure and a waitable event to signal after the work has // been done. - Callback0::Type* work_; + WorkCallback work_; base::WaitableEvent* work_done_; // The UIModelWorker responsible for scheduling us. UIModelWorker* const scheduler_; + UnrecoverableErrorInfo* error_info_; + DISALLOW_COPY_AND_ASSIGN(CallDoWorkAndSignalTask); }; @@ -65,8 +72,9 @@ class UIModelWorker : public browser_sync::ModelSafeWorker { void Stop(); // ModelSafeWorker implementation. Called on syncapi SyncerThread. - virtual void DoWorkAndWaitUntilDone(Callback0::Type* work); - virtual ModelSafeGroup GetModelSafeGroup(); + virtual UnrecoverableErrorInfo DoWorkAndWaitUntilDone( + const WorkCallback& work) OVERRIDE; + virtual ModelSafeGroup GetModelSafeGroup() OVERRIDE; // Upon receiving this idempotent call, the ModelSafeWorker can // assume no work will ever be scheduled again from now on. If it has any work diff --git a/chrome/browser/sync/glue/ui_model_worker_unittest.cc b/chrome/browser/sync/glue/ui_model_worker_unittest.cc index c0230f1..c904ad3 100644 --- a/chrome/browser/sync/glue/ui_model_worker_unittest.cc +++ b/chrome/browser/sync/glue/ui_model_worker_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/bind.h" #include "base/callback.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" @@ -9,10 +10,12 @@ #include "base/synchronization/waitable_event.h" #include "base/threading/thread.h" #include "chrome/browser/sync/glue/ui_model_worker.h" +#include "chrome/browser/sync/util/unrecoverable_error_info.h" #include "content/browser/browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" using browser_sync::UIModelWorker; +using browser_sync::UnrecoverableErrorInfo; // Various boilerplate, primarily for the StopWithPendingWork test. @@ -24,11 +27,12 @@ class UIModelWorkerVisitor { was_run_(was_run) { } virtual ~UIModelWorkerVisitor() { } - virtual void DoWork() { + virtual UnrecoverableErrorInfo DoWork() { EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); was_run_->Signal(); if (quit_loop_when_run_) MessageLoop::current()->Quit(); + return UnrecoverableErrorInfo(); } private: @@ -44,9 +48,10 @@ class Syncer { ~Syncer() {} void SyncShare(UIModelWorkerVisitor* visitor) { - scoped_ptr<Callback0::Type> c(NewCallback(visitor, - &UIModelWorkerVisitor::DoWork)); - worker_->DoWorkAndWaitUntilDone(c.get()); + // We wait until the callback is executed. So it is safe to use Unretained. + browser_sync::WorkCallback c = base::Bind(&UIModelWorkerVisitor::DoWork, + base::Unretained(visitor)); + worker_->DoWorkAndWaitUntilDone(c); } private: scoped_refptr<UIModelWorker> worker_; diff --git a/chrome/browser/sync/util/unrecoverable_error_info.cc b/chrome/browser/sync/util/unrecoverable_error_info.cc new file mode 100644 index 0000000..579eb38 --- /dev/null +++ b/chrome/browser/sync/util/unrecoverable_error_info.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/sync/util/unrecoverable_error_info.h" + +namespace browser_sync { + +UnrecoverableErrorInfo::UnrecoverableErrorInfo() + : is_set_(false) { +} + +UnrecoverableErrorInfo::UnrecoverableErrorInfo( + const tracked_objects::Location& location, + const std::string& message) + : location_(location), + message_(message), + is_set_(true) { +} + +UnrecoverableErrorInfo::~UnrecoverableErrorInfo() { +} + +void UnrecoverableErrorInfo::Reset( + const tracked_objects::Location& location, + const std::string& message) { + location_ = location; + message_ = message; + is_set_ = true; +} + +bool UnrecoverableErrorInfo::IsSet() const { + return is_set_; +} + +const tracked_objects::Location& UnrecoverableErrorInfo::location() const { + return location_; +} + +const std::string& UnrecoverableErrorInfo::message() const { + return message_; +} + +} // namespace browser_sync diff --git a/chrome/browser/sync/util/unrecoverable_error_info.h b/chrome/browser/sync/util/unrecoverable_error_info.h new file mode 100644 index 0000000..dd62c30 --- /dev/null +++ b/chrome/browser/sync/util/unrecoverable_error_info.h @@ -0,0 +1,41 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_SYNC_UTIL_UNRECOVERABLE_ERROR_INFO_H_ +#define CHROME_BROWSER_SYNC_UTIL_UNRECOVERABLE_ERROR_INFO_H_ +// TODO(lipalani): Figure out the right location for this class so it is +// accessible outside of sync engine as well. +#pragma once + +#include <string> + +#include "base/location.h" + +namespace browser_sync { + +class UnrecoverableErrorInfo { + public: + UnrecoverableErrorInfo(); + UnrecoverableErrorInfo( + const tracked_objects::Location& location, + const std::string& message); + ~UnrecoverableErrorInfo(); + + void Reset(const tracked_objects::Location& location, + const std::string& message); + + bool IsSet() const; + + const tracked_objects::Location& location() const; + const std::string& message() const; + + private: + tracked_objects::Location location_; + std::string message_; + bool is_set_; +}; + +} // namespace browser_sync + +#endif // CHROME_BROWSER_SYNC_UTIL_UNRECOVERABLE_ERROR_INFO_H_ diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 1901409..f24c509 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -710,6 +710,8 @@ 'browser/sync/util/sqlite_utils.h', 'browser/sync/util/time.cc', 'browser/sync/util/time.h', + 'browser/sync/util/unrecoverable_error_info.h', + 'browser/sync/util/unrecoverable_error_info.cc', 'browser/sync/util/user_settings.cc', 'browser/sync/util/user_settings.h', 'browser/sync/util/user_settings_posix.cc', |