Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: components/offline_pages/core/background/offliner_policy.h

Issue 2755753005: [Offline Pages] Add Android version check for timeout in offliner policy. (Closed)
Patch Set: fix test Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/offline_pages/core/background/pick_request_task_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_POLICY_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_POLICY_H_
6 #define COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_POLICY_H_ 6 #define COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_POLICY_H_
7 7
8 #include "base/sys_info.h"
9
8 namespace { 10 namespace {
9 // The max number of started tries is to guard against pages that make the 11 // The max number of started tries is to guard against pages that make the
10 // prerenderer crash. It should be greater than or equal to the max number of 12 // prerenderer crash. It should be greater than or equal to the max number of
11 // completed tries. 13 // completed tries.
12 const int kMaxStartedTries = 5; 14 const int kMaxStartedTries = 5;
13 // The number of max completed tries is based on Gin2G-poor testing showing that 15 // The number of max completed tries is based on Gin2G-poor testing showing that
14 // we often need about 4 tries with a 2 minute window, or 3 retries with a 3 16 // we often need about 4 tries with a 2 minute window, or 3 retries with a 3
15 // minute window. Also, we count one try now for foreground/disabled requests. 17 // minute window. Also, we count one try now for foreground/disabled requests.
16 const int kMaxCompletedTries = 3; 18 const int kMaxCompletedTries = 3;
17 // By the time we get to a week, the user has forgotten asking for a page. 19 // By the time we get to a week, the user has forgotten asking for a page.
18 const int kRequestExpirationTimeInSeconds = 60 * 60 * 24 * 7; 20 const int kRequestExpirationTimeInSeconds = 60 * 60 * 24 * 7;
19 21
20 // Scheduled background processing time limits. 22 // Scheduled background processing time limits for doze mode, which requires
23 // Android version >= 6.0 (API level >= 23). Otherwise the scheduled background
24 // processing time should be the same as immediate loading (4 min 50 secs), it's
25 // capped by the Prerenderer's 5 minute timeout.
21 const int kDozeModeBackgroundServiceWindowSeconds = 60 * 3; 26 const int kDozeModeBackgroundServiceWindowSeconds = 60 * 3;
22 const int kDefaultBackgroundProcessingTimeBudgetSeconds = 27 const int kDefaultBackgroundProcessingTimeBudgetSeconds =
23 kDozeModeBackgroundServiceWindowSeconds - 10; 28 kDozeModeBackgroundServiceWindowSeconds - 10;
24 const int kSinglePageTimeLimitWhenBackgroundScheduledSeconds = 29 const int kSinglePageTimeLimitWhenBackgroundScheduledSeconds =
25 kDozeModeBackgroundServiceWindowSeconds - 10; 30 kDozeModeBackgroundServiceWindowSeconds - 10;
26 31
32 const int kNonDozeModeBackgroundServiceWindowSeconds = 60 * 5;
33 const int kNonDozeDefaultBackgroundProcessingTimeBudgetSeconds =
34 kNonDozeModeBackgroundServiceWindowSeconds - 10;
35 const int kNonDozeSinglePageTimeLimitWhenBackgroundScheduledSeconds =
36 kNonDozeModeBackgroundServiceWindowSeconds - 10;
37
27 // Immediate processing time limits. Note: experiments on GIN-2g-poor show many 38 // Immediate processing time limits. Note: experiments on GIN-2g-poor show many
28 // page requests took 3 or 4 attempts in background scheduled mode with timeout 39 // page requests took 3 or 4 attempts in background scheduled mode with timeout
29 // of 2 minutes. So for immediate processing mode, give page requests just under 40 // of 2 minutes. So for immediate processing mode, give page requests just under
30 // 5 minutes, which is the timeout limit for the prerender itself. Then budget 41 // 5 minutes, which is the timeout limit for the prerender itself. Then budget
31 // up to 3 of those requests in processing window. 42 // up to 3 of those requests in processing window.
32 const int kSinglePageTimeLimitForImmediateLoadSeconds = 60 * 4 + 50; 43 const int kSinglePageTimeLimitForImmediateLoadSeconds = 60 * 4 + 50;
33 const int kImmediateLoadProcessingTimeBudgetSeconds = 44 const int kImmediateLoadProcessingTimeBudgetSeconds =
34 kSinglePageTimeLimitForImmediateLoadSeconds * 5; 45 kSinglePageTimeLimitForImmediateLoadSeconds * 5;
35 } // namespace 46 } // namespace
36 47
37 namespace offline_pages { 48 namespace offline_pages {
38 49
39 // Policy for the Background Offlining system. Some policy will belong to the 50 // Policy for the Background Offlining system. Some policy will belong to the
40 // RequestCoordinator, some to the RequestQueue, and some to the Offliner. 51 // RequestCoordinator, some to the RequestQueue, and some to the Offliner.
41 class OfflinerPolicy { 52 class OfflinerPolicy {
42 public: 53 public:
43 OfflinerPolicy() 54 OfflinerPolicy()
44 : prefer_untried_requests_(true), 55 : prefer_untried_requests_(true),
45 prefer_earlier_requests_(true), 56 prefer_earlier_requests_(true),
46 retry_count_is_more_important_than_recency_(true), 57 retry_count_is_more_important_than_recency_(true),
47 max_started_tries_(kMaxStartedTries), 58 max_started_tries_(kMaxStartedTries),
48 max_completed_tries_(kMaxCompletedTries), 59 max_completed_tries_(kMaxCompletedTries) {
49 background_scheduled_processing_time_budget_( 60 int32_t os_major_version = 0;
50 kDefaultBackgroundProcessingTimeBudgetSeconds) {} 61 int32_t os_minor_version = 0;
62 int32_t os_bugfix_version = 0;
63 base::SysInfo::OperatingSystemVersionNumbers(
64 &os_major_version, &os_minor_version, &os_bugfix_version);
65 if (os_major_version < 6)
66 has_doze_mode_ = false;
67 else
68 has_doze_mode_ = true;
69 }
51 70
52 // Constructor for unit tests. 71 // Constructor for unit tests.
53 OfflinerPolicy(bool prefer_untried, 72 OfflinerPolicy(bool prefer_untried,
54 bool prefer_earlier, 73 bool prefer_earlier,
55 bool prefer_retry_count, 74 bool prefer_retry_count,
56 int max_started_tries, 75 int max_started_tries,
57 int max_completed_tries, 76 int max_completed_tries)
58 int background_processing_time_budget)
59 : prefer_untried_requests_(prefer_untried), 77 : prefer_untried_requests_(prefer_untried),
60 prefer_earlier_requests_(prefer_earlier), 78 prefer_earlier_requests_(prefer_earlier),
61 retry_count_is_more_important_than_recency_(prefer_retry_count), 79 retry_count_is_more_important_than_recency_(prefer_retry_count),
62 max_started_tries_(max_started_tries), 80 max_started_tries_(max_started_tries),
63 max_completed_tries_(max_completed_tries), 81 max_completed_tries_(max_completed_tries) {}
64 background_scheduled_processing_time_budget_(
65 background_processing_time_budget) {}
66 82
67 // TODO(petewil): Numbers here are chosen arbitrarily, do the proper studies 83 // TODO(petewil): Numbers here are chosen arbitrarily, do the proper studies
68 // to get good policy numbers. Eventually this should get data from a finch 84 // to get good policy numbers. Eventually this should get data from a finch
69 // experiment. 85 // experiment.
70 86
71 // Returns true if we should prefer retrying lesser tried requests. 87 // Returns true if we should prefer retrying lesser tried requests.
72 bool ShouldPreferUntriedRequests() const { return prefer_untried_requests_; } 88 bool ShouldPreferUntriedRequests() const { return prefer_untried_requests_; }
73 89
74 // Returns true if we should prefer older requests of equal number of tries. 90 // Returns true if we should prefer older requests of equal number of tries.
75 bool ShouldPreferEarlierRequests() const { return prefer_earlier_requests_; } 91 bool ShouldPreferEarlierRequests() const { return prefer_earlier_requests_; }
(...skipping 26 matching lines...) Expand all
102 // charging. If we decide to allow non-user requested pages when not 118 // charging. If we decide to allow non-user requested pages when not
103 // plugged in, we should raise this somewhat higher. 119 // plugged in, we should raise this somewhat higher.
104 return 25; 120 return 25;
105 } 121 }
106 122
107 // How many seconds to keep trying new pages for, before we give up, and 123 // How many seconds to keep trying new pages for, before we give up, and
108 // return to the scheduler. 124 // return to the scheduler.
109 // TODO(dougarnett): Consider parameterizing these time limit/budget 125 // TODO(dougarnett): Consider parameterizing these time limit/budget
110 // calls with processing mode. 126 // calls with processing mode.
111 int GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds() const { 127 int GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds() const {
112 return background_scheduled_processing_time_budget_; 128 if (has_doze_mode_)
129 return kDefaultBackgroundProcessingTimeBudgetSeconds;
130 return kNonDozeDefaultBackgroundProcessingTimeBudgetSeconds;
113 } 131 }
114 132
115 // How many seconds to keep trying new pages for, before we give up, when 133 // How many seconds to keep trying new pages for, before we give up, when
116 // processing started immediately (without scheduler). 134 // processing started immediately (without scheduler).
117 int GetProcessingTimeBudgetForImmediateLoadInSeconds() const { 135 int GetProcessingTimeBudgetForImmediateLoadInSeconds() const {
118 return kImmediateLoadProcessingTimeBudgetSeconds; 136 return kImmediateLoadProcessingTimeBudgetSeconds;
119 } 137 }
120 138
121 // How long do we allow a page to load before giving up on it when 139 // How long do we allow a page to load before giving up on it when
122 // background loading was scheduled. 140 // background loading was scheduled.
123 int GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() const { 141 int GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() const {
124 return kSinglePageTimeLimitWhenBackgroundScheduledSeconds; 142 if (has_doze_mode_)
143 return kSinglePageTimeLimitWhenBackgroundScheduledSeconds;
144 return kNonDozeSinglePageTimeLimitWhenBackgroundScheduledSeconds;
125 } 145 }
126 146
127 // How long do we allow a page to load before giving up on it when 147 // How long do we allow a page to load before giving up on it when
128 // immediately background loading. 148 // immediately background loading.
129 int GetSinglePageTimeLimitForImmediateLoadInSeconds() const { 149 int GetSinglePageTimeLimitForImmediateLoadInSeconds() const {
130 return kSinglePageTimeLimitForImmediateLoadSeconds; 150 return kSinglePageTimeLimitForImmediateLoadSeconds;
131 } 151 }
132 152
133 // How long we allow requests to remain in the system before giving up. 153 // How long we allow requests to remain in the system before giving up.
134 int GetRequestExpirationTimeInSeconds() const { 154 int GetRequestExpirationTimeInSeconds() const {
135 return kRequestExpirationTimeInSeconds; 155 return kRequestExpirationTimeInSeconds;
136 } 156 }
137 157
138 private: 158 private:
139 bool prefer_untried_requests_; 159 bool prefer_untried_requests_;
140 bool prefer_earlier_requests_; 160 bool prefer_earlier_requests_;
141 bool retry_count_is_more_important_than_recency_; 161 bool retry_count_is_more_important_than_recency_;
162 bool has_doze_mode_;
142 int max_started_tries_; 163 int max_started_tries_;
143 int max_completed_tries_; 164 int max_completed_tries_;
144 int background_scheduled_processing_time_budget_;
145 }; 165 };
146 } // namespace offline_pages 166 } // namespace offline_pages
147 167
148 #endif // COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_POLICY_H_ 168 #endif // COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_POLICY_H_
OLDNEW
« no previous file with comments | « no previous file | components/offline_pages/core/background/pick_request_task_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698