• Torne (Richard Coles)'s avatar
    Modernize JavaRef and its subclasses. · 2ac4c6ca
    Torne (Richard Coles) authored
    Modernize the interface for JavaRef and its subclasses - make better use
    of C++11 features, and mark existing confusing/easily misused APIs as
    deprecated. Also. fully reformat the file while it's being changed this
    much.
    
    Notable changes:
     - JavaRef can now be converted to bool in bool contexts, so "if (obj)"
       works and "!obj.is_null()" is no longer necessary.
     - ScopedJavaLocalRef<T>::Adopt() now exists to make it more explicit
       that the caller is adopting an existing reference, not creating a new
       one. This should only be used when dealing with return values from
       JNIEnv methods.
     - Conversion constructors/assignments now exist, allowing for example
       JavaRef<jstring> to be assigned to ScopedJavaLocalRef<jobject>.
     - Local references can be constructed or assigned from global
       references and vice versa without needing to use Reset().
     - Confusing forms of Reset() that take different parameters, or behave
       differently from, construction/assignment have been deprecated.
    
    The new API is intended to be somewhat similar to scoped_refptr, which
    is the closest native equivalent.
    
    Bug: 519562
    Test: base_unittests
    Change-Id: I8a989dd04b357e83bc2a28a6ec9b7e14495ccbd2
    Reviewed-on: https://chromium-review.googlesource.com/c/1262115
    Commit-Queue: Richard Coles <torne@chromium.org>
    Reviewed-by: default avataragrieve <agrieve@chromium.org>
    Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
    Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#598800}
    2ac4c6ca
scoped_java_ref.h 13.2 KB