OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/favicon_helper.h" | 5 #include "chrome/browser/android/favicon_helper.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
11 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/browser/favicon/favicon_service.h" | 15 #include "chrome/browser/favicon/favicon_service.h" |
16 #include "chrome/browser/favicon/favicon_service_factory.h" | 16 #include "chrome/browser/favicon/favicon_service_factory.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/profiles/profile_android.h" | 18 #include "chrome/browser/profiles/profile_android.h" |
19 #include "chrome/browser/sync/glue/session_model_associator.h" | 19 #include "chrome/browser/sync/open_tabs_ui_delegate.h" |
20 #include "chrome/browser/sync/glue/session_model_associator.h" | |
21 #include "chrome/browser/sync/profile_sync_service.h" | 20 #include "chrome/browser/sync/profile_sync_service.h" |
22 #include "chrome/browser/sync/profile_sync_service_factory.h" | 21 #include "chrome/browser/sync/profile_sync_service_factory.h" |
23 #include "chrome/browser/sync/profile_sync_service_factory.h" | 22 #include "chrome/browser/sync/profile_sync_service_factory.h" |
24 #include "jni/FaviconHelper_jni.h" | 23 #include "jni/FaviconHelper_jni.h" |
25 #include "third_party/skia/include/core/SkBitmap.h" | 24 #include "third_party/skia/include/core/SkBitmap.h" |
26 #include "ui/gfx/android/java_bitmap.h" | 25 #include "ui/gfx/android/java_bitmap.h" |
27 #include "ui/gfx/color_analysis.h" | 26 #include "ui/gfx/color_analysis.h" |
28 #include "ui/gfx/color_utils.h" | 27 #include "ui/gfx/color_utils.h" |
29 | 28 |
30 using base::android::ScopedJavaGlobalRef; | 29 using base::android::ScopedJavaGlobalRef; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); | 115 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); |
117 DCHECK(profile); | 116 DCHECK(profile); |
118 | 117 |
119 std::string page_url = ConvertJavaStringToUTF8(env, j_page_url); | 118 std::string page_url = ConvertJavaStringToUTF8(env, j_page_url); |
120 | 119 |
121 ProfileSyncService* sync_service = | 120 ProfileSyncService* sync_service = |
122 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 121 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
123 DCHECK(sync_service); | 122 DCHECK(sync_service); |
124 | 123 |
125 scoped_refptr<base::RefCountedMemory> favicon_png; | 124 scoped_refptr<base::RefCountedMemory> favicon_png; |
126 browser_sync::SessionModelAssociator* associator = | 125 browser_sync::OpenTabsUIDelegate* open_tabs = |
127 sync_service->GetSessionModelAssociator(); | 126 sync_service->GetOpenTabsUIDelegate(); |
128 DCHECK(associator); | 127 DCHECK(open_tabs); |
129 | 128 |
130 if (!associator->GetSyncedFaviconForPageURL(page_url, &favicon_png)) | 129 if (!open_tabs->GetSyncedFaviconForPageURL(page_url, &favicon_png)) |
131 return ScopedJavaLocalRef<jobject>(); | 130 return ScopedJavaLocalRef<jobject>(); |
132 | 131 |
133 // Convert favicon_image_result to java objects. | 132 // Convert favicon_image_result to java objects. |
134 gfx::Image favicon_image = gfx::Image::CreateFrom1xPNGBytes( | 133 gfx::Image favicon_image = gfx::Image::CreateFrom1xPNGBytes( |
135 favicon_png->front(), favicon_png->size()); | 134 favicon_png->front(), favicon_png->size()); |
136 SkBitmap favicon_bitmap = favicon_image.AsBitmap(); | 135 SkBitmap favicon_bitmap = favicon_image.AsBitmap(); |
137 | 136 |
138 ScopedJavaLocalRef<jobject> j_favicon_bitmap; | 137 ScopedJavaLocalRef<jobject> j_favicon_bitmap; |
139 if (favicon_bitmap.isNull()) | 138 if (favicon_bitmap.isNull()) |
140 return ScopedJavaLocalRef<jobject>(); | 139 return ScopedJavaLocalRef<jobject>(); |
(...skipping 18 matching lines...) Expand all Loading... |
159 return color_utils::CalculateKMeanColorOfPNG( | 158 return color_utils::CalculateKMeanColorOfPNG( |
160 png_data, min_darkness, max_brightness, &sampler); | 159 png_data, min_darkness, max_brightness, &sampler); |
161 } | 160 } |
162 | 161 |
163 FaviconHelper::~FaviconHelper() {} | 162 FaviconHelper::~FaviconHelper() {} |
164 | 163 |
165 // static | 164 // static |
166 bool FaviconHelper::RegisterFaviconHelper(JNIEnv* env) { | 165 bool FaviconHelper::RegisterFaviconHelper(JNIEnv* env) { |
167 return RegisterNativesImpl(env); | 166 return RegisterNativesImpl(env); |
168 } | 167 } |
OLD | NEW |