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

Side by Side 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: Minor edit (removing one empty line). 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/ntp_snippets/ntp_snippets_fetcher.h" 5 #include "components/ntp_snippets/ntp_snippets_fetcher.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "base/task_runner_util.h" 13 #include "base/task_runner_util.h"
13 #include "google_apis/google_api_keys.h" 14 #include "google_apis/google_api_keys.h"
14 #include "net/base/load_flags.h" 15 #include "net/base/load_flags.h"
15 #include "net/http/http_request_headers.h" 16 #include "net/http/http_request_headers.h"
16 #include "net/http/http_response_headers.h" 17 #include "net/http/http_response_headers.h"
17 #include "net/http/http_status_code.h" 18 #include "net/http/http_status_code.h"
18 #include "net/url_request/url_fetcher.h" 19 #include "net/url_request/url_fetcher.h"
19 20
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // Try to make fetching the files bit more robust even with poor connection. 104 // Try to make fetching the files bit more robust even with poor connection.
104 url_fetcher_->SetMaxRetriesOn5xx(3); 105 url_fetcher_->SetMaxRetriesOn5xx(3);
105 url_fetcher_->Start(); 106 url_fetcher_->Start();
106 } 107 }
107 108
108 //////////////////////////////////////////////////////////////////////////////// 109 ////////////////////////////////////////////////////////////////////////////////
109 // URLFetcherDelegate overrides 110 // URLFetcherDelegate overrides
110 void NTPSnippetsFetcher::OnURLFetchComplete(const URLFetcher* source) { 111 void NTPSnippetsFetcher::OnURLFetchComplete(const URLFetcher* source) {
111 DCHECK_EQ(url_fetcher_.get(), source); 112 DCHECK_EQ(url_fetcher_.get(), source);
112 113
114 std::string message;
113 const URLRequestStatus& status = source->GetStatus(); 115 const URLRequestStatus& status = source->GetStatus();
114 if (!status.is_success()) { 116 if (!status.is_success())
115 DLOG(WARNING) << "URLRequestStatus error " << status.error() 117 message = "URLRequestStatus error " + base::IntToString(status.error());
Bernhard Bauer 2016/04/22 09:42:17 Can we do the same thing here? Thanks!
jkrcal 2016/04/22 11:11:59 Done.
116 << " while trying to download " << source->GetURL().spec(); 118 else if (source->GetResponseCode() != net::HTTP_OK)
117 return; 119 message = "HTTP error " + base::IntToString(source->GetResponseCode());
120
121 std::string response;
122 if (!message.empty()) {
123 DLOG(WARNING) << message << " while trying to download "
124 << source->GetURL().spec();
125
126 } else {
127 bool stores_result_to_string = source->GetResponseAsString(&response);
128 DCHECK(stores_result_to_string);
118 } 129 }
119 130
120 int response_code = source->GetResponseCode(); 131 callback_list_.Notify(response, message);
121 if (response_code != net::HTTP_OK) {
122 DLOG(WARNING) << "HTTP error " << response_code
123 << " while trying to download " << source->GetURL().spec();
124 return;
125 }
126
127 std::string response;
128 bool stores_result_to_string = source->GetResponseAsString(&response);
129 DCHECK(stores_result_to_string);
130
131 callback_list_.Notify(response);
132 } 132 }
133 133
134 } // namespace ntp_snippets 134 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698