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

ash / birch / birch_ranker.h [blame]

// Copyright 2024 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_BIRCH_BIRCH_RANKER_H_
#define ASH_BIRCH_BIRCH_RANKER_H_

#include "ash/ash_export.h"
#include "ash/birch/birch_item.h"
#include "base/time/time.h"

namespace ash {

class BirchAttachmentItem;
class BirchCalendarItem;
class BirchCoralItem;
class BirchFileItem;
class BirchTabItem;
class BirchWeatherItem;
class BirchLostMediaItem;

// Computes a ranking for birch items of various types. The ranking depends on
// the time of day. The "now" time is a constructor parameter to allow testing.
// The ranking numbers are the row numbers from the "Triggers & Priority"
// spreadsheet, http://go/birch-triggers
class ASH_EXPORT BirchRanker {
 public:
  explicit BirchRanker(base::Time now);
  BirchRanker(const BirchRanker&) = delete;
  BirchRanker& operator=(const BirchRanker&) = delete;
  ~BirchRanker();

  // Ranks BirchItems of the appropriate time. The items are mutated in place
  // to have their ranking field updated. This avoids copying the items.
  void RankCalendarItems(std::vector<BirchCalendarItem>* items);
  void RankAttachmentItems(std::vector<BirchAttachmentItem>* items);
  void RankFileSuggestItems(std::vector<BirchFileItem>* items);
  void RankRecentTabItems(std::vector<BirchTabItem>* items);
  void RankLastActiveItems(std::vector<BirchLastActiveItem>* items);
  void RankMostVisitedItems(std::vector<BirchMostVisitedItem>* items);
  void RankSelfShareItems(std::vector<BirchSelfShareItem>* items);
  void RankLostMediaItems(std::vector<BirchLostMediaItem>* items);
  void RankWeatherItems(std::vector<BirchWeatherItem>* items);
  void RankReleaseNotesItems(std::vector<BirchReleaseNotesItem>* items);
  void RankCoralItems(std::vector<BirchCoralItem>* items);

  // Returns whether `now_` is before noon today. Public for testing.
  bool IsMorning() const;

  // Returns whether `now_` is after 5pm today. Public for testing.
  bool IsEvening() const;

 private:
  // Returns whether `now_` is in the middle of a calendar event's times.
  bool IsOngoingEvent(const BirchCalendarItem& item) const;

  // Returns whether `item` is scheduled tomorrow (after midnight tonight).
  bool IsTomorrowEvent(const BirchCalendarItem& item) const;

  float GetReleaseNotesItemRanking(const BirchReleaseNotesItem& item) const;

  base::Time now_;
};

}  // namespace ash

#endif  // ASH_BIRCH_BIRCH_RANKER_H_