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

Side by Side Diff: chrome/browser/ui/search/new_tab_page_interceptor.cc

Issue 845973005: [New Tab Page] Change the mechanism to intercept online NTP errors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove file Created 5 years, 11 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/search/new_tab_page_interceptor.h"
6
7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/search/search.h"
9 #include "chrome/common/url_constants.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "net/http/http_status_code.h"
12 #include "net/url_request/url_request.h"
13 #include "net/url_request/url_request_job.h"
14 #include "net/url_request/url_request_redirect_job.h"
15
16 namespace {
17
18 // Log a histogram for NTP load failure.
19 void RecordNTPLoadFailure() {
20 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
21 UMA_HISTOGRAM_ENUMERATION("InstantExtended.CacheableNTPLoad",
22 chrome::CACHEABLE_NTP_LOAD_FAILED,
23 chrome::CACHEABLE_NTP_LOAD_MAX);
24 }
25
26 } // namespace
27
28 NewTabPageInterceptor::NewTabPageInterceptor(const GURL& new_tab_url)
29 : new_tab_url_(new_tab_url), weak_factory_(this) {
30 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
31 }
32
33 NewTabPageInterceptor::~NewTabPageInterceptor() {
34 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
35 }
36
37 base::WeakPtr<NewTabPageInterceptor> NewTabPageInterceptor::GetWeakPtr() {
38 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
39 return weak_factory_.GetWeakPtr();
40 }
41
42 void NewTabPageInterceptor::SetNewTabPageURL(const GURL& new_tab_page_url) {
43 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
44 new_tab_url_ = new_tab_page_url;
45 }
46
47 net::URLRequestJob* NewTabPageInterceptor::MaybeInterceptRequest(
48 net::URLRequest* request,
49 net::NetworkDelegate* network_delegate) const {
50 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
51 return nullptr;
52 }
53
54 net::URLRequestJob* NewTabPageInterceptor::MaybeInterceptResponse(
55 net::URLRequest* request,
56 net::NetworkDelegate* network_delegate) const {
57 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
58 if ((request->url() != new_tab_url_) ||
59 (request->url() == GURL(chrome::kChromeSearchLocalNtpUrl))) {
mmenke 2015/01/15 22:35:30 optional: The second comparison left me scratchin
Mathieu 2015/01/22 19:21:58 Done with your first comment. I think the point w
60 return nullptr;
61 }
62 // User has canceled this navigation so it shouldn't be redirected.
63 if (request->status().status() == net::URLRequestStatus::CANCELED) {
mmenke 2015/01/15 22:35:30 Should also check for status() == net::URLRequestS
Mathieu 2015/01/22 19:21:58 Done.
64 return nullptr;
65 }
66
67 if (!request->status().is_success() ||
68 request->GetResponseCode() == net::HTTP_NO_CONTENT ||
69 request->GetResponseCode() >= 400) {
mmenke 2015/01/15 22:35:30 optional: Early return is generally preferred.
Mathieu 2015/01/22 19:21:58 Done.
70 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
71 base::Bind(&RecordNTPLoadFailure));
mmenke 2015/01/15 22:35:30 Histograms are threadsafe, so no reason to post a
Mathieu 2015/01/22 19:21:58 Done.
72 return new net::URLRequestRedirectJob(
73 request, network_delegate, GURL(chrome::kChromeSearchLocalNtpUrl),
74 net::URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT,
75 "NTP Request Interceptor");
76 }
77 return nullptr;
78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698