Home | History | Annotate | Download | only in java
      1 // Copyright (c) 2011 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.
      4 
      5 #ifndef CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_METHOD_H_
      6 #define CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_METHOD_H_
      7 
      8 #include <jni.h>
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "base/android/scoped_java_ref.h"
     13 #include "content/browser/renderer_host/java/java_type.h"
     14 
     15 namespace content {
     16 
     17 // Wrapper around java.lang.reflect.Method. This class must be used on a single
     18 // thread only.
     19 class JavaMethod {
     20  public:
     21   explicit JavaMethod(const base::android::JavaRef<jobject>& method);
     22   ~JavaMethod();
     23 
     24   const std::string& name() const { return name_; }
     25   size_t num_parameters() const;
     26   const JavaType& parameter_type(size_t index) const;
     27   const JavaType& return_type() const;
     28   jmethodID id() const;
     29 
     30  private:
     31   void EnsureNumParametersIsSetUp() const;
     32   void EnsureTypesAndIDAreSetUp() const;
     33 
     34   std::string name_;
     35   mutable base::android::ScopedJavaGlobalRef<jobject> java_method_;
     36   mutable bool have_calculated_num_parameters_;
     37   mutable size_t num_parameters_;
     38   mutable std::vector<JavaType> parameter_types_;
     39   mutable JavaType return_type_;
     40   mutable jmethodID id_;
     41 
     42   DISALLOW_IMPLICIT_CONSTRUCTORS(JavaMethod);
     43 };
     44 
     45 }  // namespace content
     46 
     47 #endif  // CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_METHOD_H_
     48