File: profile_customization_bubble_sync_controller.h

package info (click to toggle)
chromium 139.0.7258.138-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,120,676 kB
  • sloc: cpp: 35,100,869; 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 (100 lines) | stat: -rw-r--r-- 3,808 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
// 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_UI_VIEWS_PROFILES_PROFILE_CUSTOMIZATION_BUBBLE_SYNC_CONTROLLER_H_
#define CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CUSTOMIZATION_BUBBLE_SYNC_CONTROLLER_H_

#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "base/supports_user_data.h"
#include "chrome/browser/themes/theme_syncable_service.h"
#include "chrome/browser/ui/profiles/profile_customization_synced_theme_waiter.h"
#include "components/sync/service/sync_service.h"
#include "components/sync/service/sync_service_observer.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/views/view.h"
#include "ui/views/view_observer.h"

namespace views {
class View;
}  // namespace views

class Browser;
class Profile;

// Helper class for logic to show / delay showing the profile customization
// bubble. Owned by a Browser.
class ProfileCustomizationBubbleSyncController
    : public base::SupportsUserData::Data {
 public:
  enum class Outcome {
    kShowBubble,
    kSkipBubble,
    // The browser is being destroyed.
    kAbort
  };
  using ShowBubbleCallback = base::OnceCallback<void(Outcome outcome)>;

  ~ProfileCustomizationBubbleSyncController() override;

  ProfileCustomizationBubbleSyncController(
      const ProfileCustomizationBubbleSyncController& other) = delete;
  ProfileCustomizationBubbleSyncController& operator=(
      const ProfileCustomizationBubbleSyncController& other) = delete;

  // Applies `suggested_profile_color` and shows the profile customization
  // bubble if either (a) theme sync cannot start (see `CanThemeSyncStart()`) or
  // (b) theme sync is successful and results in the default theme in this
  // profile (either no value was synced before or the default theme was
  // synced). In all other cases, the call has no visible impact. This also
  // includes the case when sync can start but is blocked on the user to enter
  // the custom passphrase.
  static void ApplyColorAndShowBubbleWhenNoValueSynced(
      Browser* browser,
      SkColor suggested_profile_color);

  // A version of ApplyColorAndShowBubbleWhenNoValueSynced() that allows simpler
  // mocking.
  static void ApplyColorAndShowBubbleWhenNoValueSyncedForTesting(
      Browser* browser,
      syncer::SyncService* sync_service,
      ThemeService* theme_service,
      ShowBubbleCallback show_bubble_callback,
      SkColor suggested_profile_color);

  // Returns whether theme sync can start (i.e. is not disabled by policy,
  // theme sync is enabled, ...).
  static bool CanThemeSyncStart(Profile* profile);

 private:
  static void SetCurrentControllerAndInit(
      std::unique_ptr<ProfileCustomizationBubbleSyncController> controller);

  ProfileCustomizationBubbleSyncController(
      Browser* browser,
      syncer::SyncService* sync_service,
      ThemeService* theme_service,
      ShowBubbleCallback show_bubble_callback,
      SkColor suggested_profile_color);

  // This function may delete the object.
  void Init();

  void OnSyncedThemeReady(
      ProfileCustomizationSyncedThemeWaiter::Outcome outcome);

  // Functions that finalize the control logic by either showing or skipping the
  // bubble (or aborting completely) and deleting itself.
  void ApplyDefaultColorAndShowBubble();
  void InvokeCallbackAndDeleteItself(Outcome outcome);

  const raw_ptr<Browser> browser_;
  const raw_ptr<ThemeService> theme_service_;
  std::unique_ptr<ProfileCustomizationSyncedThemeWaiter> theme_waiter_;
  ShowBubbleCallback show_bubble_callback_;
  SkColor const suggested_profile_color_;
};

#endif  // CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CUSTOMIZATION_BUBBLE_SYNC_CONTROLLER_H_