Chromium Code Reviews| Index: chrome/browser/ui/search/new_tab_page_interceptor_service.cc |
| diff --git a/chrome/browser/ui/search/new_tab_page_interceptor_service.cc b/chrome/browser/ui/search/new_tab_page_interceptor_service.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..168ca42b7ff08e0f849544fb4b55610d85da83a2 |
| --- /dev/null |
| +++ b/chrome/browser/ui/search/new_tab_page_interceptor_service.cc |
| @@ -0,0 +1,43 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/search/new_tab_page_interceptor_service.h" |
| + |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/search/search.h" |
| +#include "chrome/browser/search_engines/template_url_service_factory.h" |
| +#include "chrome/browser/ui/search/new_tab_page_interceptor.h" |
| +#include "components/search_engines/template_url_service.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +NewTabPageInterceptorService::NewTabPageInterceptorService(Profile* profile) |
| + : profile_(profile), |
| + template_url_service_(TemplateURLServiceFactory::GetForProfile(profile)) { |
| + DCHECK(profile_); |
| + if (template_url_service_) |
| + template_url_service_->AddObserver(this); |
| +} |
| + |
| +NewTabPageInterceptorService::~NewTabPageInterceptorService() { |
| + if (template_url_service_) |
| + template_url_service_->RemoveObserver(this); |
| +} |
| + |
| +void NewTabPageInterceptorService::OnTemplateURLServiceChanged() { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
|
Mathieu
2015/01/21 21:29:39
kmadhusu@: Do you think it's worth replicating the
kmadhusu
2015/01/22 20:06:30
I looked at the latest patch. These changes seems
kmadhusu
2015/01/23 00:59:32
Tested the latest patch. NTP interceptor works as
|
| + GURL new_tab_page_url(chrome::GetNewTabPageURL(profile_)); |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::IO, FROM_HERE, |
| + base::Bind(&NewTabPageInterceptor::SetNewTabPageURL, interceptor_, |
| + new_tab_page_url)); |
| +} |
| + |
| +scoped_ptr<net::URLRequestInterceptor> |
| +NewTabPageInterceptorService::CreateInterceptor() { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + scoped_ptr<NewTabPageInterceptor> interceptor( |
| + new NewTabPageInterceptor(chrome::GetNewTabPageURL(profile_))); |
| + interceptor_ = interceptor->GetWeakPtr(); |
| + return interceptor.Pass(); |
| +} |