OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/search/new_tab_page_interceptor_service.h" | 5 #include "chrome/browser/ui/search/new_tab_page_interceptor_service.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 // Request to NTP was successful. | 71 // Request to NTP was successful. |
72 if (request->status().is_success() && | 72 if (request->status().is_success() && |
73 request->GetResponseCode() != net::HTTP_NO_CONTENT && | 73 request->GetResponseCode() != net::HTTP_NO_CONTENT && |
74 request->GetResponseCode() < 400) { | 74 request->GetResponseCode() < 400) { |
75 return nullptr; | 75 return nullptr; |
76 } | 76 } |
77 | 77 |
78 // Failure to load the NTP correctly; redirect to Local NTP. | 78 // Failure to load the NTP correctly; redirect to Local NTP. |
79 UMA_HISTOGRAM_ENUMERATION("InstantExtended.CacheableNTPLoad", | 79 UMA_HISTOGRAM_ENUMERATION("InstantExtended.CacheableNTPLoad", |
80 chrome::CACHEABLE_NTP_LOAD_FAILED, | 80 search::CACHEABLE_NTP_LOAD_FAILED, |
81 chrome::CACHEABLE_NTP_LOAD_MAX); | 81 search::CACHEABLE_NTP_LOAD_MAX); |
82 return new net::URLRequestRedirectJob( | 82 return new net::URLRequestRedirectJob( |
83 request, network_delegate, GURL(chrome::kChromeSearchLocalNtpUrl), | 83 request, network_delegate, GURL(chrome::kChromeSearchLocalNtpUrl), |
84 net::URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, | 84 net::URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, |
85 "NTP Request Interceptor"); | 85 "NTP Request Interceptor"); |
86 } | 86 } |
87 | 87 |
88 GURL new_tab_url_; | 88 GURL new_tab_url_; |
89 base::WeakPtrFactory<NewTabPageInterceptor> weak_factory_; | 89 base::WeakPtrFactory<NewTabPageInterceptor> weak_factory_; |
90 | 90 |
91 DISALLOW_COPY_AND_ASSIGN(NewTabPageInterceptor); | 91 DISALLOW_COPY_AND_ASSIGN(NewTabPageInterceptor); |
92 }; | 92 }; |
93 | 93 |
94 NewTabPageInterceptorService::NewTabPageInterceptorService(Profile* profile) | 94 NewTabPageInterceptorService::NewTabPageInterceptorService(Profile* profile) |
95 : profile_(profile), | 95 : profile_(profile), |
96 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile)) { | 96 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile)) { |
97 DCHECK(profile_); | 97 DCHECK(profile_); |
98 if (template_url_service_) | 98 if (template_url_service_) |
99 template_url_service_->AddObserver(this); | 99 template_url_service_->AddObserver(this); |
100 } | 100 } |
101 | 101 |
102 NewTabPageInterceptorService::~NewTabPageInterceptorService() { | 102 NewTabPageInterceptorService::~NewTabPageInterceptorService() { |
103 if (template_url_service_) | 103 if (template_url_service_) |
104 template_url_service_->RemoveObserver(this); | 104 template_url_service_->RemoveObserver(this); |
105 } | 105 } |
106 | 106 |
107 void NewTabPageInterceptorService::OnTemplateURLServiceChanged() { | 107 void NewTabPageInterceptorService::OnTemplateURLServiceChanged() { |
108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
109 GURL new_tab_page_url(chrome::GetNewTabPageURL(profile_)); | 109 GURL new_tab_page_url(search::GetNewTabPageURL(profile_)); |
110 content::BrowserThread::PostTask( | 110 content::BrowserThread::PostTask( |
111 content::BrowserThread::IO, FROM_HERE, | 111 content::BrowserThread::IO, FROM_HERE, |
112 base::Bind(&NewTabPageInterceptor::SetNewTabPageURL, interceptor_, | 112 base::Bind(&NewTabPageInterceptor::SetNewTabPageURL, interceptor_, |
113 new_tab_page_url)); | 113 new_tab_page_url)); |
114 } | 114 } |
115 | 115 |
116 scoped_ptr<net::URLRequestInterceptor> | 116 scoped_ptr<net::URLRequestInterceptor> |
117 NewTabPageInterceptorService::CreateInterceptor() { | 117 NewTabPageInterceptorService::CreateInterceptor() { |
118 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 118 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
119 scoped_ptr<NewTabPageInterceptor> interceptor( | 119 scoped_ptr<NewTabPageInterceptor> interceptor( |
120 new NewTabPageInterceptor(chrome::GetNewTabPageURL(profile_))); | 120 new NewTabPageInterceptor(search::GetNewTabPageURL(profile_))); |
121 interceptor_ = interceptor->GetWeakPtr(); | 121 interceptor_ = interceptor->GetWeakPtr(); |
122 return interceptor.Pass(); | 122 return interceptor.Pass(); |
123 } | 123 } |
OLD | NEW |