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

Side by Side Diff: chrome/browser/ui/webui/snippets_internals_message_handler.cc

Issue 2668263002: [NTP::Cleanup] Add brackets in snippets_internals_message_handler.cc. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/ui/webui/snippets_internals_message_handler.h" 5 #include "chrome/browser/ui/webui/snippets_internals_message_handler.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 web_ui()->RegisterMessageCallback( 134 web_ui()->RegisterMessageCallback(
135 "toggleDismissedSuggestions", 135 "toggleDismissedSuggestions",
136 base::Bind( 136 base::Bind(
137 &SnippetsInternalsMessageHandler::HandleToggleDismissedSuggestions, 137 &SnippetsInternalsMessageHandler::HandleToggleDismissedSuggestions,
138 base::Unretained(this))); 138 base::Unretained(this)));
139 139
140 content_suggestions_service_observer_.Add(content_suggestions_service_); 140 content_suggestions_service_observer_.Add(content_suggestions_service_);
141 } 141 }
142 142
143 void SnippetsInternalsMessageHandler::OnNewSuggestions(Category category) { 143 void SnippetsInternalsMessageHandler::OnNewSuggestions(Category category) {
144 if (!dom_loaded_) 144 if (!dom_loaded_) {
145 return; 145 return;
146 }
146 SendContentSuggestions(); 147 SendContentSuggestions();
147 } 148 }
148 149
149 void SnippetsInternalsMessageHandler::OnCategoryStatusChanged( 150 void SnippetsInternalsMessageHandler::OnCategoryStatusChanged(
150 Category category, 151 Category category,
151 CategoryStatus new_status) { 152 CategoryStatus new_status) {
152 if (!dom_loaded_) 153 if (!dom_loaded_) {
153 return; 154 return;
155 }
154 SendContentSuggestions(); 156 SendContentSuggestions();
155 } 157 }
156 158
157 void SnippetsInternalsMessageHandler::OnSuggestionInvalidated( 159 void SnippetsInternalsMessageHandler::OnSuggestionInvalidated(
158 const ntp_snippets::ContentSuggestion::ID& suggestion_id) { 160 const ntp_snippets::ContentSuggestion::ID& suggestion_id) {
159 if (!dom_loaded_) 161 if (!dom_loaded_) {
160 return; 162 return;
163 }
161 SendContentSuggestions(); 164 SendContentSuggestions();
162 } 165 }
163 166
164 void SnippetsInternalsMessageHandler::OnFullRefreshRequired() { 167 void SnippetsInternalsMessageHandler::OnFullRefreshRequired() {
165 if (!dom_loaded_) { 168 if (!dom_loaded_) {
166 return; 169 return;
167 } 170 }
168 SendContentSuggestions(); 171 SendContentSuggestions();
169 } 172 }
170 173
(...skipping 19 matching lines...) Expand all
190 193
191 SendAllContent(); 194 SendAllContent();
192 } 195 }
193 196
194 void SnippetsInternalsMessageHandler::HandleDownload( 197 void SnippetsInternalsMessageHandler::HandleDownload(
195 const base::ListValue* args) { 198 const base::ListValue* args) {
196 DCHECK_EQ(0u, args->GetSize()); 199 DCHECK_EQ(0u, args->GetSize());
197 200
198 SendString("remote-status", std::string()); 201 SendString("remote-status", std::string());
199 202
200 if (!remote_suggestions_provider_) 203 if (!remote_suggestions_provider_) {
201 return; 204 return;
205 }
202 206
203 remote_suggestions_provider_->ReloadSuggestions(); 207 remote_suggestions_provider_->ReloadSuggestions();
204 } 208 }
205 209
206 void SnippetsInternalsMessageHandler::HandleClearCachedSuggestions( 210 void SnippetsInternalsMessageHandler::HandleClearCachedSuggestions(
207 const base::ListValue* args) { 211 const base::ListValue* args) {
208 DCHECK_EQ(1u, args->GetSize()); 212 DCHECK_EQ(1u, args->GetSize());
209 213
210 int category_id; 214 int category_id;
211 if (!args->GetInteger(0, &category_id)) 215 if (!args->GetInteger(0, &category_id)) {
212 return; 216 return;
217 }
213 218
214 content_suggestions_service_->ClearCachedSuggestions( 219 content_suggestions_service_->ClearCachedSuggestions(
215 Category::FromIDValue(category_id)); 220 Category::FromIDValue(category_id));
216 SendContentSuggestions(); 221 SendContentSuggestions();
217 } 222 }
218 223
219 void SnippetsInternalsMessageHandler::HandleClearDismissedSuggestions( 224 void SnippetsInternalsMessageHandler::HandleClearDismissedSuggestions(
220 const base::ListValue* args) { 225 const base::ListValue* args) {
221 DCHECK_EQ(1u, args->GetSize()); 226 DCHECK_EQ(1u, args->GetSize());
222 227
223 int category_id; 228 int category_id;
224 if (!args->GetInteger(0, &category_id)) 229 if (!args->GetInteger(0, &category_id)) {
225 return; 230 return;
231 }
226 232
227 Category category = Category::FromIDValue(category_id); 233 Category category = Category::FromIDValue(category_id);
228 content_suggestions_service_->ClearDismissedSuggestionsForDebugging(category); 234 content_suggestions_service_->ClearDismissedSuggestionsForDebugging(category);
229 SendContentSuggestions(); 235 SendContentSuggestions();
230 dismissed_state_[category] = DismissedState::LOADING; 236 dismissed_state_[category] = DismissedState::LOADING;
231 content_suggestions_service_->GetDismissedSuggestionsForDebugging( 237 content_suggestions_service_->GetDismissedSuggestionsForDebugging(
232 category, 238 category,
233 base::Bind(&SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded, 239 base::Bind(&SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded,
234 weak_ptr_factory_.GetWeakPtr(), category)); 240 weak_ptr_factory_.GetWeakPtr(), category));
235 } 241 }
236 242
237 void SnippetsInternalsMessageHandler::HandleToggleDismissedSuggestions( 243 void SnippetsInternalsMessageHandler::HandleToggleDismissedSuggestions(
238 const base::ListValue* args) { 244 const base::ListValue* args) {
239 DCHECK_EQ(2u, args->GetSize()); 245 DCHECK_EQ(2u, args->GetSize());
240 246
241 int category_id; 247 int category_id;
242 if (!args->GetInteger(0, &category_id)) 248 if (!args->GetInteger(0, &category_id)) {
243 return; 249 return;
250 }
244 bool dismissed_visible; 251 bool dismissed_visible;
245 if (!args->GetBoolean(1, &dismissed_visible)) 252 if (!args->GetBoolean(1, &dismissed_visible)) {
246 return; 253 return;
254 }
247 255
248 Category category = Category::FromIDValue(category_id); 256 Category category = Category::FromIDValue(category_id);
249 if (dismissed_visible) { 257 if (dismissed_visible) {
250 dismissed_state_[category] = DismissedState::LOADING; 258 dismissed_state_[category] = DismissedState::LOADING;
251 content_suggestions_service_->GetDismissedSuggestionsForDebugging( 259 content_suggestions_service_->GetDismissedSuggestionsForDebugging(
252 category, 260 category,
253 base::Bind( 261 base::Bind(
254 &SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded, 262 &SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded,
255 weak_ptr_factory_.GetWeakPtr(), category)); 263 weak_ptr_factory_.GetWeakPtr(), category));
256 } else { 264 } else {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 category_entry->SetString("status", GetCategoryStatusName(status)); 386 category_entry->SetString("status", GetCategoryStatusName(status));
379 category_entry->Set("suggestions", std::move(suggestions_list)); 387 category_entry->Set("suggestions", std::move(suggestions_list));
380 category_entry->Set("dismissedSuggestions", std::move(dismissed_list)); 388 category_entry->Set("dismissedSuggestions", std::move(dismissed_list));
381 categories_list->Append(std::move(category_entry)); 389 categories_list->Append(std::move(category_entry));
382 } 390 }
383 391
384 if (remote_suggestions_provider_) { 392 if (remote_suggestions_provider_) {
385 const std::string& status = 393 const std::string& status =
386 remote_suggestions_provider_->suggestions_fetcher_for_debugging() 394 remote_suggestions_provider_->suggestions_fetcher_for_debugging()
387 ->last_status(); 395 ->last_status();
388 if (!status.empty()) 396 if (!status.empty()) {
389 SendString("remote-status", "Finished: " + status); 397 SendString("remote-status", "Finished: " + status);
398 }
390 } 399 }
391 400
392 base::DictionaryValue result; 401 base::DictionaryValue result;
393 result.Set("list", std::move(categories_list)); 402 result.Set("list", std::move(categories_list));
394 web_ui()->CallJavascriptFunctionUnsafe( 403 web_ui()->CallJavascriptFunctionUnsafe(
395 "chrome.SnippetsInternals.receiveContentSuggestions", result); 404 "chrome.SnippetsInternals.receiveContentSuggestions", result);
396 } 405 }
397 406
398 void SnippetsInternalsMessageHandler::SendBoolean(const std::string& name, 407 void SnippetsInternalsMessageHandler::SendBoolean(const std::string& name,
399 bool value) { 408 bool value) {
400 SendString(name, value ? "True" : "False"); 409 SendString(name, value ? "True" : "False");
401 } 410 }
402 411
403 void SnippetsInternalsMessageHandler::SendString(const std::string& name, 412 void SnippetsInternalsMessageHandler::SendString(const std::string& name,
404 const std::string& value) { 413 const std::string& value) {
405 base::StringValue string_name(name); 414 base::StringValue string_name(name);
406 base::StringValue string_value(value); 415 base::StringValue string_value(value);
407 416
408 web_ui()->CallJavascriptFunctionUnsafe( 417 web_ui()->CallJavascriptFunctionUnsafe(
409 "chrome.SnippetsInternals.receiveProperty", string_name, string_value); 418 "chrome.SnippetsInternals.receiveProperty", string_name, string_value);
410 } 419 }
411 420
412 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded( 421 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded(
413 Category category, 422 Category category,
414 std::vector<ContentSuggestion> dismissed_suggestions) { 423 std::vector<ContentSuggestion> dismissed_suggestions) {
415 if (dismissed_state_[category] == DismissedState::HIDDEN) 424 if (dismissed_state_[category] == DismissedState::HIDDEN) {
416 return; 425 return;
426 }
417 dismissed_suggestions_[category] = std::move(dismissed_suggestions); 427 dismissed_suggestions_[category] = std::move(dismissed_suggestions);
418 dismissed_state_[category] = DismissedState::VISIBLE; 428 dismissed_state_[category] = DismissedState::VISIBLE;
419 SendContentSuggestions(); 429 SendContentSuggestions();
420 } 430 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698