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> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/predictors/autocomplete_action_predictor.h" | 12 #include "chrome/browser/predictors/autocomplete_action_predictor.h" |
13 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" | 13 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" |
14 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 14 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
15 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" | 15 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" |
16 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" | 16 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "content/public/browser/web_ui.h" | 18 #include "content/public/browser/web_ui.h" |
19 #include "content/public/common/resource_type.h" | 19 #include "content/public/common/resource_type.h" |
20 | 20 |
21 using predictors::AutocompleteActionPredictor; | 21 using predictors::AutocompleteActionPredictor; |
22 using predictors::ResourcePrefetchPredictor; | 22 using predictors::ResourcePrefetchPredictor; |
23 using predictors::ResourcePrefetchPredictorTables; | 23 using predictors::ResourcePrefetchPredictorTables; |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 std::string ConvertResourceType(content::ResourceType type) { | 27 using ::chrome_browser_predictors::ResourceData; |
| 28 using ResourceType = ::chrome_browser_predictors::ResourceData_ResourceType; |
| 29 |
| 30 std::string ConvertResourceType(ResourceType type) { |
28 switch (type) { | 31 switch (type) { |
29 case content::RESOURCE_TYPE_IMAGE: | 32 case ResourceData::RESOURCE_TYPE_IMAGE: |
30 return "Image"; | 33 return "Image"; |
31 case content::RESOURCE_TYPE_STYLESHEET: | 34 case ResourceData::RESOURCE_TYPE_STYLESHEET: |
32 return "Stylesheet"; | 35 return "Stylesheet"; |
33 case content::RESOURCE_TYPE_SCRIPT: | 36 case ResourceData::RESOURCE_TYPE_SCRIPT: |
34 return "Script"; | 37 return "Script"; |
| 38 case ResourceData::RESOURCE_TYPE_FONT_RESOURCE: |
| 39 return "Font"; |
35 default: | 40 default: |
36 return "Unknown"; | 41 return "Unknown"; |
37 } | 42 } |
38 } | 43 } |
39 | 44 |
40 } // namespace | 45 } // namespace |
41 | 46 |
42 PredictorsHandler::PredictorsHandler(Profile* profile) { | 47 PredictorsHandler::PredictorsHandler(Profile* profile) { |
43 autocomplete_action_predictor_ = | 48 autocomplete_action_predictor_ = |
44 predictors::AutocompleteActionPredictorFactory::GetForProfile(profile); | 49 predictors::AutocompleteActionPredictorFactory::GetForProfile(profile); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 dict.Set("host_db", db); | 108 dict.Set("host_db", db); |
104 } | 109 } |
105 | 110 |
106 web_ui()->CallJavascriptFunctionUnsafe("updateResourcePrefetchPredictorDb", | 111 web_ui()->CallJavascriptFunctionUnsafe("updateResourcePrefetchPredictorDb", |
107 dict); | 112 dict); |
108 } | 113 } |
109 | 114 |
110 void PredictorsHandler::AddPrefetchDataMapToListValue( | 115 void PredictorsHandler::AddPrefetchDataMapToListValue( |
111 const ResourcePrefetchPredictor::PrefetchDataMap& data_map, | 116 const ResourcePrefetchPredictor::PrefetchDataMap& data_map, |
112 base::ListValue* db) const { | 117 base::ListValue* db) const { |
113 for (ResourcePrefetchPredictor::PrefetchDataMap::const_iterator it = | 118 for (const auto& p : data_map) { |
114 data_map.begin(); it != data_map.end(); ++it) { | |
115 std::unique_ptr<base::DictionaryValue> main(new base::DictionaryValue()); | 119 std::unique_ptr<base::DictionaryValue> main(new base::DictionaryValue()); |
116 main->SetString("main_frame_url", it->first); | 120 main->SetString("main_frame_url", p.first); |
117 base::ListValue* resources = new base::ListValue(); | 121 base::ListValue* resources = new base::ListValue(); |
118 for (ResourcePrefetchPredictor::ResourceRows::const_iterator | 122 for (const ResourceData& r : p.second.resources) { |
119 row = it->second.resources.begin(); | |
120 row != it->second.resources.end(); ++row) { | |
121 std::unique_ptr<base::DictionaryValue> resource( | 123 std::unique_ptr<base::DictionaryValue> resource( |
122 new base::DictionaryValue()); | 124 new base::DictionaryValue()); |
123 resource->SetString("resource_url", row->resource_url.spec()); | 125 resource->SetString("resource_url", r.resource_url()); |
124 resource->SetString("resource_type", | 126 resource->SetString("resource_type", |
125 ConvertResourceType(row->resource_type)); | 127 ConvertResourceType(r.resource_type())); |
126 resource->SetInteger("number_of_hits", row->number_of_hits); | 128 resource->SetInteger("number_of_hits", r.number_of_hits()); |
127 resource->SetInteger("number_of_misses", row->number_of_misses); | 129 resource->SetInteger("number_of_misses", r.number_of_misses()); |
128 resource->SetInteger("consecutive_misses", row->consecutive_misses); | 130 resource->SetInteger("consecutive_misses", r.consecutive_misses()); |
129 resource->SetDouble("position", row->average_position); | 131 resource->SetDouble("position", r.average_position()); |
130 resource->SetDouble("score", row->score); | 132 resource->SetDouble("score", r.score()); |
131 resources->Append(std::move(resource)); | 133 resources->Append(std::move(resource)); |
132 } | 134 } |
133 main->Set("resources", resources); | 135 main->Set("resources", resources); |
134 db->Append(std::move(main)); | 136 db->Append(std::move(main)); |
135 } | 137 } |
136 } | 138 } |
OLD | NEW |