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
ash / system / focus_mode / focus_mode_retry_util.h [blame]
// 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 ASH_SYSTEM_FOCUS_MODE_FOCUS_MODE_RETRY_UTIL_H_
#define ASH_SYSTEM_FOCUS_MODE_FOCUS_MODE_RETRY_UTIL_H_
#include "ash/ash_export.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "base/types/expected.h"
#include "google_apis/common/api_error_codes.h"
namespace ash {
// Max number of retries.
inline constexpr int kMaxRetryOverall = 5;
// Max number of retries for too many requests error.
inline constexpr int kMaxRetryTooManyRequests = 3;
// Max number of retries for explicit track.
inline constexpr int kMaxRetryExplicitTrack = 10;
// Initial wait time of the exponential backoff policy for overall errors.
inline constexpr base::TimeDelta kWaitTimeOverall = base::Seconds(1);
// Wait time when the client runs out of quota.
inline constexpr base::TimeDelta kWaitTimeTooManyRequests = base::Seconds(30);
// Wait time when the track is explicit.
inline constexpr base::TimeDelta kWaitTimeExplicitTrack = base::Seconds(1);
// Struct that keeps track of focus mode request retry state.
struct ASH_EXPORT FocusModeRetryState {
FocusModeRetryState();
~FocusModeRetryState();
void Reset();
int retry_index = 0;
base::OneShotTimer timer;
};
// Returns if it should retry the given http error.
ASH_EXPORT bool ShouldRetryHttpError(
const google_apis::ApiErrorCode http_error);
// Returns wait time for the exponential backoff retry. For each new attempt,
// the wait time doubles, e.g. 1s, 2s, 4s, 8s, 16s.
ASH_EXPORT base::TimeDelta GetExponentialBackoffRetryWaitTime(
const int retry_index);
} // namespace ash
#endif // ASH_SYSTEM_FOCUS_MODE_FOCUS_MODE_RETRY_UTIL_H_