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

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

Issue 2119613002: Adds a prerenderer watchdog timer. (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_REQUEST_COORDINATOR_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/timer/timer.h"
13 #include "components/keyed_service/core/keyed_service.h" 14 #include "components/keyed_service/core/keyed_service.h"
14 #include "components/offline_pages/background/device_conditions.h" 15 #include "components/offline_pages/background/device_conditions.h"
15 #include "components/offline_pages/background/offliner.h" 16 #include "components/offline_pages/background/offliner.h"
16 #include "components/offline_pages/background/request_coordinator_event_logger.h " 17 #include "components/offline_pages/background/request_coordinator_event_logger.h "
17 #include "components/offline_pages/background/request_queue.h" 18 #include "components/offline_pages/background/request_queue.h"
18 #include "components/offline_pages/background/scheduler.h" 19 #include "components/offline_pages/background/scheduler.h"
19 #include "url/gurl.h" 20 #include "url/gurl.h"
20 21
21 namespace offline_pages { 22 namespace offline_pages {
22 23
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // tests). 111 // tests).
111 void OfflinerDoneCallback(const SavePageRequest& request, 112 void OfflinerDoneCallback(const SavePageRequest& request,
112 Offliner::RequestStatus status); 113 Offliner::RequestStatus status);
113 114
114 void TryNextRequest(); 115 void TryNextRequest();
115 116
116 // Returns the appropriate offliner to use, getting a new one from the factory 117 // Returns the appropriate offliner to use, getting a new one from the factory
117 // if needed. 118 // if needed.
118 void GetOffliner(); 119 void GetOffliner();
119 120
121 void SetOfflinerTimeoutForTest(long timeout) {
122 offliner_timeout_ = timeout;
123 }
124
120 friend class RequestCoordinatorTest; 125 friend class RequestCoordinatorTest;
121 126
122 // The offliner can only handle one request at a time - if the offliner is 127 // The offliner can only handle one request at a time - if the offliner is
123 // busy, prevent other requests. This flag marks whether the offliner is in 128 // busy, prevent other requests. This flag marks whether the offliner is in
124 // use. 129 // use.
125 bool is_busy_; 130 bool is_busy_;
126 // True if the current request has been canceled. 131 // True if the current request has been canceled.
127 bool is_canceled_; 132 bool is_canceled_;
133 // How long to wait for an offliner before giving up.
dougarnett 2016/06/30 19:16:48 ... an offliner request ... ?
Pete Williamson 2016/07/01 17:16:55 Done.
134 long offliner_timeout_;
dewittj 2016/06/30 20:38:33 Please use base::TimeDelta here so the units are u
Pete Williamson 2016/07/01 17:16:55 Done.
128 // Unowned pointer to the current offliner, if any. 135 // Unowned pointer to the current offliner, if any.
129 Offliner* offliner_; 136 Offliner* offliner_;
130 // RequestCoordinator takes over ownership of the policy 137 // RequestCoordinator takes over ownership of the policy
131 std::unique_ptr<OfflinerPolicy> policy_; 138 std::unique_ptr<OfflinerPolicy> policy_;
132 // OfflinerFactory. Used to create offline pages. Owned. 139 // OfflinerFactory. Used to create offline pages. Owned.
133 std::unique_ptr<OfflinerFactory> factory_; 140 std::unique_ptr<OfflinerFactory> factory_;
134 // RequestQueue. Used to store incoming requests. Owned. 141 // RequestQueue. Used to store incoming requests. Owned.
135 std::unique_ptr<RequestQueue> queue_; 142 std::unique_ptr<RequestQueue> queue_;
136 // Scheduler. Used to request a callback when network is available. Owned. 143 // Scheduler. Used to request a callback when network is available. Owned.
137 std::unique_ptr<Scheduler> scheduler_; 144 std::unique_ptr<Scheduler> scheduler_;
138 // Status of the most recent offlining. 145 // Status of the most recent offlining.
139 Offliner::RequestStatus last_offlining_status_; 146 Offliner::RequestStatus last_offlining_status_;
140 // Class to choose which request to schedule next 147 // Class to choose which request to schedule next
141 std::unique_ptr<RequestPicker> picker_; 148 std::unique_ptr<RequestPicker> picker_;
142 // Calling this returns to the scheduler across the JNI bridge. 149 // Calling this returns to the scheduler across the JNI bridge.
143 base::Callback<void(bool)> scheduler_callback_; 150 base::Callback<void(bool)> scheduler_callback_;
144 // Logger to record events. 151 // Logger to record events.
145 RequestCoordinatorEventLogger event_logger_; 152 RequestCoordinatorEventLogger event_logger_;
153 // Timer to watch for pre-render attempts running too long.
154 base::OneShotTimer watchdog_timer_;
146 // Allows us to pass a weak pointer to callbacks. 155 // Allows us to pass a weak pointer to callbacks.
147 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; 156 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_;
148 157
149 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); 158 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator);
150 }; 159 };
151 160
152 } // namespace offline_pages 161 } // namespace offline_pages
153 162
154 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 163 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698