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

Side by Side Diff: chrome/browser/enhanced_bookmarks/android/enhanced_bookmarks_bridge.cc

Issue 1184613002: [Android] Remove search feature from enhanced bookmarks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/enhanced_bookmarks/android/enhanced_bookmarks_bridge.h" 5 #include "chrome/browser/enhanced_bookmarks/android/enhanced_bookmarks_bridge.h"
6 6
7 #include "base/android/jni_array.h" 7 #include "base/android/jni_array.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 Profile* profile) : weak_java_ref_(env, obj) { 73 Profile* profile) : weak_java_ref_(env, obj) {
74 profile_ = profile; 74 profile_ = profile;
75 enhanced_bookmark_model_ = 75 enhanced_bookmark_model_ =
76 EnhancedBookmarkModelFactory::GetForBrowserContext(profile_); 76 EnhancedBookmarkModelFactory::GetForBrowserContext(profile_);
77 enhanced_bookmark_model_->SetVersionSuffix(chrome::VersionInfo().OSType()); 77 enhanced_bookmark_model_->SetVersionSuffix(chrome::VersionInfo().OSType());
78 cluster_service_ = 78 cluster_service_ =
79 BookmarkServerClusterServiceFactory::GetForBrowserContext(profile_); 79 BookmarkServerClusterServiceFactory::GetForBrowserContext(profile_);
80 cluster_service_->AddObserver(this); 80 cluster_service_->AddObserver(this);
81 bookmark_image_service_ = static_cast<BookmarkImageServiceAndroid*>( 81 bookmark_image_service_ = static_cast<BookmarkImageServiceAndroid*>(
82 BookmarkImageServiceFactory::GetForBrowserContext(profile_)); 82 BookmarkImageServiceFactory::GetForBrowserContext(profile_));
83 search_service_.reset(new BookmarkServerSearchService(
84 profile_->GetRequestContext(),
85 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_),
86 SigninManagerFactory::GetForProfile(profile_),
87 EnhancedBookmarkModelFactory::GetForBrowserContext(profile_)));
88 search_service_->AddObserver(this);
89 } 83 }
90 84
91 EnhancedBookmarksBridge::~EnhancedBookmarksBridge() { 85 EnhancedBookmarksBridge::~EnhancedBookmarksBridge() {
92 cluster_service_->RemoveObserver(this); 86 cluster_service_->RemoveObserver(this);
93 search_service_->RemoveObserver(this);
94 } 87 }
95 88
96 void EnhancedBookmarksBridge::Destroy(JNIEnv*, jobject) { 89 void EnhancedBookmarksBridge::Destroy(JNIEnv*, jobject) {
97 delete this; 90 delete this;
98 } 91 }
99 92
100 void EnhancedBookmarksBridge::SalientImageForUrl(JNIEnv* env, 93 void EnhancedBookmarksBridge::SalientImageForUrl(JNIEnv* env,
101 jobject obj, 94 jobject obj,
102 jstring j_url, 95 jstring j_url,
103 jobject j_callback) { 96 jobject j_callback) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 base::Time::Now()); 247 base::Time::Now());
255 if (!new_node) { 248 if (!new_node) {
256 NOTREACHED(); 249 NOTREACHED();
257 return ScopedJavaLocalRef<jobject>(); 250 return ScopedJavaLocalRef<jobject>();
258 } 251 }
259 ScopedJavaLocalRef<jobject> new_java_obj = JavaBookmarkIdCreateBookmarkId( 252 ScopedJavaLocalRef<jobject> new_java_obj = JavaBookmarkIdCreateBookmarkId(
260 env, new_node->id(), BookmarkType::BOOKMARK_TYPE_NORMAL); 253 env, new_node->id(), BookmarkType::BOOKMARK_TYPE_NORMAL);
261 return new_java_obj; 254 return new_java_obj;
262 } 255 }
263 256
264 void EnhancedBookmarksBridge::SendSearchRequest(JNIEnv* env,
265 jobject obj,
266 jstring j_query) {
267 search_service_->Search(base::android::ConvertJavaStringToUTF8(env, j_query));
268 }
269
270 ScopedJavaLocalRef<jobject> EnhancedBookmarksBridge::GetSearchResults(
271 JNIEnv* env,
272 jobject obj,
273 jstring j_query) {
274 DCHECK(enhanced_bookmark_model_->loaded());
275
276 ScopedJavaLocalRef<jobject> j_list =
277 Java_EnhancedBookmarksBridge_createBookmarkIdList(env);
278 scoped_ptr<std::vector<const BookmarkNode*>> results =
279 search_service_->ResultForQuery(
280 base::android::ConvertJavaStringToUTF8(env, j_query));
281
282 // If result is null, return a null java reference.
283 if (!results.get())
284 return ScopedJavaLocalRef<jobject>();
285
286 for (const BookmarkNode* node : *results) {
287 Java_EnhancedBookmarksBridge_addToBookmarkIdList(env, j_list.obj(),
288 node->id(), node->type());
289 }
290 return j_list;
291 }
292
293 void EnhancedBookmarksBridge::OnChange(BookmarkServerService* service) { 257 void EnhancedBookmarksBridge::OnChange(BookmarkServerService* service) {
294 DCHECK(enhanced_bookmark_model_->loaded()); 258 DCHECK(enhanced_bookmark_model_->loaded());
295 JNIEnv* env = AttachCurrentThread(); 259 JNIEnv* env = AttachCurrentThread();
296 260
297 ScopedJavaLocalRef<jobject> obj = weak_java_ref_.get(env); 261 ScopedJavaLocalRef<jobject> obj = weak_java_ref_.get(env);
298 if (obj.is_null()) 262 if (obj.is_null())
299 return; 263 return;
300 264
301 if (service == cluster_service_) { 265 if (service == cluster_service_) {
302 Java_EnhancedBookmarksBridge_onFiltersChanged(env, obj.obj()); 266 Java_EnhancedBookmarksBridge_onFiltersChanged(env, obj.obj());
303 } else if (service == search_service_.get()) {
304 Java_EnhancedBookmarksBridge_onSearchResultReturned(env, obj.obj());
305 } 267 }
306 } 268 }
307 269
308 bool EnhancedBookmarksBridge::IsEditable(const BookmarkNode* node) const { 270 bool EnhancedBookmarksBridge::IsEditable(const BookmarkNode* node) const {
309 if (!node || (node->type() != BookmarkNode::FOLDER && 271 if (!node || (node->type() != BookmarkNode::FOLDER &&
310 node->type() != BookmarkNode::URL)) { 272 node->type() != BookmarkNode::URL)) {
311 return false; 273 return false;
312 } 274 }
313 return profile_->GetPrefs()->GetBoolean( 275 return profile_->GetPrefs()->GetBoolean(
314 bookmarks::prefs::kEditBookmarksEnabled); 276 bookmarks::prefs::kEditBookmarksEnabled);
315 } 277 }
316 278
317 static jint GetDefaultViewMode(JNIEnv* env, jclass jcaller) { 279 static jint GetDefaultViewMode(JNIEnv* env, jclass jcaller) {
318 return enhanced_bookmarks::GetDefaultViewMode(); 280 return enhanced_bookmarks::GetDefaultViewMode();
319 } 281 }
320 282
321 static jlong Init(JNIEnv* env, jobject obj, jobject j_profile) { 283 static jlong Init(JNIEnv* env, jobject obj, jobject j_profile) {
322 return reinterpret_cast<jlong>(new EnhancedBookmarksBridge( 284 return reinterpret_cast<jlong>(new EnhancedBookmarksBridge(
323 env, obj, ProfileAndroid::FromProfileAndroid(j_profile))); 285 env, obj, ProfileAndroid::FromProfileAndroid(j_profile)));
324 } 286 }
325 287
326 bool RegisterEnhancedBookmarksBridge(JNIEnv* env) { 288 bool RegisterEnhancedBookmarksBridge(JNIEnv* env) {
327 return RegisterNativesImpl(env); 289 return RegisterNativesImpl(env);
328 } 290 }
329 291
330 } // namespace android 292 } // namespace android
331 } // namespace enhanced_bookmarks 293 } // namespace enhanced_bookmarks
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698