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

Side by Side Diff: chrome/browser/search_engines/search_provider_install_state_impl.cc

Issue 2072613003: Convert GetSearchProviderInstallState to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change security owners Created 4 years, 6 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 (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_message_fi lter.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/render_messages.h" 13 #include "chrome/common/render_messages.h"
14 #include "chrome/common/search_provider.mojom.h"
14 #include "content/public/browser/render_process_host.h" 15 #include "content/public/browser/render_process_host.h"
15 #include "url/gurl.h" 16 #include "url/gurl.h"
16 17
17 using content::BrowserThread; 18 using content::BrowserThread;
18 19
19 SearchProviderInstallStateMessageFilter:: 20 // Adapter used to store the impl in user data and to make sure it's deleted on
20 SearchProviderInstallStateMessageFilter( 21 // the right thread.
22 class SearchProviderInstallStateImplAdapter
23 : public base::SupportsUserData::Data {
24 public:
25 explicit SearchProviderInstallStateImplAdapter(
26 std::unique_ptr<SearchProviderInstallStateImpl,
27 content::BrowserThread::DeleteOnIOThread> filter);
28 ~SearchProviderInstallStateImplAdapter() override = default;
29
30 SearchProviderInstallStateImpl* get() { return ptr_.get(); }
31
32 private:
33 std::unique_ptr<SearchProviderInstallStateImpl,
34 content::BrowserThread::DeleteOnIOThread>
35 ptr_;
36
37 DISALLOW_COPY_AND_ASSIGN(SearchProviderInstallStateImplAdapter);
38 };
39
40 SearchProviderInstallStateImplAdapter::SearchProviderInstallStateImplAdapter(
41 std::unique_ptr<SearchProviderInstallStateImpl,
42 content::BrowserThread::DeleteOnIOThread> filter)
43 : ptr_(std::move(filter)) {}
44
45 // Key used to attach the filter to the RenderProcessHost.
46 static const char kRenderProcessHostKey[] = "kRenderProcessHostKey";
47
48 SearchProviderInstallStateImpl::SearchProviderInstallStateImpl(
21 int render_process_id, 49 int render_process_id,
22 Profile* profile) 50 Profile* profile)
23 : BrowserMessageFilter(ChromeMsgStart), 51 : provider_data_(TemplateURLServiceFactory::GetForProfile(profile),
24 provider_data_(TemplateURLServiceFactory::GetForProfile(profile),
25 UIThreadSearchTermsData(profile).GoogleBaseURLValue(), 52 UIThreadSearchTermsData(profile).GoogleBaseURLValue(),
26 GoogleURLTrackerFactory::GetForProfile(profile), 53 GoogleURLTrackerFactory::GetForProfile(profile),
27 content::RenderProcessHost::FromID(render_process_id)), 54 content::RenderProcessHost::FromID(render_process_id)),
28 is_off_the_record_(profile->IsOffTheRecord()), 55 is_off_the_record_(profile->IsOffTheRecord()),
29 weak_factory_(this) { 56 weak_factory_(this) {
30 // This is initialized by RenderProcessHostImpl. Do not add any non-trivial 57 // This is initialized by RenderProcessHostImpl. Do not add any non-trivial
31 // initialization here. Instead do it lazily when required. 58 // initialization here. Instead do it lazily when required.
32 DCHECK_CURRENTLY_ON(BrowserThread::UI); 59 DCHECK_CURRENTLY_ON(BrowserThread::UI);
33 } 60 }
34 61
35 bool SearchProviderInstallStateMessageFilter::OnMessageReceived( 62 SearchProviderInstallStateImpl::~SearchProviderInstallStateImpl() {
36 const IPC::Message& message) {
37 DCHECK_CURRENTLY_ON(BrowserThread::IO);
38 bool handled = true;
39 IPC_BEGIN_MESSAGE_MAP(SearchProviderInstallStateMessageFilter, message)
40 IPC_MESSAGE_HANDLER_DELAY_REPLY(
41 ChromeViewHostMsg_GetSearchProviderInstallState,
42 OnGetSearchProviderInstallState)
43 IPC_MESSAGE_UNHANDLED(handled = false)
44 IPC_END_MESSAGE_MAP()
45 return handled;
46 }
47
48 SearchProviderInstallStateMessageFilter::
49 ~SearchProviderInstallStateMessageFilter() {
50 DCHECK_CURRENTLY_ON(BrowserThread::IO); 63 DCHECK_CURRENTLY_ON(BrowserThread::IO);
51 } 64 }
52 65
66 void SearchProviderInstallStateImpl::InstallService(
67 content::RenderProcessHost* host) {
68 int id = host->GetID();
69 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
70 auto* adapter = new SearchProviderInstallStateImplAdapter(
71 std::unique_ptr<SearchProviderInstallStateImpl,
72 content::BrowserThread::DeleteOnIOThread>(
73 new SearchProviderInstallStateImpl(id, profile)));
74 host->GetServiceRegistry()
75 ->AddService<chrome::mojom::SearchProviderInstallState>(
76 base::Bind(&SearchProviderInstallStateImpl::Bind,
77 base::Unretained(adapter->get())),
78 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
79 host->SetUserData(kRenderProcessHostKey, adapter);
80 }
81
82 void SearchProviderInstallStateImpl::Bind(
83 chrome::mojom::SearchProviderInstallStateRequest request) {
84 binding_set_.AddBinding(this, std::move(request));
85 }
86
53 search_provider::InstallState 87 search_provider::InstallState
54 SearchProviderInstallStateMessageFilter::GetSearchProviderInstallState( 88 SearchProviderInstallStateImpl::GetSearchProviderInstallState(
55 const GURL& page_location, 89 const GURL& page_location,
56 const GURL& requested_host) { 90 const GURL& requested_host) {
57 GURL requested_origin = requested_host.GetOrigin(); 91 GURL requested_origin = requested_host.GetOrigin();
58 92
59 // Do the security check before any others to avoid information leaks. 93 // Do the security check before any others to avoid information leaks.
60 if (page_location.GetOrigin() != requested_origin) 94 if (page_location.GetOrigin() != requested_origin)
61 return search_provider::DENIED; 95 return search_provider::DENIED;
62 96
63 // In incognito mode, no search information is exposed. (This check must be 97 // In incognito mode, no search information is exposed. (This check must be
64 // done after the security check or else a web site can detect that the 98 // done after the security check or else a web site can detect that the
65 // user is in incognito mode just by doing a cross origin request.) 99 // user is in incognito mode just by doing a cross origin request.)
66 if (is_off_the_record_) 100 if (is_off_the_record_)
67 return search_provider::NOT_INSTALLED; 101 return search_provider::NOT_INSTALLED;
68 102
69 switch (provider_data_.GetInstallState(requested_origin)) { 103 switch (provider_data_.GetInstallState(requested_origin)) {
70 case SearchProviderInstallData::NOT_INSTALLED: 104 case SearchProviderInstallData::NOT_INSTALLED:
71 return search_provider::NOT_INSTALLED; 105 return search_provider::NOT_INSTALLED;
72 106
73 case SearchProviderInstallData::INSTALLED_BUT_NOT_DEFAULT: 107 case SearchProviderInstallData::INSTALLED_BUT_NOT_DEFAULT:
74 return search_provider::INSTALLED_BUT_NOT_DEFAULT; 108 return search_provider::INSTALLED_BUT_NOT_DEFAULT;
75 109
76 case SearchProviderInstallData::INSTALLED_AS_DEFAULT: 110 case SearchProviderInstallData::INSTALLED_AS_DEFAULT:
77 return search_provider::INSTALLED_AS_DEFAULT; 111 return search_provider::INSTALLED_AS_DEFAULT;
78 } 112 }
79 113
80 NOTREACHED(); 114 NOTREACHED();
81 return search_provider::NOT_INSTALLED; 115 return search_provider::NOT_INSTALLED;
82 } 116 }
83 117
84 void 118 void SearchProviderInstallStateImpl::GetInstallState(
85 SearchProviderInstallStateMessageFilter::OnGetSearchProviderInstallState(
86 const GURL& page_location, 119 const GURL& page_location,
87 const GURL& requested_host, 120 const GURL& requested_host,
88 IPC::Message* reply_msg) { 121 const GetInstallStateCallback& callback) {
89 provider_data_.CallWhenLoaded( 122 DCHECK_CURRENTLY_ON(BrowserThread::IO);
90 base::Bind( 123 provider_data_.CallWhenLoaded(base::Bind(
91 &SearchProviderInstallStateMessageFilter:: 124 &SearchProviderInstallStateImpl::ReplyWithProviderInstallState,
92 ReplyWithProviderInstallState, 125 weak_factory_.GetWeakPtr(), page_location, requested_host, callback));
93 weak_factory_.GetWeakPtr(),
94 page_location,
95 requested_host,
96 reply_msg));
97 } 126 }
98 127
99 void SearchProviderInstallStateMessageFilter::ReplyWithProviderInstallState( 128 void SearchProviderInstallStateImpl::ReplyWithProviderInstallState(
100 const GURL& page_location, 129 const GURL& page_location,
101 const GURL& requested_host, 130 const GURL& requested_host,
102 IPC::Message* reply_msg) { 131 const GetInstallStateCallback& callback) {
103 DCHECK(reply_msg);
104 search_provider::InstallState install_state = 132 search_provider::InstallState install_state =
105 GetSearchProviderInstallState(page_location, requested_host); 133 GetSearchProviderInstallState(page_location, requested_host);
106 134
107 ChromeViewHostMsg_GetSearchProviderInstallState::WriteReplyParams( 135 callback.Run(install_state);
108 reply_msg,
109 install_state);
110 Send(reply_msg);
111 } 136 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698