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

Unified Diff: chrome/browser/android/provider/run_on_ui_thread_blocking.h

Issue 10912172: [Android] Upstream ChromeBrowserProvider, the Android port ContentProvider implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: temporarily removing tests until we can compile and run them (soon) Created 8 years, 3 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
« no previous file with comments | « chrome/browser/android/provider/chrome_browser_provider.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/provider/run_on_ui_thread_blocking.h
diff --git a/chrome/browser/android/provider/run_on_ui_thread_blocking.h b/chrome/browser/android/provider/run_on_ui_thread_blocking.h
new file mode 100644
index 0000000000000000000000000000000000000000..04ea537928c7d2b7cc03b86df6084e2f61bc6391
--- /dev/null
+++ b/chrome/browser/android/provider/run_on_ui_thread_blocking.h
@@ -0,0 +1,39 @@
+// Copyright (c) 2012 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_ANDROID_PROVIDER_RUN_ON_UI_THREAD_BLOCKING_H_
+#define CHROME_BROWSER_ANDROID_PROVIDER_RUN_ON_UI_THREAD_BLOCKING_H_
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/synchronization/waitable_event.h"
+#include "content/public/browser/browser_thread.h"
+
+// Runs code synchronously on the UI thread. Should never be called directly
+// from the UI thread. To be used only within the provider classes.
+class RunOnUIThreadBlocking {
+ public:
+ // Runs the provided runnable in the UI thread synchronously.
+ // The runnable argument can be defined using base::Bind.
+ template <typename Signature>
+ static void Run(base::Callback<Signature> runnable) {
+ DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ base::WaitableEvent finished(false, false);
+ content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&RunOnUIThreadBlocking::RunOnUIThread<Signature>,
+ runnable, &finished));
+ finished.Wait();
+ }
+
+ private:
+ template <typename Signature>
+ static void RunOnUIThread(base::Callback<Signature> runnable,
+ base::WaitableEvent* finished) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ runnable.Run();
+ finished->Signal();
+ }
+};
+
+#endif // CHROME_BROWSER_ANDROID_PROVIDER_RUN_ON_UI_THREAD_BLOCKING_H_
« no previous file with comments | « chrome/browser/android/provider/chrome_browser_provider.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698