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 ...@@ -643,6 +643,12 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
mNativeFeedStreamSurface, FeedStreamSurface.this, data); mNativeFeedStreamSurface, FeedStreamSurface.this, data);
} }
@Override
public void processViewAction(byte[] data) {
FeedStreamSurfaceJni.get().processViewAction(
mNativeFeedStreamSurface, FeedStreamSurface.this, data);
}
@Override @Override
public void sendFeedback(Map<String, String> productSpecificDataMap) { public void sendFeedback(Map<String, String> productSpecificDataMap) {
FeedStreamSurfaceJni.get().reportSendFeedbackAction( FeedStreamSurfaceJni.get().reportSendFeedbackAction(
...@@ -827,6 +833,7 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand ...@@ -827,6 +833,7 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
long nativeFeedStreamSurface, FeedStreamSurface caller, Callback<Boolean> callback); long nativeFeedStreamSurface, FeedStreamSurface caller, Callback<Boolean> callback);
void processThereAndBackAgain( void processThereAndBackAgain(
long nativeFeedStreamSurface, FeedStreamSurface caller, byte[] data); long nativeFeedStreamSurface, FeedStreamSurface caller, byte[] data);
void processViewAction(long nativeFeedStreamSurface, FeedStreamSurface caller, byte[] data);
int executeEphemeralChange( int executeEphemeralChange(
long nativeFeedStreamSurface, FeedStreamSurface caller, byte[] data); long nativeFeedStreamSurface, FeedStreamSurface caller, byte[] data);
void commitEphemeralChange( void commitEphemeralChange(
......
...@@ -109,6 +109,15 @@ void FeedStreamSurface::ProcessThereAndBackAgain( ...@@ -109,6 +109,15 @@ void FeedStreamSurface::ProcessThereAndBackAgain(
feed_stream_api_->ProcessThereAndBackAgain(data_string); 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( int FeedStreamSurface::ExecuteEphemeralChange(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jobject>& obj, const JavaParamRef<jobject>& obj,
......
...@@ -43,6 +43,10 @@ class FeedStreamSurface : public FeedStreamApi::SurfaceInterface { ...@@ -43,6 +43,10 @@ class FeedStreamSurface : public FeedStreamApi::SurfaceInterface {
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jbyteArray>& data); const base::android::JavaParamRef<jbyteArray>& data);
void ProcessViewAction(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jbyteArray>& data);
int ExecuteEphemeralChange( int ExecuteEphemeralChange(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
......
...@@ -23,6 +23,12 @@ public interface FeedActionsHandler { ...@@ -23,6 +23,12 @@ public interface FeedActionsHandler {
*/ */
default void processThereAndBackAgainData(byte[] data) {} 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. * Triggers Chrome to send user feedback for this card.
*/ */
......
...@@ -343,6 +343,12 @@ void FeedStream::ProcessThereAndBackAgain(base::StringPiece data) { ...@@ -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( void FeedStream::GetPrefetchSuggestions(
base::OnceCallback<void(std::vector<offline_pages::PrefetchSuggestion>)> base::OnceCallback<void(std::vector<offline_pages::PrefetchSuggestion>)>
suggestions_callback) { suggestions_callback) {
......
...@@ -135,6 +135,7 @@ class FeedStream : public FeedStreamApi, ...@@ -135,6 +135,7 @@ class FeedStream : public FeedStreamApi,
bool CommitEphemeralChange(EphemeralChangeId id) override; bool CommitEphemeralChange(EphemeralChangeId id) override;
bool RejectEphemeralChange(EphemeralChangeId id) override; bool RejectEphemeralChange(EphemeralChangeId id) override;
void ProcessThereAndBackAgain(base::StringPiece data) override; void ProcessThereAndBackAgain(base::StringPiece data) override;
void ProcessViewAction(base::StringPiece data) override;
DebugStreamData GetDebugStreamData() override; DebugStreamData GetDebugStreamData() override;
void ForceRefreshForDebugging() override; void ForceRefreshForDebugging() override;
std::string DumpStateForDebugging() override; std::string DumpStateForDebugging() override;
......
...@@ -1414,6 +1414,22 @@ TEST_F(FeedStreamTest, StorePendingActionAndUploadNow) { ...@@ -1414,6 +1414,22 @@ TEST_F(FeedStreamTest, StorePendingActionAndUploadNow) {
ASSERT_EQ(0ul, result.size()); 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) { TEST_F(FeedStreamTest, LoadStreamFromNetworkUploadsActions) {
stream_->UploadAction(MakeFeedAction(99ul), false, base::DoNothing()); stream_->UploadAction(MakeFeedAction(99ul), false, base::DoNothing());
WaitForIdleTaskQueue(); WaitForIdleTaskQueue();
......
...@@ -91,6 +91,9 @@ class FeedStreamApi { ...@@ -91,6 +91,9 @@ class FeedStreamApi {
// Sends 'ThereAndBackAgainData' back to the server. |data| is a serialized // Sends 'ThereAndBackAgainData' back to the server. |data| is a serialized
// |feedwire::ThereAndBackAgainData| message. // |feedwire::ThereAndBackAgainData| message.
virtual void ProcessThereAndBackAgain(base::StringPiece data) = 0; 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 // User interaction reporting. These should have no side-effects other than
// reporting metrics. // 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