Commit a374ac64 authored by Ian Wells's avatar Ian Wells Committed by Commit Bot

Add example query textproto and a script to generate a query request URL

Bug: 1044139
Change-Id: I6c394dbc3f3c70715134b83a33ecea9388b63c2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2137488
Commit-Queue: Ian Wells <iwells@chromium.org>
Reviewed-by: default avatarDan H <harringtond@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756853}
parent 17d0b1dd
...@@ -21,7 +21,10 @@ message ClientInfo { ...@@ -21,7 +21,10 @@ message ClientInfo {
IOS = 2; IOS = 2;
} }
enum AppType { CHROME = 3; } enum AppType {
TEST_APP = 2; // For use with AGA endpoint for testing.
CHROME = 3;
}
// The type of OS that the client is running. // The type of OS that the client is running.
optional PlatformType platform_type = 1; optional PlatformType platform_type = 1;
......
request_version: FEED_QUERY
feed_request {
client_info {
platform_type: ANDROID_ID
platform_version {
major: 10
architecture: ARM64
build_type: DEV
api_version: 29
}
app_type: CHROME
app_version {
major: 79
minor: 0
build: 3945
revision: 93
architecture: ARM64
build_type: RELEASE
}
locale: "en-US"
display_info {
screen_density: 2.625
screen_width_in_pixels: 1080
screen_height_in_pixels: 1794
}
}
feed_query {
reason: SCHEDULED_REFRESH
}
client_capability: BASE_UI
consistency_token {
}
}
#!/bin/bash
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Usage: make_feed_query_request.sh request.textproto
CHROMIUM_SRC=$(realpath $(dirname $(readlink -f $0))/../../../../..)
PLD=$(python3 \
$CHROMIUM_SRC/components/feed/core/v2/tools/textpb_to_binarypb.py \
--chromium_path=$CHROMIUM_SRC \
--message=feedwire.Request \
--output_format=base64 \
--source_file=$1)
BASE_URL="https://www.google.com/httpservice"
ENDPOINT="TrellisClankService/FeedQuery"
QUERY_URL="$BASE_URL/retry/$ENDPOINT"
echo "$QUERY_URL?fmt=bin&hl=en-US&reqpld=$PLD"
...@@ -18,8 +18,12 @@ def run_command(args, input): ...@@ -18,8 +18,12 @@ def run_command(args, input):
args, args,
input=input, input=input,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE
check=True) )
if proc.returncode != 0:
raise RuntimeError(proc.stderr.decode('utf-8'))
return proc.stdout return proc.stdout
......
...@@ -19,16 +19,25 @@ import glob ...@@ -19,16 +19,25 @@ import glob
import os import os
import protoc_util import protoc_util
import subprocess import subprocess
import base64
import urllib.parse
from absl import app from absl import app
from absl import flags from absl import flags
DEFAULT_MESSAGE = 'feedwire.Response' DEFAULT_MESSAGE = 'feedwire.Response'
FLAGS = flags.FLAGS
FLAGS = flags.FLAGS FLAGS = flags.FLAGS
flags.DEFINE_string('chromium_path', '', 'The path of your chromium depot.') flags.DEFINE_string('chromium_path', '', 'The path of your chromium depot.')
flags.DEFINE_string('output_file', '', 'The target output binary file path.') flags.DEFINE_string(
'output_file',
'',
'The target output file path. If not set, writes to stdout.')
flags.DEFINE_string(
'output_format',
'bin',
'When encoding text to binary, this may be set to base64 to encode output '
+ 'suitable for URLs.')
flags.DEFINE_string('source_file', '', flags.DEFINE_string('source_file', '',
'The source proto file, in textpb format, path.') 'The source proto file, in textpb format, path.')
flags.DEFINE_string('message', flags.DEFINE_string('message',
...@@ -46,8 +55,16 @@ def text_to_binary(): ...@@ -46,8 +55,16 @@ def text_to_binary():
encoded = protoc_util.encode_proto(value_text_proto, FLAGS.message, encoded = protoc_util.encode_proto(value_text_proto, FLAGS.message,
FLAGS.chromium_path, FLAGS.chromium_path,
COMPONENT_FEED_PROTO_PATH) COMPONENT_FEED_PROTO_PATH)
with open(FLAGS.output_file, mode='wb') as file:
file.write(encoded) if FLAGS.output_format == 'base64':
encoded = urllib.parse.quote(
base64.urlsafe_b64encode(encoded).decode('utf-8'))
if FLAGS.output_file:
with open(FLAGS.output_file, mode='wb') as file:
file.write(encoded)
else:
print(encoded)
def binary_to_text(): def binary_to_text():
with open(FLAGS.source_file, mode='rb') as file: with open(FLAGS.source_file, mode='rb') as file:
...@@ -57,18 +74,19 @@ def binary_to_text(): ...@@ -57,18 +74,19 @@ def binary_to_text():
FLAGS.chromium_path, FLAGS.chromium_path,
COMPONENT_FEED_PROTO_PATH) COMPONENT_FEED_PROTO_PATH)
with open(FLAGS.output_file, mode='w') as file: if FLAGS.output_file:
file.write(encoded) with open(FLAGS.output_file, mode='w') as file:
file.write(encoded)
else:
print(encoded)
def main(argv): def main(argv):
if len(argv) > 1: if len(argv) > 1:
raise app.UsageError('Too many command-line arguments.') raise app.UsageError('Too many arguments. Unknown: ' + ' '.join(argv[1:]))
if not FLAGS.chromium_path: if not FLAGS.chromium_path:
raise app.UsageError('chromium_path flag must be set.') raise app.UsageError('chromium_path flag must be set.')
if not FLAGS.source_file: if not FLAGS.source_file:
raise app.UsageError('source_file flag must be set.') raise app.UsageError('source_file flag must be set.')
if not FLAGS.output_file:
raise app.UsageError('output_file flag must be set.')
if FLAGS.direction != 'forward' and FLAGS.direction != 'reverse': if FLAGS.direction != 'forward' and FLAGS.direction != 'reverse':
raise app.UsageError('direction must be forward or reverse') raise app.UsageError('direction must be forward or reverse')
......
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