| OLD | NEW |
| 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" |
| 11 #include "chrome/browser/enhanced_bookmarks/android/bookmark_image_service_andro
id.h" |
| 11 #include "chrome/browser/enhanced_bookmarks/android/bookmark_image_service_facto
ry.h" | 12 #include "chrome/browser/enhanced_bookmarks/android/bookmark_image_service_facto
ry.h" |
| 12 #include "chrome/browser/enhanced_bookmarks/chrome_bookmark_server_cluster_servi
ce.h" | 13 #include "chrome/browser/enhanced_bookmarks/chrome_bookmark_server_cluster_servi
ce.h" |
| 13 #include "chrome/browser/enhanced_bookmarks/chrome_bookmark_server_cluster_servi
ce_factory.h" | 14 #include "chrome/browser/enhanced_bookmarks/chrome_bookmark_server_cluster_servi
ce_factory.h" |
| 14 #include "chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h" | 15 #include "chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h" |
| 15 #include "chrome/browser/profiles/profile_android.h" | 16 #include "chrome/browser/profiles/profile_android.h" |
| 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 17 #include "chrome/browser/signin/signin_manager_factory.h" | 18 #include "chrome/browser/signin/signin_manager_factory.h" |
| 18 #include "chrome/common/chrome_version_info.h" | 19 #include "chrome/common/chrome_version_info.h" |
| 19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 20 #include "components/bookmarks/browser/bookmark_model.h" | 21 #include "components/bookmarks/browser/bookmark_model.h" |
| 21 #include "components/bookmarks/browser/bookmark_utils.h" | 22 #include "components/bookmarks/browser/bookmark_utils.h" |
| 22 #include "components/bookmarks/common/android/bookmark_id.h" | 23 #include "components/bookmarks/common/android/bookmark_id.h" |
| 23 #include "components/bookmarks/common/android/bookmark_type.h" | 24 #include "components/bookmarks/common/android/bookmark_type.h" |
| 24 #include "components/enhanced_bookmarks/bookmark_image_service.h" | |
| 25 #include "components/enhanced_bookmarks/enhanced_bookmark_model.h" | 25 #include "components/enhanced_bookmarks/enhanced_bookmark_model.h" |
| 26 #include "components/enhanced_bookmarks/image_record.h" | 26 #include "components/enhanced_bookmarks/image_record.h" |
| 27 #include "components/signin/core/browser/signin_manager.h" | 27 #include "components/signin/core/browser/signin_manager.h" |
| 28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/web_contents.h" |
| 29 #include "jni/EnhancedBookmarksBridge_jni.h" | 30 #include "jni/EnhancedBookmarksBridge_jni.h" |
| 30 #include "ui/gfx/android/java_bitmap.h" | 31 #include "ui/gfx/android/java_bitmap.h" |
| 31 #include "ui/gfx/image/image.h" | 32 #include "ui/gfx/image/image.h" |
| 32 | 33 |
| 33 using base::android::AttachCurrentThread; | 34 using base::android::AttachCurrentThread; |
| 34 using base::android::ScopedJavaGlobalRef; | 35 using base::android::ScopedJavaGlobalRef; |
| 35 using bookmarks::android::JavaBookmarkIdCreateBookmarkId; | 36 using bookmarks::android::JavaBookmarkIdCreateBookmarkId; |
| 36 using bookmarks::android::JavaBookmarkIdGetId; | 37 using bookmarks::android::JavaBookmarkIdGetId; |
| 37 using bookmarks::android::JavaBookmarkIdGetType; | 38 using bookmarks::android::JavaBookmarkIdGetType; |
| 38 using bookmarks::BookmarkNode; | 39 using bookmarks::BookmarkNode; |
| 39 using bookmarks::BookmarkType; | 40 using bookmarks::BookmarkType; |
| 41 using content::WebContents; |
| 40 using content::BrowserThread; | 42 using content::BrowserThread; |
| 41 using enhanced_bookmarks::ImageRecord; | 43 using enhanced_bookmarks::ImageRecord; |
| 42 | 44 |
| 43 namespace { | 45 namespace { |
| 44 | 46 |
| 45 void Callback(ScopedJavaGlobalRef<jobject>* j_callback, | 47 void Callback(ScopedJavaGlobalRef<jobject>* j_callback, |
| 46 const ImageRecord& image_record) { | 48 const ImageRecord& image_record) { |
| 47 JNIEnv* env = base::android::AttachCurrentThread(); | 49 JNIEnv* env = base::android::AttachCurrentThread(); |
| 48 | 50 |
| 49 scoped_ptr<ScopedJavaGlobalRef<jobject> > j_callback_ptr(j_callback); | 51 scoped_ptr<ScopedJavaGlobalRef<jobject> > j_callback_ptr(j_callback); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 68 EnhancedBookmarksBridge::EnhancedBookmarksBridge(JNIEnv* env, | 70 EnhancedBookmarksBridge::EnhancedBookmarksBridge(JNIEnv* env, |
| 69 jobject obj, | 71 jobject obj, |
| 70 Profile* profile) : weak_java_ref_(env, obj) { | 72 Profile* profile) : weak_java_ref_(env, obj) { |
| 71 profile_ = profile; | 73 profile_ = profile; |
| 72 enhanced_bookmark_model_ = | 74 enhanced_bookmark_model_ = |
| 73 EnhancedBookmarkModelFactory::GetForBrowserContext(profile_); | 75 EnhancedBookmarkModelFactory::GetForBrowserContext(profile_); |
| 74 enhanced_bookmark_model_->SetVersionSuffix(chrome::VersionInfo().OSType()); | 76 enhanced_bookmark_model_->SetVersionSuffix(chrome::VersionInfo().OSType()); |
| 75 cluster_service_ = | 77 cluster_service_ = |
| 76 ChromeBookmarkServerClusterServiceFactory::GetForBrowserContext(profile_); | 78 ChromeBookmarkServerClusterServiceFactory::GetForBrowserContext(profile_); |
| 77 cluster_service_->AddObserver(this); | 79 cluster_service_->AddObserver(this); |
| 78 bookmark_image_service_ = | 80 bookmark_image_service_ = static_cast<BookmarkImageServiceAndroid*>( |
| 79 BookmarkImageServiceFactory::GetForBrowserContext(profile_); | 81 BookmarkImageServiceFactory::GetForBrowserContext(profile_)); |
| 80 search_service_.reset(new BookmarkServerSearchService( | 82 search_service_.reset(new BookmarkServerSearchService( |
| 81 profile_->GetRequestContext(), | 83 profile_->GetRequestContext(), |
| 82 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), | 84 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), |
| 83 SigninManagerFactory::GetForProfile(profile_), | 85 SigninManagerFactory::GetForProfile(profile_), |
| 84 EnhancedBookmarkModelFactory::GetForBrowserContext(profile_))); | 86 EnhancedBookmarkModelFactory::GetForBrowserContext(profile_))); |
| 85 search_service_->AddObserver(this); | 87 search_service_->AddObserver(this); |
| 86 } | 88 } |
| 87 | 89 |
| 88 EnhancedBookmarksBridge::~EnhancedBookmarksBridge() { | 90 EnhancedBookmarksBridge::~EnhancedBookmarksBridge() { |
| 89 cluster_service_->RemoveObserver(this); | 91 cluster_service_->RemoveObserver(this); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 101 DCHECK(j_callback); | 103 DCHECK(j_callback); |
| 102 | 104 |
| 103 GURL url(base::android::ConvertJavaStringToUTF16(env, j_url)); | 105 GURL url(base::android::ConvertJavaStringToUTF16(env, j_url)); |
| 104 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_callback_ptr( | 106 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_callback_ptr( |
| 105 new ScopedJavaGlobalRef<jobject>()); | 107 new ScopedJavaGlobalRef<jobject>()); |
| 106 j_callback_ptr->Reset(env, j_callback); | 108 j_callback_ptr->Reset(env, j_callback); |
| 107 bookmark_image_service_->SalientImageForUrl( | 109 bookmark_image_service_->SalientImageForUrl( |
| 108 url, base::Bind(&Callback, j_callback_ptr.release())); | 110 url, base::Bind(&Callback, j_callback_ptr.release())); |
| 109 } | 111 } |
| 110 | 112 |
| 113 void EnhancedBookmarksBridge::FetchImageForTab(JNIEnv* env, |
| 114 jobject obj, |
| 115 jobject j_web_contents) { |
| 116 WebContents* web_contents = WebContents::FromJavaWebContents(j_web_contents); |
| 117 bookmark_image_service_->RetrieveSalientImageFromContext( |
| 118 web_contents->GetMainFrame(), web_contents->GetURL(), true); |
| 119 } |
| 120 |
| 111 ScopedJavaLocalRef<jstring> EnhancedBookmarksBridge::GetBookmarkDescription( | 121 ScopedJavaLocalRef<jstring> EnhancedBookmarksBridge::GetBookmarkDescription( |
| 112 JNIEnv* env, jobject obj, jlong id, jint type) { | 122 JNIEnv* env, jobject obj, jlong id, jint type) { |
| 113 DCHECK(enhanced_bookmark_model_->loaded()); | 123 DCHECK(enhanced_bookmark_model_->loaded()); |
| 114 if (type != BookmarkType::BOOKMARK_TYPE_NORMAL) { | 124 if (type != BookmarkType::BOOKMARK_TYPE_NORMAL) { |
| 115 return base::android::ConvertUTF8ToJavaString(env, std::string()); | 125 return base::android::ConvertUTF8ToJavaString(env, std::string()); |
| 116 } | 126 } |
| 117 | 127 |
| 118 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID( | 128 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID( |
| 119 enhanced_bookmark_model_->bookmark_model(), static_cast<int64>(id)); | 129 enhanced_bookmark_model_->bookmark_model(), static_cast<int64>(id)); |
| 120 | 130 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 return reinterpret_cast<jlong>(new EnhancedBookmarksBridge( | 317 return reinterpret_cast<jlong>(new EnhancedBookmarksBridge( |
| 308 env, obj, ProfileAndroid::FromProfileAndroid(j_profile))); | 318 env, obj, ProfileAndroid::FromProfileAndroid(j_profile))); |
| 309 } | 319 } |
| 310 | 320 |
| 311 bool RegisterEnhancedBookmarksBridge(JNIEnv* env) { | 321 bool RegisterEnhancedBookmarksBridge(JNIEnv* env) { |
| 312 return RegisterNativesImpl(env); | 322 return RegisterNativesImpl(env); |
| 313 } | 323 } |
| 314 | 324 |
| 315 } // namespace android | 325 } // namespace android |
| 316 } // namespace enhanced_bookmarks | 326 } // namespace enhanced_bookmarks |
| OLD | NEW |