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

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

Issue 2178723002: Add more unit tests for RequestPicker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
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_BACKGROUND_OFFLINER_POLICY_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_ 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_
7 7
8 namespace { 8 namespace {
9 const int kMaxRetries = 2; 9 const int kMaxRetries = 2;
10 const int kBackgroundTimeBudgetSeconds = 170; 10 const int kBackgroundTimeBudgetSeconds = 170;
11 const int kSinglePageTimeBudgetSeconds = 120; 11 const int kSinglePageTimeBudgetSeconds = 120;
12 const int kMinimumBatteryPercentageForNonUserRequestOfflining = 50; 12 const int kMinimumBatteryPercentageForNonUserRequestOfflining = 50;
13 } // namespace 13 } // namespace
14 14
15 namespace offline_pages { 15 namespace offline_pages {
16 16
17 // Policy for the Background Offlining system. Some policy will belong to the 17 // Policy for the Background Offlining system. Some policy will belong to the
18 // RequestCoordinator, some to the RequestQueue, and some to the Offliner. 18 // RequestCoordinator, some to the RequestQueue, and some to the Offliner.
19 class OfflinerPolicy { 19 class OfflinerPolicy {
20 public: 20 public:
21 OfflinerPolicy(){}; 21 OfflinerPolicy()
22 : prefer_untried_requests_(false),
fgorski 2016/07/25 16:22:57 please put that into the .cc file.
Pete Williamson 2016/07/25 19:54:20 There is no .cc file yet. It will be coming in a
23 prefer_earlier_requests_(true),
24 retry_count_is_more_important_than_recency_(true) {}
25
26 OfflinerPolicy(bool prefer_untried, bool prefer_earlier,
fgorski 2016/07/25 16:22:57 same here + git cl format.
Pete Williamson 2016/07/25 19:54:20 Format done
27 bool prefer_retry_count)
28 : prefer_untried_requests_(prefer_untried),
29 prefer_earlier_requests_(prefer_earlier),
30 retry_count_is_more_important_than_recency_(prefer_retry_count) {}
22 31
23 // TODO(petewil): Numbers here are chosen arbitrarily, do the proper studies 32 // TODO(petewil): Numbers here are chosen arbitrarily, do the proper studies
24 // to get good policy numbers. 33 // to get good policy numbers.
25 34
26 // TODO(petewil): Eventually this should get data from a finch experiment. 35 // TODO(petewil): Eventually this should get data from a finch experiment.
27 36
28 // Returns true if we should prefer retrying lesser tried requests. 37 // Returns true if we should prefer retrying lesser tried requests.
29 bool ShouldPreferUntriedRequests() { return false; } 38 bool ShouldPreferUntriedRequests() { return prefer_untried_requests_; }
fgorski 2016/07/25 16:22:57 Can this method be marked const? Same for the 2 th
Pete Williamson 2016/07/25 19:54:21 Done.
30 39
31 // Returns true if we should prefer older requests of equal number of tries. 40 // Returns true if we should prefer older requests of equal number of tries.
32 bool ShouldPreferEarlierRequests() { return true; } 41 bool ShouldPreferEarlierRequests() { return prefer_earlier_requests_; }
33 42
34 // Returns true if retry count is considered more important than recency in 43 // Returns true if retry count is considered more important than recency in
35 // picking which request to try next. 44 // picking which request to try next.
36 bool RetryCountIsMoreImportantThanRecency() { return true; } 45 bool RetryCountIsMoreImportantThanRecency() {
46 return retry_count_is_more_important_than_recency_;
47 }
37 48
38 // The max number of times we will retry a request. 49 // The max number of times we will retry a request.
39 int GetMaxRetries() { return kMaxRetries; } 50 int GetMaxRetries() { return kMaxRetries; }
40 51
41 // How many seconds to keep trying new pages for, before we give up, and 52 // How many seconds to keep trying new pages for, before we give up, and
42 // return to the scheduler. 53 // return to the scheduler.
43 int GetBackgroundProcessingTimeBudgetSeconds() { 54 int GetBackgroundProcessingTimeBudgetSeconds() {
44 return kBackgroundTimeBudgetSeconds; 55 return kBackgroundTimeBudgetSeconds;
45 } 56 }
46 57
47 // How long do we allow a page to load before giving up on it 58 // How long do we allow a page to load before giving up on it
48 int GetSinglePageTimeBudgetInSeconds() { 59 int GetSinglePageTimeBudgetInSeconds() {
49 return kSinglePageTimeBudgetSeconds; 60 return kSinglePageTimeBudgetSeconds;
50 } 61 }
51 62
52 // How much battery must we have before fetching a page not explicitly 63 // How much battery must we have before fetching a page not explicitly
53 // requested by the user? 64 // requested by the user?
54 int GetMinimumBatteryPercentageForNonUserRequestOfflining() { 65 int GetMinimumBatteryPercentageForNonUserRequestOfflining() {
55 return kMinimumBatteryPercentageForNonUserRequestOfflining; 66 return kMinimumBatteryPercentageForNonUserRequestOfflining;
56 } 67 }
68
69 private:
70 bool prefer_untried_requests_;
71 bool prefer_earlier_requests_;
72 bool retry_count_is_more_important_than_recency_;
57 }; 73 };
58 } 74 }
59 75
60 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_ 76 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698