[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / ownership / owner_settings_service.h
index a105537..66354bb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -9,8 +9,8 @@
 #include <string>
 #include <vector>
 
-#include "base/callback_forward.h"
-#include "base/macros.h"
+#include "base/feature_list.h"
+#include "base/functional/callback_forward.h"
 #include "base/memory/ref_counted.h"
 #include "base/memory/weak_ptr.h"
 #include "base/observer_list.h"
 namespace base {
 class TaskRunner;
 class Value;
-}
+}  // namespace base
 
 namespace ownership {
 class OwnerKeyUtil;
 class PrivateKey;
 class PublicKey;
 
+// Feature flag to toggle Chrome-side owner key generation (see
+// go/generate-owner-key-in-chrome). If enabled, Chrome will take the
+// responsibility of generating the owner key from session_manager. If disabled,
+// Chrome will still load/generate the owner key using the new code in parallel,
+// but the result will be discarded (see OwnerKeyDarkLaunchTracker).
+OWNERSHIP_EXPORT
+BASE_DECLARE_FEATURE(kChromeSideOwnerKeyGeneration);
+
 // This class is a common interface for platform-specific classes
 // which deal with ownership, keypairs and owner-related settings.
 class OWNERSHIP_EXPORT OwnerSettingsService : public KeyedService {
@@ -51,15 +59,19 @@ class OWNERSHIP_EXPORT OwnerSettingsService : public KeyedService {
         const enterprise_management::PolicyData& policy_data) {}
   };
 
-  typedef base::Callback<void(
-      std::unique_ptr<enterprise_management::PolicyFetchResponse>
-          policy_response)>
+  typedef base::OnceCallback<void(
+      scoped_refptr<ownership::PublicKey>,
+      std::unique_ptr<enterprise_management::PolicyFetchResponse>)>
       AssembleAndSignPolicyAsyncCallback;
 
-  typedef base::Callback<void(bool is_owner)> IsOwnerCallback;
+  using IsOwnerCallback = base::OnceCallback<void(bool is_owner)>;
 
   explicit OwnerSettingsService(
       const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util);
+
+  OwnerSettingsService(const OwnerSettingsService&) = delete;
+  OwnerSettingsService& operator=(const OwnerSettingsService&) = delete;
+
   ~OwnerSettingsService() override;
 
   base::WeakPtr<OwnerSettingsService> as_weak_ptr() {
@@ -70,21 +82,26 @@ class OWNERSHIP_EXPORT OwnerSettingsService : public KeyedService {
 
   void RemoveObserver(Observer* observer);
 
-  // Returns whether current user is owner or not. When this method
-  // is called too early, incorrect result can be returned because
-  // private key loading may be in progress.
+  // Returns whether this OwnerSettingsService has finished loading keys, and so
+  // we are able to confirm whether the current user is the owner or not.
+  virtual bool IsReady();
+
+  // Returns whether current user is owner or not - as long as IsReady()
+  // returns true. When IsReady() is false, we don't yet know if the current
+  // user is the owner or not. In that case this method returns false.
   virtual bool IsOwner();
 
-  // Determines whether current user is owner or not, responds via
-  // |callback|.
-  virtual void IsOwnerAsync(const IsOwnerCallback& callback);
+  // Determines whether current user is owner or not, responds via |callback|.
+  // Reliably returns the correct value, but will not respond on the callback
+  // until IsReady() returns true.
+  virtual void IsOwnerAsync(IsOwnerCallback callback);
 
   // Assembles and signs |policy| on the |task_runner|, responds on
   // the original thread via |callback|.
   bool AssembleAndSignPolicyAsync(
       base::TaskRunner* task_runner,
       std::unique_ptr<enterprise_management::PolicyData> policy,
-      const AssembleAndSignPolicyAsyncCallback& callback);
+      AssembleAndSignPolicyAsyncCallback callback);
 
   // Checks whether |setting| is handled by OwnerSettingsService.
   virtual bool HandlesSetting(const std::string& setting) = 0;
@@ -114,16 +131,24 @@ class OWNERSHIP_EXPORT OwnerSettingsService : public KeyedService {
   bool SetDouble(const std::string& setting, double value);
   bool SetString(const std::string& setting, const std::string& value);
 
+  // Run callbacks in test setting. Mocks ownership when full device setup is
+  // not needed.
+  void RunPendingIsOwnerCallbacksForTesting(bool is_owner);
+
  protected:
   void ReloadKeypair();
 
-  void OnKeypairLoaded(const scoped_refptr<PublicKey>& public_key,
-                       const scoped_refptr<PrivateKey>& private_key);
+  // Stores the provided keys. Ensures that |public_key_| and |private_key_| are
+  // not null (even if the key objects themself are empty) to indicate that the
+  // key loading finished.
+  void OnKeypairLoaded(scoped_refptr<PublicKey> public_key,
+                       scoped_refptr<PrivateKey> private_key);
 
   // Platform-specific keypair loading algorithm.
-  virtual void ReloadKeypairImpl(const base::Callback<
-      void(const scoped_refptr<PublicKey>& public_key,
-           const scoped_refptr<PrivateKey>& private_key)>& callback) = 0;
+  virtual void ReloadKeypairImpl(
+      base::OnceCallback<void(scoped_refptr<PublicKey> public_key,
+                              scoped_refptr<PrivateKey> private_key)>
+          callback) = 0;
 
   // Plafrom-specific actions which should be performed when keypair is loaded.
   virtual void OnPostKeypairLoadedActions() = 0;
@@ -141,9 +166,7 @@ class OWNERSHIP_EXPORT OwnerSettingsService : public KeyedService {
   base::ThreadChecker thread_checker_;
 
  private:
-  base::WeakPtrFactory<OwnerSettingsService> weak_factory_;
-
-  DISALLOW_COPY_AND_ASSIGN(OwnerSettingsService);
+  base::WeakPtrFactory<OwnerSettingsService> weak_factory_{this};
 };
 
 }  // namespace ownership