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