| 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.h" |
| 9 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
| 10 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
| 12 #include "components/browsing_data/browsing_data_utils.h" |
| 11 #include "jni/BrowsingDataCounterBridge_jni.h" | 13 #include "jni/BrowsingDataCounterBridge_jni.h" |
| 12 | 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, browsing_data::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<browsing_data::BrowsingDataType>(data_type), &pref)) { |
| 22 return; | 24 return; |
| 23 } | 25 } |
| 24 | 26 |
| 25 counter_.reset(CreateCounterForPreference(pref)); | 27 Profile* profile = |
| 28 ProfileManager::GetActiveUserProfile()->GetOriginalProfile(); |
| 29 counter_.reset(CreateCounterForPreference(pref, profile)); |
| 26 | 30 |
| 27 if (!counter_) | 31 if (!counter_) |
| 28 return; | 32 return; |
| 29 | 33 |
| 30 counter_->Init( | 34 counter_->Init(profile->GetPrefs(), |
| 31 ProfileManager::GetActiveUserProfile()->GetOriginalProfile(), | 35 base::Bind(&BrowsingDataCounterBridge::onCounterFinished, |
| 32 base::Bind(&BrowsingDataCounterBridge::onCounterFinished, | 36 base::Unretained(this))); |
| 33 base::Unretained(this))); | |
| 34 counter_->Restart(); | 37 counter_->Restart(); |
| 35 } | 38 } |
| 36 | 39 |
| 37 BrowsingDataCounterBridge::~BrowsingDataCounterBridge() { | 40 BrowsingDataCounterBridge::~BrowsingDataCounterBridge() { |
| 38 } | 41 } |
| 39 | 42 |
| 40 void BrowsingDataCounterBridge::Destroy(JNIEnv* env, | 43 void BrowsingDataCounterBridge::Destroy(JNIEnv* env, |
| 41 const JavaParamRef<jobject>& obj) { | 44 const JavaParamRef<jobject>& obj) { |
| 42 delete this; | 45 delete this; |
| 43 } | 46 } |
| 44 | 47 |
| 45 // static | 48 // static |
| 46 bool BrowsingDataCounterBridge::Register(JNIEnv* env) { | 49 bool BrowsingDataCounterBridge::Register(JNIEnv* env) { |
| 47 return RegisterNativesImpl(env); | 50 return RegisterNativesImpl(env); |
| 48 } | 51 } |
| 49 | 52 |
| 50 void BrowsingDataCounterBridge::onCounterFinished( | 53 void BrowsingDataCounterBridge::onCounterFinished( |
| 51 std::unique_ptr<BrowsingDataCounter::Result> result) { | 54 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
| 52 JNIEnv* env = base::android::AttachCurrentThread(); | 55 JNIEnv* env = base::android::AttachCurrentThread(); |
| 53 ScopedJavaLocalRef<jstring> result_string = | 56 ScopedJavaLocalRef<jstring> result_string = |
| 54 base::android::ConvertUTF16ToJavaString( | 57 base::android::ConvertUTF16ToJavaString( |
| 55 env, GetCounterTextFromResult(result.get())); | 58 env, 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 |