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

Side by Side Diff: chrome/browser/android/tab_android.cc

Issue 1973033002: [Offline pages] Lighting up the bookmark star for saved recent pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 #include "chrome/browser/android/tab_android.h" 5 #include "chrome/browser/android/tab_android.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 render_frame_host->GetRoutingID())); 754 render_frame_host->GetRoutingID()));
755 } 755 }
756 756
757 jlong TabAndroid::GetBookmarkId(JNIEnv* env, 757 jlong TabAndroid::GetBookmarkId(JNIEnv* env,
758 const JavaParamRef<jobject>& obj, 758 const JavaParamRef<jobject>& obj,
759 jboolean only_editable) { 759 jboolean only_editable) {
760 GURL url = dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl( 760 GURL url = dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(
761 web_contents()->GetURL()); 761 web_contents()->GetURL());
762 Profile* profile = GetProfile(); 762 Profile* profile = GetProfile();
763 763
764 // If the url points to an offline page, it already has a bookmark ID that it 764 // If the url points to an offline page, then we need to get its original URL.
765 // is related to. 765 if (offline_pages::OfflinePageUtils::IsOfflinePage(profile, url)) {
766 int64_t candidate_bookmark_id = 766 url = offline_pages::OfflinePageUtils::GetOnlineURLForOfflineURL(profile,
767 offline_pages::OfflinePageUtils::GetBookmarkIdForOfflineURL(profile, url); 767 url);
768 }
768 769
769 // Get all the nodes for |url| and sort them by date added. 770 // Get all the nodes for |url| and sort them by date added.
770 std::vector<const bookmarks::BookmarkNode*> nodes; 771 std::vector<const bookmarks::BookmarkNode*> nodes;
771 bookmarks::ManagedBookmarkService* managed = 772 bookmarks::ManagedBookmarkService* managed =
772 ManagedBookmarkServiceFactory::GetForProfile(profile); 773 ManagedBookmarkServiceFactory::GetForProfile(profile);
773 bookmarks::BookmarkModel* model = 774 bookmarks::BookmarkModel* model =
774 BookmarkModelFactory::GetForProfile(profile); 775 BookmarkModelFactory::GetForProfile(profile);
775 776
776 // If we have a candidate bookmark ID from the offline page model and that ID
777 // matches an existing bookmark, return it.
778 if (candidate_bookmark_id != -1 &&
779 bookmarks::GetBookmarkNodeByID(model, candidate_bookmark_id) != nullptr) {
780 return candidate_bookmark_id;
781 }
782
783 model->GetNodesByURL(url, &nodes); 777 model->GetNodesByURL(url, &nodes);
784 std::sort(nodes.begin(), nodes.end(), &bookmarks::MoreRecentlyAdded); 778 std::sort(nodes.begin(), nodes.end(), &bookmarks::MoreRecentlyAdded);
785 779
786 // Return the first node matching the search criteria. 780 // Return the first node matching the search criteria.
787 for (size_t i = 0; i < nodes.size(); ++i) { 781 for (size_t i = 0; i < nodes.size(); ++i) {
788 if (only_editable && !managed->CanBeEditedByUser(nodes[i])) 782 if (only_editable && !managed->CanBeEditedByUser(nodes[i]))
789 continue; 783 continue;
790 return nodes[i]->id(); 784 return nodes[i]->id();
791 } 785 }
792 786
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 910 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
917 TRACE_EVENT0("native", "TabAndroid::Init"); 911 TRACE_EVENT0("native", "TabAndroid::Init");
918 // This will automatically bind to the Java object and pass ownership there. 912 // This will automatically bind to the Java object and pass ownership there.
919 new TabAndroid(env, obj); 913 new TabAndroid(env, obj);
920 } 914 }
921 915
922 // static 916 // static
923 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { 917 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) {
924 return RegisterNativesImpl(env); 918 return RegisterNativesImpl(env);
925 } 919 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698