File: file_suggest_util.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (129 lines) | stat: -rw-r--r-- 4,375 bytes parent folder | download | duplicates (6)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_FILE_SUGGEST_FILE_SUGGEST_UTIL_H_
#define CHROME_BROWSER_ASH_FILE_SUGGEST_FILE_SUGGEST_UTIL_H_

#include <optional>

#include "base/files/file_path.h"
#include "base/functional/callback_forward.h"
#include "base/time/time.h"

namespace ash {

struct FileSuggestData;
using GetSuggestFileDataCallback = base::OnceCallback<void(
    const std::optional<std::vector<FileSuggestData>>&)>;

// Outcome of a call to `FileSuggestKeyedService::GetSuggestFileData()`. These
// values persist to logs. Entries should not be renumbered and numeric values
// should never be reused.
enum class DriveSuggestValidationStatus {
  kOk = 0,
  kDriveFSNotMounted = 1,
  kNoResults = 2,
  kPathLocationFailed = 3,
  kAllFilesErrored = 4,
  kDriveDisabled = 5,
  kMaxValue = kDriveDisabled,
};

// The types of the file suggestion data, ordered by decreasing precedence.
enum class FileSuggestionType {
  // The drive file suggestion.
  kDriveFile,

  // The local file suggestion.
  kLocalFile,
};

// The reason the file is suggested.
enum class FileSuggestionJustificationType {
  // Used only for deprecated suggestions from drive's ItemSuggest API, for
  // which the exact justification type is obscured.
  kUnknown,

  // The user recently viewed the file.
  kViewed,

  // The file was recently modified, usually by another user.
  kModified,

  // The file was recently modified by the current user.
  kModifiedByCurrentUser,

  // The file was shared with the current user.
  kShared,
};

// Returns the max amount of time from now that a file was modified or viewed to
// be available as a file suggestion.
base::TimeDelta GetMaxFileSuggestionRecency();

// Creates a suggestion score in interval [0, 1] based on the suggestion
// timestamps. Assumes that the timestamps are at most `max_recency` old.
double ToTimestampBasedScore(const FileSuggestData& suggestion_data,
                             base::TimeDelta max_recency);

// The data of an individual file suggested by `FileSuggestKeyedService`.
struct FileSuggestData {
  FileSuggestData(FileSuggestionType new_type,
                  const base::FilePath& new_file_path,
                  const std::optional<std::string>& title,
                  const std::optional<std::u16string>& new_prediction_reason,
                  const std::optional<base::Time>& modified_time,
                  const std::optional<base::Time>& viewed_time,
                  const std::optional<base::Time>& shared_time,
                  std::optional<float> new_score,
                  const std::optional<std::string>& drive_file_id,
                  const std::optional<std::string>& icon_url);
  FileSuggestData(FileSuggestData&&);
  FileSuggestData(const FileSuggestData&);
  FileSuggestData& operator=(const FileSuggestData&);
  ~FileSuggestData();

  // The type of the suggested file (e.g. a drive file).
  FileSuggestionType type;

  // The path to the suggested file.
  base::FilePath file_path;

  // The title of the file. The title can contain path separators like "/",
  // which is the reason that this title member is used instead of the file name
  // in `file_path`.
  std::optional<std::string> title;

  // The suggestion id. Calculated from `type` and `file_path`.
  std::string id;

  // The reason why the file is suggested.
  std::optional<std::u16string> prediction_reason;

  // Timestamp of when the file was last modified by the user.
  std::optional<base::Time> modified_time;

  // Timestamp of when the file was last viewed by the user.
  std::optional<base::Time> viewed_time;

  // Timestamp of when the file was shared with the user.
  std::optional<base::Time> shared_time;

  // Only has a value when `type` == `FileSuggestionType::kLocalFile`.
  std::optional<float> score;

  // The drive file id for the file.
  std::optional<std::string> drive_file_id;

  // The custom icon url for the file.
  std::optional<std::string> icon_url;
};

// Calculates the id of a file suggestion specified by `type` and `file_path`.
std::string CalculateSuggestionId(FileSuggestionType type,
                                  const base::FilePath& file_path);

}  // namespace ash

#endif  // CHROME_BROWSER_ASH_FILE_SUGGEST_FILE_SUGGEST_UTIL_H_