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

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

Issue 2658513004: [Offline Pages] Adding a network check in test scheduler. (Closed)
Patch Set: comments. Created 3 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 31
32 void GetAllRequestsDone( 32 void GetAllRequestsDone(
33 std::vector<std::unique_ptr<SavePageRequest>> requests) { 33 std::vector<std::unique_ptr<SavePageRequest>> requests) {
34 if (requests.size() > 0) { 34 if (requests.size() > 0) {
35 Profile* profile = ProfileManager::GetLastUsedProfile(); 35 Profile* profile = ProfileManager::GetLastUsedProfile();
36 RequestCoordinator* coordinator = 36 RequestCoordinator* coordinator =
37 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile); 37 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile);
38 // TODO(romax) Maybe get current real condition. 38 // TODO(romax) Maybe get current real condition.
39 DeviceConditions device_conditions( 39 DeviceConditions device_conditions(
40 true, 0, net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI); 40 true, 0, net::NetworkChangeNotifier::GetConnectionType());
41 coordinator->StartImmediateProcessing(device_conditions, 41 coordinator->StartImmediateProcessing(device_conditions,
42 base::Bind(&ProcessingDoneCallback)); 42 base::Bind(&ProcessingDoneCallback));
43 } 43 }
44 } 44 }
45 45
46 void StartProcessing() { 46 void StartProcessing() {
47 // If there's no network connection then try in 2 seconds.
48 if (net::NetworkChangeNotifier::GetConnectionType() ==
49 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) {
50 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
51 FROM_HERE, base::Bind(&StartProcessing),
52 base::TimeDelta::FromSeconds(2));
53 return;
54 }
47 Profile* profile = ProfileManager::GetLastUsedProfile(); 55 Profile* profile = ProfileManager::GetLastUsedProfile();
48 RequestCoordinator* coordinator = 56 RequestCoordinator* coordinator =
49 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile); 57 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile);
50 coordinator->GetAllRequests(base::Bind(&GetAllRequestsDone)); 58 coordinator->GetAllRequests(base::Bind(&GetAllRequestsDone));
51 } 59 }
52 60
53 } // namespace 61 } // namespace
54 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) {
82 // This method is not expected to be called in test harness. Adding a log in
83 // case we somehow get called here and need to implement the method.
84 coordinator_->GetLogger()->RecordActivity(std::string(kLogTag) +
85 " BackupSchedule called!");
86 }
74 87
75 void EvaluationTestScheduler::Unschedule() {} 88 void EvaluationTestScheduler::Unschedule() {
89 // 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.
91 coordinator_->GetLogger()->RecordActivity(std::string(kLogTag) +
92 " Unschedule called!");
93 }
76 94
77 void EvaluationTestScheduler::ImmediateScheduleCallback(bool result) { 95 void EvaluationTestScheduler::ImmediateScheduleCallback(bool result) {
78 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 96 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
79 base::Bind(&StartProcessing)); 97 base::Bind(&StartProcessing));
80 } 98 }
81 99
82 } // namespace android 100 } // namespace android
83 } // namespace offline_pages 101 } // namespace offline_pages
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698