| 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/predictors_handler.h" | 5 #include "chrome/browser/ui/webui/predictors/predictors_handler.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 #include <utility> |
| 9 |
| 7 #include "base/bind.h" | 10 #include "base/bind.h" |
| 8 #include "base/values.h" | 11 #include "base/values.h" |
| 9 #include "chrome/browser/predictors/autocomplete_action_predictor.h" | 12 #include "chrome/browser/predictors/autocomplete_action_predictor.h" |
| 10 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" | 13 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" |
| 11 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 14 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 12 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" | 15 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" |
| 13 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" | 16 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 15 #include "content/public/browser/web_ui.h" | 18 #include "content/public/browser/web_ui.h" |
| 16 #include "content/public/common/resource_type.h" | 19 #include "content/public/common/resource_type.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 const base::ListValue* args) { | 61 const base::ListValue* args) { |
| 59 const bool enabled = (autocomplete_action_predictor_ != NULL); | 62 const bool enabled = (autocomplete_action_predictor_ != NULL); |
| 60 base::DictionaryValue dict; | 63 base::DictionaryValue dict; |
| 61 dict.SetBoolean("enabled", enabled); | 64 dict.SetBoolean("enabled", enabled); |
| 62 if (enabled) { | 65 if (enabled) { |
| 63 base::ListValue* db = new base::ListValue(); | 66 base::ListValue* db = new base::ListValue(); |
| 64 for (AutocompleteActionPredictor::DBCacheMap::const_iterator it = | 67 for (AutocompleteActionPredictor::DBCacheMap::const_iterator it = |
| 65 autocomplete_action_predictor_->db_cache_.begin(); | 68 autocomplete_action_predictor_->db_cache_.begin(); |
| 66 it != autocomplete_action_predictor_->db_cache_.end(); | 69 it != autocomplete_action_predictor_->db_cache_.end(); |
| 67 ++it) { | 70 ++it) { |
| 68 base::DictionaryValue* entry = new base::DictionaryValue(); | 71 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue()); |
| 69 entry->SetString("user_text", it->first.user_text); | 72 entry->SetString("user_text", it->first.user_text); |
| 70 entry->SetString("url", it->first.url.spec()); | 73 entry->SetString("url", it->first.url.spec()); |
| 71 entry->SetInteger("hit_count", it->second.number_of_hits); | 74 entry->SetInteger("hit_count", it->second.number_of_hits); |
| 72 entry->SetInteger("miss_count", it->second.number_of_misses); | 75 entry->SetInteger("miss_count", it->second.number_of_misses); |
| 73 entry->SetDouble("confidence", | 76 entry->SetDouble("confidence", |
| 74 autocomplete_action_predictor_->CalculateConfidenceForDbEntry(it)); | 77 autocomplete_action_predictor_->CalculateConfidenceForDbEntry(it)); |
| 75 db->Append(entry); | 78 db->Append(std::move(entry)); |
| 76 } | 79 } |
| 77 dict.Set("db", db); | 80 dict.Set("db", db); |
| 78 } | 81 } |
| 79 | 82 |
| 80 web_ui()->CallJavascriptFunctionUnsafe("updateAutocompleteActionPredictorDb", | 83 web_ui()->CallJavascriptFunctionUnsafe("updateAutocompleteActionPredictorDb", |
| 81 dict); | 84 dict); |
| 82 } | 85 } |
| 83 | 86 |
| 84 void PredictorsHandler::RequestResourcePrefetchPredictorDb( | 87 void PredictorsHandler::RequestResourcePrefetchPredictorDb( |
| 85 const base::ListValue* args) { | 88 const base::ListValue* args) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 102 | 105 |
| 103 web_ui()->CallJavascriptFunctionUnsafe("updateResourcePrefetchPredictorDb", | 106 web_ui()->CallJavascriptFunctionUnsafe("updateResourcePrefetchPredictorDb", |
| 104 dict); | 107 dict); |
| 105 } | 108 } |
| 106 | 109 |
| 107 void PredictorsHandler::AddPrefetchDataMapToListValue( | 110 void PredictorsHandler::AddPrefetchDataMapToListValue( |
| 108 const ResourcePrefetchPredictor::PrefetchDataMap& data_map, | 111 const ResourcePrefetchPredictor::PrefetchDataMap& data_map, |
| 109 base::ListValue* db) const { | 112 base::ListValue* db) const { |
| 110 for (ResourcePrefetchPredictor::PrefetchDataMap::const_iterator it = | 113 for (ResourcePrefetchPredictor::PrefetchDataMap::const_iterator it = |
| 111 data_map.begin(); it != data_map.end(); ++it) { | 114 data_map.begin(); it != data_map.end(); ++it) { |
| 112 base::DictionaryValue* main = new base::DictionaryValue(); | 115 std::unique_ptr<base::DictionaryValue> main(new base::DictionaryValue()); |
| 113 main->SetString("main_frame_url", it->first); | 116 main->SetString("main_frame_url", it->first); |
| 114 base::ListValue* resources = new base::ListValue(); | 117 base::ListValue* resources = new base::ListValue(); |
| 115 for (ResourcePrefetchPredictor::ResourceRows::const_iterator | 118 for (ResourcePrefetchPredictor::ResourceRows::const_iterator |
| 116 row = it->second.resources.begin(); | 119 row = it->second.resources.begin(); |
| 117 row != it->second.resources.end(); ++row) { | 120 row != it->second.resources.end(); ++row) { |
| 118 base::DictionaryValue* resource = new base::DictionaryValue(); | 121 std::unique_ptr<base::DictionaryValue> resource( |
| 122 new base::DictionaryValue()); |
| 119 resource->SetString("resource_url", row->resource_url.spec()); | 123 resource->SetString("resource_url", row->resource_url.spec()); |
| 120 resource->SetString("resource_type", | 124 resource->SetString("resource_type", |
| 121 ConvertResourceType(row->resource_type)); | 125 ConvertResourceType(row->resource_type)); |
| 122 resource->SetInteger("number_of_hits", row->number_of_hits); | 126 resource->SetInteger("number_of_hits", row->number_of_hits); |
| 123 resource->SetInteger("number_of_misses", row->number_of_misses); | 127 resource->SetInteger("number_of_misses", row->number_of_misses); |
| 124 resource->SetInteger("consecutive_misses", row->consecutive_misses); | 128 resource->SetInteger("consecutive_misses", row->consecutive_misses); |
| 125 resource->SetDouble("position", row->average_position); | 129 resource->SetDouble("position", row->average_position); |
| 126 resource->SetDouble("score", row->score); | 130 resource->SetDouble("score", row->score); |
| 127 resources->Append(resource); | 131 resources->Append(std::move(resource)); |
| 128 } | 132 } |
| 129 main->Set("resources", resources); | 133 main->Set("resources", resources); |
| 130 db->Append(main); | 134 db->Append(std::move(main)); |
| 131 } | 135 } |
| 132 } | 136 } |
| OLD | NEW |