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