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

Side by Side Diff: chrome/browser/android/offline_pages/evaluation/evaluation_test_scheduler.cc

Issue 2662103003: Always get device conditions from Java for every attempt. (Closed)
Patch Set: Created 3 years, 10 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 #include "chrome/browser/android/offline_pages/evaluation/evaluation_test_schedu ler.h" 5 #include "chrome/browser/android/offline_pages/evaluation/evaluation_test_schedu ler.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/threading/thread_task_runner_handle.h" 8 #include "base/threading/thread_task_runner_handle.h"
9 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" 9 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "components/offline_pages/core/background/device_conditions.h" 12 #include "components/offline_pages/core/background/device_conditions.h"
13 #include "components/offline_pages/core/background/request_coordinator.h" 13 #include "components/offline_pages/core/background/request_coordinator.h"
14 #include "components/offline_pages/core/offline_event_logger.h" 14 #include "components/offline_pages/core/offline_event_logger.h"
15 #include "net/base/network_change_notifier.h" 15 #include "net/base/network_change_notifier.h"
16 16
17 namespace {
18 const int kBatteryPercentageHigh = 75;
19 const bool kPowerRequired = true;
20 } // namespace
21
17 namespace offline_pages { 22 namespace offline_pages {
18 23
19 namespace android { 24 namespace android {
20 25
21 namespace { 26 namespace {
22 27
23 const char kLogTag[] = "EvaluationTestScheduler"; 28 const char kLogTag[] = "EvaluationTestScheduler";
24 29
25 void StartProcessing(); 30 void StartProcessing();
26 31
27 void ProcessingDoneCallback(bool result) { 32 void ProcessingDoneCallback(bool result) {
28 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 33 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
29 base::Bind(&StartProcessing)); 34 base::Bind(&StartProcessing));
30 } 35 }
31 36
32 void GetAllRequestsDone( 37 void GetAllRequestsDone(
33 std::vector<std::unique_ptr<SavePageRequest>> requests) { 38 std::vector<std::unique_ptr<SavePageRequest>> requests) {
34 if (requests.size() > 0) { 39 if (requests.size() > 0) {
35 Profile* profile = ProfileManager::GetLastUsedProfile(); 40 Profile* profile = ProfileManager::GetLastUsedProfile();
36 RequestCoordinator* coordinator = 41 RequestCoordinator* coordinator =
37 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile); 42 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile);
38 // TODO(romax) Maybe get current real condition. 43 coordinator->StartImmediateProcessing(base::Bind(&ProcessingDoneCallback));
39 DeviceConditions device_conditions(
40 true, 0, net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI);
41 coordinator->StartImmediateProcessing(device_conditions,
42 base::Bind(&ProcessingDoneCallback));
43 } 44 }
44 } 45 }
45 46
46 void StartProcessing() { 47 void StartProcessing() {
47 Profile* profile = ProfileManager::GetLastUsedProfile(); 48 Profile* profile = ProfileManager::GetLastUsedProfile();
48 RequestCoordinator* coordinator = 49 RequestCoordinator* coordinator =
49 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile); 50 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile);
50 coordinator->GetAllRequests(base::Bind(&GetAllRequestsDone)); 51 coordinator->GetAllRequests(base::Bind(&GetAllRequestsDone));
51 } 52 }
52 53
53 } // namespace 54 } // namespace
54 55
56 EvaluationTestScheduler::EvaluationTestScheduler()
57 : device_conditions_(kPowerRequired,
58 kBatteryPercentageHigh,
59 net::NetworkChangeNotifier::CONNECTION_2G) {}
60
61 EvaluationTestScheduler::~EvaluationTestScheduler() {}
62
55 void EvaluationTestScheduler::Schedule( 63 void EvaluationTestScheduler::Schedule(
56 const TriggerConditions& trigger_conditions) { 64 const TriggerConditions& trigger_conditions) {
57 Profile* profile = ProfileManager::GetLastUsedProfile(); 65 Profile* profile = ProfileManager::GetLastUsedProfile();
58 if (!coordinator_) { 66 if (!coordinator_) {
59 coordinator_ = 67 coordinator_ =
60 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile); 68 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile);
61 // It's not expected that the coordinator would be nullptr since this bridge 69 // It's not expected that the coordinator would be nullptr since this bridge
62 // would only be used for testing scenario. 70 // would only be used for testing scenario.
63 DCHECK(coordinator_); 71 DCHECK(coordinator_);
64 } 72 }
65 coordinator_->GetLogger()->RecordActivity(std::string(kLogTag) + 73 coordinator_->GetLogger()->RecordActivity(std::string(kLogTag) +
66 " Start schedule!"); 74 " Start schedule!");
67 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 75 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
68 base::Bind(&StartProcessing)); 76 base::Bind(&StartProcessing));
69 } 77 }
70 78
71 void EvaluationTestScheduler::BackupSchedule( 79 void EvaluationTestScheduler::BackupSchedule(
72 const TriggerConditions& trigger_conditions, 80 const TriggerConditions& trigger_conditions,
73 long delay_in_seconds) {} 81 long delay_in_seconds) {}
74 82
75 void EvaluationTestScheduler::Unschedule() {} 83 void EvaluationTestScheduler::Unschedule() {}
76 84
85 DeviceConditions& EvaluationTestScheduler::GetCurrentDeviceConditions() {
86 return device_conditions_;
87 }
88
77 void EvaluationTestScheduler::ImmediateScheduleCallback(bool result) { 89 void EvaluationTestScheduler::ImmediateScheduleCallback(bool result) {
78 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 90 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
79 base::Bind(&StartProcessing)); 91 base::Bind(&StartProcessing));
80 } 92 }
81 93
82 } // namespace android 94 } // namespace android
83 } // namespace offline_pages 95 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698