File: plus_address_suggestion_generator.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; 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 (104 lines) | stat: -rw-r--r-- 4,389 bytes parent folder | download | duplicates (3)
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
// 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 COMPONENTS_PLUS_ADDRESSES_PLUS_ADDRESS_SUGGESTION_GENERATOR_H_
#define COMPONENTS_PLUS_ADDRESSES_PLUS_ADDRESS_SUGGESTION_GENERATOR_H_

#include <vector>

#include "base/memory/raw_ref.h"
#include "base/memory/stack_allocated.h"
#include "components/autofill/core/browser/integrators/password_form_classification.h"
#include "components/plus_addresses/plus_address_types.h"
#include "url/origin.h"

namespace autofill {
class FormData;
struct Suggestion;
}  // namespace autofill

namespace plus_addresses {

class PlusAddressAllocator;
class PlusAddressSettingService;

// Helper class for generation plus address suggestions. Objects of this class
// are not intended to be saved into a member - instead, their lifetime should
// be scoped to a method call that generates suggestions.
class PlusAddressSuggestionGenerator final {
  STACK_ALLOCATED();

 public:
  PlusAddressSuggestionGenerator(
      const PlusAddressSettingService* setting_service,
      PlusAddressAllocator* allocator,
      url::Origin origin);
  ~PlusAddressSuggestionGenerator();

  // Returns the suggestions to be offered on the field in `focused_form` with
  // `focused_field_id` with Password Manager classification
  // `focused_form_classification`. `affiliated_profiles` are assumed to be the
  // plus profiles affiliated with the primary main frame origin.
  // Note that the method CHECKs that a field with `focused_field_id` is
  // contained in `focused_form`.
  [[nodiscard]] std::vector<autofill::Suggestion> GetSuggestions(
      const std::vector<std::string>& affiliated_plus_addresses,
      bool is_creation_enabled,
      const autofill::FormData& focused_form,
      const autofill::FormFieldData& focused_field,
      const base::flat_map<autofill::FieldGlobalId, autofill::FieldTypeGroup>&
          form_field_type_groups,
      const autofill::PasswordFormClassification& focused_form_classification,
      autofill::AutofillSuggestionTriggerSource trigger_source);

  // Updates `suggestion` with a refreshed plus address by setting a new
  // payload.
  void RefreshPlusAddressForSuggestion(autofill::Suggestion& suggestion);

  // Returns a suggestion for managing plus addresses.
  static autofill::Suggestion GetManagePlusAddressSuggestion();

  // Returns a suggestion for displaying an error during plus address
  // reservation. The type of `error` determines which string to show and
  // whether to offer refresh.
  static autofill::Suggestion GetPlusAddressErrorSuggestion(
      const PlusAddressRequestError& error);

  // Updates `suggestion` to have `plus_address` as the proposed suggestions.
  // `CHECK`s that `suggestion` is of type `kCreateNewPlusAddressInline`.
  static void SetSuggestedPlusAddressForSuggestion(
      const PlusAddress& plus_address,
      autofill::Suggestion& suggestion);

  // Updates the `suggestion`'s style to indicate whether it `is_loading`.
  static void SetLoadingStateForSuggestion(bool is_loading,
                                           autofill::Suggestion& suggestion);

 private:
  // Returns a suggestion to create a new plus address.
  autofill::Suggestion CreateNewPlusAddressSuggestion();

  // Returns whether it is allowed to generate plus addresses inline. This is
  // true on Desktop platforms if the user has accepted the legal notice.
  bool IsInlineGenerationEnabled() const;

  // Returns a suggestion to generate a new plus address inline. If there are
  // pre-allocated plus addresses, it adds the next suggested plus address as
  // payload. Otherwise, the payload is left empty (and the UI will need to
  // request a suggested plus address on showing the suggestion). If
  // `refreshed_suggestion` is true, the function will return a plus address
  // that's different to the last one that was offered.
  autofill::Suggestion CreateNewPlusAddressInlineSuggestion(
      bool refreshed_suggestion);

  const raw_ref<const PlusAddressSettingService> setting_service_;
  const raw_ref<PlusAddressAllocator> allocator_;
  // TODO(crbug.com/362445807): Eliminate this parameter once the allocator
  // no longer needs it.
  const url::Origin origin_;
};

}  // namespace plus_addresses

#endif  // COMPONENTS_PLUS_ADDRESSES_PLUS_ADDRESS_SUGGESTION_GENERATOR_H_