Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(786)

Unified Diff: components/ntp_snippets/ntp_snippets_fetcher.cc

Issue 1910633005: Display status message for "Add snippets" on chrome://snippets-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: The final version ;) Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/ntp_snippets/ntp_snippets_fetcher.h ('k') | components/ntp_snippets/ntp_snippets_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ntp_snippets/ntp_snippets_fetcher.cc
diff --git a/components/ntp_snippets/ntp_snippets_fetcher.cc b/components/ntp_snippets/ntp_snippets_fetcher.cc
index c0eb082d9e8c6ae71c8623e7bf773a8914f66d78..0dbf7024d7ebbbfa16bcfdca0fd94bc079ae3e07 100644
--- a/components/ntp_snippets/ntp_snippets_fetcher.cc
+++ b/components/ntp_snippets/ntp_snippets_fetcher.cc
@@ -7,6 +7,7 @@
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/task_runner_util.h"
@@ -24,6 +25,11 @@ using net::URLRequestStatus;
namespace ntp_snippets {
+namespace {
+
+const char kStatusMessageURLRequestErrorFormat[] = "URLRequestStatus error %d";
+const char kStatusMessageHTTPErrorFormat[] = "HTTP error %d";
+
const char kContentSnippetsServerFormat[] =
"https://chromereader-pa.googleapis.com/v1/fetch?key=%s";
@@ -61,6 +67,8 @@ const char kHostRestrictFormat[] =
" \"value\": \"%s\""
" }";
+} // namespace
+
NTPSnippetsFetcher::NTPSnippetsFetcher(
scoped_refptr<base::SequencedTaskRunner> file_task_runner,
scoped_refptr<URLRequestContextGetter> url_request_context_getter,
@@ -110,25 +118,27 @@ void NTPSnippetsFetcher::FetchSnippets(const std::set<std::string>& hosts) {
void NTPSnippetsFetcher::OnURLFetchComplete(const URLFetcher* source) {
DCHECK_EQ(url_fetcher_.get(), source);
+ std::string message;
const URLRequestStatus& status = source->GetStatus();
if (!status.is_success()) {
- DLOG(WARNING) << "URLRequestStatus error " << status.error()
- << " while trying to download " << source->GetURL().spec();
- return;
- }
-
- int response_code = source->GetResponseCode();
- if (response_code != net::HTTP_OK) {
- DLOG(WARNING) << "HTTP error " << response_code
- << " while trying to download " << source->GetURL().spec();
- return;
+ message = base::StringPrintf(kStatusMessageURLRequestErrorFormat,
+ status.error());
+ } else if (source->GetResponseCode() != net::HTTP_OK) {
+ message = base::StringPrintf(kStatusMessageHTTPErrorFormat,
+ source->GetResponseCode());
}
std::string response;
- bool stores_result_to_string = source->GetResponseAsString(&response);
- DCHECK(stores_result_to_string);
+ if (!message.empty()) {
+ DLOG(WARNING) << message << " while trying to download "
+ << source->GetURL().spec();
+
+ } else {
+ bool stores_result_to_string = source->GetResponseAsString(&response);
+ DCHECK(stores_result_to_string);
+ }
- callback_list_.Notify(response);
+ callback_list_.Notify(response, message);
}
} // namespace ntp_snippets
« no previous file with comments | « components/ntp_snippets/ntp_snippets_fetcher.h ('k') | components/ntp_snippets/ntp_snippets_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698