mac: Let IPhotoDataProvider::GetAlbumNames() return albums in a deterministic order.
[chromium-blink-merge.git] / base / android / java_handler_thread.h
blobc9a2c02d3546ed3ffb557061db65f06bc487cd8f
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_ANDROID_JAVA_HANDLER_THREAD_H_
6 #define BASE_ANDROID_JAVA_HANDLER_THREAD_H_
8 #include <jni.h>
10 #include "base/android/scoped_java_ref.h"
11 #include "base/memory/scoped_ptr.h"
13 namespace base {
15 class MessageLoop;
16 class WaitableEvent;
18 namespace android {
20 // A Java Thread with a native message loop. To run tasks, post them
21 // to the message loop and they will be scheduled along with Java tasks
22 // on the thread.
23 // This is useful for callbacks where the receiver expects a thread
24 // with a prepared Looper.
25 class BASE_EXPORT JavaHandlerThread {
26 public:
27 JavaHandlerThread(const char* name);
28 virtual ~JavaHandlerThread();
30 base::MessageLoop* message_loop() const { return message_loop_.get(); }
31 void Start();
32 void Stop();
34 // Called from java on the newly created thread.
35 // Start() will not return before this methods has finished.
36 void InitializeThread(JNIEnv* env, jobject obj, jlong event);
37 void StopThread(JNIEnv* env, jobject obj, jlong event);
39 static bool RegisterBindings(JNIEnv* env);
41 private:
42 scoped_ptr<base::MessageLoop> message_loop_;
43 ScopedJavaGlobalRef<jobject> java_thread_;
46 } // namespace android
47 } // namespace base
49 #endif // BASE_ANDROID_JAVA_HANDLER_THREAD_H_