How to use CefPostTask correctly?

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 to use CefPostTask correctly?

Postby rjxray » Sun Feb 06, 2022 6:38 am

I'm implementing GetAuthCredentials() and now need to switch the callback from the IO to UI thread but am having problems with using CefPostTask() and base::bindOnce()

I'm following the examples given in the GeneralUsage wiki Posting Tasks section but I'm getting these compile errors:
Error C2027 use of undefined type 'base::OnceCallback<void (void)>'
Error C2665 'CefPostTask': none of the 3 overloads could convert all the argument types

Attempting to compile this code from the wiki in a separate module gives the same errors for both bind::Once() calls
Code: Select all
#include "cef_callback.h"
#include "cef_ref_counted.h"
#include "cef_closure_task.h"
#include "cef_helpers.h"

// Define a function.
void MyFunc(int arg) { /* do something with |arg| on the UI thread */ }

// Post a task that will execute MyFunc on the UI thread and pass an |arg|
// value of 5.
void doBind() {
   CefPostTask(TID_UI, base::BindOnce(&MyFunc, 5));
}

// To execute a bound method:

// Define a class.
class MyClass : public CefBaseRefCounted {
public:
   MyClass() {}
   void MyMethod(int arg) { /* do something with |arg| on the UI thread */ }
private:
   IMPLEMENT_REFCOUNTING(MyClass);
};

void doBindMethod() {

   // Create an instance of MyClass.
   CefRefPtr<MyClass> instance = new MyClass();

   // Post a task that will execute MyClass::MyMethod on the UI thread and pass
   // an |arg| value of 5. |instance| will be kept alive until after the task
   // completes.
   CefPostTask(TID_UI, base::BindOnce(&MyClass::MyMethod, instance, 5));
}


Any help would be greatly appreciated.
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am

Re: How to use CefPostTask correctly?

Postby magreenblatt » Sun Feb 06, 2022 1:47 pm

What CEF version are you using? The docs are for supported versions. Older versions might have base::Bind (without the Once prefix/suffix).
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to use CefPostTask correctly?

Postby rjxray » Sun Feb 06, 2022 5:04 pm

I'm using CEF 4638 with off screen rendering under Windows 10.

I implemented the fix for this issue https://bitbucket.org/chromiumembedded/cef/issues/3125/cefrequesthandler-getauthcredentials-is in my CEF build and I do get the callback OK
Then I tried implementing the callback as described here https://stackoverflow.com/questions/38266264/cefauthcallbackcontinue-how-to-call-it-outside-the-getauthcredentials-method.
I got errors using base::Bind and checked the wiki and found it no longer existed and had been replaced with BindOnce.

I just tried reverting to Bind in the code I posted above and got these errors:
E0135 namespace "base" has no member "Bind"
C2039 'Bind': is not a member of 'base'
C3861 Bind': identifier not found

I'm also using the shared textures patch from https://bitbucket.org/chromiumembedded/cef/pull-requests/285 so it would be a lot of work to update my CEF version right now.

So if its possible to give me any hints in how to implement CefPostTask in 4638 I would really appreciate it.
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am

Re: How to use CefPostTask correctly?

Postby rjxray » Sun Feb 06, 2022 6:29 pm

I looked at the wiki history and saw the update on 2022-01-31.
I tried including cef_bind.h instead of cef_callback.h, but base::Bind is still undefined.
I looked at the CEF commit history and saw the change was made here https://bitbucket.org/chromiumembedded/cef/commits/69b7dc3148b35a1c63b5a6aaea0ead803131229d in version 4638.
I checked our repo, and we forked four commits later from 00d4ad5 so we do have these changes.
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am

Re: How to use CefPostTask correctly?

Postby magreenblatt » Sun Feb 06, 2022 6:35 pm

So if its possible to give me any hints in how to implement CefPostTask in 4638 I would really appreciate it.


You should find some examples of base::Bind usage in the sample apps included with your CEF version.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to use CefPostTask correctly?

Postby rjxray » Mon Feb 07, 2022 3:31 am

I previously looked for examples and didn't find any in cefclient but there were lots in ceftests. They all seemed to be using bindOnce in the same way as I was and compiled OK.
I was wondering if I was missing any dependencies which is why I posted.

Today I've tried manually adding the code I posted yesterday to a new module in my CEF build which was made from the binary distribution I create from a chromium/cef source build.
After fixing the include paths it compiles without errors.

I use the includes, dlls, libs and resources from this build in our own project build.
We use an in house project generator to create a cmake file from which our project.sln is created.
I've compared the C/++ properties of that with those of cef.sln and found a few differences but changing ours to be the same as cef.sln has not fixed the errors.
(BTW they don't show up in intellisense)

If I eventually do find something I'll let you know.
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am

Re: How to use CefPostTask correctly?

Postby rjxray » Mon Feb 07, 2022 9:05 am

We finally got it working OK.
with just these includes in the test module
Code: Select all
#include "cef_callback.h"
#include "cef_ref_counted.h"
#include "cef_closure_task.h"
#include "cef_helpers.h"

We had to modify cef_bind.h to include cef_callback.h to pick up the definition of OnceCallback
I really don't know why that was required in our app, but not in cefclient, but its working for us.
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am

Re: How to use CefPostTask correctly?

Postby evanburkert » Wed Apr 06, 2022 5:47 pm

I ran into this as well migrating from ::Bind to ::BindOnce. Included cef_callback.h in cef_bind.h. Thanks!
evanburkert
Newbie
 
Posts: 9
Joined: Wed Apr 06, 2022 11:14 am

Re: How to use CefPostTask correctly?

Postby tapineb371 » Wed Oct 25, 2023 10:45 pm

Any solution to this found?
tapineb371
Techie
 
Posts: 14
Joined: Mon Sep 04, 2023 8:49 pm

Re: How to use CefPostTask correctly?

Postby rjxray » Thu Oct 26, 2023 2:19 am

I had a suspicion that it might be to do with the ordering of includes in our own project (which is not based on cefclient) but I haven't really tried to resolve it. I'm just using the above fix.
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 211 guests

cron