File: sync_ui_util.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 (152 lines) | stat: -rw-r--r-- 5,728 bytes parent folder | download | duplicates (5)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Copyright 2012 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_SYNC_SYNC_UI_UTIL_H_
#define CHROME_BROWSER_SYNC_SYNC_UI_UTIL_H_

#include <optional>

#include "build/build_config.h"
#include "components/sync/service/sync_service_utils.h"

class Profile;

#if !BUILDFLAG(IS_ANDROID)
class Browser;
#endif

namespace signin {
class IdentityManager;
}  // namespace signin

namespace syncer {
class SyncService;
}  // namespace syncer

// Utility functions to gather current sync status information from the sync
// service and constructs messages suitable for showing in UI.

enum class SyncStatusMessageType {
  // User has not set up sync.
  kPreSynced,
  // We are synced and authenticated to a gmail account.
  kSynced,
  // A sync error (such as invalid credentials) has occurred.
  kSyncError,
  // Same as kSyncError but affecting passwords only.
  kPasswordsOnlySyncError,
};

// The action associated with the sync status in settings.
enum class SyncStatusActionType {
  // No action to take.
  kNoAction,
  // User needs to reauthenticate.
  kReauthenticate,
  // User needs to upgrade the client.
  kUpgradeClient,
  // User needs to enter their passphrase.
  kEnterPassphrase,
  // User needs to go through key retrieval.
  kRetrieveTrustedVaultKeys,
  // User needs to confirm sync settings.
  kConfirmSyncSettings,
};

// Sync errors that should be exposed to the user through the avatar button.
enum AvatarSyncErrorType {
  // Unrecoverable error for managed users.
  kManagedUserUnrecoverableError,
  // Unrecoverable error for regular users.
  kUnrecoverableError,
  // Sync paused (e.g. persistent authentication error).
  kSyncPaused,
  // Out-of-date client error.
  kUpgradeClientError,
  // Sync passphrase error.
  kPassphraseError,
  // Trusted vault keys missing for all sync datatypes (encrypt everything is
  // enabled).
  kTrustedVaultKeyMissingForEverythingError,
  // Trusted vault keys missing for always-encrypted datatypes (passwords).
  kTrustedVaultKeyMissingForPasswordsError,
  // User needs to improve recoverability of the trusted vault (encrypt
  // everything is enabled).
  kTrustedVaultRecoverabilityDegradedForEverythingError,
  // User needs to improve recoverability of the trusted vault (passwords).
  kTrustedVaultRecoverabilityDegradedForPasswordsError,
  // Sync settings dialog not confirmed yet.
  kSettingsUnconfirmedError,
};

struct SyncStatusLabels {
  SyncStatusMessageType message_type = SyncStatusMessageType::kPreSynced;
  int status_label_string_id = 0;
  int button_string_id = 0;
  int secondary_button_string_id = 0;
  SyncStatusActionType action_type = SyncStatusActionType::kNoAction;
};

// Returns the high-level sync status by querying |sync_service| and
// |identity_manager|.
SyncStatusLabels GetSyncStatusLabels(
    syncer::SyncService* sync_service,
    signin::IdentityManager* identity_manager,
    bool is_user_clear_primary_account_allowed);

// Returns the high-level sync status by querying |profile|. This is a
// convenience version of GetSyncStatusLabels that use the |sync_service| and
// |identity_manager| associated to |profile| via their respective factories.
SyncStatusLabels GetSyncStatusLabels(Profile* profile);

// Convenience version of GetSyncStatusLabels for when you're only interested in
// the message type.
SyncStatusMessageType GetSyncStatusMessageType(Profile* profile);

#if !BUILDFLAG(IS_ANDROID)
SyncStatusLabels GetSyncStatusLabelsForSettings(
    const syncer::SyncService* service);

SyncStatusLabels GetAvatarSyncErrorLabelsForSettings(AvatarSyncErrorType error);

// Gets the error in the sync machinery (if any) that should be exposed to the
// user through the titlebar avatar button. If std::nullopt is returned, this
// does NOT mean sync-the-feature/sync-the-transport is enabled, simply that
// there's no error. Furthermore, an error may be returned even if only
// sync-the-transport is running. One such case is when the user wishes to run
// an encrypted data type on transport mode and must first go through a reauth.
std::optional<AvatarSyncErrorType> GetAvatarSyncErrorType(Profile* profile);

// When |error| is present, this returns the string to be shown both as the
// tooltip of the avatar button, and in the profile menu body (the menu opened
// by clicking the avatar button).
std::u16string GetAvatarSyncErrorDescription(AvatarSyncErrorType error,
                                             bool is_sync_feature_enabled,
                                             const std::string& user_email);
#endif

// Whether sync is currently blocked from starting because the sync
// confirmation dialog hasn't been shown. Note that once the dialog is
// showing (i.e. IsSetupInProgress() is true), this will return false.
bool ShouldRequestSyncConfirmation(const syncer::SyncService* service);

// Returns whether it makes sense to show a Sync passphrase error UI, i.e.
// whether a missing passphrase is preventing Sync from fully starting up.
bool ShouldShowSyncPassphraseError(const syncer::SyncService* service);

#if !BUILDFLAG(IS_ANDROID)
// Opens a tab for the purpose of retrieving the trusted vault keys, which
// usually requires a reauth.
void OpenTabForSyncKeyRetrieval(
    Browser* browser,
    syncer::TrustedVaultUserActionTriggerForUMA trigger);

// Opens a tab for the purpose of improving the recoverability of the trusted
// vault keys, which usually requires a reauth.
void OpenTabForSyncKeyRecoverabilityDegraded(
    Browser* browser,
    syncer::TrustedVaultUserActionTriggerForUMA trigger);
#endif  // !BUILDFLAG(IS_ANDROID)

#endif  // CHROME_BROWSER_SYNC_SYNC_UI_UTIL_H_