Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / webui / predictors / predictors_handler.cc
blobbd7f39b674624320ce6e2825a25df1b011c003c8
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/predictors/predictors_handler.h"
7 #include "base/bind.h"
8 #include "base/values.h"
9 #include "chrome/browser/predictors/autocomplete_action_predictor.h"
10 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "content/public/browser/web_ui.h"
14 using predictors::AutocompleteActionPredictor;
16 PredictorsHandler::PredictorsHandler(Profile* profile) {
17 autocomplete_action_predictor_ =
18 predictors::AutocompleteActionPredictorFactory::GetForProfile(profile);
21 PredictorsHandler::~PredictorsHandler() { }
23 void PredictorsHandler::RegisterMessages() {
24 web_ui()->RegisterMessageCallback("requestAutocompleteActionPredictorDb",
25 base::Bind(&PredictorsHandler::RequestAutocompleteActionPredictorDb,
26 base::Unretained(this)));
29 void PredictorsHandler::RequestAutocompleteActionPredictorDb(
30 const base::ListValue* args) {
31 const bool enabled = (autocomplete_action_predictor_ != NULL);
32 base::DictionaryValue dict;
33 dict.SetBoolean("enabled", enabled);
34 if (enabled) {
35 base::ListValue* db = new base::ListValue();
36 for (AutocompleteActionPredictor::DBCacheMap::const_iterator it =
37 autocomplete_action_predictor_->db_cache_.begin();
38 it != autocomplete_action_predictor_->db_cache_.end();
39 ++it) {
40 base::DictionaryValue* entry = new base::DictionaryValue();
41 entry->SetString("user_text", it->first.user_text);
42 entry->SetString("url", it->first.url.spec());
43 entry->SetInteger("hit_count", it->second.number_of_hits);
44 entry->SetInteger("miss_count", it->second.number_of_misses);
45 entry->SetDouble("confidence",
46 autocomplete_action_predictor_->CalculateConfidenceForDbEntry(it));
47 db->Append(entry);
49 dict.Set("db", db);
52 web_ui()->CallJavascriptFunction("updateAutocompleteActionPredictorDb", dict);