| 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/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/scoped_observer.h" | 19 #include "base/scoped_observer.h" |
| 20 #include "chrome/browser/supervised_user/supervised_user_service.h" | 20 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 21 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" | 21 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" |
| 22 #include "components/history/core/browser/history_types.h" | 22 #include "components/history/core/browser/history_types.h" |
| 23 #include "components/history/core/browser/top_sites_observer.h" | 23 #include "components/history/core/browser/top_sites_observer.h" |
| 24 #include "components/suggestions/proto/suggestions.pb.h" | 24 #include "components/suggestions/proto/suggestions.pb.h" |
| 25 #include "components/sync_driver/sync_service_observer.h" | 25 #include "components/suggestions/suggestions_service.h" |
| 26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 27 | 27 |
| 28 namespace suggestions { | 28 namespace suggestions { |
| 29 class SuggestionsService; | 29 class SuggestionsService; |
| 30 } | 30 } |
| 31 | 31 |
| 32 namespace user_prefs { | 32 namespace user_prefs { |
| 33 class PrefRegistrySyncable; | 33 class PrefRegistrySyncable; |
| 34 } | 34 } |
| 35 | 35 |
| 36 class PopularSites; | 36 class PopularSites; |
| 37 class Profile; | 37 class Profile; |
| 38 | 38 |
| 39 // Provides the list of most visited sites and their thumbnails to Java. | 39 // Provides the list of most visited sites and their thumbnails to Java. |
| 40 class MostVisitedSites : public sync_driver::SyncServiceObserver, | 40 class MostVisitedSites : public history::TopSitesObserver, |
| 41 public history::TopSitesObserver, | |
| 42 public SupervisedUserServiceObserver { | 41 public SupervisedUserServiceObserver { |
| 43 public: | 42 public: |
| 44 explicit MostVisitedSites(Profile* profile); | 43 explicit MostVisitedSites(Profile* profile); |
| 45 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | 44 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 46 void SetMostVisitedURLsObserver( | 45 void SetMostVisitedURLsObserver( |
| 47 JNIEnv* env, | 46 JNIEnv* env, |
| 48 const base::android::JavaParamRef<jobject>& obj, | 47 const base::android::JavaParamRef<jobject>& obj, |
| 49 const base::android::JavaParamRef<jobject>& j_observer, | 48 const base::android::JavaParamRef<jobject>& j_observer, |
| 50 jint num_sites); | 49 jint num_sites); |
| 51 void GetURLThumbnail(JNIEnv* env, | 50 void GetURLThumbnail(JNIEnv* env, |
| 52 const base::android::JavaParamRef<jobject>& obj, | 51 const base::android::JavaParamRef<jobject>& obj, |
| 53 const base::android::JavaParamRef<jstring>& url, | 52 const base::android::JavaParamRef<jstring>& url, |
| 54 const base::android::JavaParamRef<jobject>& j_callback); | 53 const base::android::JavaParamRef<jobject>& j_callback); |
| 55 | 54 |
| 56 void AddOrRemoveBlacklistedUrl( | 55 void AddOrRemoveBlacklistedUrl( |
| 57 JNIEnv* env, | 56 JNIEnv* env, |
| 58 const base::android::JavaParamRef<jobject>& obj, | 57 const base::android::JavaParamRef<jobject>& obj, |
| 59 const base::android::JavaParamRef<jstring>& j_url, | 58 const base::android::JavaParamRef<jstring>& j_url, |
| 60 jboolean add_url); | 59 jboolean add_url); |
| 61 void RecordTileTypeMetrics( | 60 void RecordTileTypeMetrics( |
| 62 JNIEnv* env, | 61 JNIEnv* env, |
| 63 const base::android::JavaParamRef<jobject>& obj, | 62 const base::android::JavaParamRef<jobject>& obj, |
| 64 const base::android::JavaParamRef<jintArray>& jtile_types); | 63 const base::android::JavaParamRef<jintArray>& jtile_types); |
| 65 void RecordOpenedMostVisitedItem( | 64 void RecordOpenedMostVisitedItem( |
| 66 JNIEnv* env, | 65 JNIEnv* env, |
| 67 const base::android::JavaParamRef<jobject>& obj, | 66 const base::android::JavaParamRef<jobject>& obj, |
| 68 jint index, | 67 jint index, |
| 69 jint tile_type); | 68 jint tile_type); |
| 70 | 69 |
| 71 // sync_driver::SyncServiceObserver implementation. | |
| 72 void OnStateChanged() override; | |
| 73 | |
| 74 // SupervisedUserServiceObserver implementation. | 70 // SupervisedUserServiceObserver implementation. |
| 75 void OnURLFilterChanged() override; | 71 void OnURLFilterChanged() override; |
| 76 | 72 |
| 77 // Registers JNI methods. | 73 // Registers JNI methods. |
| 78 static bool Register(JNIEnv* env); | 74 static bool Register(JNIEnv* env); |
| 79 | 75 |
| 80 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 76 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 81 | 77 |
| 82 private: | 78 private: |
| 83 friend class MostVisitedSitesTest; | 79 friend class MostVisitedSitesTest; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // Inserts suggestions from |src_suggestions| at positions |insert_positions| | 167 // Inserts suggestions from |src_suggestions| at positions |insert_positions| |
| 172 // into |dst_suggestions| where ever empty starting from |start_position|. | 168 // into |dst_suggestions| where ever empty starting from |start_position|. |
| 173 // Returns the last filled position so that future insertions can start from | 169 // Returns the last filled position so that future insertions can start from |
| 174 // there. | 170 // there. |
| 175 static size_t InsertAllSuggestions( | 171 static size_t InsertAllSuggestions( |
| 176 size_t start_position, | 172 size_t start_position, |
| 177 const std::vector<size_t>& insert_positions, | 173 const std::vector<size_t>& insert_positions, |
| 178 SuggestionsVector* src_suggestions, | 174 SuggestionsVector* src_suggestions, |
| 179 SuggestionsVector* dst_suggestions); | 175 SuggestionsVector* dst_suggestions); |
| 180 | 176 |
| 181 // Notify the Java side observer about the availability of Most Visited Urls. | 177 // Notifies the Java side observer about the availability of suggestions. |
| 178 // Also records impressions UMA if not done already. |
| 182 void NotifyMostVisitedURLsObserver(); | 179 void NotifyMostVisitedURLsObserver(); |
| 183 | 180 |
| 184 void OnPopularSitesAvailable(bool success); | 181 void OnPopularSitesAvailable(bool success); |
| 185 | 182 |
| 186 // Runs on the UI Thread. | 183 // Runs on the UI Thread. |
| 187 void OnLocalThumbnailFetched( | 184 void OnLocalThumbnailFetched( |
| 188 const GURL& url, | 185 const GURL& url, |
| 189 scoped_ptr<base::android::ScopedJavaGlobalRef<jobject>> j_callback, | 186 scoped_ptr<base::android::ScopedJavaGlobalRef<jobject>> j_callback, |
| 190 scoped_ptr<SkBitmap> bitmap); | 187 scoped_ptr<SkBitmap> bitmap); |
| 191 | 188 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 222 bool received_most_visited_sites_; | 219 bool received_most_visited_sites_; |
| 223 | 220 |
| 224 // 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 |
| 225 // if popular sites are disabled. | 222 // if popular sites are disabled. |
| 226 bool received_popular_sites_; | 223 bool received_popular_sites_; |
| 227 | 224 |
| 228 // Whether we have recorded one-shot UMA metrics such as impressions. They are | 225 // Whether we have recorded one-shot UMA metrics such as impressions. They are |
| 229 // recorded once both the previous flags are true. | 226 // recorded once both the previous flags are true. |
| 230 bool recorded_uma_; | 227 bool recorded_uma_; |
| 231 | 228 |
| 229 scoped_ptr< |
| 230 suggestions::SuggestionsService::ResponseCallbackList::Subscription> |
| 231 suggestions_subscription_; |
| 232 |
| 232 ScopedObserver<history::TopSites, history::TopSitesObserver> scoped_observer_; | 233 ScopedObserver<history::TopSites, history::TopSitesObserver> scoped_observer_; |
| 233 | 234 |
| 234 MostVisitedSource mv_source_; | 235 MostVisitedSource mv_source_; |
| 235 | 236 |
| 236 scoped_ptr<PopularSites> popular_sites_; | 237 scoped_ptr<PopularSites> popular_sites_; |
| 237 | 238 |
| 238 SuggestionsVector current_suggestions_; | 239 SuggestionsVector current_suggestions_; |
| 239 | 240 |
| 240 // For callbacks may be run after destruction. | 241 // For callbacks may be run after destruction. |
| 241 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; | 242 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; |
| 242 | 243 |
| 243 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); | 244 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); |
| 244 }; | 245 }; |
| 245 | 246 |
| 246 #endif // CHROME_BROWSER_ANDROID_MOST_VISITED_SITES_H_ | 247 #endif // CHROME_BROWSER_ANDROID_MOST_VISITED_SITES_H_ |
| OLD | NEW |