Commit 3ba3dcc8 authored by Sam Bowen's avatar Sam Bowen Committed by Commit Bot

[Media Feeds] Display error logs in media feeds UI.

Bug: 1081515
Change-Id: Id60a43f4a9d3093992670676627a05baac258b88
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2210795
Commit-Queue: Sam Bowen <sgbowen@google.com>
Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771991}
parent 4a7e3938
...@@ -263,8 +263,10 @@ IN_PROC_BROWSER_TEST_F(MediaFeedsBrowserTest, DiscoverAndFetch) { ...@@ -263,8 +263,10 @@ IN_PROC_BROWSER_TEST_F(MediaFeedsBrowserTest, DiscoverAndFetch) {
EXPECT_EQ(1u, discovered_feeds.size()); EXPECT_EQ(1u, discovered_feeds.size());
base::RunLoop run_loop; base::RunLoop run_loop;
GetMediaFeedsService()->FetchMediaFeed(discovered_feeds[0]->id, GetMediaFeedsService()->FetchMediaFeed(
run_loop.QuitClosure()); discovered_feeds[0]->id,
base::BindLambdaForTesting(
[&](const std::string& ignored) { run_loop.Quit(); }));
run_loop.Run(); run_loop.Run();
WaitForDB(); WaitForDB();
...@@ -663,8 +665,10 @@ IN_PROC_BROWSER_TEST_F(MediaFeedsBrowserTest, DiscoverAndFetchMinimal) { ...@@ -663,8 +665,10 @@ IN_PROC_BROWSER_TEST_F(MediaFeedsBrowserTest, DiscoverAndFetchMinimal) {
EXPECT_EQ(1u, discovered_feeds.size()); EXPECT_EQ(1u, discovered_feeds.size());
base::RunLoop run_loop; base::RunLoop run_loop;
GetMediaFeedsService()->FetchMediaFeed(discovered_feeds[0]->id, GetMediaFeedsService()->FetchMediaFeed(
run_loop.QuitClosure()); discovered_feeds[0]->id,
base::BindLambdaForTesting(
[&](const std::string& ignored) { run_loop.Quit(); }));
run_loop.Run(); run_loop.Run();
WaitForDB(); WaitForDB();
...@@ -809,8 +813,10 @@ IN_PROC_BROWSER_TEST_F(MediaFeedsBrowserTest, ResetMediaFeed_OnNavigation) { ...@@ -809,8 +813,10 @@ IN_PROC_BROWSER_TEST_F(MediaFeedsBrowserTest, ResetMediaFeed_OnNavigation) {
// Fetch the feed. // Fetch the feed.
base::RunLoop run_loop; base::RunLoop run_loop;
GetMediaFeedsService()->FetchMediaFeed(feeds[0]->id, GetMediaFeedsService()->FetchMediaFeed(
run_loop.QuitClosure()); feeds[0]->id,
base::BindLambdaForTesting(
[&](const std::string& ignored) { run_loop.Quit(); }));
run_loop.Run(); run_loop.Run();
WaitForDB(); WaitForDB();
} }
...@@ -868,8 +874,10 @@ IN_PROC_BROWSER_TEST_F(MediaFeedsBrowserTest, ...@@ -868,8 +874,10 @@ IN_PROC_BROWSER_TEST_F(MediaFeedsBrowserTest,
// Fetch the feed. // Fetch the feed.
base::RunLoop run_loop; base::RunLoop run_loop;
GetMediaFeedsService()->FetchMediaFeed(feeds[0]->id, GetMediaFeedsService()->FetchMediaFeed(
run_loop.QuitClosure()); feeds[0]->id,
base::BindLambdaForTesting(
[&](const std::string& ignored) { run_loop.Quit(); }));
run_loop.Run(); run_loop.Run();
WaitForDB(); WaitForDB();
} }
...@@ -899,8 +907,10 @@ IN_PROC_BROWSER_TEST_F(MediaFeedsBrowserTest, ...@@ -899,8 +907,10 @@ IN_PROC_BROWSER_TEST_F(MediaFeedsBrowserTest,
// Fetch the feed. // Fetch the feed.
base::RunLoop run_loop; base::RunLoop run_loop;
GetMediaFeedsService()->FetchMediaFeed(feeds[0]->id, GetMediaFeedsService()->FetchMediaFeed(
run_loop.QuitClosure()); feeds[0]->id,
base::BindLambdaForTesting(
[&](const std::string& ignored) { run_loop.Quit(); }));
run_loop.Run(); run_loop.Run();
WaitForDB(); WaitForDB();
} }
......
...@@ -187,7 +187,7 @@ void MediaFeedsService::SetSafeSearchCompletionCallbackForTest( ...@@ -187,7 +187,7 @@ void MediaFeedsService::SetSafeSearchCompletionCallbackForTest(
} }
void MediaFeedsService::FetchMediaFeed(int64_t feed_id, void MediaFeedsService::FetchMediaFeed(int64_t feed_id,
base::OnceClosure callback) { FetchMediaFeedCallback callback) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
// Skip the fetch if there is already an ongoing fetch for this feed. However, // Skip the fetch if there is already an ongoing fetch for this feed. However,
...@@ -352,7 +352,7 @@ bool MediaFeedsService::IsSafeSearchCheckingEnabled() const { ...@@ -352,7 +352,7 @@ bool MediaFeedsService::IsSafeSearchCheckingEnabled() const {
MediaFeedsService::InflightFeedFetch::InflightFeedFetch( MediaFeedsService::InflightFeedFetch::InflightFeedFetch(
std::unique_ptr<MediaFeedsFetcher> fetcher, std::unique_ptr<MediaFeedsFetcher> fetcher,
base::OnceClosure callback) FetchMediaFeedCallback callback)
: fetcher(std::move(fetcher)) { : fetcher(std::move(fetcher)) {
callbacks.push_back(std::move(callback)); callbacks.push_back(std::move(callback));
} }
...@@ -378,7 +378,7 @@ void MediaFeedsService::OnGotFetchDetails( ...@@ -378,7 +378,7 @@ void MediaFeedsService::OnGotFetchDetails(
DCHECK(base::Contains(fetches_, feed_id)); DCHECK(base::Contains(fetches_, feed_id));
if (!details.has_value()) { if (!details.has_value()) {
OnCompleteFetch(feed_id, false); OnCompleteFetch(feed_id, false, "Missing feed fetch details");
return; return;
} }
...@@ -402,7 +402,9 @@ void MediaFeedsService::OnFetchResponse( ...@@ -402,7 +402,9 @@ void MediaFeedsService::OnFetchResponse(
if (result.gone) { if (result.gone) {
GetMediaHistoryService()->DeleteMediaFeed( GetMediaHistoryService()->DeleteMediaFeed(
feed_id, base::BindOnce(&MediaFeedsService::OnCompleteFetch, feed_id, base::BindOnce(&MediaFeedsService::OnCompleteFetch,
weak_factory_.GetWeakPtr(), feed_id, false)); weak_factory_.GetWeakPtr(), feed_id, false,
"The server returned 410 Gone which resulted "
"in the feed being deleted."));
return; return;
} }
...@@ -410,20 +412,23 @@ void MediaFeedsService::OnFetchResponse( ...@@ -410,20 +412,23 @@ void MediaFeedsService::OnFetchResponse(
result.reset_token = reset_token; result.reset_token = reset_token;
const bool has_items = !result.items.empty(); const bool has_items = !result.items.empty();
std::string error_logs;
error_logs.swap(result.error_logs);
GetMediaHistoryService()->StoreMediaFeedFetchResult( GetMediaHistoryService()->StoreMediaFeedFetchResult(
std::move(result), std::move(result), base::BindOnce(&MediaFeedsService::OnCompleteFetch,
base::BindOnce(&MediaFeedsService::OnCompleteFetch, weak_factory_.GetWeakPtr(), feed_id,
weak_factory_.GetWeakPtr(), feed_id, has_items)); has_items, error_logs));
} }
void MediaFeedsService::OnCompleteFetch(const int64_t feed_id, void MediaFeedsService::OnCompleteFetch(const int64_t feed_id,
const bool has_items) { const bool has_items,
const std::string& error_logs) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(base::Contains(fetches_, feed_id)); DCHECK(base::Contains(fetches_, feed_id));
for (auto& callback : fetches_.at(feed_id).callbacks) { for (auto& callback : fetches_.at(feed_id).callbacks) {
std::move(callback).Run(); std::move(callback).Run(error_logs);
} }
fetches_.erase(feed_id); fetches_.erase(feed_id);
......
...@@ -39,6 +39,9 @@ class MediaFeedsService : public KeyedService { ...@@ -39,6 +39,9 @@ class MediaFeedsService : public KeyedService {
public: public:
static const char kSafeSearchResultHistogramName[]; static const char kSafeSearchResultHistogramName[];
using FetchMediaFeedCallback =
base::OnceCallback<void(const std::string& logs)>;
explicit MediaFeedsService(Profile* profile); explicit MediaFeedsService(Profile* profile);
~MediaFeedsService() override; ~MediaFeedsService() override;
MediaFeedsService(const MediaFeedsService& t) = delete; MediaFeedsService(const MediaFeedsService& t) = delete;
...@@ -67,8 +70,7 @@ class MediaFeedsService : public KeyedService { ...@@ -67,8 +70,7 @@ class MediaFeedsService : public KeyedService {
// Fetches a media feed with the given ID and then store it in the // Fetches a media feed with the given ID and then store it in the
// feeds table in media history. Runs the given callback after storing. The // feeds table in media history. Runs the given callback after storing. The
// fetch will be skipped if another fetch is currently ongoing. // fetch will be skipped if another fetch is currently ongoing.
void FetchMediaFeed(int64_t feed_id, void FetchMediaFeed(int64_t feed_id, FetchMediaFeedCallback callback);
base::OnceClosure callback);
// Stores a callback to be called once we have completed all inflight checks. // Stores a callback to be called once we have completed all inflight checks.
void SetCookieChangeCallbackForTest(base::OnceClosure callback); void SetCookieChangeCallbackForTest(base::OnceClosure callback);
...@@ -103,7 +105,9 @@ class MediaFeedsService : public KeyedService { ...@@ -103,7 +105,9 @@ class MediaFeedsService : public KeyedService {
base::Optional<base::UnguessableToken> reset_token, base::Optional<base::UnguessableToken> reset_token,
media_history::MediaHistoryKeyedService::MediaFeedFetchResult result); media_history::MediaHistoryKeyedService::MediaFeedFetchResult result);
void OnCompleteFetch(const int64_t feed_id, const bool has_items); void OnCompleteFetch(const int64_t feed_id,
const bool has_items,
const std::string& error_logs);
void OnSafeSearchPrefChanged(); void OnSafeSearchPrefChanged();
...@@ -121,13 +125,13 @@ class MediaFeedsService : public KeyedService { ...@@ -121,13 +125,13 @@ class MediaFeedsService : public KeyedService {
struct InflightFeedFetch { struct InflightFeedFetch {
InflightFeedFetch(std::unique_ptr<MediaFeedsFetcher> fetcher, InflightFeedFetch(std::unique_ptr<MediaFeedsFetcher> fetcher,
base::OnceClosure callback); FetchMediaFeedCallback callback);
~InflightFeedFetch(); ~InflightFeedFetch();
InflightFeedFetch(InflightFeedFetch&& t); InflightFeedFetch(InflightFeedFetch&& t);
InflightFeedFetch(const InflightFeedFetch&) = delete; InflightFeedFetch(const InflightFeedFetch&) = delete;
InflightFeedFetch& operator=(const InflightFeedFetch&) = delete; InflightFeedFetch& operator=(const InflightFeedFetch&) = delete;
std::vector<base::OnceClosure> callbacks; std::vector<FetchMediaFeedCallback> callbacks;
std::unique_ptr<MediaFeedsFetcher> fetcher; std::unique_ptr<MediaFeedsFetcher> fetcher;
}; };
......
...@@ -341,7 +341,9 @@ TEST_F(MediaFeedsServiceTest, FetchFeed_Success) { ...@@ -341,7 +341,9 @@ TEST_F(MediaFeedsServiceTest, FetchFeed_Success) {
// Fetch the Media Feed. // Fetch the Media Feed.
base::RunLoop run_loop; base::RunLoop run_loop;
GetMediaFeedsService()->FetchMediaFeed(1, run_loop.QuitClosure()); GetMediaFeedsService()->FetchMediaFeed(
1, base::BindLambdaForTesting(
[&](const std::string& ignored) { run_loop.Quit(); }));
WaitForDB(); WaitForDB();
ASSERT_TRUE(RespondToPendingFeedFetch(feed_url)); ASSERT_TRUE(RespondToPendingFeedFetch(feed_url));
run_loop.Run(); run_loop.Run();
...@@ -366,7 +368,9 @@ TEST_F(MediaFeedsServiceTest, FetchFeed_SuccessFromCache) { ...@@ -366,7 +368,9 @@ TEST_F(MediaFeedsServiceTest, FetchFeed_SuccessFromCache) {
// Fetch the Media Feed. // Fetch the Media Feed.
base::RunLoop run_loop; base::RunLoop run_loop;
GetMediaFeedsService()->FetchMediaFeed(1, run_loop.QuitClosure()); GetMediaFeedsService()->FetchMediaFeed(
1, base::BindLambdaForTesting(
[&](const std::string& ignored) { run_loop.Quit(); }));
WaitForDB(); WaitForDB();
ASSERT_TRUE(RespondToPendingFeedFetch(feed_url, true)); ASSERT_TRUE(RespondToPendingFeedFetch(feed_url, true));
run_loop.Run(); run_loop.Run();
...@@ -391,7 +395,9 @@ TEST_F(MediaFeedsServiceTest, FetchFeed_BackendError) { ...@@ -391,7 +395,9 @@ TEST_F(MediaFeedsServiceTest, FetchFeed_BackendError) {
// Fetch the Media Feed. // Fetch the Media Feed.
base::RunLoop run_loop; base::RunLoop run_loop;
GetMediaFeedsService()->FetchMediaFeed(1, run_loop.QuitClosure()); GetMediaFeedsService()->FetchMediaFeed(
1, base::BindLambdaForTesting(
[&](const std::string& ignored) { run_loop.Quit(); }));
WaitForDB(); WaitForDB();
ASSERT_TRUE(RespondToPendingFeedFetchWithStatus( ASSERT_TRUE(RespondToPendingFeedFetchWithStatus(
feed_url, net::HTTP_INTERNAL_SERVER_ERROR)); feed_url, net::HTTP_INTERNAL_SERVER_ERROR));
...@@ -416,7 +422,9 @@ TEST_F(MediaFeedsServiceTest, FetchFeed_NotFoundError) { ...@@ -416,7 +422,9 @@ TEST_F(MediaFeedsServiceTest, FetchFeed_NotFoundError) {
// Fetch the Media Feed. // Fetch the Media Feed.
base::RunLoop run_loop; base::RunLoop run_loop;
GetMediaFeedsService()->FetchMediaFeed(1, run_loop.QuitClosure()); GetMediaFeedsService()->FetchMediaFeed(
1, base::BindLambdaForTesting(
[&](const std::string& ignored) { run_loop.Quit(); }));
WaitForDB(); WaitForDB();
ASSERT_TRUE(RespondToPendingFeedFetchWithStatus(feed_url, net::HTTP_OK)); ASSERT_TRUE(RespondToPendingFeedFetchWithStatus(feed_url, net::HTTP_OK));
run_loop.Run(); run_loop.Run();
...@@ -941,7 +949,9 @@ TEST_F(MediaFeedsServiceTest, FetcherShouldTriggerSafeSearch) { ...@@ -941,7 +949,9 @@ TEST_F(MediaFeedsServiceTest, FetcherShouldTriggerSafeSearch) {
{ {
// Fetch the Media Feed. // Fetch the Media Feed.
base::RunLoop run_loop; base::RunLoop run_loop;
GetMediaFeedsService()->FetchMediaFeed(1, run_loop.QuitClosure()); GetMediaFeedsService()->FetchMediaFeed(
1, base::BindLambdaForTesting(
[&](const std::string& ignored) { run_loop.Quit(); }));
WaitForDB(); WaitForDB();
ASSERT_TRUE(RespondToPendingFeedFetch(feed_url)); ASSERT_TRUE(RespondToPendingFeedFetch(feed_url));
run_loop.Run(); run_loop.Run();
...@@ -1039,11 +1049,15 @@ TEST_F(MediaFeedsServiceTest, FetcherShouldSupportMultipleFetchesForSameFeed) { ...@@ -1039,11 +1049,15 @@ TEST_F(MediaFeedsServiceTest, FetcherShouldSupportMultipleFetchesForSameFeed) {
// Fetch the same feed twice. // Fetch the same feed twice.
base::RunLoop run_loop; base::RunLoop run_loop;
GetMediaFeedsService()->FetchMediaFeed(1, run_loop.QuitClosure()); GetMediaFeedsService()->FetchMediaFeed(
1, base::BindLambdaForTesting(
[&](const std::string& ignored) { run_loop.Quit(); }));
WaitForDB(); WaitForDB();
base::RunLoop run_loop_alt; base::RunLoop run_loop_alt;
GetMediaFeedsService()->FetchMediaFeed(1, run_loop_alt.QuitClosure()); GetMediaFeedsService()->FetchMediaFeed(
1, base::BindLambdaForTesting(
[&](const std::string& ignored) { run_loop_alt.Quit(); }));
WaitForDB(); WaitForDB();
// Respond and make sure both run loop quit closures were called. // Respond and make sure both run loop quit closures were called.
...@@ -1081,7 +1095,9 @@ TEST_F(MediaFeedsServiceTest, FetcherShouldHandleReset) { ...@@ -1081,7 +1095,9 @@ TEST_F(MediaFeedsServiceTest, FetcherShouldHandleReset) {
// Start fetching the feed but do not resolve the request. // Start fetching the feed but do not resolve the request.
base::RunLoop run_loop; base::RunLoop run_loop;
GetMediaFeedsService()->FetchMediaFeed(1, run_loop.QuitClosure()); GetMediaFeedsService()->FetchMediaFeed(
1, base::BindLambdaForTesting(
[&](const std::string& ignored) { run_loop.Quit(); }));
WaitForDB(); WaitForDB();
// The last request was successful so we can hit the cache. // The last request was successful so we can hit the cache.
...@@ -1124,7 +1140,9 @@ TEST_F(MediaFeedsServiceTest, FetcherShouldHandleReset) { ...@@ -1124,7 +1140,9 @@ TEST_F(MediaFeedsServiceTest, FetcherShouldHandleReset) {
// Start fetching the feed but do not resolve the request. // Start fetching the feed but do not resolve the request.
base::RunLoop run_loop_alt; base::RunLoop run_loop_alt;
GetMediaFeedsService()->FetchMediaFeed(1, run_loop_alt.QuitClosure()); GetMediaFeedsService()->FetchMediaFeed(
1, base::BindLambdaForTesting(
[&](const std::string& ignored) { run_loop_alt.Quit(); }));
WaitForDB(); WaitForDB();
// The last request failed so we should not hit the cache. // The last request failed so we should not hit the cache.
......
...@@ -437,6 +437,7 @@ interface MediaFeedsStore { ...@@ -437,6 +437,7 @@ interface MediaFeedsStore {
// Fetch the details of a previously-discovered media feed and store them in // Fetch the details of a previously-discovered media feed and store them in
// media history. The feed ID is the unique ID for the feed from the Media // media history. The feed ID is the unique ID for the feed from the Media
// History store. // History store. The logs contain information about any problems fetching or
FetchMediaFeed(int64 feed_id) => (); // parsing the feed.
FetchMediaFeed(int64 feed_id) => (string logs);
}; };
...@@ -135,7 +135,7 @@ class MediaHistoryKeyedService : public KeyedService, ...@@ -135,7 +135,7 @@ class MediaHistoryKeyedService : public KeyedService,
std::string cookie_name_filter; std::string cookie_name_filter;
// Logs about any errors that may have occurred while fetching or converting // Logs about any errors that may have occurred while fetching or converting
// the feed data. // the feed data. New-line delimited human-readable text.
std::string error_logs; std::string error_logs;
// If true then the backend returned a 410 Gone error. // If true then the backend returned a 410 Gone error.
......
...@@ -80,6 +80,10 @@ ...@@ -80,6 +80,10 @@
content: '▼'; content: '▼';
position: absolute; position: absolute;
} }
div#fetch-logs-content {
color: red;
}
</style> </style>
</head> </head>
<body> <body>
...@@ -236,6 +240,10 @@ ...@@ -236,6 +240,10 @@
<tbody> <tbody>
</tbody> </tbody>
</table> </table>
<div id="fetch-logs">
<h3>Fetch logs:</h3>
<div id="fetch-logs-content"></div>
</div>
</div> </div>
</body> </body>
</html> </html>
...@@ -53,6 +53,10 @@ class MediaFeedsTableDelegate { ...@@ -53,6 +53,10 @@ class MediaFeedsTableDelegate {
a.addEventListener('click', () => { a.addEventListener('click', () => {
showFeedContents(dataRow); showFeedContents(dataRow);
// Clear old logs and hide the area from display.
$('fetch-logs').style.display = 'none';
$('fetch-logs-content').textContent = '';
}); });
td.appendChild(document.createElement('br')); td.appendChild(document.createElement('br'));
...@@ -66,6 +70,9 @@ class MediaFeedsTableDelegate { ...@@ -66,6 +70,9 @@ class MediaFeedsTableDelegate {
store.fetchMediaFeed(dataRow.id).then(response => { store.fetchMediaFeed(dataRow.id).then(response => {
updateFeedsTable(); updateFeedsTable();
showFeedContents(dataRow); showFeedContents(dataRow);
$('fetch-logs').style.display = 'block';
$('fetch-logs-content').textContent = response.logs;
}); });
}); });
} }
......
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