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

Side by Side Diff: chrome/browser/android/ntp/ntp_snippets_bridge.cc

Issue 2514343003: [NTP] Cleanup: specific category related data and bridge. (Closed)
Patch Set: rebase & mvanouerwerk@ nits. Created 4 years, 1 month 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 | « chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsBridge.java ('k') | 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ntp/ntp_snippets_bridge.h" 5 #include "chrome/browser/android/ntp/ntp_snippets_bridge.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 // Converts a vector of ContentSuggestions to its Java equivalent. 55 // Converts a vector of ContentSuggestions to its Java equivalent.
56 ScopedJavaLocalRef<jobject> ToJavaSuggestionList( 56 ScopedJavaLocalRef<jobject> ToJavaSuggestionList(
57 JNIEnv* env, 57 JNIEnv* env,
58 const Category& category, 58 const Category& category,
59 const CategoryInfo& info, 59 const CategoryInfo& info,
60 const std::vector<ContentSuggestion>& suggestions) { 60 const std::vector<ContentSuggestion>& suggestions) {
61 ScopedJavaLocalRef<jobject> result = 61 ScopedJavaLocalRef<jobject> result =
62 Java_SnippetsBridge_createSuggestionList(env); 62 Java_SnippetsBridge_createSuggestionList(env);
63 for (const ContentSuggestion& suggestion : suggestions) { 63 for (const ContentSuggestion& suggestion : suggestions) {
64 Java_SnippetsBridge_addSuggestion( 64 ScopedJavaLocalRef<jobject> java_suggestion =
65 env, result, category.id(), 65 Java_SnippetsBridge_addSuggestion(
66 ConvertUTF8ToJavaString(env, suggestion.id().id_within_category()), 66 env, result, category.id(),
67 ConvertUTF16ToJavaString(env, suggestion.title()), 67 ConvertUTF8ToJavaString(env, suggestion.id().id_within_category()),
68 ConvertUTF16ToJavaString(env, suggestion.publisher_name()), 68 ConvertUTF16ToJavaString(env, suggestion.title()),
69 ConvertUTF16ToJavaString(env, suggestion.snippet_text()), 69 ConvertUTF16ToJavaString(env, suggestion.publisher_name()),
70 ConvertUTF8ToJavaString(env, suggestion.url().spec()), 70 ConvertUTF16ToJavaString(env, suggestion.snippet_text()),
71 ConvertUTF8ToJavaString(env, suggestion.amp_url().spec()), 71 ConvertUTF8ToJavaString(env, suggestion.url().spec()),
72 suggestion.publish_date().ToJavaTime(), suggestion.score(), 72 ConvertUTF8ToJavaString(env, suggestion.amp_url().spec()),
73 static_cast<int>(info.card_layout())); 73 suggestion.publish_date().ToJavaTime(), suggestion.score(),
74 static_cast<int>(info.card_layout()));
74 if (suggestion.id().category().IsKnownCategory( 75 if (suggestion.id().category().IsKnownCategory(
75 KnownCategories::DOWNLOADS) && 76 KnownCategories::DOWNLOADS) &&
76 suggestion.download_suggestion_extra() != nullptr) { 77 suggestion.download_suggestion_extra() != nullptr) {
77 if (suggestion.download_suggestion_extra()->is_download_asset) { 78 if (suggestion.download_suggestion_extra()->is_download_asset) {
78 Java_SnippetsBridge_setDownloadAssetDataForLastSuggestion( 79 Java_SnippetsBridge_setAssetDownloadDataForSuggestion(
79 env, result, 80 env, java_suggestion,
80 ConvertUTF8ToJavaString(env, suggestion.download_suggestion_extra() 81 ConvertUTF8ToJavaString(env, suggestion.download_suggestion_extra()
81 ->target_file_path.value()), 82 ->target_file_path.value()),
82 ConvertUTF8ToJavaString( 83 ConvertUTF8ToJavaString(
83 env, suggestion.download_suggestion_extra()->mime_type)); 84 env, suggestion.download_suggestion_extra()->mime_type));
84 } else { 85 } else {
85 Java_SnippetsBridge_setDownloadOfflinePageDataForLastSuggestion( 86 Java_SnippetsBridge_setOfflinePageDownloadDataForSuggestion(
86 env, result, 87 env, java_suggestion,
87 suggestion.download_suggestion_extra()->offline_page_id); 88 suggestion.download_suggestion_extra()->offline_page_id);
88 } 89 }
89 } 90 }
90 if (suggestion.id().category().IsKnownCategory( 91 if (suggestion.id().category().IsKnownCategory(
91 KnownCategories::RECENT_TABS) && 92 KnownCategories::RECENT_TABS) &&
92 suggestion.recent_tab_suggestion_extra() != nullptr) { 93 suggestion.recent_tab_suggestion_extra() != nullptr) {
93 Java_SnippetsBridge_setRecentTabDataForLastSuggestion( 94 Java_SnippetsBridge_setRecentTabDataForSuggestion(
94 env, result, 95 env, java_suggestion,
95 ConvertUTF8ToJavaString( 96 ConvertUTF8ToJavaString(
96 env, suggestion.recent_tab_suggestion_extra()->tab_id), 97 env, suggestion.recent_tab_suggestion_extra()->tab_id),
97 suggestion.recent_tab_suggestion_extra()->offline_page_id); 98 suggestion.recent_tab_suggestion_extra()->offline_page_id);
98 } 99 }
99 } 100 }
100 101
101 return result; 102 return result;
102 } 103 }
103 104
104 } // namespace 105 } // namespace
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 } 467 }
467 468
468 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) { 469 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) {
469 return content_suggestions_service_->category_factory()->FromIDValue(id); 470 return content_suggestions_service_->category_factory()->FromIDValue(id);
470 } 471 }
471 472
472 // static 473 // static
473 bool NTPSnippetsBridge::Register(JNIEnv* env) { 474 bool NTPSnippetsBridge::Register(JNIEnv* env) {
474 return RegisterNativesImpl(env); 475 return RegisterNativesImpl(env);
475 } 476 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsBridge.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698