| 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. |
| 54 // |
| 55 // Do not use, except from MostVisitedSitesBridge. The interface is in flux |
| 56 // while we are extracting the functionality of the Java class to make available |
| 57 // in C++. |
| 58 // |
| 59 // TODO(sfiera): finalize interface. |
| 56 class MostVisitedSites : public history::TopSitesObserver, | 60 class MostVisitedSites : public history::TopSitesObserver, |
| 57 public SupervisedUserServiceObserver { | 61 public SupervisedUserServiceObserver { |
| 58 public: | 62 public: |
| 59 explicit MostVisitedSites(Profile* profile); | 63 explicit MostVisitedSites(Profile* profile); |
| 60 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | |
| 61 | 64 |
| 62 // Java methods | 65 ~MostVisitedSites() override; |
| 63 | 66 |
| 67 // Does not take ownership of |observer|, which must outlive this object. |
| 64 void SetMostVisitedURLsObserver( | 68 void SetMostVisitedURLsObserver( |
| 65 JNIEnv* env, | 69 MostVisitedSitesObserver* observer, int num_sites); |
| 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 | 70 |
| 95 using ThumbnailCallback = base::Callback< | 71 using ThumbnailCallback = base::Callback< |
| 96 void(bool /* is_local_thumbnail */, const SkBitmap* /* bitmap */)>; | 72 void(bool /* is_local_thumbnail */, const SkBitmap* /* bitmap */)>; |
| 97 void GetURLThumbnail(const GURL& url, const ThumbnailCallback& callback); | 73 void GetURLThumbnail(const GURL& url, const ThumbnailCallback& callback); |
| 98 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url); | 74 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url); |
| 99 void RecordTileTypeMetrics(const std::vector<int>& tile_types); | 75 void RecordTileTypeMetrics(const std::vector<int>& tile_types); |
| 100 void RecordOpenedMostVisitedItem(int index, int tile_type); | 76 void RecordOpenedMostVisitedItem(int index, int tile_type); |
| 101 | 77 |
| 102 // SupervisedUserServiceObserver implementation. | 78 // SupervisedUserServiceObserver implementation. |
| 103 void OnURLFilterChanged() override; | 79 void OnURLFilterChanged() override; |
| 104 | 80 |
| 105 // Registers JNI methods. | |
| 106 static bool Register(JNIEnv* env); | |
| 107 | |
| 108 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 81 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 109 | 82 |
| 110 private: | 83 private: |
| 111 friend class MostVisitedSitesTest; | 84 friend class MostVisitedSitesTest; |
| 112 | 85 |
| 113 // The source of the Most Visited sites. | 86 // The source of the Most Visited sites. |
| 114 enum MostVisitedSource { TOP_SITES, SUGGESTIONS_SERVICE, POPULAR, WHITELIST }; | 87 enum MostVisitedSource { TOP_SITES, SUGGESTIONS_SERVICE, POPULAR, WHITELIST }; |
| 115 | 88 |
| 116 struct Suggestion { | 89 struct Suggestion { |
| 117 base::string16 title; | 90 base::string16 title; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 129 | 102 |
| 130 // Get the Histogram name associated with the source. | 103 // Get the Histogram name associated with the source. |
| 131 std::string GetSourceHistogramName() const; | 104 std::string GetSourceHistogramName() const; |
| 132 | 105 |
| 133 private: | 106 private: |
| 134 DISALLOW_COPY_AND_ASSIGN(Suggestion); | 107 DISALLOW_COPY_AND_ASSIGN(Suggestion); |
| 135 }; | 108 }; |
| 136 | 109 |
| 137 using SuggestionsVector = std::vector<std::unique_ptr<Suggestion>>; | 110 using SuggestionsVector = std::vector<std::unique_ptr<Suggestion>>; |
| 138 | 111 |
| 139 ~MostVisitedSites() override; | |
| 140 void QueryMostVisitedURLs(); | 112 void QueryMostVisitedURLs(); |
| 141 | 113 |
| 142 // Initialize the query to Top Sites. Called if the SuggestionsService is not | 114 // Initialize the query to Top Sites. Called if the SuggestionsService is not |
| 143 // enabled, or if it returns no data. | 115 // enabled, or if it returns no data. |
| 144 void InitiateTopSitesQuery(); | 116 void InitiateTopSitesQuery(); |
| 145 | 117 |
| 146 // If there's a whitelist entry point for the URL, return the large icon path. | 118 // If there's a whitelist entry point for the URL, return the large icon path. |
| 147 base::FilePath GetWhitelistLargeIconPath(const GURL& url); | 119 base::FilePath GetWhitelistLargeIconPath(const GURL& url); |
| 148 | 120 |
| 149 // Callback for when data is available from TopSites. | 121 // Callback for when data is available from TopSites. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 void RecordImpressionUMAMetrics(); | 203 void RecordImpressionUMAMetrics(); |
| 232 | 204 |
| 233 // history::TopSitesObserver implementation. | 205 // history::TopSitesObserver implementation. |
| 234 void TopSitesLoaded(history::TopSites* top_sites) override; | 206 void TopSitesLoaded(history::TopSites* top_sites) override; |
| 235 void TopSitesChanged(history::TopSites* top_sites, | 207 void TopSitesChanged(history::TopSites* top_sites, |
| 236 ChangeReason change_reason) override; | 208 ChangeReason change_reason) override; |
| 237 | 209 |
| 238 // The profile whose most visited sites will be queried. | 210 // The profile whose most visited sites will be queried. |
| 239 Profile* profile_; | 211 Profile* profile_; |
| 240 | 212 |
| 241 std::unique_ptr<MostVisitedSitesObserver> observer_; | 213 MostVisitedSitesObserver* observer_; |
| 242 | 214 |
| 243 // The maximum number of most visited sites to return. | 215 // The maximum number of most visited sites to return. |
| 244 int num_sites_; | 216 int num_sites_; |
| 245 | 217 |
| 246 // Whether we have received an initial set of most visited sites (from either | 218 // Whether we have received an initial set of most visited sites (from either |
| 247 // TopSites or the SuggestionsService). | 219 // TopSites or the SuggestionsService). |
| 248 bool received_most_visited_sites_; | 220 bool received_most_visited_sites_; |
| 249 | 221 |
| 250 // Whether we have received the set of popular sites. Immediately set to true | 222 // Whether we have received the set of popular sites. Immediately set to true |
| 251 // if popular sites are disabled. | 223 // if popular sites are disabled. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 267 | 239 |
| 268 SuggestionsVector current_suggestions_; | 240 SuggestionsVector current_suggestions_; |
| 269 | 241 |
| 270 // For callbacks may be run after destruction. | 242 // For callbacks may be run after destruction. |
| 271 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; | 243 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; |
| 272 | 244 |
| 273 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); | 245 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); |
| 274 }; | 246 }; |
| 275 | 247 |
| 276 #endif // CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ | 248 #endif // CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ |
| OLD | NEW |