How does a CefRefPtr become "owned"?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

How does a CefRefPtr become "owned"?

Postby sketch34 » Tue Jan 31, 2023 8:24 pm

I want to understand this. The header files mention ownership and how it may be lost but don't describe how ownership is established in the first place or what the concept of "ownership" means exactly for CefRefPtr.

For example:
Code: Select all
    auto rp = CefValue::Create();
    CATCH_REQUIRE(!rp->IsOwned());

    auto d = CefDictionaryValue::Create();
    CATCH_REQUIRE(!d->IsOwned());

    rp->SetDictionary(d);
    CATCH_REQUIRE(d->IsOwned());   // Fails.

    rp->SetDictionary(std::move(d));
    CATCH_REQUIRE(rp->GetDictionary()->IsOwned());    // Also fails. What would cause IsOwned() to be true?

sketch34
Techie
 
Posts: 11
Joined: Sun Apr 25, 2021 8:24 pm

Re: How does a CefRefPtr become "owned"?

Postby magreenblatt » Tue Jan 31, 2023 10:58 pm

For CefValue, ownership means that the internal data object is “owned” by some other internal data object (list, map, etc). These internal objects are base::Values which are not ref-counted. Any assignment of one CefValue to another therefore needs to be an ownership transfer or a copy internally. We try to avoid copies where possible because they can be expensive.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: How does a CefRefPtr become "owned"?

Postby sketch34 » Wed Feb 01, 2023 2:12 am

Thank you, I'm still not clear on this, sorry.

Code: Select all
///
// Class that wraps other data value types. Complex types (binary, dictionary
// and list) will be referenced but not owned by this object. Can be used on any
// process and thread.
///
/*--cef(source=library)--*/
class CefValue : public virtual CefBaseRefCounted {


So complex types will never be owned by a CefValue.

Any assignment of one CefValue to another...


Code: Select all
auto v1 = CefValue::Create();
auto v2 = CefValue::Create();
v2->SetInt(77);
CATCH_REQUIRE(!v2->IsOwned());
v1 = v2;
CATCH_REQUIRE(v1->GetInt() == 77);
CATCH_REQUIRE(v2->IsOwned());          // Fails.


Would you mind posting a small code sample that would cause IsOwned() to be true?
sketch34
Techie
 
Posts: 11
Joined: Sun Apr 25, 2021 8:24 pm

Re: How does a CefRefPtr become "owned"?

Postby magreenblatt » Wed Feb 01, 2023 11:32 am

sketch34 wrote:Would you mind posting a small code sample that would cause IsOwned() to be true?

https://github.com/chromiumembedded/cef ... st.cc#L164
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 39 guests