Rename GetIconID to GetIconId
[chromium-blink-merge.git] / chrome / browser / android / contextualsearch / contextual_search_tab_helper.cc
blob6e635c5a92cfc6a43e25090bdc3070c930ea38c1
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.
5 #include "chrome/browser/android/contextualsearch/contextual_search_tab_helper.h"
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"
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()));
29 ContextualSearchTabHelper::~ContextualSearchTabHelper() {
30 pref_change_registrar_->RemoveAll();
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());
39 void ContextualSearchTabHelper::Destroy(JNIEnv* env, jobject obj) {
40 delete this;
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);
51 bool RegisterContextualSearchTabHelper(JNIEnv* env) {
52 return RegisterNativesImpl(env);