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

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

Issue 2659813006: Always get device conditions from Java for every attempt. (Closed)
Patch Set: fixes per DewittJ 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::GetConnectionType());
41 coordinator->StartImmediateProcessing(device_conditions,
42 base::Bind(&ProcessingDoneCallback));
43 } 44 }
44 } 45 }
45 46
46 void StartProcessing() { 47 void StartProcessing() {
47 // If there's no network connection then try in 2 seconds. 48 // If there's no network connection then try in 2 seconds.
48 if (net::NetworkChangeNotifier::GetConnectionType() == 49 if (net::NetworkChangeNotifier::GetConnectionType() ==
49 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) { 50 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) {
50 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 51 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
51 FROM_HERE, base::Bind(&StartProcessing), 52 FROM_HERE, base::Bind(&StartProcessing),
52 base::TimeDelta::FromSeconds(2)); 53 base::TimeDelta::FromSeconds(2));
53 return; 54 return;
54 } 55 }
55 Profile* profile = ProfileManager::GetLastUsedProfile(); 56 Profile* profile = ProfileManager::GetLastUsedProfile();
56 RequestCoordinator* coordinator = 57 RequestCoordinator* coordinator =
57 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile); 58 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile);
58 coordinator->GetAllRequests(base::Bind(&GetAllRequestsDone)); 59 coordinator->GetAllRequests(base::Bind(&GetAllRequestsDone));
59 } 60 }
60 61
61 } // namespace 62 } // namespace
62 63
64 EvaluationTestScheduler::EvaluationTestScheduler()
65 : device_conditions_(kPowerRequired,
66 kBatteryPercentageHigh,
67 net::NetworkChangeNotifier::CONNECTION_2G) {}
68
69 EvaluationTestScheduler::~EvaluationTestScheduler() {}
70
63 void EvaluationTestScheduler::Schedule( 71 void EvaluationTestScheduler::Schedule(
64 const TriggerConditions& trigger_conditions) { 72 const TriggerConditions& trigger_conditions) {
65 Profile* profile = ProfileManager::GetLastUsedProfile(); 73 Profile* profile = ProfileManager::GetLastUsedProfile();
66 if (!coordinator_) { 74 if (!coordinator_) {
67 coordinator_ = 75 coordinator_ =
68 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile); 76 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile);
69 // It's not expected that the coordinator would be nullptr since this bridge 77 // It's not expected that the coordinator would be nullptr since this bridge
70 // would only be used for testing scenario. 78 // would only be used for testing scenario.
71 DCHECK(coordinator_); 79 DCHECK(coordinator_);
72 } 80 }
(...skipping 12 matching lines...) Expand all
85 " BackupSchedule called!"); 93 " BackupSchedule called!");
86 } 94 }
87 95
88 void EvaluationTestScheduler::Unschedule() { 96 void EvaluationTestScheduler::Unschedule() {
89 // This method is not expected to be called in test harness. Adding a log in 97 // This method is not expected to be called in test harness. Adding a log in
90 // case we somehow get called here and need to implement the method. 98 // case we somehow get called here and need to implement the method.
91 coordinator_->GetLogger()->RecordActivity(std::string(kLogTag) + 99 coordinator_->GetLogger()->RecordActivity(std::string(kLogTag) +
92 " Unschedule called!"); 100 " Unschedule called!");
93 } 101 }
94 102
103 DeviceConditions& EvaluationTestScheduler::GetCurrentDeviceConditions() {
104 return device_conditions_;
105 }
106
95 void EvaluationTestScheduler::ImmediateScheduleCallback(bool result) { 107 void EvaluationTestScheduler::ImmediateScheduleCallback(bool result) {
96 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 108 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
97 base::Bind(&StartProcessing)); 109 base::Bind(&StartProcessing));
98 } 110 }
99 111
100 } // namespace android 112 } // namespace android
101 } // namespace offline_pages 113 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698