Commit 89245a01 authored by dougarnett's avatar dougarnett Committed by Commit bot

[OfflinePages] Renames StartProcessing to StartScheduledProcessing

This is preparation for exposing new api for immediate procesing.

BUG=672584

Review-Url: https://codereview.chromium.org/2572503002
Cr-Commit-Position: refs/heads/master@{#438213}
parent c6ce8aec
......@@ -81,8 +81,8 @@ public class BackgroundOfflinerTask {
// TODO(petewil): Nothing is holding the Wake Lock. We need some solution to
// keep hold of it. Options discussed so far are having a fresh set of functions
// to grab and release a countdown latch, or holding onto the wake lock ourselves,
// or grabbing the wake lock and then starting chrome and running startProcessing
// on the UI thread.
// or grabbing the wake lock and then starting chrome and running
// startScheduledProcessing on the UI thread.
// TODO(petewil): Decode the TriggerConditions from the bundle.
......@@ -100,7 +100,7 @@ public class BackgroundOfflinerTask {
};
// Pass the activation on to the bridge to the C++ RequestCoordinator.
if (!mBridge.startProcessing(deviceConditions, callback)) {
if (!mBridge.startScheduledProcessing(deviceConditions, callback)) {
// Processing not started currently. Let callback know.
callback.onResult(false);
}
......
......@@ -24,9 +24,9 @@ public class BackgroundSchedulerBridge {
// not receive a callback.
// TODO(dougarnett): consider adding policy check api to let caller
// separately determine if not allowed by policy.
public static boolean startProcessing(
public static boolean startScheduledProcessing(
DeviceConditions deviceConditions, Callback<Boolean> callback) {
return nativeStartProcessing(deviceConditions.isPowerConnected(),
return nativeStartScheduledProcessing(deviceConditions.isPowerConnected(),
deviceConditions.getBatteryPercentage(), deviceConditions.getNetConnectionType(),
callback);
}
......@@ -59,6 +59,6 @@ public class BackgroundSchedulerBridge {
}
/** Instructs the native RequestCoordinator to start processing. */
private static native boolean nativeStartProcessing(boolean powerConnected,
private static native boolean nativeStartScheduledProcessing(boolean powerConnected,
int batteryPercentage, int netConnectionType, Callback<Boolean> callback);
}
......@@ -13,8 +13,9 @@ import org.chromium.chrome.browser.offlinepages.interfaces.BackgroundSchedulerPr
*/
public class BackgroundSchedulerProcessorImpl implements BackgroundSchedulerProcessor {
@Override
public boolean startProcessing(DeviceConditions deviceConditions, Callback<Boolean> callback) {
BackgroundSchedulerBridge.startProcessing(deviceConditions, callback);
public boolean startScheduledProcessing(
DeviceConditions deviceConditions, Callback<Boolean> callback) {
BackgroundSchedulerBridge.startScheduledProcessing(deviceConditions, callback);
return true;
}
......
......@@ -18,5 +18,5 @@ public interface BackgroundSchedulerProcessor {
* terminated). If processing was already active or not able to process for some other reason,
* returns false and this calling instance will not receive a callback.
*/
boolean startProcessing(DeviceConditions deviceConditions, Callback<Boolean> callback);
boolean startScheduledProcessing(DeviceConditions deviceConditions, Callback<Boolean> callback);
}
......@@ -20,6 +20,16 @@ import android.os.Bundle;
import com.google.android.gms.gcm.GcmNetworkManager;
import com.google.android.gms.gcm.Task;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.internal.ShadowExtractor;
import org.chromium.base.ActivityState;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.BaseChromiumApplication;
......@@ -30,15 +40,6 @@ import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.ChromeBackgroundServiceWaiter;
import org.chromium.net.ConnectionType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.internal.ShadowExtractor;
/**
* Unit tests for BackgroundOfflinerTask.
......@@ -115,7 +116,7 @@ public class BackgroundOfflinerTaskTest {
ChromeBackgroundServiceWaiter waiter = new ChromeBackgroundServiceWaiter(1000);
task.processBackgroundRequests(mTaskExtras, mDeviceConditions, waiter);
// Check with ShadowBackgroundBackgroundSchedulerProcessor that it started processing.
// Check with BackgroundSchedulerProcessor that it started processing.
assertTrue(mStubBackgroundSchedulerProcessor.getDidStartProcessing());
assertSame(mDeviceConditions, mStubBackgroundSchedulerProcessor.getDeviceConditions());
......@@ -132,10 +133,10 @@ public class BackgroundOfflinerTaskTest {
ChromeBackgroundServiceWaiter waiter = new ChromeBackgroundServiceWaiter(1000);
task.processBackgroundRequests(mTaskExtras, mDeviceConditions, waiter);
// Check with ShadowBackgroundBackgroundSchedulerProcessor that it did not start.
// Check with BackgroundSchedulerProcessor that it did not start.
assertFalse(mStubBackgroundSchedulerProcessor.getDidStartProcessing());
// The waiter should not block if startProcessing returned false.
// The waiter should not block if startScheduledProcessing returned false.
waiter.startWaiting();
}
......@@ -154,7 +155,7 @@ public class BackgroundOfflinerTaskTest {
assertEquals(mTriggerConditions,
TaskExtrasPacker.unpackTriggerConditionsFromBundle(gcmTask.getExtras()));
// Check with ShadowBackgroundBackgroundSchedulerProcessor that startProcessing got called.
// Check with BackgroundSchedulerProcessor that startScheduledProcessing got called.
assertTrue(mStubBackgroundSchedulerProcessor.getDidStartProcessing());
assertSame(mDeviceConditions, mStubBackgroundSchedulerProcessor.getDeviceConditions());
}
......@@ -178,7 +179,7 @@ public class BackgroundOfflinerTaskTest {
assertEquals(mTriggerConditions,
TaskExtrasPacker.unpackTriggerConditionsFromBundle(gcmTask.getExtras()));
// Check that startProcessing was NOT called.
// Check that startScheduledProcessing was NOT called.
assertFalse(mStubBackgroundSchedulerProcessor.getDidStartProcessing());
// Now verify low battery level but with power connected will start processing.
......@@ -212,7 +213,7 @@ public class BackgroundOfflinerTaskTest {
assertEquals(mTriggerConditions,
TaskExtrasPacker.unpackTriggerConditionsFromBundle(gcmTask.getExtras()));
// Check that startProcessing was NOT called.
// Check that startScheduledProcessing was NOT called.
assertFalse(mStubBackgroundSchedulerProcessor.getDidStartProcessing());
// Now verify will start processing when Activity is stopped.
......
......@@ -33,7 +33,8 @@ public class StubBackgroundSchedulerProcessor implements BackgroundSchedulerProc
}
@Override
public boolean startProcessing(DeviceConditions deviceConditions, Callback<Boolean> callback) {
public boolean startScheduledProcessing(
DeviceConditions deviceConditions, Callback<Boolean> callback) {
if (mFailToStart) {
return false;
}
......
......@@ -30,8 +30,9 @@ void ProcessingDoneCallback(
} // namespace
// JNI call to start request processing.
static jboolean StartProcessing(JNIEnv* env,
// JNI call to start request processing in scheduled mode.
static jboolean StartScheduledProcessing(
JNIEnv* env,
const JavaParamRef<jclass>& jcaller,
const jboolean j_power_connected,
const jint j_battery_percentage,
......@@ -40,8 +41,8 @@ static jboolean StartProcessing(JNIEnv* env,
ScopedJavaGlobalRef<jobject> j_callback_ref;
j_callback_ref.Reset(env, j_callback_obj);
// Lookup/create RequestCoordinator KeyedService and call StartProcessing on
// it with bound j_callback_obj.
// Lookup/create RequestCoordinator KeyedService and call
// StartScheduledProcessing on it with bound j_callback_obj.
Profile* profile = ProfileManager::GetLastUsedProfile();
RequestCoordinator* coordinator =
RequestCoordinatorFactory::GetInstance()->
......@@ -51,7 +52,7 @@ static jboolean StartProcessing(JNIEnv* env,
j_power_connected, j_battery_percentage,
static_cast<net::NetworkChangeNotifier::ConnectionType>(
j_net_connection_type));
return coordinator->StartProcessing(
return coordinator->StartScheduledProcessing(
device_conditions, base::Bind(&ProcessingDoneCallback, j_callback_ref));
}
......
......@@ -38,7 +38,7 @@ void GetAllRequestsDone(
// TODO(romax) Maybe get current real condition.
DeviceConditions device_conditions(
true, 0, net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI);
coordinator->StartProcessing(device_conditions,
coordinator->StartScheduledProcessing(device_conditions,
base::Bind(&ProcessingDoneCallback));
}
}
......
......@@ -295,7 +295,7 @@ bool OfflinePageEvaluationBridge::PushRequestProcessing(
net::NetworkChangeNotifier::ConnectionType connection =
net::NetworkChangeNotifier::GetConnectionType();
DeviceConditions device_conditions(false, 0, connection);
return request_coordinator_->StartProcessing(
return request_coordinator_->StartScheduledProcessing(
device_conditions, base::Bind(&OnPushRequestsDone, j_callback_ref));
}
......
......@@ -509,7 +509,7 @@ void RequestCoordinator::HandleWatchdogTimeout() {
// Returns true if the caller should expect a callback, false otherwise. For
// instance, this would return false if a request is already in progress.
bool RequestCoordinator::StartProcessing(
bool RequestCoordinator::StartScheduledProcessing(
const DeviceConditions& device_conditions,
const base::Callback<void(bool)>& callback) {
DVLOG(2) << "Scheduled " << __func__;
......
......@@ -103,10 +103,11 @@ class RequestCoordinator : public KeyedService,
// Get all save page request items in the callback.
void GetAllRequests(const GetRequestsCallback& callback);
// Starts processing of one or more queued save page later requests.
// Starts processing of one or more queued save page later requests
// in scheduled background mode.
// Returns whether processing was started and that caller should expect
// a callback. If processing was already active, returns false.
bool StartProcessing(const DeviceConditions& device_conditions,
bool StartScheduledProcessing(const DeviceConditions& device_conditions,
const base::Callback<void(bool)>& callback);
// Stops the current request processing if active. This is a way for
......@@ -179,7 +180,7 @@ class RequestCoordinator : public KeyedService,
bool is_starting() { return is_starting_; }
// Tracks whether the last offlining attempt got canceled. This is reset by
// the next StartProcessing() call.
// the next call to start processing.
bool is_canceled() {
return processing_state_ == ProcessingWindowState::STOPPED;
}
......
......@@ -397,8 +397,8 @@ SavePageRequest RequestCoordinatorTest::AddRequest2() {
return request2;
}
TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) {
EXPECT_TRUE(coordinator()->StartProcessing(device_conditions(),
TEST_F(RequestCoordinatorTest, StartScheduledProcessingWithNoRequests) {
EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(),
immediate_callback()));
PumpLoop();
......@@ -415,7 +415,7 @@ TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) {
}
}
TEST_F(RequestCoordinatorTest, StartProcessingWithRequestInProgress) {
TEST_F(RequestCoordinatorTest, StartScheduledProcessingWithRequestInProgress) {
// Start processing for this request.
EXPECT_NE(coordinator()->SavePageLater(
kUrl1, kClientId1, kUserRequested,
......@@ -427,7 +427,7 @@ TEST_F(RequestCoordinatorTest, StartProcessingWithRequestInProgress) {
EnableOfflinerCallback(false);
// Sending the request to the offliner should make it busy.
EXPECT_TRUE(coordinator()->StartProcessing(device_conditions(),
EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(),
immediate_callback()));
PumpLoop();
......@@ -436,7 +436,7 @@ TEST_F(RequestCoordinatorTest, StartProcessingWithRequestInProgress) {
EXPECT_FALSE(immediate_schedule_callback_called());
// Now trying to start processing on another request should return false.
EXPECT_FALSE(coordinator()->StartProcessing(device_conditions(),
EXPECT_FALSE(coordinator()->StartScheduledProcessing(device_conditions(),
immediate_callback()));
}
......@@ -748,7 +748,8 @@ TEST_F(RequestCoordinatorTest, OfflinerDonePrerenderingCancel) {
// If one item completes, and there are no more user requeted items left,
// we should make a scheduler entry for a non-user requested item.
TEST_F(RequestCoordinatorTest, RequestNotPickedDisabledItemsRemain) {
coordinator()->StartProcessing(device_conditions(), immediate_callback());
coordinator()->StartScheduledProcessing(device_conditions(),
immediate_callback());
EXPECT_TRUE(is_starting());
// Call RequestNotPicked, simulating a request on the disabled list.
......@@ -768,7 +769,8 @@ TEST_F(RequestCoordinatorTest, RequestNotPickedDisabledItemsRemain) {
// If one item completes, and there are no more user requeted items left,
// we should make a scheduler entry for a non-user requested item.
TEST_F(RequestCoordinatorTest, RequestNotPickedNonUserRequestedItemsRemain) {
coordinator()->StartProcessing(device_conditions(), immediate_callback());
coordinator()->StartScheduledProcessing(device_conditions(),
immediate_callback());
EXPECT_TRUE(is_starting());
// Call RequestNotPicked, and make sure we pick schedule a task for non user
......@@ -824,13 +826,13 @@ TEST_F(RequestCoordinatorTest, SchedulerGetsLeastRestrictiveConditions) {
coordinator()->policy()->UnmeteredNetworkRequired(kUserRequested));
}
TEST_F(RequestCoordinatorTest, StartProcessingWithLoadingDisabled) {
TEST_F(RequestCoordinatorTest, StartScheduledProcessingWithLoadingDisabled) {
// Add a request to the queue, wait for callbacks to finish.
AddRequest1();
PumpLoop();
DisableLoading();
EXPECT_TRUE(coordinator()->StartProcessing(device_conditions(),
EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(),
immediate_callback()));
// Let the async callbacks in the request coordinator run.
......@@ -842,13 +844,14 @@ TEST_F(RequestCoordinatorTest, StartProcessingWithLoadingDisabled) {
}
// This tests a StopProcessing call before we have actually started the
// prerenderer.
TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) {
// offliner.
TEST_F(RequestCoordinatorTest,
StartScheduledProcessingThenStopProcessingImmediately) {
// Add a request to the queue, wait for callbacks to finish.
AddRequest1();
PumpLoop();
EXPECT_TRUE(coordinator()->StartProcessing(device_conditions(),
EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(),
immediate_callback()));
EXPECT_TRUE(is_starting());
......@@ -871,7 +874,8 @@ TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) {
}
// This tests a StopProcessing call after the prerenderer has been started.
TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingLater) {
TEST_F(RequestCoordinatorTest,
StartScheduledProcessingThenStopProcessingLater) {
// Add a request to the queue, wait for callbacks to finish.
AddRequest1();
PumpLoop();
......@@ -879,7 +883,7 @@ TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingLater) {
// Ensure the start processing request stops before the completion callback.
EnableOfflinerCallback(false);
EXPECT_TRUE(coordinator()->StartProcessing(device_conditions(),
EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(),
immediate_callback()));
EXPECT_TRUE(is_starting());
......@@ -930,7 +934,7 @@ TEST_F(RequestCoordinatorTest, RemoveInflightRequest) {
// Ensure the start processing request stops before the completion callback.
EnableOfflinerCallback(false);
EXPECT_TRUE(coordinator()->StartProcessing(device_conditions(),
EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(),
immediate_callback()));
// Let all the async parts of the start processing pipeline run to completion.
......@@ -1016,8 +1020,8 @@ TEST_F(RequestCoordinatorTest, WatchdogTimeoutForScheduledProcessing) {
EnableOfflinerCallback(false);
// Sending the request to the offliner.
EXPECT_TRUE(
coordinator()->StartProcessing(device_conditions(), waiting_callback()));
EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(),
waiting_callback()));
PumpLoop();
// Advance the mock clock far enough to cause a watchdog timeout
......@@ -1090,8 +1094,8 @@ TEST_F(RequestCoordinatorTest, TimeBudgetExceeded) {
PumpLoop();
// Sending the request to the offliner.
EXPECT_TRUE(
coordinator()->StartProcessing(device_conditions(), waiting_callback()));
EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(),
waiting_callback()));
PumpLoop();
// Advance the mock clock far enough to exceed our time budget.
......@@ -1118,12 +1122,12 @@ TEST_F(RequestCoordinatorTest, TryNextRequestWithNoNetwork) {
AddRequest2();
PumpLoop();
// Set up for the call to StartProcessing.
// Set up for the call to StartScheduledProcessing.
EnableOfflinerCallback(false);
// Sending the request to the offliner.
EXPECT_TRUE(
coordinator()->StartProcessing(device_conditions(), waiting_callback()));
EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(),
waiting_callback()));
PumpLoop();
EXPECT_TRUE(coordinator()->is_busy());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment