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 | 9 |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chrome/browser/history/history_types.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
16 | 17 |
17 namespace suggestions { | 18 namespace suggestions { |
18 class SuggestionsProfile; | 19 class SuggestionsProfile; |
19 } | 20 } |
20 | 21 |
21 // Provides the list of most visited sites and their thumbnails to Java. | 22 // Provides the list of most visited sites and their thumbnails to Java. |
22 class MostVisitedSites : public content::NotificationObserver { | 23 class MostVisitedSites : public content::NotificationObserver { |
(...skipping 19 matching lines...) Expand all Loading... |
42 static bool Register(JNIEnv* env); | 43 static bool Register(JNIEnv* env); |
43 | 44 |
44 private: | 45 private: |
45 virtual ~MostVisitedSites(); | 46 virtual ~MostVisitedSites(); |
46 void QueryMostVisitedURLs(); | 47 void QueryMostVisitedURLs(); |
47 | 48 |
48 // Initialize the query to Top Sites. Called if the SuggestionsService is not | 49 // Initialize the query to Top Sites. Called if the SuggestionsService is not |
49 // enabled, or if it returns no data. | 50 // enabled, or if it returns no data. |
50 void InitiateTopSitesQuery(); | 51 void InitiateTopSitesQuery(); |
51 | 52 |
| 53 // Callback for when data is available from TopSites. |
| 54 void OnMostVisitedURLsAvailable( |
| 55 base::android::ScopedJavaGlobalRef<jobject>* j_observer, |
| 56 int num_sites, |
| 57 const history::MostVisitedURLList& visited_list); |
| 58 |
52 // Callback for when data is available from the SuggestionsService. | 59 // Callback for when data is available from the SuggestionsService. |
53 void OnSuggestionsProfileAvailable( | 60 void OnSuggestionsProfileAvailable( |
54 base::android::ScopedJavaGlobalRef<jobject>* j_observer, | 61 base::android::ScopedJavaGlobalRef<jobject>* j_observer, |
55 const suggestions::SuggestionsProfile& suggestions_profile); | 62 const suggestions::SuggestionsProfile& suggestions_profile); |
56 | 63 |
57 // The profile whose most visited sites will be queried. | 64 // The profile whose most visited sites will be queried. |
58 Profile* profile_; | 65 Profile* profile_; |
59 | 66 |
60 // The observer to be notified when the list of most visited sites changes. | 67 // The observer to be notified when the list of most visited sites changes. |
61 base::android::ScopedJavaGlobalRef<jobject> observer_; | 68 base::android::ScopedJavaGlobalRef<jobject> observer_; |
62 | 69 |
63 // The maximum number of most visited sites to return. | 70 // The maximum number of most visited sites to return. |
64 int num_sites_; | 71 int num_sites_; |
65 | 72 |
66 // For callbacks may be run after destruction. | 73 // For callbacks may be run after destruction. |
67 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; | 74 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; |
68 | 75 |
69 content::NotificationRegistrar registrar_; | 76 content::NotificationRegistrar registrar_; |
70 | 77 |
| 78 // The source of the Most Visited sites. |
| 79 enum MostVisitedSource { |
| 80 TOP_SITES, |
| 81 SUGGESTIONS_SERVICE |
| 82 }; |
| 83 MostVisitedSource mv_source_; |
| 84 |
71 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); | 85 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); |
72 }; | 86 }; |
73 | 87 |
74 #endif // CHROME_BROWSER_ANDROID_MOST_VISITED_SITES_H_ | 88 #endif // CHROME_BROWSER_ANDROID_MOST_VISITED_SITES_H_ |
OLD | NEW |