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

Unified Diff: chrome/browser/android/provider/blocking_ui_thread_async_request.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
Index: chrome/browser/android/provider/blocking_ui_thread_async_request.h
diff --git a/chrome/browser/android/provider/blocking_ui_thread_async_request.h b/chrome/browser/android/provider/blocking_ui_thread_async_request.h
new file mode 100644
index 0000000000000000000000000000000000000000..5e2a6f9d05b83aa42e66481a46aed9d69fe00204
--- /dev/null
+++ b/chrome/browser/android/provider/blocking_ui_thread_async_request.h
@@ -0,0 +1,55 @@
+// 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_BLOCKING_UI_THREAD_ASYNC_REQUEST_H_
+#define CHROME_BROWSER_ANDROID_PROVIDER_BLOCKING_UI_THREAD_ASYNC_REQUEST_H_
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/synchronization/waitable_event.h"
+#include "chrome/browser/android/provider/run_on_ui_thread_blocking.h"
+#include "content/public/browser/browser_thread.h"
+
+// Allows making async requests and blocking the current thread until the
+// response arrives. The request is performed in the UI thread.
+// Users of this class MUST call RequestCompleted when receiving the response.
+// Cannot be called directly from the UI thread.
+class BlockingUIThreadAsyncRequest {
+ public:
+ BlockingUIThreadAsyncRequest();
+
+ // Runs an asynchronous request, blocking the invoking thread until a response
+ // is received. Class users MUST call RequestCompleted when this happens.
+ // Make sure that the response is also delivered to the UI thread.
+ // The request argument can be defined using base::Bind.
+ template <typename Signature>
+ void RunAsyncRequestOnUIThreadBlocking(base::Callback<Signature> request) {
+ DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ // Make the request in the UI thread.
+ request_completed_.Reset();
+ RunOnUIThreadBlocking::Run(
+ base::Bind(
+ &BlockingUIThreadAsyncRequest::RunRequestOnUIThread<Signature>,
+ request));
+
+ // Wait until the request callback invokes Finished.
+ request_completed_.Wait();
+ }
+
+ // Notifies about a finished request.
+ void RequestCompleted();
+
+ private:
+ template <typename Signature>
+ static void RunRequestOnUIThread(base::Callback<Signature> request) {
+ request.Run();
+ }
+
+ base::WaitableEvent request_completed_;
+
+ DISALLOW_COPY_AND_ASSIGN(BlockingUIThreadAsyncRequest);
+};
+
+#endif // CHROME_BROWSER_ANDROID_PROVIDER_BLOCKING_UI_THREAD_ASYNC_REQUEST_H_
« no previous file with comments | « chrome/browser/android/chrome_jni_registrar.cc ('k') | chrome/browser/android/provider/blocking_ui_thread_async_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698