| OLD | NEW |
| 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 #include "components/offline_pages/background/request_coordinator.h" | 5 #include "components/offline_pages/background/request_coordinator.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
| 17 #include "base/test/histogram_tester.h" | 17 #include "base/test/histogram_tester.h" |
| 18 #include "base/test/scoped_feature_list.h" | 18 #include "base/test/scoped_feature_list.h" |
| 19 #include "base/test/test_mock_time_task_runner.h" | 19 #include "base/test/test_mock_time_task_runner.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "components/offline_pages/background/device_conditions.h" | 22 #include "components/offline_pages/background/device_conditions.h" |
| 23 #include "components/offline_pages/background/network_quality_provider_stub.h" | 23 #include "components/offline_pages/background/network_quality_provider_stub.h" |
| 24 #include "components/offline_pages/background/offliner.h" | 24 #include "components/offline_pages/background/offliner.h" |
| 25 #include "components/offline_pages/background/offliner_factory.h" | 25 #include "components/offline_pages/background/offliner_factory.h" |
| 26 #include "components/offline_pages/background/offliner_factory_stub.h" | 26 #include "components/offline_pages/background/offliner_factory_stub.h" |
| 27 #include "components/offline_pages/background/offliner_policy.h" | 27 #include "components/offline_pages/background/offliner_policy.h" |
| 28 #include "components/offline_pages/background/offliner_stub.h" | 28 #include "components/offline_pages/background/offliner_stub.h" |
| 29 #include "components/offline_pages/background/pick_request_task_factory.h" | |
| 30 #include "components/offline_pages/background/request_queue.h" | 29 #include "components/offline_pages/background/request_queue.h" |
| 31 #include "components/offline_pages/background/request_queue_in_memory_store.h" | 30 #include "components/offline_pages/background/request_queue_in_memory_store.h" |
| 32 #include "components/offline_pages/background/save_page_request.h" | 31 #include "components/offline_pages/background/save_page_request.h" |
| 33 #include "components/offline_pages/background/scheduler.h" | 32 #include "components/offline_pages/background/scheduler.h" |
| 34 #include "components/offline_pages/background/scheduler_stub.h" | 33 #include "components/offline_pages/background/scheduler_stub.h" |
| 35 #include "components/offline_pages/offline_page_feature.h" | 34 #include "components/offline_pages/offline_page_feature.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 37 | 36 |
| 38 namespace offline_pages { | 37 namespace offline_pages { |
| 39 | 38 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 217 |
| 219 void ScheduleForTest() { coordinator_->ScheduleAsNeeded(); } | 218 void ScheduleForTest() { coordinator_->ScheduleAsNeeded(); } |
| 220 | 219 |
| 221 void CallRequestNotPicked(bool non_user_requested_tasks_remaining, | 220 void CallRequestNotPicked(bool non_user_requested_tasks_remaining, |
| 222 bool disabled_tasks_remaining) { | 221 bool disabled_tasks_remaining) { |
| 223 if (disabled_tasks_remaining) | 222 if (disabled_tasks_remaining) |
| 224 coordinator_->disabled_requests_.insert(kRequestId1); | 223 coordinator_->disabled_requests_.insert(kRequestId1); |
| 225 else | 224 else |
| 226 coordinator_->disabled_requests_.clear(); | 225 coordinator_->disabled_requests_.clear(); |
| 227 | 226 |
| 228 coordinator_->RequestNotPicked(non_user_requested_tasks_remaining); | 227 coordinator_->RequestNotPicked(non_user_requested_tasks_remaining, false); |
| 229 } | 228 } |
| 230 | 229 |
| 231 void SetDeviceConditionsForTest(DeviceConditions device_conditions) { | 230 void SetDeviceConditionsForTest(DeviceConditions device_conditions) { |
| 232 coordinator_->SetDeviceConditionsForTest(device_conditions); | 231 coordinator_->SetDeviceConditionsForTest(device_conditions); |
| 233 } | 232 } |
| 234 | 233 |
| 235 void WaitForCallback() { | 234 void WaitForCallback() { |
| 236 waiter_.Wait(); | 235 waiter_.Wait(); |
| 237 } | 236 } |
| 238 | 237 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 std::unique_ptr<RequestQueueInMemoryStore> | 311 std::unique_ptr<RequestQueueInMemoryStore> |
| 313 store(new RequestQueueInMemoryStore()); | 312 store(new RequestQueueInMemoryStore()); |
| 314 std::unique_ptr<RequestQueue> queue(new RequestQueue(std::move(store))); | 313 std::unique_ptr<RequestQueue> queue(new RequestQueue(std::move(store))); |
| 315 std::unique_ptr<Scheduler> scheduler_stub(new SchedulerStub()); | 314 std::unique_ptr<Scheduler> scheduler_stub(new SchedulerStub()); |
| 316 network_quality_estimator_.reset(new NetworkQualityProviderStub()); | 315 network_quality_estimator_.reset(new NetworkQualityProviderStub()); |
| 317 coordinator_.reset(new RequestCoordinator( | 316 coordinator_.reset(new RequestCoordinator( |
| 318 std::move(policy), std::move(offliner_factory), std::move(queue), | 317 std::move(policy), std::move(offliner_factory), std::move(queue), |
| 319 std::move(scheduler_stub), network_quality_estimator_.get())); | 318 std::move(scheduler_stub), network_quality_estimator_.get())); |
| 320 coordinator_->AddObserver(&observer_); | 319 coordinator_->AddObserver(&observer_); |
| 321 SetNetworkConnected(true); | 320 SetNetworkConnected(true); |
| 322 std::unique_ptr<PickRequestTaskFactory> picker_factory( | |
| 323 new PickRequestTaskFactory( | |
| 324 coordinator_->policy(), | |
| 325 static_cast<RequestNotifier*>(coordinator_.get()), | |
| 326 coordinator_->GetLogger())); | |
| 327 coordinator_->queue()->SetPickerFactory(std::move(picker_factory)); | |
| 328 immediate_callback_ = | 321 immediate_callback_ = |
| 329 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction, | 322 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction, |
| 330 base::Unretained(this)); | 323 base::Unretained(this)); |
| 331 // Override the normal immediate callback with a wait releasing callback. | 324 // Override the normal immediate callback with a wait releasing callback. |
| 332 waiting_callback_ = base::Bind( | 325 waiting_callback_ = base::Bind( |
| 333 &RequestCoordinatorTest::WaitingCallbackFunction, base::Unretained(this)); | 326 &RequestCoordinatorTest::WaitingCallbackFunction, base::Unretained(this)); |
| 334 SetDeviceConditionsForTest(device_conditions_); | 327 SetDeviceConditionsForTest(device_conditions_); |
| 335 EnableOfflinerCallback(true); | 328 EnableOfflinerCallback(true); |
| 336 } | 329 } |
| 337 | 330 |
| (...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 // Now whether processing triggered immediately depends on whether test | 1305 // Now whether processing triggered immediately depends on whether test |
| 1313 // is run on svelte device or not. | 1306 // is run on svelte device or not. |
| 1314 if (base::SysInfo::IsLowEndDevice()) { | 1307 if (base::SysInfo::IsLowEndDevice()) { |
| 1315 EXPECT_FALSE(is_busy()); | 1308 EXPECT_FALSE(is_busy()); |
| 1316 } else { | 1309 } else { |
| 1317 EXPECT_TRUE(is_busy()); | 1310 EXPECT_TRUE(is_busy()); |
| 1318 } | 1311 } |
| 1319 } | 1312 } |
| 1320 | 1313 |
| 1321 } // namespace offline_pages | 1314 } // namespace offline_pages |
| OLD | NEW |