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

Side by Side Diff: chrome/browser/ui/webui/predictors/predictors_handler.cc

Issue 1995113002: Rename WebUI::CallJavascriptFunction to WebUI::CallJavascriptFunctionUnsafe (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 unified diff | Download patch
OLDNEW
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/predictors_handler.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"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 entry->SetString("url", it->first.url.spec()); 70 entry->SetString("url", it->first.url.spec());
71 entry->SetInteger("hit_count", it->second.number_of_hits); 71 entry->SetInteger("hit_count", it->second.number_of_hits);
72 entry->SetInteger("miss_count", it->second.number_of_misses); 72 entry->SetInteger("miss_count", it->second.number_of_misses);
73 entry->SetDouble("confidence", 73 entry->SetDouble("confidence",
74 autocomplete_action_predictor_->CalculateConfidenceForDbEntry(it)); 74 autocomplete_action_predictor_->CalculateConfidenceForDbEntry(it));
75 db->Append(entry); 75 db->Append(entry);
76 } 76 }
77 dict.Set("db", db); 77 dict.Set("db", db);
78 } 78 }
79 79
80 web_ui()->CallJavascriptFunction("updateAutocompleteActionPredictorDb", dict); 80 web_ui()->CallJavascriptFunctionUnsafe("updateAutocompleteActionPredictorDb",
81 dict);
81 } 82 }
82 83
83 void PredictorsHandler::RequestResourcePrefetchPredictorDb( 84 void PredictorsHandler::RequestResourcePrefetchPredictorDb(
84 const base::ListValue* args) { 85 const base::ListValue* args) {
85 const bool enabled = (resource_prefetch_predictor_ != NULL); 86 const bool enabled = (resource_prefetch_predictor_ != NULL);
86 base::DictionaryValue dict; 87 base::DictionaryValue dict;
87 dict.SetBoolean("enabled", enabled); 88 dict.SetBoolean("enabled", enabled);
88 89
89 if (enabled) { 90 if (enabled) {
90 // Url Database cache. 91 // Url Database cache.
91 base::ListValue* db = new base::ListValue(); 92 base::ListValue* db = new base::ListValue();
92 AddPrefetchDataMapToListValue( 93 AddPrefetchDataMapToListValue(
93 *resource_prefetch_predictor_->url_table_cache_, db); 94 *resource_prefetch_predictor_->url_table_cache_, db);
94 dict.Set("url_db", db); 95 dict.Set("url_db", db);
95 96
96 db = new base::ListValue(); 97 db = new base::ListValue();
97 AddPrefetchDataMapToListValue( 98 AddPrefetchDataMapToListValue(
98 *resource_prefetch_predictor_->host_table_cache_, db); 99 *resource_prefetch_predictor_->host_table_cache_, db);
99 dict.Set("host_db", db); 100 dict.Set("host_db", db);
100 } 101 }
101 102
102 web_ui()->CallJavascriptFunction("updateResourcePrefetchPredictorDb", dict); 103 web_ui()->CallJavascriptFunctionUnsafe("updateResourcePrefetchPredictorDb",
104 dict);
103 } 105 }
104 106
105 void PredictorsHandler::AddPrefetchDataMapToListValue( 107 void PredictorsHandler::AddPrefetchDataMapToListValue(
106 const ResourcePrefetchPredictor::PrefetchDataMap& data_map, 108 const ResourcePrefetchPredictor::PrefetchDataMap& data_map,
107 base::ListValue* db) const { 109 base::ListValue* db) const {
108 for (ResourcePrefetchPredictor::PrefetchDataMap::const_iterator it = 110 for (ResourcePrefetchPredictor::PrefetchDataMap::const_iterator it =
109 data_map.begin(); it != data_map.end(); ++it) { 111 data_map.begin(); it != data_map.end(); ++it) {
110 base::DictionaryValue* main = new base::DictionaryValue(); 112 base::DictionaryValue* main = new base::DictionaryValue();
111 main->SetString("main_frame_url", it->first); 113 main->SetString("main_frame_url", it->first);
112 base::ListValue* resources = new base::ListValue(); 114 base::ListValue* resources = new base::ListValue();
113 for (ResourcePrefetchPredictor::ResourceRows::const_iterator 115 for (ResourcePrefetchPredictor::ResourceRows::const_iterator
114 row = it->second.resources.begin(); 116 row = it->second.resources.begin();
115 row != it->second.resources.end(); ++row) { 117 row != it->second.resources.end(); ++row) {
116 base::DictionaryValue* resource = new base::DictionaryValue(); 118 base::DictionaryValue* resource = new base::DictionaryValue();
117 resource->SetString("resource_url", row->resource_url.spec()); 119 resource->SetString("resource_url", row->resource_url.spec());
118 resource->SetString("resource_type", 120 resource->SetString("resource_type",
119 ConvertResourceType(row->resource_type)); 121 ConvertResourceType(row->resource_type));
120 resource->SetInteger("number_of_hits", row->number_of_hits); 122 resource->SetInteger("number_of_hits", row->number_of_hits);
121 resource->SetInteger("number_of_misses", row->number_of_misses); 123 resource->SetInteger("number_of_misses", row->number_of_misses);
122 resource->SetInteger("consecutive_misses", row->consecutive_misses); 124 resource->SetInteger("consecutive_misses", row->consecutive_misses);
123 resource->SetDouble("position", row->average_position); 125 resource->SetDouble("position", row->average_position);
124 resource->SetDouble("score", row->score); 126 resource->SetDouble("score", row->score);
125 resources->Append(resource); 127 resources->Append(resource);
126 } 128 }
127 main->Set("resources", resources); 129 main->Set("resources", resources);
128 db->Append(main); 130 db->Append(main);
129 } 131 }
130 } 132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698