OLD | NEW |
(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/browsing_data/browsing_data_counter_bridge.h" |
| 6 |
| 7 #include "base/android/jni_string.h" |
| 8 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" |
| 9 #include "chrome/browser/profiles/profile_manager.h" |
| 10 #include "chrome/common/pref_names.h" |
| 11 #include "jni/BrowsingDataCounterBridge_jni.h" |
| 12 |
| 13 BrowsingDataCounterBridge::BrowsingDataCounterBridge( |
| 14 JNIEnv* env, const JavaParamRef<jobject>& obj, jint data_type) |
| 15 : jobject_(obj) { |
| 16 DCHECK_GE(data_type, 0); |
| 17 DCHECK_LT(data_type, BrowsingDataType::NUM_TYPES); |
| 18 |
| 19 std::string pref; |
| 20 if (!GetDeletionPreferenceFromDataType( |
| 21 static_cast<BrowsingDataType>(data_type), &pref)) { |
| 22 return; |
| 23 } |
| 24 |
| 25 counter_.reset(CreateCounterForPreference(pref)); |
| 26 |
| 27 if (!counter_) |
| 28 return; |
| 29 |
| 30 counter_->Init( |
| 31 ProfileManager::GetActiveUserProfile()->GetOriginalProfile(), |
| 32 base::Bind(&BrowsingDataCounterBridge::onCounterFinished, |
| 33 base::Unretained(this))); |
| 34 counter_->Restart(); |
| 35 } |
| 36 |
| 37 BrowsingDataCounterBridge::~BrowsingDataCounterBridge() { |
| 38 } |
| 39 |
| 40 void BrowsingDataCounterBridge::Destroy(JNIEnv* env, |
| 41 const JavaParamRef<jobject>& obj) { |
| 42 delete this; |
| 43 } |
| 44 |
| 45 // static |
| 46 bool BrowsingDataCounterBridge::Register(JNIEnv* env) { |
| 47 return RegisterNativesImpl(env); |
| 48 } |
| 49 |
| 50 void BrowsingDataCounterBridge::onCounterFinished( |
| 51 scoped_ptr<BrowsingDataCounter::Result> result) { |
| 52 JNIEnv* env = base::android::AttachCurrentThread(); |
| 53 ScopedJavaLocalRef<jstring> result_string = |
| 54 base::android::ConvertUTF16ToJavaString( |
| 55 env, GetCounterTextFromResult(result.get())); |
| 56 Java_BrowsingDataCounterBridge_onBrowsingDataCounterFinished( |
| 57 env, jobject_.obj(), result_string.obj()); |
| 58 } |
| 59 |
| 60 static jlong Init( |
| 61 JNIEnv* env, const JavaParamRef<jobject>& obj, int data_type) { |
| 62 return reinterpret_cast<intptr_t>( |
| 63 new BrowsingDataCounterBridge(env, obj, data_type)); |
| 64 } |
OLD | NEW |