2020-07-04 04:51:17 +02:00
|
|
|
// Copyright 2020 The Chromium Embedded Framework Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_CONTEXT_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_CONTEXT_H_
|
|
|
|
#pragma once
|
|
|
|
|
2024-05-11 17:48:38 +02:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2021-04-07 00:09:45 +02:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/browser_context.h"
|
2021-04-07 00:09:45 +02:00
|
|
|
#include "chrome/browser/profiles/profile_manager.h"
|
2021-07-23 21:55:22 +02:00
|
|
|
#include "chrome/browser/profiles/profile_observer.h"
|
|
|
|
|
|
|
|
class ScopedProfileKeepAlive;
|
2021-04-07 00:09:45 +02:00
|
|
|
|
2020-07-04 04:51:17 +02:00
|
|
|
// See CefBrowserContext documentation for usage. Only accessed on the UI thread
|
|
|
|
// unless otherwise indicated.
|
2021-07-23 21:55:22 +02:00
|
|
|
class ChromeBrowserContext : public CefBrowserContext, public ProfileObserver {
|
2020-07-04 04:51:17 +02:00
|
|
|
public:
|
|
|
|
explicit ChromeBrowserContext(const CefRequestContextSettings& settings);
|
|
|
|
|
2021-12-06 21:40:25 +01:00
|
|
|
ChromeBrowserContext(const ChromeBrowserContext&) = delete;
|
|
|
|
ChromeBrowserContext& operator=(const ChromeBrowserContext&) = delete;
|
|
|
|
|
2024-02-08 19:41:18 +01:00
|
|
|
// Returns a ChromeBrowserContext for the specified |profile|.
|
|
|
|
static ChromeBrowserContext* GetOrCreateForProfile(Profile* profile);
|
|
|
|
|
2021-04-07 00:09:45 +02:00
|
|
|
void InitializeAsync(base::OnceClosure initialized_cb);
|
|
|
|
|
2020-07-04 04:51:17 +02:00
|
|
|
// CefBrowserContext overrides.
|
|
|
|
content::BrowserContext* AsBrowserContext() override;
|
|
|
|
Profile* AsProfile() override;
|
2021-04-15 01:28:22 +02:00
|
|
|
bool IsInitialized() const override;
|
|
|
|
void StoreOrTriggerInitCallback(base::OnceClosure callback) override;
|
2020-07-04 04:51:17 +02:00
|
|
|
void Shutdown() override;
|
2024-04-17 18:01:26 +02:00
|
|
|
void AddVisitedURLs(const GURL& url,
|
|
|
|
const std::vector<GURL>& redirect_chain,
|
|
|
|
ui::PageTransition transition) override;
|
2020-07-04 04:51:17 +02:00
|
|
|
|
2021-07-23 21:55:22 +02:00
|
|
|
// ProfileObserver overrides.
|
|
|
|
void OnProfileWillBeDestroyed(Profile* profile) override;
|
|
|
|
|
2020-07-04 04:51:17 +02:00
|
|
|
private:
|
|
|
|
~ChromeBrowserContext() override;
|
|
|
|
|
2024-03-19 22:11:42 +01:00
|
|
|
enum class CreateStatus {
|
|
|
|
// Default to creating a new/unique OffTheRecord profile.
|
|
|
|
kDefault,
|
|
|
|
// Profile created but before initializing extensions and promo resources.
|
|
|
|
kCreated,
|
|
|
|
// Profile is created, extensions and promo resources are initialized.
|
|
|
|
kInitialized,
|
|
|
|
};
|
|
|
|
|
|
|
|
void ProfileCreated(CreateStatus status, Profile* profile);
|
2021-04-07 00:09:45 +02:00
|
|
|
|
|
|
|
base::OnceClosure initialized_cb_;
|
2024-05-11 17:48:38 +02:00
|
|
|
raw_ptr<Profile> profile_ = nullptr;
|
2021-04-07 00:09:45 +02:00
|
|
|
bool should_destroy_ = false;
|
|
|
|
|
2021-07-23 21:55:22 +02:00
|
|
|
bool destroyed_ = false;
|
|
|
|
std::unique_ptr<ScopedProfileKeepAlive> profile_keep_alive_;
|
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
std::vector<base::OnceClosure> init_callbacks_;
|
|
|
|
|
2021-04-07 00:09:45 +02:00
|
|
|
base::WeakPtrFactory<ChromeBrowserContext> weak_ptr_factory_;
|
2020-07-04 04:51:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_CONTEXT_H_
|