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

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

Issue 2260783002: Make GetDismissedSuggestionsForDebugging asynchronous (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 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 #ifndef CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_MESSAGE_HANDLER_H_ 5 #ifndef CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_MESSAGE_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_MESSAGE_HANDLER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_MESSAGE_HANDLER_H_
7 7
8 #include <map>
8 #include <string> 9 #include <string>
10 #include <vector>
9 11
10 #include "base/macros.h" 12 #include "base/macros.h"
11 #include "base/scoped_observer.h" 13 #include "base/scoped_observer.h"
12 #include "components/ntp_snippets/category.h" 14 #include "components/ntp_snippets/category.h"
13 #include "components/ntp_snippets/category_status.h" 15 #include "components/ntp_snippets/category_status.h"
14 #include "components/ntp_snippets/content_suggestions_service.h" 16 #include "components/ntp_snippets/content_suggestions_service.h"
15 #include "components/ntp_snippets/ntp_snippets_service.h" 17 #include "components/ntp_snippets/ntp_snippets_service.h"
16 #include "content/public/browser/web_ui_message_handler.h" 18 #include "content/public/browser/web_ui_message_handler.h"
17 19
18 namespace base { 20 namespace base {
19 class ListValue; 21 class ListValue;
20 } // namespace base 22 } // namespace base
21 23
22 // The implementation for the chrome://snippets-internals page. 24 // The implementation for the chrome://snippets-internals page.
23 class SnippetsInternalsMessageHandler 25 class SnippetsInternalsMessageHandler
24 : public content::WebUIMessageHandler, 26 : public content::WebUIMessageHandler,
25 public ntp_snippets::ContentSuggestionsService::Observer { 27 public ntp_snippets::ContentSuggestionsService::Observer {
26 public: 28 public:
27 SnippetsInternalsMessageHandler(); 29 SnippetsInternalsMessageHandler();
28 ~SnippetsInternalsMessageHandler() override; 30 ~SnippetsInternalsMessageHandler() override;
29 31
30 private: 32 private:
33 enum class DismissedState { HIDDEN, LOADING, VISIBLE };
34
31 // content::WebUIMessageHandler: 35 // content::WebUIMessageHandler:
32 void RegisterMessages() override; 36 void RegisterMessages() override;
33 37
34 // ntp_snippets::ContentSuggestionsService::Observer: 38 // ntp_snippets::ContentSuggestionsService::Observer:
35 void OnNewSuggestions(ntp_snippets::Category category) override; 39 void OnNewSuggestions(ntp_snippets::Category category) override;
36 void OnCategoryStatusChanged( 40 void OnCategoryStatusChanged(
37 ntp_snippets::Category category, 41 ntp_snippets::Category category,
38 ntp_snippets::CategoryStatus new_status) override; 42 ntp_snippets::CategoryStatus new_status) override;
39 void OnSuggestionInvalidated(ntp_snippets::Category category, 43 void OnSuggestionInvalidated(ntp_snippets::Category category,
40 const std::string& suggestion_id) override; 44 const std::string& suggestion_id) override;
41 void ContentSuggestionsServiceShutdown() override; 45 void ContentSuggestionsServiceShutdown() override;
42 46
43 void HandleRefreshContent(const base::ListValue* args); 47 void HandleRefreshContent(const base::ListValue* args);
44 void HandleDownload(const base::ListValue* args); 48 void HandleDownload(const base::ListValue* args);
45 void HandleClearCachedSuggestions(const base::ListValue* args); 49 void HandleClearCachedSuggestions(const base::ListValue* args);
46 void HandleClearDismissedSuggestions(const base::ListValue* args); 50 void HandleClearDismissedSuggestions(const base::ListValue* args);
51 void HandleToggleDismissedSuggestions(const base::ListValue* args);
47 52
48 void SendAllContent(); 53 void SendAllContent();
49 void SendHosts(); 54 void SendHosts();
50 void SendContentSuggestions(); 55 void SendContentSuggestions();
51 void SendBoolean(const std::string& name, bool value); 56 void SendBoolean(const std::string& name, bool value);
52 void SendString(const std::string& name, const std::string& value); 57 void SendString(const std::string& name, const std::string& value);
53 58
59 void OnDismissedSuggestionsLoaded(
60 ntp_snippets::Category category,
61 std::vector<ntp_snippets::ContentSuggestion> dismissed_suggestions);
62
54 ScopedObserver<ntp_snippets::ContentSuggestionsService, 63 ScopedObserver<ntp_snippets::ContentSuggestionsService,
55 ntp_snippets::ContentSuggestionsService::Observer> 64 ntp_snippets::ContentSuggestionsService::Observer>
56 content_suggestions_service_observer_; 65 content_suggestions_service_observer_;
57 66
58 // Tracks whether we can already send messages to the page. 67 // Tracks whether we can already send messages to the page.
59 bool dom_loaded_; 68 bool dom_loaded_;
60 69
61 ntp_snippets::NTPSnippetsService* ntp_snippets_service_; 70 ntp_snippets::NTPSnippetsService* ntp_snippets_service_;
62 ntp_snippets::ContentSuggestionsService* content_suggestions_service_; 71 ntp_snippets::ContentSuggestionsService* content_suggestions_service_;
63 72
73 std::map<ntp_snippets::Category,
74 DismissedState,
75 ntp_snippets::Category::CompareByID>
76 dismissed_state_;
77 std::map<ntp_snippets::Category,
78 std::vector<ntp_snippets::ContentSuggestion>,
79 ntp_snippets::Category::CompareByID>
80 dismissed_suggestions_;
Marc Treib 2016/08/19 10:07:51 Maybe make a struct that contains DismissedState a
Philipp Keck 2016/08/19 12:11:53 Not sure that would help readability (except if it
81
64 DISALLOW_COPY_AND_ASSIGN(SnippetsInternalsMessageHandler); 82 DISALLOW_COPY_AND_ASSIGN(SnippetsInternalsMessageHandler);
65 }; 83 };
66 84
67 #endif // CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_MESSAGE_HANDLER_H_ 85 #endif // CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_MESSAGE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698