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_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> |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 // Callback for when data is available from TopSites. | 72 // Callback for when data is available from TopSites. |
| 73 void OnMostVisitedURLsAvailable( | 73 void OnMostVisitedURLsAvailable( |
| 74 const history::MostVisitedURLList& visited_list); | 74 const history::MostVisitedURLList& visited_list); |
| 75 | 75 |
| 76 // Callback for when data is available from the SuggestionsService. | 76 // Callback for when data is available from the SuggestionsService. |
| 77 void OnSuggestionsProfileAvailable( | 77 void OnSuggestionsProfileAvailable( |
| 78 const suggestions::SuggestionsProfile& suggestions_profile); | 78 const suggestions::SuggestionsProfile& suggestions_profile); |
| 79 | 79 |
| 80 // Adds the suggestions from |popular_sites_| into |titles| and |urls|. This | 80 // Adds the suggestions from |popular_sites_| into |titles| and |urls|. This |
| 81 // might reorder |titles| and |urls| to retain the absolute positions of the | 81 // might reorder |titles| and |urls| to retain the absolute positions of the |
| 82 // popular suggestions. | 82 // popular suggestions. Also updates |tile_sources_| accordingly. |
| 83 void AddPopularSites(std::vector<base::string16>* titles, | 83 void AddPopularSites(std::vector<base::string16>* titles, |
| 84 std::vector<std::string>* urls) const; | 84 std::vector<std::string>* urls); |
| 85 | 85 |
| 86 // Workhorse for AddPopularSites above. Implemented as a separate static | 86 // Workhorse for AddPopularSites above. Implemented as a separate static |
| 87 // method for ease of testing. | 87 // method for ease of testing. |
| 88 static void AddPopularSitesImpl( | 88 static void AddPopularSitesImpl( |
| 89 int num_sites, | 89 int num_sites, |
| 90 std::vector<base::string16>* titles, | 90 std::vector<base::string16>* titles, |
| 91 std::vector<std::string>* urls, | 91 std::vector<std::string>* urls, |
| 92 std::vector<std::string>* tile_sources, | |
|
Alexei Svitkine (slow)
2015/08/25 15:01:19
Nit: Output parameters should be last.
Marc Treib
2015/08/25 15:19:32
Done.
| |
| 92 const std::vector<base::string16>& popular_titles, | 93 const std::vector<base::string16>& popular_titles, |
| 93 const std::vector<std::string>& popular_urls); | 94 const std::vector<std::string>& popular_urls); |
| 94 | 95 |
| 95 // Notify the Java side observer about the availability of Most Visited Urls. | 96 // Notify the Java side observer about the availability of Most Visited Urls. |
| 96 void NotifyMostVisitedURLsObserver(const std::vector<base::string16>& titles, | 97 void NotifyMostVisitedURLsObserver(const std::vector<base::string16>& titles, |
| 97 const std::vector<std::string>& urls); | 98 const std::vector<std::string>& urls); |
| 98 | 99 |
| 99 void OnPopularSitesAvailable(bool success); | 100 void OnPopularSitesAvailable(bool success); |
| 100 | 101 |
| 101 // Runs on the UI Thread. | 102 // Runs on the UI Thread. |
| 102 void OnLocalThumbnailFetched( | 103 void OnLocalThumbnailFetched( |
| 103 const GURL& url, | 104 const GURL& url, |
| 104 scoped_ptr<base::android::ScopedJavaGlobalRef<jobject>> j_callback, | 105 scoped_ptr<base::android::ScopedJavaGlobalRef<jobject>> j_callback, |
| 105 scoped_ptr<SkBitmap> bitmap); | 106 scoped_ptr<SkBitmap> bitmap); |
| 106 | 107 |
| 107 // Callback for when the thumbnail lookup is complete. | 108 // Callback for when the thumbnail lookup is complete. |
| 108 // Runs on the UI Thread. | 109 // Runs on the UI Thread. |
| 109 void OnObtainedThumbnail( | 110 void OnObtainedThumbnail( |
| 110 bool is_local_thumbnail, | 111 bool is_local_thumbnail, |
| 111 scoped_ptr<base::android::ScopedJavaGlobalRef<jobject>> j_callback, | 112 scoped_ptr<base::android::ScopedJavaGlobalRef<jobject>> j_callback, |
| 112 const GURL& url, | 113 const GURL& url, |
| 113 const SkBitmap* bitmap); | 114 const SkBitmap* bitmap); |
| 114 | 115 |
| 115 // Records specific UMA histogram metrics. | 116 // Records thumbnail-related UMA histogram metrics. |
| 116 void RecordUMAMetrics(); | 117 void RecordThumbnailUMAMetrics(); |
| 118 | |
| 119 // Records UMA histogram metrics related to the number of impressions. | |
| 120 void RecordImpressionUMAMetrics(); | |
| 117 | 121 |
| 118 // history::TopSitesObserver implementation. | 122 // history::TopSitesObserver implementation. |
| 119 void TopSitesLoaded(history::TopSites* top_sites) override; | 123 void TopSitesLoaded(history::TopSites* top_sites) override; |
| 120 void TopSitesChanged(history::TopSites* top_sites, | 124 void TopSitesChanged(history::TopSites* top_sites, |
| 121 ChangeReason change_reason) override; | 125 ChangeReason change_reason) override; |
| 122 | 126 |
| 123 // The profile whose most visited sites will be queried. | 127 // The profile whose most visited sites will be queried. |
| 124 Profile* profile_; | 128 Profile* profile_; |
| 125 | 129 |
| 126 // The observer to be notified when the list of most visited sites changes. | 130 // The observer to be notified when the list of most visited sites changes. |
| 127 base::android::ScopedJavaGlobalRef<jobject> observer_; | 131 base::android::ScopedJavaGlobalRef<jobject> observer_; |
| 128 | 132 |
| 129 // The maximum number of most visited sites to return. | 133 // The maximum number of most visited sites to return. |
| 130 int num_sites_; | 134 int num_sites_; |
| 131 | 135 |
| 132 // Keeps track of whether the initial NTP load has been done. | 136 // Whether we have received an initial set of most visited sites (from either |
| 133 bool initial_load_done_; | 137 // TopSites or the SuggestionsService). |
| 138 bool received_most_visited_sites_; | |
| 139 | |
| 140 // Whether we have received the set of popular sites. Immediately set to true | |
| 141 // if popular sites are disabled. | |
| 142 bool received_popular_sites_; | |
| 143 | |
| 144 // Whether we have recorded one-shot UMA metrics such as impressions. They are | |
| 145 // recorded once both the previous flags are true. | |
| 146 bool recorded_uma_; | |
| 134 | 147 |
| 135 // Counters for UMA metrics. | 148 // Counters for UMA metrics. |
| 136 | 149 |
| 137 // Number of tiles using a local thumbnail image for this NTP session. | 150 // Number of tiles using a local thumbnail image for this NTP session. |
| 138 int num_local_thumbs_; | 151 int num_local_thumbs_; |
| 139 // Number of tiles for which a server thumbnail is provided. | 152 // Number of tiles for which a server thumbnail is provided. |
| 140 int num_server_thumbs_; | 153 int num_server_thumbs_; |
| 141 // Number of tiles for which no thumbnail is found/specified. | 154 // Number of tiles for which no thumbnail is found/specified. |
| 142 // In this case a gray tile is used as the main tile. | 155 // In this case a gray tile is used as the main tile. |
| 143 int num_empty_thumbs_; | 156 int num_empty_thumbs_; |
| 144 | 157 |
| 145 // Copy of the server suggestions (if enabled). Used for logging. | 158 // Identifier for where each tile came from (client, server, popular). Used |
| 146 suggestions::SuggestionsProfile server_suggestions_; | 159 // for logging. |
| 160 std::vector<std::string> tile_sources_; | |
| 147 | 161 |
| 148 ScopedObserver<history::TopSites, history::TopSitesObserver> scoped_observer_; | 162 ScopedObserver<history::TopSites, history::TopSitesObserver> scoped_observer_; |
| 149 | 163 |
| 150 MostVisitedSource mv_source_; | 164 MostVisitedSource mv_source_; |
| 151 | 165 |
| 152 scoped_ptr<PopularSites> popular_sites_; | 166 scoped_ptr<PopularSites> popular_sites_; |
| 153 | 167 |
| 154 // For callbacks may be run after destruction. | 168 // For callbacks may be run after destruction. |
| 155 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; | 169 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; |
| 156 | 170 |
| 157 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); | 171 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); |
| 158 }; | 172 }; |
| 159 | 173 |
| 160 #endif // CHROME_BROWSER_ANDROID_MOST_VISITED_SITES_H_ | 174 #endif // CHROME_BROWSER_ANDROID_MOST_VISITED_SITES_H_ |
| OLD | NEW |