| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/android/offline_pages/evaluation/evaluation_test_schedu
ler.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" |
| 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "components/offline_pages/background/device_conditions.h" |
| 13 #include "components/offline_pages/background/request_coordinator.h" |
| 14 #include "net/base/network_change_notifier.h" |
| 15 |
| 16 namespace offline_pages { |
| 17 |
| 18 namespace android { |
| 19 |
| 20 namespace { |
| 21 |
| 22 void StartProcessing(); |
| 23 |
| 24 void ProcessingDoneCallback(bool result) { |
| 25 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 26 base::Bind(&StartProcessing)); |
| 27 } |
| 28 |
| 29 void GetAllRequestsDone( |
| 30 std::vector<std::unique_ptr<SavePageRequest>> requests) { |
| 31 if (requests.size() > 0) { |
| 32 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 33 RequestCoordinator* coordinator = |
| 34 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile); |
| 35 // TODO(romax) Maybe get current real condition. |
| 36 DeviceConditions device_conditions( |
| 37 true, 0, net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI); |
| 38 coordinator->StartProcessing(device_conditions, |
| 39 base::Bind(&ProcessingDoneCallback)); |
| 40 } |
| 41 } |
| 42 |
| 43 void StartProcessing() { |
| 44 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 45 RequestCoordinator* coordinator = |
| 46 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile); |
| 47 coordinator->GetAllRequests(base::Bind(&GetAllRequestsDone)); |
| 48 } |
| 49 |
| 50 } // namespace |
| 51 |
| 52 void EvaluationTestScheduler::Schedule( |
| 53 const TriggerConditions& trigger_conditions) { |
| 54 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 55 base::Bind(&StartProcessing)); |
| 56 } |
| 57 |
| 58 void EvaluationTestScheduler::BackupSchedule( |
| 59 const TriggerConditions& trigger_conditions, |
| 60 long delay_in_seconds) {} |
| 61 |
| 62 void EvaluationTestScheduler::Unschedule() {} |
| 63 |
| 64 void EvaluationTestScheduler::ImmediateScheduleCallback(bool result) { |
| 65 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 66 base::Bind(&StartProcessing)); |
| 67 } |
| 68 |
| 69 } // namespace android |
| 70 } // namespace offline_pages |
| OLD | NEW |