File: file_result.h

package info (click to toggle)
chromium 139.0.7258.127-1~deb13u1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,096 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 (116 lines) | stat: -rw-r--r-- 4,266 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
// Copyright 2020 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_APP_LIST_SEARCH_FILES_FILE_RESULT_H_
#define CHROME_BROWSER_ASH_APP_LIST_SEARCH_FILES_FILE_RESULT_H_

#include <iosfwd>
#include <optional>

#include "ash/public/cpp/holding_space/holding_space_image.h"
#include "ash/public/cpp/style/color_mode_observer.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/memory/raw_ptr.h"
#include "chrome/browser/ash/app_list/search/chrome_search_result.h"

class Profile;

namespace ash {
class ThumbnailLoader;
namespace string_matching {
class TokenizedString;
}  // namespace string_matching
}  // namespace ash

namespace app_list {

// This result class is shared between four file search providers:
// {drive,local} {zero-state,search}.
class FileResult : public ChromeSearchResult, public ash::ColorModeObserver {
 public:
  enum class Type { kFile, kDirectory, kSharedDirectory };

  // Note: `thumbnail_loader_` is only used for list and image search items to
  // load the thumbnail image to be used for the result. It can be nullptr, in
  // which case the result will use the default file type icon for the result.
  FileResult(const std::string& id,
             const base::FilePath& filepath,
             const std::optional<std::u16string>& details,
             ResultType result_type,
             DisplayType display_type,
             float relevance,
             const std::u16string& query,
             Type type,
             Profile* profile,
             ash::ThumbnailLoader* thumbnail_loader);
  ~FileResult() override;

  FileResult(const FileResult&) = delete;
  FileResult& operator=(const FileResult&) = delete;

  // ChromeSearchResult overrides:
  void Open(int event_flags) override;
  std::optional<std::string> DriveId() const override;
  std::optional<GURL> url() const override;

  // Calculates file's match relevance score. Will return a default score if the
  // query is missing or the filename is empty.
  static double CalculateRelevance(
      const std::optional<ash::string_matching::TokenizedString>& query,
      const base::FilePath& filepath,
      const std::optional<base::Time>& last_accessed);


  void set_drive_id(const std::optional<std::string>& drive_id) {
    drive_id_ = drive_id;
  }

  void set_url(const std::optional<GURL>& url) { url_ = url; }

 private:
  // ash::ColorModeObserver:
  void OnColorModeChanged(bool dark_mode_enabled) override;

  // Called by `thumbnail_image_` to generate the thumbnail image to be used for
  // the result icon.
  void RequestThumbnail(const base::FilePath& file_path,
                        const gfx::Size& size,
                        ash::HoldingSpaceImage::BitmapCallback callback);

  // Called by `thumbnail_image_` to generate the placeholder image to be used
  // for the result icon.
  gfx::ImageSkia GetPlaceholderImage(const base::FilePath& file_path,
                                     const gfx::Size& size,
                                     const std::optional<bool>& dark_background,
                                     const std::optional<bool>& is_folder);

  void UpdateChipIcon();
  void UpdateThumbnailIcon();

  const base::FilePath filepath_;
  const Type type_;
  const raw_ptr<Profile> profile_;
  const raw_ptr<ash::ThumbnailLoader> thumbnail_loader_;

  std::optional<std::string> drive_id_;
  std::optional<GURL> url_;

  // Helper to handle lazy loading of the file thumbnail image - it manages an
  // ImageSkia that defaults to a "placeholder" icon - the default file icon,
  // and request a thumbnail load, using `thumbnail_loader_` when the image is
  // first requested (e.g. to paint it in the UI).
  // Allows for `thumbnail_loader_` to be nullptr, in which case the image will
  // remain in placeholder state.
  std::unique_ptr<ash::HoldingSpaceImage> thumbnail_image_;
  std::optional<base::CallbackListSubscription> thumbnail_image_update_sub_;

  base::WeakPtrFactory<FileResult> weak_factory_{this};
};

::std::ostream& operator<<(::std::ostream& os, const FileResult& result);

}  // namespace app_list

#endif  // CHROME_BROWSER_ASH_APP_LIST_SEARCH_FILES_FILE_RESULT_H_