OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_NTP_SNIPPETS_SESSIONS_FOREIGN_SESSIONS_SUGGESTIONS_PROVIDER_H _ | |
6 #define COMPONENTS_NTP_SNIPPETS_SESSIONS_FOREIGN_SESSIONS_SUGGESTIONS_PROVIDER_H _ | |
7 | |
8 #include <memory> | |
9 #include <set> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/macros.h" | |
14 #include "components/ntp_snippets/category.h" | |
15 #include "components/ntp_snippets/category_status.h" | |
16 #include "components/ntp_snippets/content_suggestions_provider.h" | |
17 #include "components/sync_sessions/synced_session.h" | |
18 | |
19 class PrefRegistrySimple; | |
20 class PrefService; | |
21 | |
22 namespace sync_driver { | |
23 class OpenTabsUIDelegate; | |
24 } // namespace sync_driver | |
25 | |
26 namespace ntp_snippets { | |
27 | |
28 // Provides content suggestions from foreign sessions. | |
29 class ForeignSessionsSuggestionsProvider : public ContentSuggestionsProvider { | |
30 public: | |
31 // Simple interface to get OpenTabsUIDelegate on demand and on change. | |
32 class OpenTabsUIDelegateProvider { | |
tschumann
2016/09/16 13:33:20
not feeling strongly, but IMO this doesn't have to
skym
2016/09/16 18:18:49
Done. I find I have a hard time understand if thin
tschumann
2016/09/17 15:52:56
Exactly. I try to avoid nested classes unless they
| |
33 public: | |
34 typedef base::Callback<void(sync_driver::OpenTabsUIDelegate*)> | |
35 OnChangeWithDelegate; | |
Marc Treib
2016/09/16 12:26:48
nit: I prefer
using OnChangeWithDelegate = base::C
skym
2016/09/16 18:18:49
Done. And then removed in favor of base::Closure
| |
36 virtual ~OpenTabsUIDelegateProvider() {} | |
37 virtual sync_driver::OpenTabsUIDelegate* GetOpenTabsUIDelegate() = 0; | |
38 virtual void SubscribeForForeignTabChange( | |
39 const OnChangeWithDelegate& callback) = 0; | |
40 }; | |
41 | |
42 ForeignSessionsSuggestionsProvider( | |
43 ContentSuggestionsProvider::Observer* observer, | |
44 CategoryFactory* category_factory, | |
45 std::unique_ptr<OpenTabsUIDelegateProvider> delegate_provider, | |
46 PrefService* pref_service); | |
47 ~ForeignSessionsSuggestionsProvider() override; | |
48 | |
49 static void RegisterProfilePrefs(PrefRegistrySimple* registry); | |
50 | |
51 private: | |
52 friend class ForeignSessionsSuggestionsProviderTest; | |
53 | |
54 // ContentSuggestionsProvider implementation. | |
55 CategoryStatus GetCategoryStatus(Category category) override; | |
56 CategoryInfo GetCategoryInfo(Category category) override; | |
57 void DismissSuggestion(const std::string& suggestion_id) override; | |
58 void FetchSuggestionImage(const std::string& suggestion_id, | |
59 const ImageFetchedCallback& callback) override; | |
60 void ClearHistory( | |
61 base::Time begin, | |
62 base::Time end, | |
63 const base::Callback<bool(const GURL& url)>& filter) override; | |
64 void ClearCachedSuggestions(Category category) override; | |
65 void GetDismissedSuggestionsForDebugging( | |
66 Category category, | |
67 const DismissedSuggestionsCallback& callback) override; | |
68 void ClearDismissedSuggestionsForDebugging(Category category) override; | |
69 | |
70 void OnForeignTabChange( | |
71 sync_driver::OpenTabsUIDelegate* open_tabs_ui_delegate); | |
72 std::vector<ContentSuggestion> BuildSuggestions( | |
73 const std::vector<const sync_driver::SyncedSession*>& foreign_sessions); | |
74 ContentSuggestion BuildSuggestion( | |
75 const sync_driver::SyncedSession& session, | |
76 const sessions::SessionTab& tab, | |
77 const sessions::SerializedNavigationEntry& navigation); | |
78 | |
79 CategoryStatus category_status_; | |
80 const Category provided_category_; | |
81 std::unique_ptr<OpenTabsUIDelegateProvider> delegate_provider_; | |
82 PrefService* pref_service_; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(ForeignSessionsSuggestionsProvider); | |
85 }; | |
86 | |
87 } // namespace ntp_snippets | |
88 | |
89 #endif // COMPONENTS_NTP_SNIPPETS_SESSIONS_FOREIGN_SESSIONS_SUGGESTIONS_PROVIDE R_H_ | |
OLD | NEW |