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

Side by Side Diff: chrome/browser/ui/webui/supervised_user_internals_message_handler.cc

Issue 2776493005: Convert SupervisedUserResourceThrottle to a NavigationThrottle. (Closed)
Patch Set: Response to comments Created 3 years, 8 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 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/webui/supervised_user_internals_message_handler.h" 5 #include "chrome/browser/ui/webui/supervised_user_internals_message_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/signin/account_tracker_service_factory.h" 17 #include "chrome/browser/signin/account_tracker_service_factory.h"
18 #include "chrome/browser/supervised_user/child_accounts/child_account_service.h" 18 #include "chrome/browser/supervised_user/child_accounts/child_account_service.h"
19 #include "chrome/browser/supervised_user/supervised_user_service.h" 19 #include "chrome/browser/supervised_user/supervised_user_service.h"
20 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" 20 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
21 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" 21 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
22 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" 22 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h"
23 #include "chrome/browser/supervised_user/supervised_user_url_filter.h"
23 #include "chrome/common/channel_info.h" 24 #include "chrome/common/channel_info.h"
24 #include "components/signin/core/browser/account_tracker_service.h" 25 #include "components/signin/core/browser/account_tracker_service.h"
25 #include "components/supervised_user_error_page/supervised_user_error_page.h" 26 #include "components/supervised_user_error_page/supervised_user_error_page.h"
26 #include "components/url_formatter/url_fixer.h" 27 #include "components/url_formatter/url_fixer.h"
27 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/web_ui.h" 29 #include "content/public/browser/web_ui.h"
29 30
30 using content::BrowserThread; 31 using content::BrowserThread;
31 32
32 namespace { 33 namespace {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return "Whitelist"; 108 return "Whitelist";
108 case supervised_user_error_page::NOT_SIGNED_IN: 109 case supervised_user_error_page::NOT_SIGNED_IN:
109 // Should never happen, only used for requests from WebView 110 // Should never happen, only used for requests from WebView
110 NOTREACHED(); 111 NOTREACHED();
111 } 112 }
112 return "Unknown/invalid"; 113 return "Unknown/invalid";
113 } 114 }
114 115
115 } // namespace 116 } // namespace
116 117
117 // Helper class that lives on the IO thread, listens to the
118 // SupervisedUserURLFilter there, and posts results back to the UI thread.
119 class SupervisedUserInternalsMessageHandler::IOThreadHelper
120 : public base::RefCountedThreadSafe<IOThreadHelper,
121 BrowserThread::DeleteOnIOThread>,
122 public SupervisedUserURLFilter::Observer {
123 public:
124 using OnURLCheckedCallback =
125 base::Callback<void(const GURL&,
126 SupervisedUserURLFilter::FilteringBehavior,
127 supervised_user_error_page::FilteringBehaviorReason,
128 bool uncertain)>;
129
130 IOThreadHelper(scoped_refptr<const SupervisedUserURLFilter> filter,
131 const OnURLCheckedCallback& callback)
132 : filter_(filter), callback_(callback) {
133 BrowserThread::PostTask(BrowserThread::IO,
134 FROM_HERE,
135 base::Bind(&IOThreadHelper::InitOnIOThread, this));
136 }
137
138 private:
139 friend class base::DeleteHelper<IOThreadHelper>;
140 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>;
141 virtual ~IOThreadHelper() {
142 DCHECK_CURRENTLY_ON(BrowserThread::IO);
143 filter_->RemoveObserver(this);
144 }
145
146 // SupervisedUserURLFilter::Observer:
147 void OnSiteListUpdated() override {}
148 void OnURLChecked(const GURL& url,
149 SupervisedUserURLFilter::FilteringBehavior behavior,
150 supervised_user_error_page::FilteringBehaviorReason reason,
151 bool uncertain) override {
152 BrowserThread::PostTask(BrowserThread::UI,
153 FROM_HERE,
154 base::Bind(callback_,
155 url, behavior, reason, uncertain));
156 }
157
158 void InitOnIOThread() {
159 DCHECK_CURRENTLY_ON(BrowserThread::IO);
160 filter_->AddObserver(this);
161 }
162
163 scoped_refptr<const SupervisedUserURLFilter> filter_;
164 OnURLCheckedCallback callback_;
165
166 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper);
167 };
168
169 SupervisedUserInternalsMessageHandler::SupervisedUserInternalsMessageHandler() 118 SupervisedUserInternalsMessageHandler::SupervisedUserInternalsMessageHandler()
170 : weak_factory_(this) { 119 : scoped_observer_(this), weak_factory_(this) {}
171 }
172 120
173 SupervisedUserInternalsMessageHandler:: 121 SupervisedUserInternalsMessageHandler::
174 ~SupervisedUserInternalsMessageHandler() { 122 ~SupervisedUserInternalsMessageHandler() {
175 } 123 }
176 124
177 void SupervisedUserInternalsMessageHandler::RegisterMessages() { 125 void SupervisedUserInternalsMessageHandler::RegisterMessages() {
178 DCHECK_CURRENTLY_ON(BrowserThread::UI); 126 DCHECK_CURRENTLY_ON(BrowserThread::UI);
179 127
180 web_ui()->RegisterMessageCallback("registerForEvents", 128 web_ui()->RegisterMessageCallback("registerForEvents",
181 base::Bind(&SupervisedUserInternalsMessageHandler:: 129 base::Bind(&SupervisedUserInternalsMessageHandler::
(...skipping 16 matching lines...) Expand all
198 SupervisedUserService* 146 SupervisedUserService*
199 SupervisedUserInternalsMessageHandler::GetSupervisedUserService() { 147 SupervisedUserInternalsMessageHandler::GetSupervisedUserService() {
200 Profile* profile = Profile::FromWebUI(web_ui()); 148 Profile* profile = Profile::FromWebUI(web_ui());
201 return SupervisedUserServiceFactory::GetForProfile( 149 return SupervisedUserServiceFactory::GetForProfile(
202 profile->GetOriginalProfile()); 150 profile->GetOriginalProfile());
203 } 151 }
204 152
205 void SupervisedUserInternalsMessageHandler::HandleRegisterForEvents( 153 void SupervisedUserInternalsMessageHandler::HandleRegisterForEvents(
206 const base::ListValue* args) { 154 const base::ListValue* args) {
207 DCHECK(args->empty()); 155 DCHECK(args->empty());
156 if (scoped_observer_.IsObservingSources())
157 return;
208 158
209 if (!io_thread_helper_.get()) { 159 scoped_observer_.Add(GetSupervisedUserService()->GetURLFilter());
210 io_thread_helper_ = new IOThreadHelper(
211 GetSupervisedUserService()->GetURLFilterForIOThread(),
212 base::Bind(&SupervisedUserInternalsMessageHandler::OnURLChecked,
213 weak_factory_.GetWeakPtr()));
214 }
215 } 160 }
216 161
217 void SupervisedUserInternalsMessageHandler::HandleGetBasicInfo( 162 void SupervisedUserInternalsMessageHandler::HandleGetBasicInfo(
218 const base::ListValue* args) { 163 const base::ListValue* args) {
219 SendBasicInfo(); 164 SendBasicInfo();
220 } 165 }
221 166
222 void SupervisedUserInternalsMessageHandler::HandleTryURL( 167 void SupervisedUserInternalsMessageHandler::HandleTryURL(
223 const base::ListValue* args) { 168 const base::ListValue* args) {
224 DCHECK_EQ(1u, args->GetSize()); 169 DCHECK_EQ(1u, args->GetSize());
225 std::string url_str; 170 std::string url_str;
226 if (!args->GetString(0, &url_str)) 171 if (!args->GetString(0, &url_str))
227 return; 172 return;
228 173
229 GURL url = url_formatter::FixupURL(url_str, std::string()); 174 GURL url = url_formatter::FixupURL(url_str, std::string());
230 if (!url.is_valid()) 175 if (!url.is_valid())
231 return; 176 return;
232 177
233 SupervisedUserURLFilter* filter = 178 SupervisedUserURLFilter* filter = GetSupervisedUserService()->GetURLFilter();
234 GetSupervisedUserService()->GetURLFilterForUIThread();
235 std::map<std::string, base::string16> whitelists = 179 std::map<std::string, base::string16> whitelists =
236 filter->GetMatchingWhitelistTitles(url); 180 filter->GetMatchingWhitelistTitles(url);
237 filter->GetFilteringBehaviorForURLWithAsyncChecks( 181 filter->GetFilteringBehaviorForURLWithAsyncChecks(
238 url, base::Bind(&SupervisedUserInternalsMessageHandler::OnTryURLResult, 182 url, base::Bind(&SupervisedUserInternalsMessageHandler::OnTryURLResult,
239 weak_factory_.GetWeakPtr(), whitelists)); 183 weak_factory_.GetWeakPtr(), whitelists));
240 } 184 }
241 185
242 void SupervisedUserInternalsMessageHandler::SendBasicInfo() { 186 void SupervisedUserInternalsMessageHandler::SendBasicInfo() {
243 std::unique_ptr<base::ListValue> section_list(new base::ListValue); 187 std::unique_ptr<base::ListValue> section_list(new base::ListValue);
244 188
245 base::ListValue* section_general = AddSection(section_list.get(), "General"); 189 base::ListValue* section_general = AddSection(section_list.get(), "General");
246 AddSectionEntry(section_general, "Chrome version", 190 AddSectionEntry(section_general, "Chrome version",
247 chrome::GetVersionString()); 191 chrome::GetVersionString());
248 AddSectionEntry(section_general, "Child detection enabled", 192 AddSectionEntry(section_general, "Child detection enabled",
249 ChildAccountService::IsChildAccountDetectionEnabled()); 193 ChildAccountService::IsChildAccountDetectionEnabled());
250 194
251 Profile* profile = Profile::FromWebUI(web_ui()); 195 Profile* profile = Profile::FromWebUI(web_ui());
252 196
253 base::ListValue* section_profile = AddSection(section_list.get(), "Profile"); 197 base::ListValue* section_profile = AddSection(section_list.get(), "Profile");
254 AddSectionEntry(section_profile, "Account", profile->GetProfileUserName()); 198 AddSectionEntry(section_profile, "Account", profile->GetProfileUserName());
255 AddSectionEntry(section_profile, "Legacy Supervised", 199 AddSectionEntry(section_profile, "Legacy Supervised",
256 profile->IsLegacySupervised()); 200 profile->IsLegacySupervised());
257 AddSectionEntry(section_profile, "Child", profile->IsChild()); 201 AddSectionEntry(section_profile, "Child", profile->IsChild());
258 202
259 SupervisedUserURLFilter* filter = 203 SupervisedUserURLFilter* filter = GetSupervisedUserService()->GetURLFilter();
260 GetSupervisedUserService()->GetURLFilterForUIThread();
261 204
262 base::ListValue* section_filter = AddSection(section_list.get(), "Filter"); 205 base::ListValue* section_filter = AddSection(section_list.get(), "Filter");
263 AddSectionEntry(section_filter, "Blacklist active", filter->HasBlacklist()); 206 AddSectionEntry(section_filter, "Blacklist active", filter->HasBlacklist());
264 AddSectionEntry(section_filter, "Online checks active", 207 AddSectionEntry(section_filter, "Online checks active",
265 filter->HasAsyncURLChecker()); 208 filter->HasAsyncURLChecker());
266 AddSectionEntry(section_filter, "Default behavior", 209 AddSectionEntry(section_filter, "Default behavior",
267 FilteringBehaviorToString( 210 FilteringBehaviorToString(
268 filter->GetDefaultFilteringBehavior())); 211 filter->GetDefaultFilteringBehavior()));
269 212
270 AccountTrackerService* account_tracker = 213 AccountTrackerService* account_tracker =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 base::DictionaryValue result; 263 base::DictionaryValue result;
321 result.SetString("allowResult", 264 result.SetString("allowResult",
322 FilteringBehaviorToString(behavior, uncertain)); 265 FilteringBehaviorToString(behavior, uncertain));
323 result.SetBoolean("manual", reason == supervised_user_error_page::MANUAL && 266 result.SetBoolean("manual", reason == supervised_user_error_page::MANUAL &&
324 behavior == SupervisedUserURLFilter::ALLOW); 267 behavior == SupervisedUserURLFilter::ALLOW);
325 result.SetString("whitelists", whitelists_str); 268 result.SetString("whitelists", whitelists_str);
326 web_ui()->CallJavascriptFunctionUnsafe( 269 web_ui()->CallJavascriptFunctionUnsafe(
327 "chrome.supervised_user_internals.receiveTryURLResult", result); 270 "chrome.supervised_user_internals.receiveTryURLResult", result);
328 } 271 }
329 272
273 void SupervisedUserInternalsMessageHandler::OnSiteListUpdated() {}
274
330 void SupervisedUserInternalsMessageHandler::OnURLChecked( 275 void SupervisedUserInternalsMessageHandler::OnURLChecked(
331 const GURL& url, 276 const GURL& url,
332 SupervisedUserURLFilter::FilteringBehavior behavior, 277 SupervisedUserURLFilter::FilteringBehavior behavior,
333 supervised_user_error_page::FilteringBehaviorReason reason, 278 supervised_user_error_page::FilteringBehaviorReason reason,
334 bool uncertain) { 279 bool uncertain) {
335 DCHECK_CURRENTLY_ON(BrowserThread::UI); 280 DCHECK_CURRENTLY_ON(BrowserThread::UI);
336 base::DictionaryValue result; 281 base::DictionaryValue result;
337 result.SetString("url", url.possibly_invalid_spec()); 282 result.SetString("url", url.possibly_invalid_spec());
338 result.SetString("result", FilteringBehaviorToString(behavior, uncertain)); 283 result.SetString("result", FilteringBehaviorToString(behavior, uncertain));
339 result.SetString("reason", FilteringBehaviorReasonToString(reason)); 284 result.SetString("reason", FilteringBehaviorReasonToString(reason));
340 web_ui()->CallJavascriptFunctionUnsafe( 285 web_ui()->CallJavascriptFunctionUnsafe(
341 "chrome.supervised_user_internals.receiveFilteringResult", result); 286 "chrome.supervised_user_internals.receiveFilteringResult", result);
342 } 287 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698