OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_ANDROID_MOST_VISITED_SITES_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_MOST_VISITED_SITES_H_ |
6 #define CHROME_BROWSER_ANDROID_MOST_VISITED_SITES_H_ | 6 #define CHROME_BROWSER_ANDROID_MOST_VISITED_SITES_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/android/scoped_java_ref.h" | 14 #include "base/android/scoped_java_ref.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/files/file_path.h" | |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
19 #include "base/scoped_observer.h" | 20 #include "base/scoped_observer.h" |
20 #include "chrome/browser/supervised_user/supervised_user_service.h" | 21 #include "chrome/browser/supervised_user/supervised_user_service.h" |
21 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" | 22 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" |
22 #include "components/history/core/browser/history_types.h" | 23 #include "components/history/core/browser/history_types.h" |
23 #include "components/history/core/browser/top_sites_observer.h" | 24 #include "components/history/core/browser/top_sites_observer.h" |
24 #include "components/suggestions/proto/suggestions.pb.h" | 25 #include "components/suggestions/proto/suggestions.pb.h" |
25 #include "components/sync_driver/sync_service_observer.h" | 26 #include "components/sync_driver/sync_service_observer.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 void OnStateChanged() override; | 73 void OnStateChanged() override; |
73 | 74 |
74 // SupervisedUserServiceObserver implementation. | 75 // SupervisedUserServiceObserver implementation. |
75 void OnURLFilterChanged() override; | 76 void OnURLFilterChanged() override; |
76 | 77 |
77 // Registers JNI methods. | 78 // Registers JNI methods. |
78 static bool Register(JNIEnv* env); | 79 static bool Register(JNIEnv* env); |
79 | 80 |
80 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 81 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
81 | 82 |
82 private: | |
83 friend class MostVisitedSitesTest; | |
84 | |
85 // The source of the Most Visited sites. | 83 // The source of the Most Visited sites. |
Marc Treib
2016/03/16 11:06:03
All this is now public only so that the Builder ca
atanasova
2016/03/16 17:58:17
Done.
| |
86 enum MostVisitedSource { TOP_SITES, SUGGESTIONS_SERVICE, POPULAR, WHITELIST }; | 84 enum MostVisitedSource { TOP_SITES, SUGGESTIONS_SERVICE, POPULAR, WHITELIST }; |
87 | 85 |
88 struct Suggestion { | 86 struct Suggestion { |
Bernhard Bauer
2016/03/16 12:14:18
Actually, now that I see this: If this is a struct
Marc Treib
2016/03/16 12:51:35
Huh. Or, alternatively, make it a class!
atanasova
2016/03/16 17:58:17
Done.
| |
89 base::string16 title; | 87 base::string16 title; |
90 GURL url; | 88 GURL url; |
91 MostVisitedSource source; | 89 MostVisitedSource source; |
90 | |
91 // Only valid for source == WHITELIST (empty otherwise). | |
92 base::FilePath whitelist_icon_path; | |
93 | |
92 // Only valid for source == SUGGESTIONS_SERVICE (-1 otherwise). | 94 // Only valid for source == SUGGESTIONS_SERVICE (-1 otherwise). |
93 int provider_index; | 95 int provider_index; |
94 | 96 |
95 Suggestion(const base::string16& title, | 97 Suggestion(const base::string16& title, |
96 const std::string& url, | |
97 MostVisitedSource source); | |
98 Suggestion(const base::string16& title, | |
99 const GURL& url, | 98 const GURL& url, |
100 MostVisitedSource source); | |
101 Suggestion(const base::string16& title, | |
102 const std::string& url, | |
103 MostVisitedSource source, | 99 MostVisitedSource source, |
100 const base::FilePath& whitelist_icon_path, | |
104 int provider_index); | 101 int provider_index); |
105 ~Suggestion(); | 102 ~Suggestion(); |
106 | 103 |
107 // Get the Histogram name associated with the source. | 104 // Get the Histogram name associated with the source. |
108 std::string GetSourceHistogramName() const; | 105 std::string GetSourceHistogramName() const; |
109 | 106 |
110 private: | 107 private: |
111 DISALLOW_COPY_AND_ASSIGN(Suggestion); | 108 DISALLOW_COPY_AND_ASSIGN(Suggestion); |
112 }; | 109 }; |
113 | 110 |
111 private: | |
112 friend class MostVisitedSitesTest; | |
113 | |
114 using SuggestionsVector = std::vector<scoped_ptr<Suggestion>>; | 114 using SuggestionsVector = std::vector<scoped_ptr<Suggestion>>; |
115 | 115 |
116 ~MostVisitedSites() override; | 116 ~MostVisitedSites() override; |
117 void QueryMostVisitedURLs(); | 117 void QueryMostVisitedURLs(); |
118 | 118 |
119 // Initialize the query to Top Sites. Called if the SuggestionsService is not | 119 // Initialize the query to Top Sites. Called if the SuggestionsService is not |
120 // enabled, or if it returns no data. | 120 // enabled, or if it returns no data. |
121 void InitiateTopSitesQuery(); | 121 void InitiateTopSitesQuery(); |
122 | 122 |
123 // Callback for when data is available from TopSites. | 123 // Callback for when data is available from TopSites. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 | 237 |
238 SuggestionsVector current_suggestions_; | 238 SuggestionsVector current_suggestions_; |
239 | 239 |
240 // For callbacks may be run after destruction. | 240 // For callbacks may be run after destruction. |
241 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; | 241 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; |
242 | 242 |
243 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); | 243 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); |
244 }; | 244 }; |
245 | 245 |
246 #endif // CHROME_BROWSER_ANDROID_MOST_VISITED_SITES_H_ | 246 #endif // CHROME_BROWSER_ANDROID_MOST_VISITED_SITES_H_ |
OLD | NEW |