Chromium Code Reviews| 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_NTP_MOST_VISITED_SITES_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ |
| 6 #define CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ | 6 #define CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ |
| 7 | 7 |
| 8 #include <jni.h> | |
| 9 #include <stddef.h> | 8 #include <stddef.h> |
| 10 | 9 |
| 11 #include <memory> | 10 #include <memory> |
| 12 #include <string> | 11 #include <string> |
| 13 #include <vector> | 12 #include <vector> |
| 14 | 13 |
| 15 #include "base/android/scoped_java_ref.h" | |
| 16 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 17 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 18 #include "base/macros.h" | 16 #include "base/macros.h" |
| 19 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 20 #include "base/scoped_observer.h" | 18 #include "base/scoped_observer.h" |
| 21 #include "chrome/browser/supervised_user/supervised_user_service.h" | 19 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 22 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" | 20 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" |
| 23 #include "components/history/core/browser/history_types.h" | 21 #include "components/history/core/browser/history_types.h" |
| 24 #include "components/history/core/browser/top_sites_observer.h" | 22 #include "components/history/core/browser/top_sites_observer.h" |
| 25 #include "components/suggestions/proto/suggestions.pb.h" | 23 #include "components/suggestions/proto/suggestions.pb.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 45 virtual void OnMostVisitedURLsAvailable( | 43 virtual void OnMostVisitedURLsAvailable( |
| 46 const std::vector<base::string16>& titles, | 44 const std::vector<base::string16>& titles, |
| 47 const std::vector<std::string>& urls, | 45 const std::vector<std::string>& urls, |
| 48 const std::vector<std::string>& whitelist_icon_paths) = 0; | 46 const std::vector<std::string>& whitelist_icon_paths) = 0; |
| 49 virtual void OnPopularURLsAvailable( | 47 virtual void OnPopularURLsAvailable( |
| 50 const std::vector<std::string>& urls, | 48 const std::vector<std::string>& urls, |
| 51 const std::vector<std::string>& favicon_urls, | 49 const std::vector<std::string>& favicon_urls, |
| 52 const std::vector<std::string>& large_icon_urls) = 0; | 50 const std::vector<std::string>& large_icon_urls) = 0; |
| 53 }; | 51 }; |
| 54 | 52 |
| 55 // Provides the list of most visited sites and their thumbnails to Java. | 53 // Tracks the list of most visited sites and their thumbnails. |
| 56 class MostVisitedSites : public history::TopSitesObserver, | 54 class MostVisitedSites : public history::TopSitesObserver, |
| 57 public SupervisedUserServiceObserver { | 55 public SupervisedUserServiceObserver { |
| 58 public: | 56 public: |
| 59 explicit MostVisitedSites(Profile* profile); | 57 explicit MostVisitedSites(Profile* profile); |
| 60 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | |
| 61 | 58 |
| 62 // Java methods | 59 ~MostVisitedSites() override; |
| 63 | 60 |
| 64 void SetMostVisitedURLsObserver( | 61 void SetMostVisitedURLsObserver( |
| 65 JNIEnv* env, | 62 MostVisitedSitesObserver* observer, int num_sites); |
|
Bernhard Bauer
2016/04/20 13:35:11
Add a comment about ownership of |observer|?
Actu
Marc Treib
2016/04/20 13:41:19
That's kinda my fault - IMO the observed class sho
Bernhard Bauer
2016/04/20 14:22:51
OTOH, this does require being more careful about o
| |
| 66 const base::android::JavaParamRef<jobject>& obj, | |
| 67 const base::android::JavaParamRef<jobject>& j_observer, | |
| 68 jint num_sites); | |
| 69 | |
| 70 void GetURLThumbnail( | |
| 71 JNIEnv* env, | |
| 72 const base::android::JavaParamRef<jobject>& obj, | |
| 73 const base::android::JavaParamRef<jstring>& url, | |
| 74 const base::android::JavaParamRef<jobject>& j_callback); | |
| 75 void AddOrRemoveBlacklistedUrl( | |
| 76 JNIEnv* env, | |
| 77 const base::android::JavaParamRef<jobject>& obj, | |
| 78 const base::android::JavaParamRef<jstring>& j_url, | |
| 79 jboolean add_url); | |
| 80 void RecordTileTypeMetrics( | |
| 81 JNIEnv* env, | |
| 82 const base::android::JavaParamRef<jobject>& obj, | |
| 83 const base::android::JavaParamRef<jintArray>& jtile_types); | |
| 84 void RecordOpenedMostVisitedItem( | |
| 85 JNIEnv* env, | |
| 86 const base::android::JavaParamRef<jobject>& obj, | |
| 87 jint index, | |
| 88 jint tile_type); | |
| 89 | |
| 90 // C++ methods | |
| 91 | |
| 92 void SetMostVisitedURLsObserver( | |
| 93 std::unique_ptr<MostVisitedSitesObserver> observer, int num_sites); | |
| 94 | 63 |
| 95 using ThumbnailCallback = base::Callback< | 64 using ThumbnailCallback = base::Callback< |
| 96 void(bool /* is_local_thumbnail */, const SkBitmap* /* bitmap */)>; | 65 void(bool /* is_local_thumbnail */, const SkBitmap* /* bitmap */)>; |
| 97 void GetURLThumbnail(const GURL& url, const ThumbnailCallback& callback); | 66 void GetURLThumbnail(const GURL& url, const ThumbnailCallback& callback); |
| 98 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url); | 67 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url); |
| 99 void RecordTileTypeMetrics(const std::vector<int>& tile_types); | 68 void RecordTileTypeMetrics(const std::vector<int>& tile_types); |
| 100 void RecordOpenedMostVisitedItem(int index, int tile_type); | 69 void RecordOpenedMostVisitedItem(int index, int tile_type); |
| 101 | 70 |
| 102 // SupervisedUserServiceObserver implementation. | 71 // SupervisedUserServiceObserver implementation. |
| 103 void OnURLFilterChanged() override; | 72 void OnURLFilterChanged() override; |
| 104 | 73 |
| 105 // Registers JNI methods. | |
| 106 static bool Register(JNIEnv* env); | |
| 107 | |
| 108 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 74 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 109 | 75 |
| 110 private: | 76 private: |
| 111 friend class MostVisitedSitesTest; | 77 friend class MostVisitedSitesTest; |
| 112 | 78 |
| 113 // The source of the Most Visited sites. | 79 // The source of the Most Visited sites. |
| 114 enum MostVisitedSource { TOP_SITES, SUGGESTIONS_SERVICE, POPULAR, WHITELIST }; | 80 enum MostVisitedSource { TOP_SITES, SUGGESTIONS_SERVICE, POPULAR, WHITELIST }; |
| 115 | 81 |
| 116 struct Suggestion { | 82 struct Suggestion { |
| 117 base::string16 title; | 83 base::string16 title; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 129 | 95 |
| 130 // Get the Histogram name associated with the source. | 96 // Get the Histogram name associated with the source. |
| 131 std::string GetSourceHistogramName() const; | 97 std::string GetSourceHistogramName() const; |
| 132 | 98 |
| 133 private: | 99 private: |
| 134 DISALLOW_COPY_AND_ASSIGN(Suggestion); | 100 DISALLOW_COPY_AND_ASSIGN(Suggestion); |
| 135 }; | 101 }; |
| 136 | 102 |
| 137 using SuggestionsVector = std::vector<std::unique_ptr<Suggestion>>; | 103 using SuggestionsVector = std::vector<std::unique_ptr<Suggestion>>; |
| 138 | 104 |
| 139 ~MostVisitedSites() override; | |
| 140 void QueryMostVisitedURLs(); | 105 void QueryMostVisitedURLs(); |
| 141 | 106 |
| 142 // Initialize the query to Top Sites. Called if the SuggestionsService is not | 107 // Initialize the query to Top Sites. Called if the SuggestionsService is not |
| 143 // enabled, or if it returns no data. | 108 // enabled, or if it returns no data. |
| 144 void InitiateTopSitesQuery(); | 109 void InitiateTopSitesQuery(); |
| 145 | 110 |
| 146 // If there's a whitelist entry point for the URL, return the large icon path. | 111 // If there's a whitelist entry point for the URL, return the large icon path. |
| 147 base::FilePath GetWhitelistLargeIconPath(const GURL& url); | 112 base::FilePath GetWhitelistLargeIconPath(const GURL& url); |
| 148 | 113 |
| 149 // Callback for when data is available from TopSites. | 114 // Callback for when data is available from TopSites. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 void RecordImpressionUMAMetrics(); | 196 void RecordImpressionUMAMetrics(); |
| 232 | 197 |
| 233 // history::TopSitesObserver implementation. | 198 // history::TopSitesObserver implementation. |
| 234 void TopSitesLoaded(history::TopSites* top_sites) override; | 199 void TopSitesLoaded(history::TopSites* top_sites) override; |
| 235 void TopSitesChanged(history::TopSites* top_sites, | 200 void TopSitesChanged(history::TopSites* top_sites, |
| 236 ChangeReason change_reason) override; | 201 ChangeReason change_reason) override; |
| 237 | 202 |
| 238 // The profile whose most visited sites will be queried. | 203 // The profile whose most visited sites will be queried. |
| 239 Profile* profile_; | 204 Profile* profile_; |
| 240 | 205 |
| 241 std::unique_ptr<MostVisitedSitesObserver> observer_; | 206 MostVisitedSitesObserver* observer_; |
| 242 | 207 |
| 243 // The maximum number of most visited sites to return. | 208 // The maximum number of most visited sites to return. |
| 244 int num_sites_; | 209 int num_sites_; |
| 245 | 210 |
| 246 // Whether we have received an initial set of most visited sites (from either | 211 // Whether we have received an initial set of most visited sites (from either |
| 247 // TopSites or the SuggestionsService). | 212 // TopSites or the SuggestionsService). |
| 248 bool received_most_visited_sites_; | 213 bool received_most_visited_sites_; |
| 249 | 214 |
| 250 // Whether we have received the set of popular sites. Immediately set to true | 215 // Whether we have received the set of popular sites. Immediately set to true |
| 251 // if popular sites are disabled. | 216 // if popular sites are disabled. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 267 | 232 |
| 268 SuggestionsVector current_suggestions_; | 233 SuggestionsVector current_suggestions_; |
| 269 | 234 |
| 270 // For callbacks may be run after destruction. | 235 // For callbacks may be run after destruction. |
| 271 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; | 236 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; |
| 272 | 237 |
| 273 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); | 238 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); |
| 274 }; | 239 }; |
| 275 | 240 |
| 276 #endif // CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ | 241 #endif // CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ |
| OLD | NEW |