File: plus_address_creation_controller_desktop.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 (102 lines) | stat: -rw-r--r-- 4,347 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
// Copyright 2023 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_UI_PLUS_ADDRESSES_PLUS_ADDRESS_CREATION_CONTROLLER_DESKTOP_H_
#define CHROME_BROWSER_UI_PLUS_ADDRESSES_PLUS_ADDRESS_CREATION_CONTROLLER_DESKTOP_H_

#include "chrome/browser/ui/plus_addresses/plus_address_creation_controller.h"
#include "components/autofill/core/common/plus_address_survey_type.h"
#include "components/plus_addresses/metrics/plus_address_metrics.h"
#include "components/plus_addresses/plus_address_types.h"
#include "components/plus_addresses/settings/plus_address_setting_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_user_data.h"
#include "url/origin.h"

namespace plus_addresses {

class PlusAddressCreationDialogDelegate;
class PlusAddressCreationView;
class PlusAddressService;
class PlusAddressSettingService;

class PlusAddressCreationControllerDesktop
    : public PlusAddressCreationController,
      public content::WebContentsUserData<
          PlusAddressCreationControllerDesktop> {
 public:
  ~PlusAddressCreationControllerDesktop() override;

  // PlusAddressCreationController implementation:
  void OfferCreation(const url::Origin& main_frame_origin,
                     bool is_manual_fallback,
                     PlusAddressCallback callback) override;
  void TryAgainToReservePlusAddress() override;
  void OnRefreshClicked() override;
  void OnConfirmed() override;
  void OnCanceled() override;
  void OnDialogDestroyed() override;

  // Used to validate the view behavior in browsertests.
  PlusAddressCreationView* get_view_for_testing();
  // A mechanism to avoid view entanglements, reducing the need for view
  // mocking, etc., while still allowing tests of specific business logic.
  void set_suppress_ui_for_testing(bool should_suppress);
  // Used to validate storage and clearing of `maybe_plus_profile_`.
  std::optional<PlusProfile> get_plus_profile_for_testing();

 private:
  // WebContentsUserData:
  explicit PlusAddressCreationControllerDesktop(
      content::WebContents* web_contents);
  friend class content::WebContentsUserData<
      PlusAddressCreationControllerDesktop>;

  PlusAddressService* GetPlusAddressService();
  PlusAddressSettingService* GetPlusAddressSettingService();

  // Returns whether we should show a notice. This is true iff the user has
  // never created a plus address before (and the feature for showing the notice
  // is enabled).
  bool ShouldShowNotice() const;

  // Populates `plus_profile_` with `maybe_plus_profile` if it's not an error.
  void OnPlusAddressReserved(const PlusProfileOrError& maybe_plus_profile);
  // Autofills `plus_address` in the targeted field by running callback_.
  void OnPlusAddressConfirmed(const PlusProfileOrError& maybe_plus_profile);
  // Shows an applicable user perception survey after the generated plus address
  // was accepted.
  void TriggerUserPerceptionSurvey(hats::SurveyType survey_type);

  base::WeakPtr<PlusAddressCreationControllerDesktop> GetWeakPtr();

  std::unique_ptr<PlusAddressCreationDialogDelegate> dialog_delegate_;
  url::Origin relevant_origin_;
  PlusAddressCallback callback_;
  bool suppress_ui_for_testing_ = false;
  // This is set by OnPlusAddressReserved and cleared when the dialog is closed.
  std::optional<PlusProfile> plus_profile_;

  // Records the time between `modal_shown_time_` and now as modal shown
  // duration and the number of refresh attempts. Resets both
  // `modal_shown_time_` and `reserve_response_count_`.
  void RecordModalShownOutcome(metrics::PlusAddressModalCompletionStatus status,
                               bool was_notice_shown);

  // This is set on `OfferCreation`.
  std::optional<base::TimeTicks> modal_shown_time_;
  std::optional<metrics::PlusAddressModalCompletionStatus> modal_error_status_;
  // The number of responses from calls to reserve a plus address that a user
  // has made. This equals 1 + number of refreshes.
  int reserve_response_count_ = 0;

  base::WeakPtrFactory<PlusAddressCreationControllerDesktop> weak_ptr_factory_{
      this};

  WEB_CONTENTS_USER_DATA_KEY_DECL();
};

}  // namespace plus_addresses

#endif  // CHROME_BROWSER_UI_PLUS_ADDRESSES_PLUS_ADDRESS_CREATION_CONTROLLER_DESKTOP_H_