Chromium Code Reviews| 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/android/tab_android.h" | |
| 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 12 #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" | 13 #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" | 14 #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" | 15 #include "chrome/browser/enhanced_bookmarks/chrome_bookmark_server_cluster_servi ce_factory.h" |
| 14 #include "chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h" | 16 #include "chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h" |
| 15 #include "chrome/browser/profiles/profile_android.h" | 17 #include "chrome/browser/profiles/profile_android.h" |
| 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 17 #include "chrome/browser/signin/signin_manager_factory.h" | 19 #include "chrome/browser/signin/signin_manager_factory.h" |
| 18 #include "chrome/common/chrome_version_info.h" | 20 #include "chrome/common/chrome_version_info.h" |
| 19 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 20 #include "components/bookmarks/browser/bookmark_model.h" | 22 #include "components/bookmarks/browser/bookmark_model.h" |
| 21 #include "components/bookmarks/browser/bookmark_utils.h" | 23 #include "components/bookmarks/browser/bookmark_utils.h" |
| 22 #include "components/bookmarks/common/android/bookmark_id.h" | 24 #include "components/bookmarks/common/android/bookmark_id.h" |
| 23 #include "components/bookmarks/common/android/bookmark_type.h" | 25 #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" | 26 #include "components/enhanced_bookmarks/enhanced_bookmark_model.h" |
| 26 #include "components/enhanced_bookmarks/image_record.h" | 27 #include "components/enhanced_bookmarks/image_record.h" |
| 27 #include "components/signin/core/browser/signin_manager.h" | 28 #include "components/signin/core/browser/signin_manager.h" |
| 28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.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; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 EnhancedBookmarksBridge::EnhancedBookmarksBridge(JNIEnv* env, | 69 EnhancedBookmarksBridge::EnhancedBookmarksBridge(JNIEnv* env, |
| 69 jobject obj, | 70 jobject obj, |
| 70 Profile* profile) : weak_java_ref_(env, obj) { | 71 Profile* profile) : weak_java_ref_(env, obj) { |
| 71 profile_ = profile; | 72 profile_ = profile; |
| 72 enhanced_bookmark_model_ = | 73 enhanced_bookmark_model_ = |
| 73 EnhancedBookmarkModelFactory::GetForBrowserContext(profile_); | 74 EnhancedBookmarkModelFactory::GetForBrowserContext(profile_); |
| 74 enhanced_bookmark_model_->SetVersionSuffix(chrome::VersionInfo().OSType()); | 75 enhanced_bookmark_model_->SetVersionSuffix(chrome::VersionInfo().OSType()); |
| 75 cluster_service_ = | 76 cluster_service_ = |
| 76 ChromeBookmarkServerClusterServiceFactory::GetForBrowserContext(profile_); | 77 ChromeBookmarkServerClusterServiceFactory::GetForBrowserContext(profile_); |
| 77 cluster_service_->AddObserver(this); | 78 cluster_service_->AddObserver(this); |
| 78 bookmark_image_service_ = | 79 bookmark_image_service_ = static_cast<BookmarkImageServiceAndroid*>( |
| 79 BookmarkImageServiceFactory::GetForBrowserContext(profile_); | 80 BookmarkImageServiceFactory::GetForBrowserContext(profile_)); |
| 80 search_service_.reset(new BookmarkServerSearchService( | 81 search_service_.reset(new BookmarkServerSearchService( |
| 81 profile_->GetRequestContext(), | 82 profile_->GetRequestContext(), |
| 82 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), | 83 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), |
| 83 SigninManagerFactory::GetForProfile(profile_), | 84 SigninManagerFactory::GetForProfile(profile_), |
| 84 EnhancedBookmarkModelFactory::GetForBrowserContext(profile_))); | 85 EnhancedBookmarkModelFactory::GetForBrowserContext(profile_))); |
| 85 search_service_->AddObserver(this); | 86 search_service_->AddObserver(this); |
| 86 } | 87 } |
| 87 | 88 |
| 88 EnhancedBookmarksBridge::~EnhancedBookmarksBridge() { | 89 EnhancedBookmarksBridge::~EnhancedBookmarksBridge() { |
| 89 cluster_service_->RemoveObserver(this); | 90 cluster_service_->RemoveObserver(this); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 101 DCHECK(j_callback); | 102 DCHECK(j_callback); |
| 102 | 103 |
| 103 GURL url(base::android::ConvertJavaStringToUTF16(env, j_url)); | 104 GURL url(base::android::ConvertJavaStringToUTF16(env, j_url)); |
| 104 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_callback_ptr( | 105 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_callback_ptr( |
| 105 new ScopedJavaGlobalRef<jobject>()); | 106 new ScopedJavaGlobalRef<jobject>()); |
| 106 j_callback_ptr->Reset(env, j_callback); | 107 j_callback_ptr->Reset(env, j_callback); |
| 107 bookmark_image_service_->SalientImageForUrl( | 108 bookmark_image_service_->SalientImageForUrl( |
| 108 url, base::Bind(&Callback, j_callback_ptr.release())); | 109 url, base::Bind(&Callback, j_callback_ptr.release())); |
| 109 } | 110 } |
| 110 | 111 |
| 112 void EnhancedBookmarksBridge::FetchImageForTab(JNIEnv* env, | |
| 113 jobject obj, | |
| 114 jobject j_tab) { | |
| 115 TabAndroid* tab = TabAndroid::GetNativeTab(env, j_tab); | |
| 116 bookmark_image_service_->RetrieveSalientImageFromContext( | |
| 117 tab->web_contents()->GetMainFrame(), tab->GetURL(), true); | |
| 118 } | |
|
Kibeom Kim (inactive)
2015/02/09 21:30:34
In addition to using WebContent, since this is par
Kibeom Kim (inactive)
2015/02/09 21:57:24
discussed offline. It's just two lines, so let's j
| |
| 119 | |
| 111 ScopedJavaLocalRef<jstring> EnhancedBookmarksBridge::GetBookmarkDescription( | 120 ScopedJavaLocalRef<jstring> EnhancedBookmarksBridge::GetBookmarkDescription( |
| 112 JNIEnv* env, jobject obj, jlong id, jint type) { | 121 JNIEnv* env, jobject obj, jlong id, jint type) { |
| 113 DCHECK(enhanced_bookmark_model_->loaded()); | 122 DCHECK(enhanced_bookmark_model_->loaded()); |
| 114 if (type != BookmarkType::BOOKMARK_TYPE_NORMAL) { | 123 if (type != BookmarkType::BOOKMARK_TYPE_NORMAL) { |
| 115 return base::android::ConvertUTF8ToJavaString(env, std::string()); | 124 return base::android::ConvertUTF8ToJavaString(env, std::string()); |
| 116 } | 125 } |
| 117 | 126 |
| 118 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID( | 127 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID( |
| 119 enhanced_bookmark_model_->bookmark_model(), static_cast<int64>(id)); | 128 enhanced_bookmark_model_->bookmark_model(), static_cast<int64>(id)); |
| 120 | 129 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 return reinterpret_cast<jlong>(new EnhancedBookmarksBridge( | 316 return reinterpret_cast<jlong>(new EnhancedBookmarksBridge( |
| 308 env, obj, ProfileAndroid::FromProfileAndroid(j_profile))); | 317 env, obj, ProfileAndroid::FromProfileAndroid(j_profile))); |
| 309 } | 318 } |
| 310 | 319 |
| 311 bool RegisterEnhancedBookmarksBridge(JNIEnv* env) { | 320 bool RegisterEnhancedBookmarksBridge(JNIEnv* env) { |
| 312 return RegisterNativesImpl(env); | 321 return RegisterNativesImpl(env); |
| 313 } | 322 } |
| 314 | 323 |
| 315 } // namespace android | 324 } // namespace android |
| 316 } // namespace enhanced_bookmarks | 325 } // namespace enhanced_bookmarks |
| OLD | NEW |