OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/ui/webui/predictors/predictors_dom_handler.h" |
| 6 |
| 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" |
| 13 |
| 14 PredictorsDOMHandler::PredictorsDOMHandler(Profile* profile) { |
| 15 autocomplete_action_predictor_ = |
| 16 predictors::AutocompleteActionPredictorFactory::GetForProfile(profile); |
| 17 } |
| 18 |
| 19 PredictorsDOMHandler::~PredictorsDOMHandler() { } |
| 20 |
| 21 void PredictorsDOMHandler::RegisterMessages() { |
| 22 web_ui()->RegisterMessageCallback("requestAutocompleteActionPredictorDb", |
| 23 base::Bind( |
| 24 &PredictorsDOMHandler::RequestAutocompleteActionPredictorDb, |
| 25 base::Unretained(this))); |
| 26 } |
| 27 |
| 28 void PredictorsDOMHandler::RequestAutocompleteActionPredictorDb( |
| 29 const base::ListValue* args) { |
| 30 const bool enabled = (autocomplete_action_predictor_ != NULL); |
| 31 base::DictionaryValue dict; |
| 32 dict.SetBoolean("enabled", enabled); |
| 33 |
| 34 if (enabled) { |
| 35 base::ListValue* db = new base::ListValue(); |
| 36 for (predictors::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); |
| 48 } |
| 49 dict.Set("db", db); |
| 50 dict.SetDouble("hit_weight", |
| 51 predictors::AutocompleteActionPredictor::get_hit_weight()); |
| 52 } |
| 53 |
| 54 web_ui()->CallJavascriptFunction("updateDatabaseTable", dict); |
| 55 } |
OLD | NEW |