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

Side by Side Diff: chrome/browser/android/contextualsearch/contextual_search_tab_helper.cc

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 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
OLDNEW
(Empty)
1 // Copyright 2015 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/contextualsearch/contextual_search_tab_helper.h "
6
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/prefs/pref_change_registrar.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_android.h"
12 #include "chrome/common/pref_names.h"
13 #include "jni/ContextualSearchTabHelper_jni.h"
14
15
16 ContextualSearchTabHelper::ContextualSearchTabHelper(JNIEnv* env,
17 jobject obj,
18 Profile* profile)
19 : weak_java_ref_(env, obj),
20 pref_change_registrar_(new PrefChangeRegistrar()),
21 weak_factory_(this) {
22 pref_change_registrar_->Init(profile->GetPrefs());
23 pref_change_registrar_->Add(
24 prefs::kContextualSearchEnabled,
25 base::Bind(&ContextualSearchTabHelper::OnContextualSearchPrefChanged,
26 weak_factory_.GetWeakPtr()));
27 }
28
29 ContextualSearchTabHelper::~ContextualSearchTabHelper() {
30 pref_change_registrar_->RemoveAll();
31 }
32
33 void ContextualSearchTabHelper::OnContextualSearchPrefChanged() {
34 JNIEnv* env = base::android::AttachCurrentThread();
35 ScopedJavaLocalRef<jobject> jobj = weak_java_ref_.get(env);
36 Java_ContextualSearchTabHelper_onContextualSearchPrefChanged(env, jobj.obj());
37 }
38
39 void ContextualSearchTabHelper::Destroy(JNIEnv* env, jobject obj) {
40 delete this;
41 }
42
43 static jlong Init(JNIEnv* env, jobject obj, jobject java_profile) {
44 Profile* profile = ProfileAndroid::FromProfileAndroid(java_profile);
45 CHECK(profile);
46 ContextualSearchTabHelper* tab = new ContextualSearchTabHelper(
47 env, obj, profile);
48 return reinterpret_cast<intptr_t>(tab);
49 }
50
51 bool RegisterContextualSearchTabHelper(JNIEnv* env) {
52 return RegisterNativesImpl(env);
53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698