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/ui/webui/predictors/autocomplete_action_predictor_dom_h
andler.h" | 5 #include "chrome/browser/ui/webui/predictors/predictors_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/predictors/autocomplete_action_predictor.h" | 9 #include "chrome/browser/predictors/autocomplete_action_predictor.h" |
10 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" | 10 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "content/public/browser/web_ui.h" | 12 #include "content/public/browser/web_ui.h" |
13 | 13 |
14 AutocompleteActionPredictorDOMHandler::AutocompleteActionPredictorDOMHandler( | 14 using predictors::AutocompleteActionPredictor; |
15 Profile* profile) { | 15 |
| 16 PredictorsHandler::PredictorsHandler(Profile* profile) { |
16 autocomplete_action_predictor_ = | 17 autocomplete_action_predictor_ = |
17 AutocompleteActionPredictorFactory::GetForProfile(profile); | 18 predictors::AutocompleteActionPredictorFactory::GetForProfile(profile); |
18 } | 19 } |
19 | 20 |
20 AutocompleteActionPredictorDOMHandler::~AutocompleteActionPredictorDOMHandler() | 21 PredictorsHandler::~PredictorsHandler() { } |
21 { | 22 |
| 23 void PredictorsHandler::RegisterMessages() { |
| 24 web_ui()->RegisterMessageCallback("requestAutocompleteActionPredictorDb", |
| 25 base::Bind(&PredictorsHandler::RequestAutocompleteActionPredictorDb, |
| 26 base::Unretained(this))); |
22 } | 27 } |
23 | 28 |
24 void AutocompleteActionPredictorDOMHandler::RegisterMessages() { | 29 void PredictorsHandler::RequestAutocompleteActionPredictorDb( |
25 web_ui()->RegisterMessageCallback("requestAutocompleteActionPredictorDb", | 30 const base::ListValue* args) { |
26 base::Bind( | |
27 &AutocompleteActionPredictorDOMHandler:: | |
28 RequestAutocompleteActionPredictorDb, | |
29 base::Unretained(this))); | |
30 } | |
31 | |
32 void | |
33 AutocompleteActionPredictorDOMHandler::RequestAutocompleteActionPredictorDb( | |
34 const base::ListValue* args) { | |
35 const bool enabled = (autocomplete_action_predictor_ != NULL); | 31 const bool enabled = (autocomplete_action_predictor_ != NULL); |
36 base::DictionaryValue dict; | 32 base::DictionaryValue dict; |
37 dict.SetBoolean("enabled", enabled); | 33 dict.SetBoolean("enabled", enabled); |
38 | 34 |
39 if (enabled) { | 35 if (enabled) { |
40 base::ListValue* db = new base::ListValue(); | 36 base::ListValue* db = new base::ListValue(); |
41 for (AutocompleteActionPredictor::DBCacheMap::const_iterator it = | 37 for (AutocompleteActionPredictor::DBCacheMap::const_iterator it = |
42 autocomplete_action_predictor_->db_cache_.begin(); | 38 autocomplete_action_predictor_->db_cache_.begin(); |
43 it != autocomplete_action_predictor_->db_cache_.end(); | 39 it != autocomplete_action_predictor_->db_cache_.end(); |
44 ++it) { | 40 ++it) { |
45 base::DictionaryValue* entry = new base::DictionaryValue(); | 41 base::DictionaryValue* entry = new base::DictionaryValue(); |
46 entry->SetString("user_text", it->first.user_text); | 42 entry->SetString("user_text", it->first.user_text); |
47 entry->SetString("url", it->first.url.spec()); | 43 entry->SetString("url", it->first.url.spec()); |
48 entry->SetInteger("hit_count", it->second.number_of_hits); | 44 entry->SetInteger("hit_count", it->second.number_of_hits); |
49 entry->SetInteger("miss_count", it->second.number_of_misses); | 45 entry->SetInteger("miss_count", it->second.number_of_misses); |
50 entry->SetDouble("confidence", | 46 entry->SetDouble("confidence", |
51 autocomplete_action_predictor_->CalculateConfidenceForDbEntry(it)); | 47 autocomplete_action_predictor_->CalculateConfidenceForDbEntry(it)); |
52 db->Append(entry); | 48 db->Append(entry); |
53 } | 49 } |
54 dict.Set("db", db); | 50 dict.Set("db", db); |
55 dict.SetDouble("hit_weight", | 51 dict.SetDouble("hit_weight", AutocompleteActionPredictor::get_hit_weight()); |
56 AutocompleteActionPredictor::get_hit_weight()); | |
57 } | 52 } |
58 | 53 |
59 web_ui()->CallJavascriptFunction("updateDatabaseTable", dict); | 54 web_ui()->CallJavascriptFunction("updateDatabaseTable", dict); |
60 } | 55 } |
OLD | NEW |