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_dom_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 PredictorsDOMHandler::PredictorsDOMHandler(Profile* profile) { |
15 Profile* profile) { | |
16 autocomplete_action_predictor_ = | 15 autocomplete_action_predictor_ = |
17 AutocompleteActionPredictorFactory::GetForProfile(profile); | 16 predictors::AutocompleteActionPredictorFactory::GetForProfile(profile); |
18 } | 17 } |
19 | 18 |
20 AutocompleteActionPredictorDOMHandler::~AutocompleteActionPredictorDOMHandler() | 19 PredictorsDOMHandler::~PredictorsDOMHandler() { } |
21 { | |
22 } | |
23 | 20 |
24 void AutocompleteActionPredictorDOMHandler::RegisterMessages() { | 21 void PredictorsDOMHandler::RegisterMessages() { |
25 web_ui()->RegisterMessageCallback("requestAutocompleteActionPredictorDb", | 22 web_ui()->RegisterMessageCallback("requestAutocompleteActionPredictorDb", |
26 base::Bind( | 23 base::Bind( |
27 &AutocompleteActionPredictorDOMHandler:: | 24 &PredictorsDOMHandler::RequestAutocompleteActionPredictorDb, |
28 RequestAutocompleteActionPredictorDb, | |
29 base::Unretained(this))); | 25 base::Unretained(this))); |
30 } | 26 } |
31 | 27 |
32 void | 28 void PredictorsDOMHandler::RequestAutocompleteActionPredictorDb( |
33 AutocompleteActionPredictorDOMHandler::RequestAutocompleteActionPredictorDb( | 29 const base::ListValue* args) { |
34 const base::ListValue* args) { | |
35 const bool enabled = (autocomplete_action_predictor_ != NULL); | 30 const bool enabled = (autocomplete_action_predictor_ != NULL); |
36 base::DictionaryValue dict; | 31 base::DictionaryValue dict; |
37 dict.SetBoolean("enabled", enabled); | 32 dict.SetBoolean("enabled", enabled); |
38 | 33 |
39 if (enabled) { | 34 if (enabled) { |
40 base::ListValue* db = new base::ListValue(); | 35 base::ListValue* db = new base::ListValue(); |
41 for (AutocompleteActionPredictor::DBCacheMap::const_iterator it = | 36 for (predictors::AutocompleteActionPredictor::DBCacheMap::const_iterator it |
Evan Stade
2012/05/09 21:34:30
I would add a using predictors::AutocompleteAction
Shishir
2012/05/09 21:47:22
Done.
| |
42 autocomplete_action_predictor_->db_cache_.begin(); | 37 = autocomplete_action_predictor_->db_cache_.begin(); |
43 it != autocomplete_action_predictor_->db_cache_.end(); | 38 it != autocomplete_action_predictor_->db_cache_.end(); |
44 ++it) { | 39 ++it) { |
45 base::DictionaryValue* entry = new base::DictionaryValue(); | 40 base::DictionaryValue* entry = new base::DictionaryValue(); |
46 entry->SetString("user_text", it->first.user_text); | 41 entry->SetString("user_text", it->first.user_text); |
47 entry->SetString("url", it->first.url.spec()); | 42 entry->SetString("url", it->first.url.spec()); |
48 entry->SetInteger("hit_count", it->second.number_of_hits); | 43 entry->SetInteger("hit_count", it->second.number_of_hits); |
49 entry->SetInteger("miss_count", it->second.number_of_misses); | 44 entry->SetInteger("miss_count", it->second.number_of_misses); |
50 entry->SetDouble("confidence", | 45 entry->SetDouble("confidence", |
51 autocomplete_action_predictor_->CalculateConfidenceForDbEntry(it)); | 46 autocomplete_action_predictor_->CalculateConfidenceForDbEntry(it)); |
52 db->Append(entry); | 47 db->Append(entry); |
53 } | 48 } |
54 dict.Set("db", db); | 49 dict.Set("db", db); |
55 dict.SetDouble("hit_weight", | 50 dict.SetDouble("hit_weight", |
56 AutocompleteActionPredictor::get_hit_weight()); | 51 predictors::AutocompleteActionPredictor::get_hit_weight()); |
57 } | 52 } |
58 | 53 |
59 web_ui()->CallJavascriptFunction("updateDatabaseTable", dict); | 54 web_ui()->CallJavascriptFunction("updateDatabaseTable", dict); |
60 } | 55 } |
OLD | NEW |