File: background_fetch_icon_loader.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (66 lines) | stat: -rw-r--r-- 2,684 bytes parent folder | download | duplicates (8)
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
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_BACKGROUND_FETCH_BACKGROUND_FETCH_ICON_LOADER_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_BACKGROUND_FETCH_BACKGROUND_FETCH_ICON_LOADER_H_

#include "third_party/blink/renderer/bindings/modules/v8/v8_image_resource.h"
#include "third_party/blink/renderer/core/loader/threaded_icon_loader.h"
#include "third_party/blink/renderer/modules/background_fetch/background_fetch_type_converters.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"

namespace blink {

class BackgroundFetchBridge;

class MODULES_EXPORT BackgroundFetchIconLoader final
    : public GarbageCollected<BackgroundFetchIconLoader> {
 public:
  // The bitmap may be empty if the request failed or the image data could not
  // be decoded. The int64_t returned is the scale of the ideal to chosen icon,
  // before resizing. This is -1 if the ideal icon size is empty, or if no icon
  // provided was suitable.
  using IconCallback = base::OnceCallback<void(const SkBitmap&, int64_t)>;

  BackgroundFetchIconLoader();

  // Asynchronously download an icon from the given url, decodes the loaded
  // data, and passes the bitmap to the given callback.
  void Start(BackgroundFetchBridge* bridge,
             ExecutionContext* execution_context,
             HeapVector<Member<ManifestImageResource>> icons,
             IconCallback icon_callback);

  // Cancels the pending load, if there is one. The |icon_callback_| will not
  // be run.
  void Stop();

  void Trace(Visitor* visitor) const;

 private:
  friend class BackgroundFetchIconLoaderTest;

  // Callback for BackgroundFetchBridge::GetIconDisplaySize()
  void DidGetIconDisplaySizeIfSoLoadIcon(
      ExecutionContext* execution_context,
      IconCallback callback,
      const gfx::Size& icon_display_size_pixels);

  void DidGetIcon(SkBitmap icon, double resize_scale);

  // Picks the best icon from the list of developer provided icons, for current
  // display, given the |ideal_size_pixels|, and returns its KURL.
  // If none of the icons is appropriate, this returns an empty URL.
  KURL PickBestIconForDisplay(ExecutionContext* execution_context,
                              int ideal_size_pixels);

  HeapVector<Member<ManifestImageResource>> icons_;
  Member<ThreadedIconLoader> threaded_icon_loader_;
  IconCallback icon_callback_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_BACKGROUND_FETCH_BACKGROUND_FETCH_ICON_LOADER_H_