1 // Copyright 2019 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 CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_MAIN_EXTRA_PARTS_CEF_H_ 6 #define CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_MAIN_EXTRA_PARTS_CEF_H_ 7 8 #include <memory> 9 10 #include "libcef/browser/request_context_impl.h" 11 12 #include "base/task/single_thread_task_runner.h" 13 #include "chrome/browser/chrome_browser_main_extra_parts.h" 14 15 // Wrapper that owns and initialize the browser memory-related extra parts. 16 class ChromeBrowserMainExtraPartsCef : public ChromeBrowserMainExtraParts { 17 public: 18 ChromeBrowserMainExtraPartsCef(); 19 20 ChromeBrowserMainExtraPartsCef(const ChromeBrowserMainExtraPartsCef&) = 21 delete; 22 ChromeBrowserMainExtraPartsCef& operator=( 23 const ChromeBrowserMainExtraPartsCef&) = delete; 24 25 ~ChromeBrowserMainExtraPartsCef() override; 26 request_context()27 CefRefPtr<CefRequestContextImpl> request_context() const { 28 return global_request_context_; 29 } 30 background_task_runner()31 scoped_refptr<base::SingleThreadTaskRunner> background_task_runner() const { 32 return background_task_runner_; 33 } user_visible_task_runner()34 scoped_refptr<base::SingleThreadTaskRunner> user_visible_task_runner() const { 35 return user_visible_task_runner_; 36 } user_blocking_task_runner()37 scoped_refptr<base::SingleThreadTaskRunner> user_blocking_task_runner() 38 const { 39 return user_blocking_task_runner_; 40 } 41 42 private: 43 // ChromeBrowserMainExtraParts overrides. 44 void PostProfileInit(Profile* profile, bool is_initial_profile) override; 45 void PreMainMessageLoopRun() override; 46 47 CefRefPtr<CefRequestContextImpl> global_request_context_; 48 49 // Blocking task runners exposed via CefTaskRunner. For consistency with 50 // previous named thread behavior always execute all pending tasks before 51 // shutdown (e.g. to make sure critical data is saved to disk). 52 scoped_refptr<base::SingleThreadTaskRunner> background_task_runner_; 53 scoped_refptr<base::SingleThreadTaskRunner> user_visible_task_runner_; 54 scoped_refptr<base::SingleThreadTaskRunner> user_blocking_task_runner_; 55 }; 56 57 #endif // CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_MAIN_EXTRA_PARTS_CEF_H_ 58