File: offliner_policy.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; 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 (148 lines) | stat: -rw-r--r-- 6,445 bytes parent folder | download | duplicates (8)
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
// Copyright 2016 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_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_POLICY_H_
#define COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_POLICY_H_

namespace offline_pages {

// The max number of started tries is to guard against pages that make the
// background loader crash. It should be greater than or equal to the max
// number of completed tries.
constexpr int kMaxStartedTries = 5;
// The number of max completed tries is based on Gin2G-poor testing showing that
// we often need about 4 tries with a 2 minute window, or 3 retries with a 3
// minute window. Also, we count one try now for foreground/disabled requests.
constexpr int kMaxCompletedTries = 3;
// By the time we get to a week, the user has forgotten asking for a page.
constexpr int kRequestExpirationTimeInSeconds = 60 * 60 * 24 * 7;

// Scheduled background processing time limits.
constexpr int kDozeModeBackgroundServiceWindowSeconds = 60 * 3;
constexpr int kDefaultBackgroundProcessingTimeBudgetSeconds =
    kDozeModeBackgroundServiceWindowSeconds - 10;
constexpr int kSinglePageTimeLimitWhenBackgroundScheduledSeconds =
    kDozeModeBackgroundServiceWindowSeconds - 10;

// Immediate processing time limits.  Note: experiments on GIN-2g-poor show many
// page requests took 3 or 4 attempts in background scheduled mode with timeout
// of 2 minutes. So for immediate processing mode, give page requests just under
// 5 minutes, which was equal to the timeout limit in prerender. Then budget up
// to 3 of those requests in processing window.
// TODO(petewil): Consider if we want to up the immediate window to 8 minutes
// now that we are always using the background loader.
constexpr int kSinglePageTimeLimitForImmediateLoadSeconds = 60 * 4 + 50;
constexpr int kImmediateLoadProcessingTimeBudgetSeconds =
    kSinglePageTimeLimitForImmediateLoadSeconds * 5;

// Policy for the Background Offlining system.  Some policy will belong to the
// RequestCoordinator, some to the RequestQueue, and some to the Offliner.
class OfflinerPolicy {
 public:
  OfflinerPolicy()
      : prefer_untried_requests_(true),
        prefer_earlier_requests_(true),
        retry_count_is_more_important_than_recency_(true),
        max_started_tries_(kMaxStartedTries),
        max_completed_tries_(kMaxCompletedTries),
        background_scheduled_processing_time_budget_(
            kDefaultBackgroundProcessingTimeBudgetSeconds) {}

  // Constructor for unit tests.
  OfflinerPolicy(bool prefer_untried,
                 bool prefer_earlier,
                 bool prefer_retry_count,
                 int max_started_tries,
                 int max_completed_tries,
                 int background_processing_time_budget)
      : prefer_untried_requests_(prefer_untried),
        prefer_earlier_requests_(prefer_earlier),
        retry_count_is_more_important_than_recency_(prefer_retry_count),
        max_started_tries_(max_started_tries),
        max_completed_tries_(max_completed_tries),
        background_scheduled_processing_time_budget_(
            background_processing_time_budget) {}

  // TODO(petewil): Numbers here are chosen arbitrarily, do the proper studies
  // to get good policy numbers. Eventually this should get data from a finch
  // experiment. crbug.com/705112.

  // Returns true if we should prefer retrying lesser tried requests.
  bool ShouldPreferUntriedRequests() const { return prefer_untried_requests_; }

  // Returns true if we should prefer older requests of equal number of tries.
  bool ShouldPreferEarlierRequests() const { return prefer_earlier_requests_; }

  // Returns true if retry count is considered more important than recency in
  // picking which request to try next.
  bool RetryCountIsMoreImportantThanRecency() const {
    return retry_count_is_more_important_than_recency_;
  }

  // The max number of times we will start a request.  Not all started attempts
  // will complete.  This may be caused by background loader issues or chromium
  // being swapped out of memory.
  int GetMaxStartedTries() const { return max_started_tries_; }

  // The max number of times we will retry a request when the attempt
  // completed, but failed.
  int GetMaxCompletedTries() const { return max_completed_tries_; }

  bool PowerRequired(bool user_requested) const { return (!user_requested); }

  bool UnmeteredNetworkRequired(bool user_requested) const {
    return !(user_requested);
  }

  int BatteryPercentageRequired(bool user_requested) const {
    if (user_requested)
      return 0;
    // This is so low because we require the device to be plugged in and
    // charging.  If we decide to allow non-user requested pages when not
    // plugged in, we should raise this somewhat higher.
    return 25;
  }

  // How many seconds to keep trying new pages for, before we give up, and
  // return to the scheduler.
  // TODO(dougarnett): Consider parameterizing these time limit/budget
  // calls with processing mode.
  int GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds() const {
    return background_scheduled_processing_time_budget_;
  }

  // How many seconds to keep trying new pages for, before we give up, when
  // processing started immediately (without scheduler).
  int GetProcessingTimeBudgetForImmediateLoadInSeconds() const {
    return kImmediateLoadProcessingTimeBudgetSeconds;
  }

  // How long do we allow a page to load before giving up on it when
  // background loading was scheduled.
  int GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() const {
    return kSinglePageTimeLimitWhenBackgroundScheduledSeconds;
  }

  // How long do we allow a page to load before giving up on it when
  // immediately background loading.
  int GetSinglePageTimeLimitForImmediateLoadInSeconds() const {
    return kSinglePageTimeLimitForImmediateLoadSeconds;
  }

  // How long we allow requests to remain in the system before giving up.
  int GetRequestExpirationTimeInSeconds() const {
    return kRequestExpirationTimeInSeconds;
  }

 private:
  bool prefer_untried_requests_;
  bool prefer_earlier_requests_;
  bool retry_count_is_more_important_than_recency_;
  int max_started_tries_;
  int max_completed_tries_;
  int background_scheduled_processing_time_budget_;
};
}  // namespace offline_pages

#endif  // COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_POLICY_H_