Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: chrome/browser/android/most_visited_sites.h

Issue 1330773002: [Android] Persist ordering of NTP suggestions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/android/scoped_java_ref.h" 13 #include "base/android/scoped_java_ref.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/scoped_observer.h" 17 #include "base/scoped_observer.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "components/history/core/browser/history_types.h" 18 #include "components/history/core/browser/history_types.h"
20 #include "components/history/core/browser/top_sites_observer.h" 19 #include "components/history/core/browser/top_sites_observer.h"
21 #include "components/suggestions/proto/suggestions.pb.h" 20 #include "components/suggestions/proto/suggestions.pb.h"
22 #include "components/sync_driver/sync_service_observer.h" 21 #include "components/sync_driver/sync_service_observer.h"
23 22
24 namespace suggestions { 23 namespace suggestions {
25 class SuggestionsService; 24 class SuggestionsService;
26 } 25 }
27 26
27 namespace user_prefs {
28 class PrefRegistrySyncable;
29 }
30
28 class GURL; 31 class GURL;
29 class PopularSites; 32 class PopularSites;
33 class Profile;
30 34
31 // Provides the list of most visited sites and their thumbnails to Java. 35 // Provides the list of most visited sites and their thumbnails to Java.
32 class MostVisitedSites : public sync_driver::SyncServiceObserver, 36 class MostVisitedSites : public sync_driver::SyncServiceObserver,
33 public history::TopSitesObserver { 37 public history::TopSitesObserver {
34 public: 38 public:
35 explicit MostVisitedSites(Profile* profile); 39 explicit MostVisitedSites(Profile* profile);
36 void Destroy(JNIEnv* env, jobject obj); 40 void Destroy(JNIEnv* env, jobject obj);
37 void OnLoadingComplete(JNIEnv* env, jobject obj); 41 void OnLoadingComplete(JNIEnv* env, jobject obj);
38 void SetMostVisitedURLsObserver(JNIEnv* env, 42 void SetMostVisitedURLsObserver(JNIEnv* env,
39 jobject obj, 43 jobject obj,
40 jobject j_observer, 44 jobject j_observer,
41 jint num_sites); 45 jint num_sites);
42 void GetURLThumbnail(JNIEnv* env, 46 void GetURLThumbnail(JNIEnv* env,
43 jobject obj, 47 jobject obj,
44 jstring url, 48 jstring url,
45 jobject j_callback); 49 jobject j_callback);
46 50
47 void BlacklistUrl(JNIEnv* env, jobject obj, jstring j_url); 51 void BlacklistUrl(JNIEnv* env, jobject obj, jstring j_url);
48 void RecordOpenedMostVisitedItem(JNIEnv* env, jobject obj, jint index); 52 void RecordOpenedMostVisitedItem(JNIEnv* env, jobject obj, jint index);
49 53
50 // sync_driver::SyncServiceObserver implementation. 54 // sync_driver::SyncServiceObserver implementation.
51 void OnStateChanged() override; 55 void OnStateChanged() override;
52 56
53 // Registers JNI methods. 57 // Registers JNI methods.
54 static bool Register(JNIEnv* env); 58 static bool Register(JNIEnv* env);
55 59
60 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
61
56 private: 62 private:
57 friend class MostVisitedSitesTest; 63 friend class MostVisitedSitesTest;
58 64
59 // The source of the Most Visited sites. 65 // The source of the Most Visited sites.
60 enum MostVisitedSource { 66 enum MostVisitedSource {
61 TOP_SITES, 67 TOP_SITES,
62 SUGGESTIONS_SERVICE 68 SUGGESTIONS_SERVICE
63 }; 69 };
64 70
65 ~MostVisitedSites() override; 71 ~MostVisitedSites() override;
66 void QueryMostVisitedURLs(); 72 void QueryMostVisitedURLs();
67 73
68 // Initialize the query to Top Sites. Called if the SuggestionsService is not 74 // Initialize the query to Top Sites. Called if the SuggestionsService is not
69 // enabled, or if it returns no data. 75 // enabled, or if it returns no data.
70 void InitiateTopSitesQuery(); 76 void InitiateTopSitesQuery();
71 77
72 // Callback for when data is available from TopSites. 78 // Callback for when data is available from TopSites.
73 void OnMostVisitedURLsAvailable( 79 void OnMostVisitedURLsAvailable(
74 const history::MostVisitedURLList& visited_list); 80 const history::MostVisitedURLList& visited_list);
75 81
76 // Callback for when data is available from the SuggestionsService. 82 // Callback for when data is available from the SuggestionsService.
77 void OnSuggestionsProfileAvailable( 83 void OnSuggestionsProfileAvailable(
78 const suggestions::SuggestionsProfile& suggestions_profile); 84 const suggestions::SuggestionsProfile& suggestions_profile);
79 85
80 // Adds the suggestions from |popular_sites_| into |titles| and |urls|. This 86 // Adds the suggestions from |popular_sites_| into |titles| and |urls|. This
Marc Treib 2015/09/07 11:13:00 Comment isn't accurate anymore now.
knn 2015/09/08 10:48:56 Done.
81 // might reorder |titles| and |urls| to retain the absolute positions of the 87 // might reorder |titles| and |urls| to retain the absolute positions of the
82 // popular suggestions. Also updates |tile_sources_| accordingly. 88 // popular suggestions. Also updates |tile_sources_| accordingly.
83 void AddPopularSites(std::vector<base::string16>* titles, 89 void AddPopularSites(std::vector<base::string16>* result_titles,
84 std::vector<std::string>* urls); 90 std::vector<std::string>* result_urls,
91 std::vector<base::string16>* personal_titles,
92 std::vector<std::string>* personal_urls);
85 93
86 // Workhorse for AddPopularSites above. Implemented as a separate static 94 // Workhorse for AddPopularSites above. Implemented as a separate static
87 // method for ease of testing. 95 // method for ease of testing.
88 static void AddPopularSitesImpl( 96 static void MergeSuggestions(
89 int num_sites, 97 // Return values.
Marc Treib 2015/09/07 11:13:00 nit: Order of arguments should be inputs, then out
knn 2015/09/08 10:48:56 Done.
90 const std::vector<base::string16>& popular_titles, 98 std::vector<bool>* result_is_personal,
91 const std::vector<std::string>& popular_urls, 99 std::vector<std::string>* result_urls,
92 std::vector<base::string16>* titles, 100 std::vector<base::string16>* result_titles,
93 std::vector<std::string>* urls, 101 // Arguments.
94 std::vector<std::string>* tile_sources); 102 size_t num_tiles,
103 size_t num_personal_suggestions,
104 size_t num_popular_suggestions,
105 // Passed as ptr for move semantics only.
106 std::vector<std::string>* personal_urls,
107 std::vector<base::string16>* personal_titles,
108 std::vector<std::string>* popular_urls,
109 std::vector<base::string16>* popular_titles,
110 const std::vector<std::string>& personal_hosts,
111 const std::vector<std::string>& popular_hosts,
112 const std::vector<std::string>& old_sites_url,
113 // Whether the site is a personal suggestion.
114 const std::vector<bool>& old_sites_source);
95 115
96 // Notify the Java side observer about the availability of Most Visited Urls. 116 // Notify the Java side observer about the availability of Most Visited Urls.
97 void NotifyMostVisitedURLsObserver(const std::vector<base::string16>& titles, 117 void NotifyMostVisitedURLsObserver(const std::vector<base::string16>& titles,
98 const std::vector<std::string>& urls); 118 const std::vector<std::string>& urls);
99 119
100 void OnPopularSitesAvailable(bool success); 120 void OnPopularSitesAvailable(bool success);
101 121
102 // Runs on the UI Thread. 122 // Runs on the UI Thread.
103 void OnLocalThumbnailFetched( 123 void OnLocalThumbnailFetched(
104 const GURL& url, 124 const GURL& url,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 185
166 scoped_ptr<PopularSites> popular_sites_; 186 scoped_ptr<PopularSites> popular_sites_;
167 187
168 // For callbacks may be run after destruction. 188 // For callbacks may be run after destruction.
169 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; 189 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_;
170 190
171 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); 191 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites);
172 }; 192 };
173 193
174 #endif // CHROME_BROWSER_ANDROID_MOST_VISITED_SITES_H_ 194 #endif // CHROME_BROWSER_ANDROID_MOST_VISITED_SITES_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/most_visited_sites.cc » ('j') | chrome/browser/android/most_visited_sites.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698