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

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

Issue 845013002: Remove TopSites notification in favor of Observers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/android/most_visited_sites.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 "base/scoped_observer.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/sync/profile_sync_service_observer.h" 15 #include "chrome/browser/sync/profile_sync_service_observer.h"
15 #include "components/history/core/browser/history_types.h" 16 #include "components/history/core/browser/history_types.h"
17 #include "components/history/core/browser/top_sites_observer.h"
16 #include "components/suggestions/proto/suggestions.pb.h" 18 #include "components/suggestions/proto/suggestions.pb.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
19 19
20 namespace suggestions { 20 namespace suggestions {
21 class SuggestionsService; 21 class SuggestionsService;
22 } 22 }
23 23
24 // Provides the list of most visited sites and their thumbnails to Java. 24 // Provides the list of most visited sites and their thumbnails to Java.
25 class MostVisitedSites : public ProfileSyncServiceObserver, 25 class MostVisitedSites : public ProfileSyncServiceObserver,
26 public content::NotificationObserver { 26 public history::TopSitesObserver {
27 public: 27 public:
28 typedef base::Callback< 28 typedef base::Callback<
29 void(base::android::ScopedJavaGlobalRef<jobject>* bitmap, 29 void(base::android::ScopedJavaGlobalRef<jobject>* bitmap,
30 base::android::ScopedJavaGlobalRef<jobject>* j_callback)> 30 base::android::ScopedJavaGlobalRef<jobject>* j_callback)>
31 LookupSuccessCallback; 31 LookupSuccessCallback;
32 32
33 explicit MostVisitedSites(Profile* profile); 33 explicit MostVisitedSites(Profile* profile);
34 void Destroy(JNIEnv* env, jobject obj); 34 void Destroy(JNIEnv* env, jobject obj);
35 void OnLoadingComplete(JNIEnv* env, jobject obj); 35 void OnLoadingComplete(JNIEnv* env, jobject obj);
36 void SetMostVisitedURLsObserver(JNIEnv* env, 36 void SetMostVisitedURLsObserver(JNIEnv* env,
37 jobject obj, 37 jobject obj,
38 jobject j_observer, 38 jobject j_observer,
39 jint num_sites); 39 jint num_sites);
40 void GetURLThumbnail(JNIEnv* env, 40 void GetURLThumbnail(JNIEnv* env,
41 jobject obj, 41 jobject obj,
42 jstring url, 42 jstring url,
43 jobject j_callback); 43 jobject j_callback);
44 void BlacklistUrl(JNIEnv* env, jobject obj, jstring j_url); 44 void BlacklistUrl(JNIEnv* env, jobject obj, jstring j_url);
45 void RecordOpenedMostVisitedItem(JNIEnv* env, jobject obj, jint index); 45 void RecordOpenedMostVisitedItem(JNIEnv* env, jobject obj, jint index);
46 46
47 // content::NotificationObserver implementation.
48 virtual void Observe(int type,
49 const content::NotificationSource& source,
50 const content::NotificationDetails& details) override;
51
52 // ProfileSyncServiceObserver implementation. 47 // ProfileSyncServiceObserver implementation.
53 virtual void OnStateChanged() override; 48 virtual void OnStateChanged() override;
54 49
55 // Registers JNI methods. 50 // Registers JNI methods.
56 static bool Register(JNIEnv* env); 51 static bool Register(JNIEnv* env);
57 52
58 private: 53 private:
59 // The source of the Most Visited sites. 54 // The source of the Most Visited sites.
60 enum MostVisitedSource { 55 enum MostVisitedSource {
61 TOP_SITES, 56 TOP_SITES,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 88
94 // Callback from the SuggestionsServer regarding the server thumbnail lookup. 89 // Callback from the SuggestionsServer regarding the server thumbnail lookup.
95 void OnSuggestionsThumbnailAvailable( 90 void OnSuggestionsThumbnailAvailable(
96 base::android::ScopedJavaGlobalRef<jobject>* j_callback, 91 base::android::ScopedJavaGlobalRef<jobject>* j_callback,
97 const GURL& url, 92 const GURL& url,
98 const SkBitmap* bitmap); 93 const SkBitmap* bitmap);
99 94
100 // Records specific UMA histogram metrics. 95 // Records specific UMA histogram metrics.
101 void RecordUMAMetrics(); 96 void RecordUMAMetrics();
102 97
98 // history::TopSitesObserver implementation.
99 void TopSitesLoaded(history::TopSites* top_sites) override;
100 void TopSitesChanged(history::TopSites* top_sites) override;
101
103 // The profile whose most visited sites will be queried. 102 // The profile whose most visited sites will be queried.
104 Profile* profile_; 103 Profile* profile_;
105 104
106 // The observer to be notified when the list of most visited sites changes. 105 // The observer to be notified when the list of most visited sites changes.
107 base::android::ScopedJavaGlobalRef<jobject> observer_; 106 base::android::ScopedJavaGlobalRef<jobject> observer_;
108 107
109 // The maximum number of most visited sites to return. 108 // The maximum number of most visited sites to return.
110 int num_sites_; 109 int num_sites_;
111 110
112 // Whether the user is in a control group for the purposes of logging. 111 // Whether the user is in a control group for the purposes of logging.
113 bool is_control_group_; 112 bool is_control_group_;
114 113
115 // Keeps track of whether the initial NTP load has been done. 114 // Keeps track of whether the initial NTP load has been done.
116 bool initial_load_done_; 115 bool initial_load_done_;
117 116
118 // Counters for UMA metrics. 117 // Counters for UMA metrics.
119 118
120 // Number of tiles using a local thumbnail image for this NTP session. 119 // Number of tiles using a local thumbnail image for this NTP session.
121 int num_local_thumbs_; 120 int num_local_thumbs_;
122 // Number of tiles for which a server thumbnail is provided. 121 // Number of tiles for which a server thumbnail is provided.
123 int num_server_thumbs_; 122 int num_server_thumbs_;
124 // Number of tiles for which no thumbnail is found/specified and a gray tile 123 // Number of tiles for which no thumbnail is found/specified and a gray tile
125 // is used as the main tile. 124 // is used as the main tile.
126 int num_empty_thumbs_; 125 int num_empty_thumbs_;
127 126
128 // Copy of the server suggestions (if enabled). Used for logging. 127 // Copy of the server suggestions (if enabled). Used for logging.
129 suggestions::SuggestionsProfile server_suggestions_; 128 suggestions::SuggestionsProfile server_suggestions_;
130 129
131 content::NotificationRegistrar registrar_; 130 ScopedObserver<history::TopSites, history::TopSitesObserver> scoped_observer_;
132 131
133 MostVisitedSource mv_source_; 132 MostVisitedSource mv_source_;
134 133
135 // For callbacks may be run after destruction. 134 // For callbacks may be run after destruction.
136 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; 135 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_;
137 136
138 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); 137 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites);
139 }; 138 };
140 139
141 #endif // CHROME_BROWSER_ANDROID_MOST_VISITED_SITES_H_ 140 #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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698