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

Side by Side Diff: components/dom_distiller/core/distilled_page_prefs_android.cc

Issue 403323005: Observer Support for DistilledPagePrefs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changed observerMap type from HashMap to Map Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « components/dom_distiller/core/distilled_page_prefs_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/dom_distiller/core/distilled_page_prefs_android.h" 5 #include "components/dom_distiller/core/distilled_page_prefs_android.h"
6 6
7 #include "components/dom_distiller/core/distilled_page_prefs.h" 7 #include "components/dom_distiller/core/distilled_page_prefs.h"
8 #include "components/dom_distiller/core/dom_distiller_service.h" 8 #include "components/dom_distiller/core/dom_distiller_service.h"
9 #include "jni/DistilledPagePrefs_jni.h" 9 #include "jni/DistilledPagePrefs_jni.h"
10 10
11 namespace dom_distiller { 11 namespace dom_distiller {
12
12 namespace android { 13 namespace android {
13 14
14 DistilledPagePrefsAndroid::DistilledPagePrefsAndroid( 15 DistilledPagePrefsAndroid::DistilledPagePrefsAndroid(
15 JNIEnv* env, 16 JNIEnv* env,
16 jobject obj, 17 jobject obj,
17 DistilledPagePrefs* distillerPagePrefsPtr) 18 DistilledPagePrefs* distilled_page_prefs_ptr)
18 : distilled_page_prefs_(distillerPagePrefsPtr) { 19 : distilled_page_prefs_(distilled_page_prefs_ptr) {
19 } 20 }
20 21
21 DistilledPagePrefsAndroid::~DistilledPagePrefsAndroid() { 22 DistilledPagePrefsAndroid::~DistilledPagePrefsAndroid() {
22 } 23 }
23 24
24 void DistilledPagePrefsAndroid::SetTheme(JNIEnv* env, jobject obj, jint theme) { 25 void DistilledPagePrefsAndroid::SetTheme(JNIEnv* env, jobject obj, jint theme) {
25 distilled_page_prefs_->SetTheme((DistilledPagePrefs::Theme)theme); 26 distilled_page_prefs_->SetTheme((DistilledPagePrefs::Theme)theme);
26 } 27 }
27 28
28 jint DistilledPagePrefsAndroid::GetTheme(JNIEnv* env, jobject obj) { 29 jint DistilledPagePrefsAndroid::GetTheme(JNIEnv* env, jobject obj) {
29 return (int)distilled_page_prefs_->GetTheme(); 30 return (int)distilled_page_prefs_->GetTheme();
30 } 31 }
31 32
32 jlong Init(JNIEnv* env, jobject obj, jlong distilledPagePrefsPtr) { 33 jlong Init(JNIEnv* env, jobject obj, jlong distilled_page_prefs_ptr) {
33 DistilledPagePrefs* distilledPagePrefs = 34 DistilledPagePrefs* distilled_page_prefs =
34 reinterpret_cast<DistilledPagePrefs*>(distilledPagePrefsPtr); 35 reinterpret_cast<DistilledPagePrefs*>(distilled_page_prefs_ptr);
35 DistilledPagePrefsAndroid* distilled_page_prefs_android = 36 DistilledPagePrefsAndroid* distilled_page_prefs_android =
36 new DistilledPagePrefsAndroid(env, obj, distilledPagePrefs); 37 new DistilledPagePrefsAndroid(env, obj, distilled_page_prefs);
37 return reinterpret_cast<intptr_t>(distilled_page_prefs_android); 38 return reinterpret_cast<intptr_t>(distilled_page_prefs_android);
38 } 39 }
39 40
40 bool DistilledPagePrefsAndroid::Register(JNIEnv* env) { 41 bool DistilledPagePrefsAndroid::Register(JNIEnv* env) {
41 return RegisterNativesImpl(env); 42 return RegisterNativesImpl(env);
42 } 43 }
43 44
45 void DistilledPagePrefsAndroid::AddObserver(JNIEnv* env,
46 jobject obj,
47 jlong observer_ptr) {
48 DistilledPagePrefsObserverAndroid* distilled_page_prefs_observer_wrapper =
49 reinterpret_cast<DistilledPagePrefsObserverAndroid*>(observer_ptr);
50 distilled_page_prefs_->AddObserver(distilled_page_prefs_observer_wrapper);
51 }
52
53 void DistilledPagePrefsAndroid::RemoveObserver(JNIEnv* env,
54 jobject obj,
55 jlong observer_ptr) {
56 DistilledPagePrefsObserverAndroid* distilled_page_prefs_observer_wrapper =
57 reinterpret_cast<DistilledPagePrefsObserverAndroid*>(observer_ptr);
58 distilled_page_prefs_->RemoveObserver(distilled_page_prefs_observer_wrapper);
59 }
60
61 DistilledPagePrefsObserverAndroid::DistilledPagePrefsObserverAndroid(
62 JNIEnv* env,
63 jobject obj) {
64 java_ref_.Reset(env, obj);
65 }
66
67 DistilledPagePrefsObserverAndroid::~DistilledPagePrefsObserverAndroid() {}
68
69 void DistilledPagePrefsObserverAndroid::DestroyObserverAndroid(JNIEnv* env,
70 jobject obj) {
71 delete this;
72 }
73
74 void DistilledPagePrefsObserverAndroid::OnChangeTheme(
75 DistilledPagePrefs::Theme new_theme) {
76 JNIEnv* env = base::android::AttachCurrentThread();
77 Java_DistilledPagePrefsObserverWrapper_onChangeTheme(
78 env, java_ref_.obj(), (int)new_theme);
79 }
80
81 jlong InitObserverAndroid(JNIEnv* env, jobject obj) {
82 DistilledPagePrefsObserverAndroid* observer_android =
83 new DistilledPagePrefsObserverAndroid(env, obj);
84 return reinterpret_cast<intptr_t>(observer_android);
85 }
86
44 } // namespace android 87 } // namespace android
88
45 } // namespace dom_distiller 89 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/core/distilled_page_prefs_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698