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

Side by Side Diff: chrome/browser/android/omnibox/answers_image_bridge.cc

Issue 312203005: [AiS] Java bridge for AnswersImageService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@img-service
Patch Set: Fix formatting. Created 6 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
« no previous file with comments | « chrome/browser/android/omnibox/answers_image_bridge.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/android/omnibox/answers_image_bridge.h"
6
7 #include <jni.h>
8
9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h"
11 #include "base/android/scoped_java_ref.h"
12 #include "base/bind.h"
13 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h"
14 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/profile_android.h"
17 #include "jni/AnswersImage_jni.h"
18 #include "third_party/skia/include/core/SkBitmap.h"
19 #include "ui/gfx/android/java_bitmap.h"
20 #include "url/gurl.h"
21
22 using base::android::ScopedJavaLocalRef;
23 using base::android::ConvertUTF8ToJavaString;
24
25 namespace {
26
27 class AnswersImageObserverAndroid : public BitmapFetcherService::Observer {
28 public:
29 explicit AnswersImageObserverAndroid(JNIEnv* env,
30 jobject java_answers_image_observer) {
31 java_answers_image_observer_.Reset(env, java_answers_image_observer);
32 }
33
34 virtual ~AnswersImageObserverAndroid() {}
35
36 // AnswersImageObserver:
37 virtual void OnImageChanged(BitmapFetcherService::RequestId request_id,
38 const SkBitmap& answers_image) OVERRIDE {
39 // An empty image signals a completed request.
40 if (answers_image.empty()) {
41 delete this;
42 return;
43 }
44
45 JNIEnv* env = base::android::AttachCurrentThread();
46 ScopedJavaLocalRef<jobject> java_bitmap =
47 gfx::ConvertToJavaBitmap(&answers_image);
48 Java_AnswersImageObserver_onAnswersImageChanged(
49 env, java_answers_image_observer_.obj(), java_bitmap.obj());
50 }
51
52 private:
53 base::android::ScopedJavaGlobalRef<jobject> java_answers_image_observer_;
54 };
55
56 } // namespace
57
58 static void CancelAnswersImageRequest(JNIEnv* env,
59 jclass,
60 jobject java_profile,
61 jint java_request_id) {
62 Profile* profile = ProfileAndroid::FromProfileAndroid(java_profile);
63 DCHECK(profile);
64 BitmapFetcherService* bitmap_fetcher_service =
65 BitmapFetcherServiceFactory::GetForBrowserContext(profile);
66 bitmap_fetcher_service->CancelRequest(java_request_id);
67 }
68
69 static int RequestAnswersImage(JNIEnv* env,
70 jclass,
71 jobject java_profile,
72 jstring java_url,
73 jobject java_callback) {
74 Profile* profile = ProfileAndroid::FromProfileAndroid(java_profile);
75 DCHECK(profile);
76 BitmapFetcherService* bitmap_fetcher_service =
77 BitmapFetcherServiceFactory::GetForBrowserContext(profile);
78 std::string url;
79 base::android::ConvertJavaStringToUTF8(env, java_url, &url);
80 return bitmap_fetcher_service->RequestImage(
81 GURL(url), new AnswersImageObserverAndroid(env, java_callback));
82 }
83
84 // static
85 bool RegisterAnswersImageBridge(JNIEnv* env) {
86 return RegisterNativesImpl(env);
87 }
OLDNEW
« no previous file with comments | « chrome/browser/android/omnibox/answers_image_bridge.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698