1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77

ash / public / cpp / desk_profiles_delegate.h [blame]

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_PUBLIC_CPP_DESK_PROFILES_DELEGATE_H_
#define ASH_PUBLIC_CPP_DESK_PROFILES_DELEGATE_H_

#include <cstdint>
#include <string>
#include <vector>

#include "ash/public/cpp/ash_public_export.h"
#include "base/observer_list_types.h"
#include "ui/gfx/image/image_skia.h"

namespace ash {

// This struct provides a summary of a profile that exists in Lacros.
struct ASH_PUBLIC_EXPORT LacrosProfileSummary {
  LacrosProfileSummary();
  LacrosProfileSummary(const LacrosProfileSummary&);
  LacrosProfileSummary(LacrosProfileSummary&&);
  LacrosProfileSummary& operator=(const LacrosProfileSummary&);
  LacrosProfileSummary& operator=(LacrosProfileSummary&&);

  uint64_t profile_id = 0;

  // Profile name.
  std::u16string name;

  // Profile email, may be empty.
  std::u16string email;

  // Profile icon.
  gfx::ImageSkia icon;
};

// This interface provides profile information from Lacros to clients in Ash. It
// is implemented by `DeskProfilesAsh`, which in turn receives profile
// information from its counterpart on the Lacros side: `DeskProfilesLacros`. It
// allows a client to get a snapshot of current profiles as well as observe
// profile modifications.
class ASH_PUBLIC_EXPORT DeskProfilesDelegate {
 public:
  class Observer : public base::CheckedObserver {
   public:
    // Called when a profile is inserted or updated.
    virtual void OnProfileUpsert(const LacrosProfileSummary& summary) {}
    // Called when a profile is removed.
    virtual void OnProfileRemoved(uint64_t profile_id) {}
  };

  virtual ~DeskProfilesDelegate() = default;

  // Returns a snapshot of the current profiles.
  virtual const std::vector<LacrosProfileSummary>& GetProfilesSnapshot()
      const = 0;

  // Returns the snapshot of profile by giving profile id.
  virtual const LacrosProfileSummary* GetProfilesSnapshotByProfileId(
      uint64_t profile_id) const = 0;

  // Returns the primary profile ID.
  virtual uint64_t GetPrimaryProfileId() const = 0;

  // If `profile_id` is zero, this returns `GetPrimaryProfileId`, otherwise
  // `profile_id` is returned as-is.
  uint64_t ResolveProfileId(uint64_t profile_id);

  // Adds or removes an observer that will receive profile updates.
  virtual void AddObserver(Observer* observer) = 0;
  virtual void RemoveObserver(Observer* observer) = 0;
};

}  // namespace ash

#endif  // ASH_PUBLIC_CPP_DESK_PROFILES_DELEGATE_H_