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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java

Issue 2150313002: NTP: Fix metrics recording crash by plumbing the necessary data to Java. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 package org.chromium.chrome.browser.ntp; 5 package org.chromium.chrome.browser.ntp;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.res.Resources; 9 import android.content.res.Resources;
10 import android.graphics.Bitmap; 10 import android.graphics.Bitmap;
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 mRecyclerView.updatePeekingCard(); 821 mRecyclerView.updatePeekingCard();
822 // The positioning of elements may have been changed (since the elem ents expand to fill 822 // The positioning of elements may have been changed (since the elem ents expand to fill
823 // the available vertical space), so adjust the scroll. 823 // the available vertical space), so adjust the scroll.
824 mRecyclerView.snapScroll(mSearchBoxView, getVerticalScroll(), getHei ght()); 824 mRecyclerView.snapScroll(mSearchBoxView, getVerticalScroll(), getHei ght());
825 } 825 }
826 } 826 }
827 827
828 // MostVisitedURLsObserver implementation 828 // MostVisitedURLsObserver implementation
829 829
830 @Override 830 @Override
831 public void onMostVisitedURLsAvailable( 831 public void onMostVisitedURLsAvailable(final String[] titles, final String[] urls,
832 final String[] titles, final String[] urls, final String[] whitelist IconPaths) { 832 final String[] whitelistIconPaths, final int[] sources, final int[] providerIndexes) {
833 Set<String> urlSet = new HashSet<>(Arrays.asList(urls)); 833 Set<String> urlSet = new HashSet<>(Arrays.asList(urls));
834 834
835 // TODO(https://crbug.com/607573): We should show offline-available cont ent in a nonblocking 835 // TODO(https://crbug.com/607573): We should show offline-available cont ent in a nonblocking
836 // way so that responsiveness of the NTP does not depend on ready availa bility of offline 836 // way so that responsiveness of the NTP does not depend on ready availa bility of offline
837 // pages. 837 // pages.
838 mManager.getUrlsAvailableOffline(urlSet, new Callback<Set<String>>() { 838 mManager.getUrlsAvailableOffline(urlSet, new Callback<Set<String>>() {
839 @Override 839 @Override
840 public void onResult(Set<String> offlineUrls) { 840 public void onResult(Set<String> offlineUrls) {
841 onOfflineUrlsAvailable(titles, urls, whitelistIconPaths, offline Urls); 841 onOfflineUrlsAvailable(
842 titles, urls, whitelistIconPaths, offlineUrls, sources, providerIndexes);
842 } 843 }
843 }); 844 });
844 } 845 }
845 846
846 private void onOfflineUrlsAvailable(final String[] titles, final String[] ur ls, 847 private void onOfflineUrlsAvailable(final String[] titles, final String[] ur ls,
847 final String[] whitelistIconPaths, final Set<String> offlineUrls) { 848 final String[] whitelistIconPaths, final Set<String> offlineUrls, fi nal int[] sources,
849 final int[] providerIndexes) {
848 mMostVisitedLayout.removeAllViews(); 850 mMostVisitedLayout.removeAllViews();
849 851
850 MostVisitedItem[] oldItems = mMostVisitedItems; 852 MostVisitedItem[] oldItems = mMostVisitedItems;
851 int oldItemCount = oldItems == null ? 0 : oldItems.length; 853 int oldItemCount = oldItems == null ? 0 : oldItems.length;
852 mMostVisitedItems = new MostVisitedItem[titles.length]; 854 mMostVisitedItems = new MostVisitedItem[titles.length];
853 855
854 final boolean isInitialLoad = !mHasReceivedMostVisitedSites; 856 final boolean isInitialLoad = !mHasReceivedMostVisitedSites;
855 LayoutInflater inflater = LayoutInflater.from(getContext()); 857 LayoutInflater inflater = LayoutInflater.from(getContext());
856 858
857 // Add the most visited items to the page. 859 // Add the most visited items to the page.
858 for (int i = 0; i < titles.length; i++) { 860 for (int i = 0; i < titles.length; i++) {
859 final String url = urls[i]; 861 final String url = urls[i];
860 final String title = titles[i]; 862 final String title = titles[i];
861 final String whitelistIconPath = whitelistIconPaths[i]; 863 final String whitelistIconPath = whitelistIconPaths[i];
864 final int source = sources[i];
865 final int providerIndex = providerIndexes[i];
866
862 boolean offlineAvailable = offlineUrls.contains(url); 867 boolean offlineAvailable = offlineUrls.contains(url);
863 868
864 // Look for an existing item to reuse. 869 // Look for an existing item to reuse.
865 MostVisitedItem item = null; 870 MostVisitedItem item = null;
866 for (int j = 0; j < oldItemCount; j++) { 871 for (int j = 0; j < oldItemCount; j++) {
867 MostVisitedItem oldItem = oldItems[j]; 872 MostVisitedItem oldItem = oldItems[j];
868 if (oldItem != null && TextUtils.equals(url, oldItem.getUrl()) 873 if (oldItem != null && TextUtils.equals(url, oldItem.getUrl())
869 && TextUtils.equals(title, oldItem.getTitle()) 874 && TextUtils.equals(title, oldItem.getTitle())
870 && offlineAvailable == oldItem.isOfflineAvailable() 875 && offlineAvailable == oldItem.isOfflineAvailable()
871 && whitelistIconPath.equals(oldItem.getWhitelistIconPath ())) { 876 && whitelistIconPath.equals(oldItem.getWhitelistIconPath ())) {
872 item = oldItem; 877 item = oldItem;
873 item.setIndex(i); 878 item.setIndex(i);
874 oldItems[j] = null; 879 oldItems[j] = null;
875 break; 880 break;
876 } 881 }
877 } 882 }
878 883
879 // If nothing can be reused, create a new item. 884 // If nothing can be reused, create a new item.
880 if (item == null) { 885 if (item == null) {
881 item = new MostVisitedItem( 886 item = new MostVisitedItem(mManager, title, url, whitelistIconPa th,
882 mManager, title, url, whitelistIconPath, offlineAvailabl e, i); 887 offlineAvailable, i, source, providerIndex);
883 View view = 888 View view =
884 mMostVisitedDesign.createMostVisitedItemView(inflater, i tem, isInitialLoad); 889 mMostVisitedDesign.createMostVisitedItemView(inflater, i tem, isInitialLoad);
885 item.initView(view); 890 item.initView(view);
886 } 891 }
887 892
888 mMostVisitedItems[i] = item; 893 mMostVisitedItems[i] = item;
889 mMostVisitedLayout.addView(item.getView()); 894 mMostVisitedLayout.addView(item.getView());
890 } 895 }
891 896
892 mHasReceivedMostVisitedSites = true; 897 mHasReceivedMostVisitedSites = true;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 } 1096 }
1092 1097
1093 private int getVerticalScroll() { 1098 private int getVerticalScroll() {
1094 if (mUseCardsUi) { 1099 if (mUseCardsUi) {
1095 return mRecyclerView.computeVerticalScrollOffset(); 1100 return mRecyclerView.computeVerticalScrollOffset();
1096 } else { 1101 } else {
1097 return mScrollView.getScrollY(); 1102 return mScrollView.getScrollY();
1098 } 1103 }
1099 } 1104 }
1100 } 1105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698