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

Unified Diff: chrome/browser/ui/webui/predictors/autocomplete_action_predictor_dom_handler.cc

Issue 9610006: Refactoring, moving and renaming the NetworkActionPredictor. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Resolved sync conflicts. Created 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/predictors/autocomplete_action_predictor_dom_handler.cc
diff --git a/chrome/browser/ui/webui/predictors/autocomplete_action_predictor_dom_handler.cc b/chrome/browser/ui/webui/predictors/autocomplete_action_predictor_dom_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a7743033acf3775441f37c0a06c00f5028a20446
--- /dev/null
+++ b/chrome/browser/ui/webui/predictors/autocomplete_action_predictor_dom_handler.cc
@@ -0,0 +1,60 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/webui/predictors/autocomplete_action_predictor_dom_handler.h"
+
+#include "base/bind.h"
+#include "base/values.h"
+#include "chrome/browser/predictors/autocomplete_action_predictor.h"
+#include "chrome/browser/predictors/autocomplete_action_predictor_factory.h"
+#include "chrome/browser/profiles/profile.h"
+#include "content/public/browser/web_ui.h"
+
+AutocompleteActionPredictorDOMHandler::AutocompleteActionPredictorDOMHandler(
+ Profile* profile) {
+ autocomplete_action_predictor_ =
+ AutocompleteActionPredictorFactory::GetForProfile(profile);
+}
+
+AutocompleteActionPredictorDOMHandler::~AutocompleteActionPredictorDOMHandler()
+{
+}
+
+void AutocompleteActionPredictorDOMHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback("requestAutocompleteActionPredictorDb",
+ base::Bind(
+ &AutocompleteActionPredictorDOMHandler::
+ RequestAutocompleteActionPredictorDb,
+ base::Unretained(this)));
+}
+
+void
+ AutocompleteActionPredictorDOMHandler::RequestAutocompleteActionPredictorDb(
+ const base::ListValue* args) {
+ const bool enabled = (autocomplete_action_predictor_ != NULL);
+ base::DictionaryValue dict;
+ dict.SetBoolean("enabled", enabled);
+
+ if (enabled) {
+ base::ListValue* db = new base::ListValue();
+ for (AutocompleteActionPredictor::DBCacheMap::const_iterator it =
+ autocomplete_action_predictor_->db_cache_.begin();
+ it != autocomplete_action_predictor_->db_cache_.end();
+ ++it) {
+ base::DictionaryValue* entry = new base::DictionaryValue();
+ entry->SetString("user_text", it->first.user_text);
+ entry->SetString("url", it->first.url.spec());
+ entry->SetInteger("hit_count", it->second.number_of_hits);
+ entry->SetInteger("miss_count", it->second.number_of_misses);
+ entry->SetDouble("confidence",
+ autocomplete_action_predictor_->CalculateConfidenceForDbEntry(it));
+ db->Append(entry);
+ }
+ dict.Set("db", db);
+ dict.SetDouble("hit_weight",
+ AutocompleteActionPredictor::get_hit_weight());
+ }
+
+ web_ui()->CallJavascriptFunction("updateDatabaseTable", dict);
+}

Powered by Google App Engine
This is Rietveld 408576698