Commit da473853 authored by Dan Harrington's avatar Dan Harrington Committed by Commit Bot

feedv2: add ProcessViewAction to FeedStreamApi

And threaded access to xsurface FeedActionsHandler

Bug: 1044139
Change-Id: I0857f876776f285728ad938f9f41e92ebea50988
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2335478Reviewed-by: default avatarVincent Boisselle <vincb@google.com>
Reviewed-by: default avatarJustin DeWitt <dewittj@chromium.org>
Commit-Queue: Dan H <harringtond@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794685}
parent f1d4fa31
......@@ -643,6 +643,12 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
mNativeFeedStreamSurface, FeedStreamSurface.this, data);
}
@Override
public void processViewAction(byte[] data) {
FeedStreamSurfaceJni.get().processViewAction(
mNativeFeedStreamSurface, FeedStreamSurface.this, data);
}
@Override
public void sendFeedback(Map<String, String> productSpecificDataMap) {
FeedStreamSurfaceJni.get().reportSendFeedbackAction(
......@@ -827,6 +833,7 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
long nativeFeedStreamSurface, FeedStreamSurface caller, Callback<Boolean> callback);
void processThereAndBackAgain(
long nativeFeedStreamSurface, FeedStreamSurface caller, byte[] data);
void processViewAction(long nativeFeedStreamSurface, FeedStreamSurface caller, byte[] data);
int executeEphemeralChange(
long nativeFeedStreamSurface, FeedStreamSurface caller, byte[] data);
void commitEphemeralChange(
......
......@@ -109,6 +109,15 @@ void FeedStreamSurface::ProcessThereAndBackAgain(
feed_stream_api_->ProcessThereAndBackAgain(data_string);
}
void FeedStreamSurface::ProcessViewAction(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jbyteArray>& data) {
std::string data_string;
base::android::JavaByteArrayToString(env, data, &data_string);
feed_stream_api_->ProcessViewAction(data_string);
}
int FeedStreamSurface::ExecuteEphemeralChange(
JNIEnv* env,
const JavaParamRef<jobject>& obj,
......
......@@ -43,6 +43,10 @@ class FeedStreamSurface : public FeedStreamApi::SurfaceInterface {
const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jbyteArray>& data);
void ProcessViewAction(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jbyteArray>& data);
int ExecuteEphemeralChange(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
......
......@@ -23,6 +23,12 @@ public interface FeedActionsHandler {
*/
default void processThereAndBackAgainData(byte[] data) {}
/**
* Stores a view FeedAction for eventual upload. 'data' is a serialized FeedAction protobuf
* message.
*/
default void processViewAction(byte[] data) {}
/**
* Triggers Chrome to send user feedback for this card.
*/
......
......@@ -343,6 +343,12 @@ void FeedStream::ProcessThereAndBackAgain(base::StringPiece data) {
}
}
void FeedStream::ProcessViewAction(base::StringPiece data) {
feedwire::FeedAction msg;
msg.ParseFromArray(data.data(), data.size());
UploadAction(std::move(msg), /*upload_now=*/false, base::DoNothing());
}
void FeedStream::GetPrefetchSuggestions(
base::OnceCallback<void(std::vector<offline_pages::PrefetchSuggestion>)>
suggestions_callback) {
......
......@@ -135,6 +135,7 @@ class FeedStream : public FeedStreamApi,
bool CommitEphemeralChange(EphemeralChangeId id) override;
bool RejectEphemeralChange(EphemeralChangeId id) override;
void ProcessThereAndBackAgain(base::StringPiece data) override;
void ProcessViewAction(base::StringPiece data) override;
DebugStreamData GetDebugStreamData() override;
void ForceRefreshForDebugging() override;
std::string DumpStateForDebugging() override;
......
......@@ -1414,6 +1414,22 @@ TEST_F(FeedStreamTest, StorePendingActionAndUploadNow) {
ASSERT_EQ(0ul, result.size());
}
TEST_F(FeedStreamTest, ProcessViewActionResultsInDelayedUpload) {
network_.consistency_token = "token-11";
stream_->ProcessViewAction(MakeFeedAction(42ul).SerializeAsString());
WaitForIdleTaskQueue();
// Verify it's not uploaded immediately.
ASSERT_EQ(0, network_.action_request_call_count);
// Trigger a network refresh.
TestSurface surface(stream_.get());
WaitForIdleTaskQueue();
// Verify the action was uploaded.
EXPECT_EQ(1, network_.action_request_call_count);
}
TEST_F(FeedStreamTest, LoadStreamFromNetworkUploadsActions) {
stream_->UploadAction(MakeFeedAction(99ul), false, base::DoNothing());
WaitForIdleTaskQueue();
......
......@@ -91,6 +91,9 @@ class FeedStreamApi {
// Sends 'ThereAndBackAgainData' back to the server. |data| is a serialized
// |feedwire::ThereAndBackAgainData| message.
virtual void ProcessThereAndBackAgain(base::StringPiece data) = 0;
// Saves a view action for eventual upload. |data| is a serialized
//|feedwire::FeedAction| message.
virtual void ProcessViewAction(base::StringPiece data) = 0;
// User interaction reporting. These should have no side-effects other than
// reporting metrics.
......
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