Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/search_engines/search_provider_install_state_impl.h" | 5 #include "chrome/browser/search_engines/search_provider_install_state_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/browser/google/google_url_tracker_factory.h" | 9 #include "chrome/browser/google/google_url_tracker_factory.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/search_engines/template_url_service_factory.h" | 11 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 12 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 12 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
| 13 #include "chrome/common/search_provider.mojom.h" | 13 #include "chrome/common/search_provider.mojom.h" |
| 14 #include "content/public/browser/owned_interface.h" | |
| 15 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 16 #include "services/shell/public/cpp/interface_registry.h" | 15 #include "services/shell/public/cpp/interface_registry.h" |
| 17 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 18 | 17 |
| 19 using content::BrowserThread; | 18 using content::BrowserThread; |
| 20 | 19 |
| 21 SearchProviderInstallStateImpl::SearchProviderInstallStateImpl( | 20 SearchProviderInstallStateImpl::SearchProviderInstallStateImpl( |
| 22 int render_process_id, | 21 int render_process_id, |
| 23 Profile* profile) | 22 Profile* profile) |
| 24 : provider_data_(TemplateURLServiceFactory::GetForProfile(profile), | 23 : provider_data_(TemplateURLServiceFactory::GetForProfile(profile), |
|
Sam McNally
2016/07/26 01:46:34
TemplateURLService is a KeyedService stored as a r
tibell
2016/07/26 02:40:48
dcheng@ is going to try to delete this code. I wil
jam
2016/07/26 05:25:36
This is safe, check out the implementation of prov
| |
| 25 UIThreadSearchTermsData(profile).GoogleBaseURLValue(), | 24 UIThreadSearchTermsData(profile).GoogleBaseURLValue(), |
| 26 GoogleURLTrackerFactory::GetForProfile(profile), | 25 GoogleURLTrackerFactory::GetForProfile(profile), |
| 27 content::RenderProcessHost::FromID(render_process_id)), | 26 content::RenderProcessHost::FromID(render_process_id)), |
| 28 is_off_the_record_(profile->IsOffTheRecord()), | 27 is_off_the_record_(profile->IsOffTheRecord()), |
| 28 binding_(this), | |
| 29 weak_factory_(this) { | 29 weak_factory_(this) { |
| 30 // This is initialized by RenderProcessHostImpl. Do not add any non-trivial | 30 // This is initialized by RenderProcessHostImpl. Do not add any non-trivial |
| 31 // initialization here. Instead do it lazily when required. | 31 // initialization here. Instead do it lazily when required. |
| 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 33 } | 33 } |
| 34 | 34 |
| 35 SearchProviderInstallStateImpl::~SearchProviderInstallStateImpl() { | 35 SearchProviderInstallStateImpl::~SearchProviderInstallStateImpl() { |
| 36 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 36 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void SearchProviderInstallStateImpl::Bind( | 39 // static |
| 40 void SearchProviderInstallStateImpl::Create( | |
| 41 int render_process_id, | |
| 42 Profile* profile, | |
| 40 chrome::mojom::SearchProviderInstallStateRequest request) { | 43 chrome::mojom::SearchProviderInstallStateRequest request) { |
| 41 binding_set_.AddBinding(this, std::move(request)); | 44 // BindOnIOThread takes ownership on the impl object: |
| 45 BrowserThread::PostTask( | |
| 46 BrowserThread::IO, FROM_HERE, | |
| 47 base::Bind(&SearchProviderInstallStateImpl::BindOnIOThread, | |
| 48 base::Unretained(new SearchProviderInstallStateImpl( | |
|
leonhsl(Using Gerrit)
2016/07/26 02:28:34
Why don't we do new/bind together on IO thread? If
tibell
2016/07/26 02:40:48
The fields in the class need to be initialized on
| |
| 49 render_process_id, profile)), | |
| 50 base::Passed(&request))); | |
| 51 } | |
| 52 | |
| 53 void SearchProviderInstallStateImpl::BindOnIOThread( | |
| 54 chrome::mojom::SearchProviderInstallStateRequest request) { | |
| 55 binding_.Bind(std::move(request)); | |
| 42 } | 56 } |
| 43 | 57 |
| 44 chrome::mojom::InstallState | 58 chrome::mojom::InstallState |
| 45 SearchProviderInstallStateImpl::GetSearchProviderInstallState( | 59 SearchProviderInstallStateImpl::GetSearchProviderInstallState( |
| 46 const GURL& page_location, | 60 const GURL& page_location, |
| 47 const GURL& requested_host) { | 61 const GURL& requested_host) { |
| 48 GURL requested_origin = requested_host.GetOrigin(); | 62 GURL requested_origin = requested_host.GetOrigin(); |
| 49 | 63 |
| 50 // Do the security check before any others to avoid information leaks. | 64 // Do the security check before any others to avoid information leaks. |
| 51 if (page_location.GetOrigin() != requested_origin) | 65 if (page_location.GetOrigin() != requested_origin) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 | 98 |
| 85 void SearchProviderInstallStateImpl::ReplyWithProviderInstallState( | 99 void SearchProviderInstallStateImpl::ReplyWithProviderInstallState( |
| 86 const GURL& page_location, | 100 const GURL& page_location, |
| 87 const GURL& requested_host, | 101 const GURL& requested_host, |
| 88 const GetInstallStateCallback& callback) { | 102 const GetInstallStateCallback& callback) { |
| 89 chrome::mojom::InstallState install_state = | 103 chrome::mojom::InstallState install_state = |
| 90 GetSearchProviderInstallState(page_location, requested_host); | 104 GetSearchProviderInstallState(page_location, requested_host); |
| 91 | 105 |
| 92 callback.Run(install_state); | 106 callback.Run(install_state); |
| 93 } | 107 } |
| OLD | NEW |