summaryrefslogtreecommitdiff
path: root/chromium/components/feed
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-01-23 17:21:03 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-01-23 16:25:15 +0000
commitc551f43206405019121bd2b2c93714319a0a3300 (patch)
tree1f48c30631c421fd4bbb3c36da20183c8a2ed7d7 /chromium/components/feed
parent7961cea6d1041e3e454dae6a1da660b453efd238 (diff)
downloadqtwebengine-chromium-c551f43206405019121bd2b2c93714319a0a3300.tar.gz
BASELINE: Update Chromium to 79.0.3945.139
Change-Id: I336b7182fab9bca80b709682489c07db112eaca5 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/feed')
-rw-r--r--chromium/components/feed/OWNERS7
-rw-r--r--chromium/components/feed/core/feed_content_database_unittest.cc6
-rw-r--r--chromium/components/feed/core/feed_journal_database_unittest.cc6
-rw-r--r--chromium/components/feed/core/feed_networking_host.cc2
-rw-r--r--chromium/components/feed/core/feed_networking_host_unittest.cc6
-rw-r--r--chromium/components/feed/core/user_classifier.cc5
-rw-r--r--chromium/components/feed/feed_feature_list.cc2
-rw-r--r--chromium/components/feed/tools/.style.yapf2
-rwxr-xr-xchromium/components/feed/tools/content_dump.py214
9 files changed, 233 insertions, 17 deletions
diff --git a/chromium/components/feed/OWNERS b/chromium/components/feed/OWNERS
index 2efa28a3bd3..0cce6adc94b 100644
--- a/chromium/components/feed/OWNERS
+++ b/chromium/components/feed/OWNERS
@@ -1,8 +1,7 @@
+carlosk@chromium.org
fgorski@chromium.org
-pavely@chromium.org
-pnoland@chromium.org
+harringtond@chromium.org
skym@chromium.org
-zea@chromium.org
-# Team: chrome-jardin-team@google.com
+# Team: feed@chromium.org
# COMPONENT: UI>Browser>ContentSuggestions>Feed
diff --git a/chromium/components/feed/core/feed_content_database_unittest.cc b/chromium/components/feed/core/feed_content_database_unittest.cc
index 2fef55d70ea..d455fe6e270 100644
--- a/chromium/components/feed/core/feed_content_database_unittest.cc
+++ b/chromium/components/feed/core/feed_content_database_unittest.cc
@@ -57,9 +57,9 @@ class FeedContentDatabaseTest : public testing::Test {
auto storage_db =
std::make_unique<FakeDB<ContentStorageProto>>(&content_db_storage_);
- task_runner_ = base::CreateSequencedTaskRunnerWithTraits(
- {base::ThreadPool(), base::MayBlock(),
- base::TaskPriority::USER_VISIBLE});
+ task_runner_ =
+ base::CreateSequencedTaskRunner({base::ThreadPool(), base::MayBlock(),
+ base::TaskPriority::USER_VISIBLE});
content_db_ = storage_db.get();
feed_db_ = std::make_unique<FeedContentDatabase>(std::move(storage_db),
diff --git a/chromium/components/feed/core/feed_journal_database_unittest.cc b/chromium/components/feed/core/feed_journal_database_unittest.cc
index 272661e459c..6f2a238835c 100644
--- a/chromium/components/feed/core/feed_journal_database_unittest.cc
+++ b/chromium/components/feed/core/feed_journal_database_unittest.cc
@@ -63,9 +63,9 @@ class FeedJournalDatabaseTest : public testing::Test {
auto storage_db =
std::make_unique<FakeDB<JournalStorageProto>>(&journal_db_storage_);
- task_runner_ = base::CreateSequencedTaskRunnerWithTraits(
- {base::ThreadPool(), base::MayBlock(),
- base::TaskPriority::USER_VISIBLE});
+ task_runner_ =
+ base::CreateSequencedTaskRunner({base::ThreadPool(), base::MayBlock(),
+ base::TaskPriority::USER_VISIBLE});
journal_db_ = storage_db.get();
feed_db_ = std::make_unique<FeedJournalDatabase>(std::move(storage_db),
diff --git a/chromium/components/feed/core/feed_networking_host.cc b/chromium/components/feed/core/feed_networking_host.cc
index 3fd9a1db591..2c729793eb9 100644
--- a/chromium/components/feed/core/feed_networking_host.cc
+++ b/chromium/components/feed/core/feed_networking_host.cc
@@ -255,7 +255,7 @@ void NetworkFetch::OnSimpleLoaderComplete(
if (status_code == net::HTTP_UNAUTHORIZED) {
identity::ScopeSet scopes{kAuthenticationScope};
- std::string account_id = identity_manager_->GetPrimaryAccountId();
+ CoreAccountId account_id = identity_manager_->GetPrimaryAccountId();
identity_manager_->RemoveAccessTokenFromCache(account_id, scopes,
access_token_);
}
diff --git a/chromium/components/feed/core/feed_networking_host_unittest.cc b/chromium/components/feed/core/feed_networking_host_unittest.cc
index d29f177e0de..4bd71f4ebe0 100644
--- a/chromium/components/feed/core/feed_networking_host_unittest.cc
+++ b/chromium/components/feed/core/feed_networking_host_unittest.cc
@@ -86,14 +86,14 @@ class FeedNetworkingHostTest : public testing::Test {
net::HttpStatusCode code = net::HTTP_OK,
network::URLLoaderCompletionStatus status =
network::URLLoaderCompletionStatus()) {
- network::ResourceResponseHead head;
+ auto head = network::mojom::URLResponseHead::New();
if (code >= 0) {
- head.headers = base::MakeRefCounted<net::HttpResponseHeaders>(
+ head->headers = base::MakeRefCounted<net::HttpResponseHeaders>(
"HTTP/1.1 " + base::NumberToString(code));
status.decoded_body_length = response_string.length();
}
- test_factory_.AddResponse(url, head, response_string, status);
+ test_factory_.AddResponse(url, std::move(head), response_string, status);
task_environment_.FastForwardUntilNoTasksRemain();
}
diff --git a/chromium/components/feed/core/user_classifier.cc b/chromium/components/feed/core/user_classifier.cc
index a8b3cdf4acd..c3061321216 100644
--- a/chromium/components/feed/core/user_classifier.cc
+++ b/chromium/components/feed/core/user_classifier.cc
@@ -9,6 +9,7 @@
#include <string>
#include "base/metrics/histogram_macros.h"
+#include "base/numerics/ranges.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/clock.h"
@@ -155,7 +156,7 @@ double GetEstimateHoursBetweenEvents(double rate,
// discount_rate * estimate_hours = log(rate / (rate - 1)),
// estimate_hours = log(rate / (rate - 1)) / discount_rate.
double estimate_hours = std::log(rate / (rate - 1)) / discount_rate_per_hour;
- return std::max(min_hours, std::min(max_hours, estimate_hours));
+ return base::ClampToRange(estimate_hours, min_hours, max_hours);
}
// The inverse of GetEstimateHoursBetweenEvents().
@@ -164,7 +165,7 @@ double GetRateForEstimateHoursBetweenEvents(double estimate_hours,
double min_hours,
double max_hours) {
// Keep the input value within [min_hours, max_hours].
- estimate_hours = std::max(min_hours, std::min(max_hours, estimate_hours));
+ estimate_hours = base::ClampToRange(estimate_hours, min_hours, max_hours);
// Return |rate| such that GetEstimateHoursBetweenEvents for |rate| returns
// |estimate_hours|. Thus, solve |rate| in
// rate = 1 + e^{-discount_rate * estimate_hours} * rate,
diff --git a/chromium/components/feed/feed_feature_list.cc b/chromium/components/feed/feed_feature_list.cc
index 0e48a1ce9e4..25e149321be 100644
--- a/chromium/components/feed/feed_feature_list.cc
+++ b/chromium/components/feed/feed_feature_list.cc
@@ -7,7 +7,7 @@
namespace feed {
const base::Feature kInterestFeedContentSuggestions{
- "InterestFeedContentSuggestions", base::FEATURE_DISABLED_BY_DEFAULT};
+ "InterestFeedContentSuggestions", base::FEATURE_ENABLED_BY_DEFAULT};
const base::FeatureParam<std::string> kDisableTriggerTypes{
&kInterestFeedContentSuggestions, "disable_trigger_types", ""};
diff --git a/chromium/components/feed/tools/.style.yapf b/chromium/components/feed/tools/.style.yapf
new file mode 100644
index 00000000000..de0c6a70f38
--- /dev/null
+++ b/chromium/components/feed/tools/.style.yapf
@@ -0,0 +1,2 @@
+[style]
+based_on_style = chromium
diff --git a/chromium/components/feed/tools/content_dump.py b/chromium/components/feed/tools/content_dump.py
new file mode 100755
index 00000000000..53ee984bad5
--- /dev/null
+++ b/chromium/components/feed/tools/content_dump.py
@@ -0,0 +1,214 @@
+#!/usr/bin/python3
+# Copyright 2019 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:
+# Dump the feed content database from a connected device to a directory on this
+# computer.
+# > content_dump.py --device=FA77D0303076 --apk='com.chrome.canary'
+# > ls /tmp/feed_dump
+#
+# Files are output as textproto.
+#
+# Make any desired modifications, and then upload the dump back to the connected
+# device.
+# > content_dump.py --device=FA77D0303076 --apk='com.chrome.canary' --reverse
+import os
+import re
+import sys
+import argparse
+import subprocess
+import glob
+from os.path import join, dirname, realpath
+
+import plyvel
+
+# A dynamic import for encoding and decoding of escaped textproto strings.
+_prototext_mod = None
+
+
+# Import text proto escape/unescape functions from third_party/protobuf.
+def prototext():
+ global _prototext_mod
+ import importlib.util
+ if _prototext_mod:
+ return _prototext_mod
+ source_path = join(
+ dirname(__file__),
+ "../../../third_party/protobuf/python/google/protobuf/text_encoding.py")
+ spec = importlib.util.spec_from_file_location("protobuf.textutil",
+ source_path)
+ _prototext_mod = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(_prototext_mod)
+ return _prototext_mod
+
+
+parser = argparse.ArgumentParser()
+parser.add_argument("--db", help="Path to db", default='/tmp/feed_dump/db')
+parser.add_argument(
+ "--dump_to", help="Dump output directory", default='/tmp/feed_dump')
+parser.add_argument(
+ "--reverse", help="Write dump back to database", action='store_true')
+parser.add_argument("--device", help="adb device to use")
+parser.add_argument(
+ "--apk", help="APK to dump from/to", default='com.chrome.canary')
+
+args = parser.parse_args()
+
+ROOT_DIR = realpath(join(dirname(__file__), "../../.."))
+DUMP_DIR = args.dump_to
+DB_PATH = args.db
+CONTENT_DB_PATH = join(DB_PATH, 'content')
+DEVICE_DB_PATH = "/data/data/{}/app_chrome/Default/feed".format(args.apk)
+_protoc_path = None
+
+
+# Returns the path to the proto compiler, protoc.
+def protoc_path():
+ global _protoc_path
+ if not _protoc_path:
+ protoc_list = list(glob.glob(join(ROOT_DIR, "out") + "/*/protoc")) + list(
+ glob.glob(join(ROOT_DIR, "out") + "/*/*/protoc"))
+ if not len(protoc_list):
+ print("Can't find a suitable build output directory",
+ "(it should have protoc)")
+ sys.exit(1)
+ _protoc_path = protoc_list[0]
+ return _protoc_path
+
+
+def adb_base_args():
+ adb_path = join(ROOT_DIR, "third_party/android_sdk/public/platform-tools/adb")
+ adb_device = args.device
+ if adb_device:
+ return [adb_path, "-s", adb_device]
+ return [adb_path]
+
+
+def adb_pull_db():
+ subprocess.check_call(
+ adb_base_args() +
+ ["pull", join(DEVICE_DB_PATH, 'content'), DB_PATH])
+
+
+def adb_push_db():
+ subprocess.check_call(adb_base_args() +
+ ["push", CONTENT_DB_PATH, DEVICE_DB_PATH])
+
+
+def get_feed_protos():
+ result = [join(ROOT_DIR, 'components/feed/core/proto/content_storage.proto')]
+ for root, _, files in os.walk(join(ROOT_DIR, "third_party/feed")):
+ result += [join(root, f) for f in files if f.endswith('.proto')]
+
+ return result
+
+
+protoc_common_args = [
+ '-I' + join(ROOT_DIR, 'third_party/feed/src'), '-I' + join(ROOT_DIR)
+] + get_feed_protos()
+
+
+def run_command(args, input):
+ proc = subprocess.run(
+ args,
+ input=input,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ check=True)
+ return proc.stdout
+
+
+# Decode a binary proto into textproto format.
+def decode_proto(data, message_name):
+ return run_command(
+ [protoc_path(), '--decode=' + message_name] + protoc_common_args,
+ data).decode('utf-8')
+
+
+# Encode a textproto into binary proto format.
+def encode_proto(text, message_name):
+ return run_command(
+ [protoc_path(), '--encode=' + message_name] + protoc_common_args,
+ text.encode())
+
+
+# Ignore DB entries with the 'sp::' prefix, as they are not yet supported.
+def is_key_supported(key):
+ return not key.startswith('sp::')
+
+
+# Return the proto message stored under the given db key.
+def proto_message_from_db_key(key):
+ if key.startswith('ss::'):
+ return 'search.now.feed.client.StreamSharedState'
+ if key.startswith('FEATURE::') or key.startswith('FSM::'):
+ return 'search.now.feed.client.StreamPayload'
+ print("Unknown Key kind", key)
+ sys.exit(1)
+
+
+# Extract a binary proto database entry into textproto.
+def extract_db_entry(key, data):
+ # DB entries are feed.ContentStorageProto messages. First extract
+ # the content_data contained within.
+ text_proto = decode_proto(data, 'feed.ContentStorageProto')
+ m = re.search(r"content_data: \"((?:\\\"|[^\"])*)\"", text_proto)
+ raw_data = prototext().CUnescape(m.group(1))
+
+ # Next, convert raw_data into a textproto. The DB key informs which message
+ # is stored.
+ result = decode_proto(raw_data, proto_message_from_db_key(key))
+ return result
+
+
+# Dump the content database to a local directory as textproto files.
+def dump():
+ os.makedirs(DUMP_DIR, exist_ok=True)
+ os.makedirs(DB_PATH, exist_ok=True)
+ adb_pull_db()
+ db = plyvel.DB(CONTENT_DB_PATH, create_if_missing=False)
+ with db.iterator() as it:
+ for i, (k, v) in enumerate(it):
+ k = k.decode('utf-8')
+ if not is_key_supported(k):
+ continue
+ with open(join(DUMP_DIR, 'entry{:03d}.key'.format(i)), 'w') as f:
+ f.write(k)
+ with open(join(DUMP_DIR, 'entry{:03d}.textproto'.format(i)), 'w') as f:
+ f.write(extract_db_entry(k, v))
+ print('Finished dumping to', DUMP_DIR)
+ db.close()
+
+
+# Reverse of dump().
+def load():
+ db = plyvel.DB(CONTENT_DB_PATH, create_if_missing=False)
+ # For each textproto file, update its database entry.
+ # No attempt is made to delete keys for deleted files.
+ for f in os.listdir(DUMP_DIR):
+ if f.endswith('.textproto'):
+ f_base, _ = os.path.splitext(f)
+ with open(join(DUMP_DIR, f_base + '.key'), 'r') as file:
+ key = file.read().strip()
+ with open(join(DUMP_DIR, f), 'r') as file:
+ value_text_proto = file.read()
+ value_encoded = encode_proto(value_text_proto,
+ proto_message_from_db_key(key))
+ # Create binary feed.ContentStorageProto by encoding its textproto.
+ content_storage_text = 'key: "{}"\ncontent_data: "{}"'.format(
+ prototext().CEscape(key, False),
+ prototext().CEscape(value_encoded, False))
+
+ store_encoded = encode_proto(content_storage_text,
+ 'feed.ContentStorageProto')
+ db.put(key.encode(), store_encoded)
+ db.close()
+ adb_push_db()
+
+
+if not args.reverse:
+ dump()
+else:
+ load()