summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-09-12 18:26:06 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2022-11-09 11:47:19 +0100
commit68ca0b28df5cf96cdb4135c60c96faba219cd32e (patch)
treebd28af300dc832d47622c63f18079ea5e5bb2a93
parent15da02238d3124d67d168944f6e336ed66d4d395 (diff)
downloadqtwebengine-chromium-68ca0b28df5cf96cdb4135c60c96faba219cd32e.tar.gz
A small Profile class
Implements a small subset of Chromium's Profile class. Change-Id: I44967861c10aa7921e4a31b2a5873b54bb71c6ec
-rw-r--r--chromium/chrome/browser/profiles/profile.cc54
-rw-r--r--chromium/chrome/browser/profiles/profile.h58
2 files changed, 112 insertions, 0 deletions
diff --git a/chromium/chrome/browser/profiles/profile.cc b/chromium/chrome/browser/profiles/profile.cc
new file mode 100644
index 00000000000..6d389075eec
--- /dev/null
+++ b/chromium/chrome/browser/profiles/profile.cc
@@ -0,0 +1,54 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/profiles/profile.h"
+
+#include "components/profile_metrics/browser_profile_type.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_ui.h"
+
+// static
+Profile* Profile::FromBrowserContext(content::BrowserContext* browser_context) {
+ // This is safe; this is the only implementation of the browser context.
+ return static_cast<Profile*>(browser_context);
+}
+
+// static
+Profile* Profile::FromWebUI(content::WebUI* web_ui) {
+ return FromBrowserContext(web_ui->GetWebContents()->GetBrowserContext());
+}
+
+Profile* Profile::GetOriginalProfile() {
+ return this;
+}
+
+const Profile* Profile::GetOriginalProfile() const {
+ return this;
+}
+
+bool Profile::IsRegularProfile() const {
+ return profile_metrics::GetBrowserProfileType(this) ==
+ profile_metrics::BrowserProfileType::kRegular;
+}
+
+bool Profile::IsIncognitoProfile() const {
+ return profile_metrics::GetBrowserProfileType(this) ==
+ profile_metrics::BrowserProfileType::kIncognito;
+}
+
+bool Profile::IsGuestSession() const {
+ return profile_metrics::GetBrowserProfileType(this) ==
+ profile_metrics::BrowserProfileType::kGuest;
+}
+
+bool Profile::IsSystemProfile() const {
+ return profile_metrics::GetBrowserProfileType(this) ==
+ profile_metrics::BrowserProfileType::kSystem;
+}
+
+#ifdef TOOLKIT_QT
+std::string Profile::GetPushMessagingEndpoint() const {
+ return "";
+}
+#endif
diff --git a/chromium/chrome/browser/profiles/profile.h b/chromium/chrome/browser/profiles/profile.h
new file mode 100644
index 00000000000..cb0057570ee
--- /dev/null
+++ b/chromium/chrome/browser/profiles/profile.h
@@ -0,0 +1,58 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This a QtWebEngine specific stripped down replacement of Chromiums's Profile
+// class, because it is used many places just for preference access.
+
+#ifndef CHROME_BROWSER_PROFILES_PROFILE_H_
+#define CHROME_BROWSER_PROFILES_PROFILE_H_
+
+#include "content/public/browser/browser_context.h"
+
+class PrefService;
+
+namespace content {
+class WebUI;
+}
+
+class Profile : public content::BrowserContext {
+ public:
+ // Returns the profile corresponding to the given browser context.
+ static Profile* FromBrowserContext(content::BrowserContext* browser_context);
+
+ // Returns the profile corresponding to the given WebUI.
+ static Profile* FromWebUI(content::WebUI* web_ui);
+
+ // Retrieves a pointer to the PrefService that manages the
+ // preferences for this user profile.
+ virtual PrefService* GetPrefs() = 0;
+ virtual const PrefService* GetPrefs() const = 0;
+
+ Profile *GetOriginalProfile();
+ const Profile *GetOriginalProfile() const;
+
+ // Returns whether the profile is new. A profile is new if the browser has
+ // not been shut down since the profile was created.
+ virtual bool IsNewProfile() const = 0;
+
+ // Returns whether it's a regular profile.
+ bool IsRegularProfile() const;
+
+ // Returns whether it is an Incognito profile. An Incognito profile is an
+ // off-the-record profile that is used for incognito mode.
+ bool IsIncognitoProfile() const;
+
+ // Returns whether it is a system profile.
+ bool IsSystemProfile() const;
+
+ // Returns whether it is a Guest session. This covers both regular and
+ // off-the-record profiles of a Guest session.
+ virtual bool IsGuestSession() const;
+
+#ifdef TOOLKIT_QT
+ virtual std::string GetPushMessagingEndpoint() const;
+#endif
+};
+
+#endif // CHROME_BROWSER_PROFILES_PROFILE_H_