Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3659)

Unified Diff: chrome/browser/extensions/test_extension_prefs.cc

Issue 11027070: Moved JsonPrefStore to use SequencedWorkerPool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/test_extension_prefs.cc
diff --git a/chrome/browser/extensions/test_extension_prefs.cc b/chrome/browser/extensions/test_extension_prefs.cc
index 6df506a9da624091f1022c832177959b653ff929..b9a8613fcf5ca008bcc664d6173289ac60305466 100644
--- a/chrome/browser/extensions/test_extension_prefs.cc
+++ b/chrome/browser/extensions/test_extension_prefs.cc
@@ -10,6 +10,8 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
+#include "base/run_loop.h"
+#include "base/sequenced_task_runner.h"
#include "base/synchronization/waitable_event.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_pref_store.h"
@@ -31,6 +33,8 @@ namespace extensions {
namespace {
+void DoNothing() {}
+
// Mock ExtensionPrefs class with artificial clock to guarantee that no two
// extensions get the same installation time stamp and we can reliably
// assert the installation order in the tests below.
@@ -54,9 +58,10 @@ class MockExtensionPrefs : public ExtensionPrefs {
} // namespace
-TestExtensionPrefs::TestExtensionPrefs()
- : pref_service_(NULL),
- extensions_disabled_(false) {
+TestExtensionPrefs::TestExtensionPrefs(
+ base::SequencedTaskRunner* task_runner) : pref_service_(NULL),
+ extensions_disabled_(false) {
+ task_runner_ = task_runner;
akalin 2012/10/19 02:00:51 initialize in constructor list
zel 2012/10/19 18:45:07 Done.
EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
preferences_file_ = temp_dir_.path().AppendASCII("Preferences");
extensions_dir_ = temp_dir_.path().AppendASCII("Extensions");
@@ -65,36 +70,27 @@ TestExtensionPrefs::TestExtensionPrefs()
RecreateExtensionPrefs();
}
-TestExtensionPrefs::~TestExtensionPrefs() {}
+TestExtensionPrefs::~TestExtensionPrefs() {
+}
void TestExtensionPrefs::RecreateExtensionPrefs() {
// We persist and reload the PrefService's PrefStores because this process
// deletes all empty dictionaries. The ExtensionPrefs implementation
// needs to be able to handle this situation.
if (pref_service_.get()) {
- // The PrefService writes its persistent file on the file thread, so we
- // need to wait for any pending I/O to complete before creating a new
- // PrefService.
- base::WaitableEvent io_finished(false, false);
- pref_service_-> CommitPendingWrite();
- EXPECT_TRUE(BrowserThread::PostTask(
- BrowserThread::FILE,
- FROM_HERE,
- base::Bind(&base::WaitableEvent::Signal,
- base::Unretained(&io_finished))));
-
- // If the FILE thread is in fact the current thread (possible in testing
- // scenarios), we have to ensure the task has a chance to run. If the FILE
- // thread is a different thread, the test must ensure that thread is running
- // (otherwise the Wait below will hang).
- MessageLoop::current()->RunAllPending();
-
- io_finished.Wait();
+ pref_service_->CommitPendingWrite();
akalin 2012/10/19 02:00:51 probably worth adding a comment. Something like:
zel 2012/10/19 18:45:07 Done.
+ base::RunLoop run_loop;
+ ASSERT_TRUE(
+ task_runner_->PostTaskAndReply(
+ FROM_HERE,
+ base::Bind(&DoNothing),
+ run_loop.QuitClosure()));
+ run_loop.Run();
}
extension_pref_value_map_.reset(new ExtensionPrefValueMap);
PrefServiceMockBuilder builder;
- builder.WithUserFilePrefs(preferences_file_);
+ builder.WithUserFilePrefs(preferences_file_, task_runner_);
builder.WithExtensionPrefs(
new ExtensionPrefStore(extension_pref_value_map_.get(), false));
pref_service_.reset(builder.Create());

Powered by Google App Engine
This is Rietveld 408576698