| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/ntp_tiles/webui/ntp_tiles_internals_message_handler.h" | 5 #include "components/ntp_tiles/webui/ntp_tiles_internals_message_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 return; | 91 return; |
| 92 } | 92 } |
| 93 | 93 |
| 94 const base::DictionaryValue* dict = nullptr; | 94 const base::DictionaryValue* dict = nullptr; |
| 95 DCHECK_EQ(1u, args->GetSize()); | 95 DCHECK_EQ(1u, args->GetSize()); |
| 96 args->GetDictionary(0, &dict); | 96 args->GetDictionary(0, &dict); |
| 97 DCHECK(dict); | 97 DCHECK(dict); |
| 98 | 98 |
| 99 PrefService* prefs = client_->GetPrefs(); | 99 PrefService* prefs = client_->GetPrefs(); |
| 100 | 100 |
| 101 if (most_visited_sites_->DoesSourceExist(ntp_tiles::NTPTileSource::POPULAR)) { | 101 if (most_visited_sites_->DoesSourceExist(ntp_tiles::TileSource::POPULAR)) { |
| 102 popular_sites_json_.clear(); | 102 popular_sites_json_.clear(); |
| 103 | 103 |
| 104 std::string url; | 104 std::string url; |
| 105 dict->GetString("popular.overrideURL", &url); | 105 dict->GetString("popular.overrideURL", &url); |
| 106 if (url.empty()) { | 106 if (url.empty()) { |
| 107 prefs->ClearPref(ntp_tiles::prefs::kPopularSitesOverrideURL); | 107 prefs->ClearPref(ntp_tiles::prefs::kPopularSitesOverrideURL); |
| 108 } else { | 108 } else { |
| 109 prefs->SetString(ntp_tiles::prefs::kPopularSitesOverrideURL, | 109 prefs->SetString(ntp_tiles::prefs::kPopularSitesOverrideURL, |
| 110 url_formatter::FixupURL(url, std::string()).spec()); | 110 url_formatter::FixupURL(url, std::string()).spec()); |
| 111 } | 111 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 132 // that will pick up changes to the Popular Sites overrides. | 132 // that will pick up changes to the Popular Sites overrides. |
| 133 most_visited_sites_ = client_->MakeMostVisitedSites(); | 133 most_visited_sites_ = client_->MakeMostVisitedSites(); |
| 134 most_visited_sites_->SetMostVisitedURLsObserver(this, site_count_); | 134 most_visited_sites_->SetMostVisitedURLsObserver(this, site_count_); |
| 135 SendSourceInfo(); | 135 SendSourceInfo(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void NTPTilesInternalsMessageHandler::HandleFetchSuggestions( | 138 void NTPTilesInternalsMessageHandler::HandleFetchSuggestions( |
| 139 const base::ListValue* args) { | 139 const base::ListValue* args) { |
| 140 DCHECK_EQ(0u, args->GetSize()); | 140 DCHECK_EQ(0u, args->GetSize()); |
| 141 if (!most_visited_sites_->DoesSourceExist( | 141 if (!most_visited_sites_->DoesSourceExist( |
| 142 ntp_tiles::NTPTileSource::SUGGESTIONS_SERVICE)) { | 142 ntp_tiles::TileSource::SUGGESTIONS_SERVICE)) { |
| 143 return; | 143 return; |
| 144 } | 144 } |
| 145 | 145 |
| 146 if (most_visited_sites_->suggestions()->FetchSuggestionsData()) { | 146 if (most_visited_sites_->suggestions()->FetchSuggestionsData()) { |
| 147 suggestions_status_ = "fetching..."; | 147 suggestions_status_ = "fetching..."; |
| 148 } else { | 148 } else { |
| 149 suggestions_status_ = "history sync is disabled, or not yet initialized"; | 149 suggestions_status_ = "history sync is disabled, or not yet initialized"; |
| 150 } | 150 } |
| 151 SendSourceInfo(); | 151 SendSourceInfo(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void NTPTilesInternalsMessageHandler::HandleViewPopularSitesJson( | 154 void NTPTilesInternalsMessageHandler::HandleViewPopularSitesJson( |
| 155 const base::ListValue* args) { | 155 const base::ListValue* args) { |
| 156 DCHECK_EQ(0u, args->GetSize()); | 156 DCHECK_EQ(0u, args->GetSize()); |
| 157 if (!most_visited_sites_->DoesSourceExist( | 157 if (!most_visited_sites_->DoesSourceExist(ntp_tiles::TileSource::POPULAR)) { |
| 158 ntp_tiles::NTPTileSource::POPULAR)) { | |
| 159 return; | 158 return; |
| 160 } | 159 } |
| 161 | 160 |
| 162 popular_sites_json_ = | 161 popular_sites_json_ = |
| 163 FormatJson(*most_visited_sites_->popular_sites()->GetCachedJson()); | 162 FormatJson(*most_visited_sites_->popular_sites()->GetCachedJson()); |
| 164 SendSourceInfo(); | 163 SendSourceInfo(); |
| 165 } | 164 } |
| 166 | 165 |
| 167 void NTPTilesInternalsMessageHandler::SendSourceInfo() { | 166 void NTPTilesInternalsMessageHandler::SendSourceInfo() { |
| 168 PrefService* prefs = client_->GetPrefs(); | 167 PrefService* prefs = client_->GetPrefs(); |
| 169 base::DictionaryValue value; | 168 base::DictionaryValue value; |
| 170 | 169 |
| 171 value.SetBoolean("topSites", most_visited_sites_->DoesSourceExist( | 170 value.SetBoolean("topSites", |
| 172 NTPTileSource::TOP_SITES)); | 171 most_visited_sites_->DoesSourceExist(TileSource::TOP_SITES)); |
| 173 value.SetBoolean("whitelist", most_visited_sites_->DoesSourceExist( | 172 value.SetBoolean("whitelist", |
| 174 NTPTileSource::WHITELIST)); | 173 most_visited_sites_->DoesSourceExist(TileSource::WHITELIST)); |
| 175 | 174 |
| 176 if (most_visited_sites_->DoesSourceExist( | 175 if (most_visited_sites_->DoesSourceExist(TileSource::SUGGESTIONS_SERVICE)) { |
| 177 NTPTileSource::SUGGESTIONS_SERVICE)) { | |
| 178 value.SetString("suggestionsService.status", suggestions_status_); | 176 value.SetString("suggestionsService.status", suggestions_status_); |
| 179 } else { | 177 } else { |
| 180 value.SetBoolean("suggestionsService", false); | 178 value.SetBoolean("suggestionsService", false); |
| 181 } | 179 } |
| 182 | 180 |
| 183 if (most_visited_sites_->DoesSourceExist(NTPTileSource::POPULAR)) { | 181 if (most_visited_sites_->DoesSourceExist(TileSource::POPULAR)) { |
| 184 auto* popular_sites = most_visited_sites_->popular_sites(); | 182 auto* popular_sites = most_visited_sites_->popular_sites(); |
| 185 value.SetString("popular.url", popular_sites->GetURLToFetch().spec()); | 183 value.SetString("popular.url", popular_sites->GetURLToFetch().spec()); |
| 186 value.SetString("popular.country", popular_sites->GetCountryToFetch()); | 184 value.SetString("popular.country", popular_sites->GetCountryToFetch()); |
| 187 value.SetString("popular.version", popular_sites->GetVersionToFetch()); | 185 value.SetString("popular.version", popular_sites->GetVersionToFetch()); |
| 188 | 186 |
| 189 value.SetString( | 187 value.SetString( |
| 190 "popular.overrideURL", | 188 "popular.overrideURL", |
| 191 prefs->GetString(ntp_tiles::prefs::kPopularSitesOverrideURL)); | 189 prefs->GetString(ntp_tiles::prefs::kPopularSitesOverrideURL)); |
| 192 value.SetString( | 190 value.SetString( |
| 193 "popular.overrideCountry", | 191 "popular.overrideCountry", |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 | 223 |
| 226 void NTPTilesInternalsMessageHandler::OnMostVisitedURLsAvailable( | 224 void NTPTilesInternalsMessageHandler::OnMostVisitedURLsAvailable( |
| 227 const NTPTilesVector& tiles) { | 225 const NTPTilesVector& tiles) { |
| 228 SendTiles(tiles); | 226 SendTiles(tiles); |
| 229 } | 227 } |
| 230 | 228 |
| 231 void NTPTilesInternalsMessageHandler::OnIconMadeAvailable( | 229 void NTPTilesInternalsMessageHandler::OnIconMadeAvailable( |
| 232 const GURL& site_url) {} | 230 const GURL& site_url) {} |
| 233 | 231 |
| 234 } // namespace ntp_tiles | 232 } // namespace ntp_tiles |
| OLD | NEW |