Chromium Code Reviews| 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_factory.h" | 8 #include "chrome/browser/browsing_data/browsing_data_counter_factory.h" |
| 9 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" | 9 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "components/browsing_data/core/browsing_data_utils.h" | |
| 14 #include "jni/BrowsingDataCounterBridge_jni.h" | 13 #include "jni/BrowsingDataCounterBridge_jni.h" |
| 15 | 14 |
| 16 using base::android::JavaParamRef; | 15 using base::android::JavaParamRef; |
| 17 using base::android::ScopedJavaLocalRef; | 16 using base::android::ScopedJavaLocalRef; |
| 18 | 17 |
| 19 BrowsingDataCounterBridge::BrowsingDataCounterBridge( | 18 BrowsingDataCounterBridge::BrowsingDataCounterBridge( |
| 20 JNIEnv* env, const JavaParamRef<jobject>& obj, jint data_type) | 19 JNIEnv* env, |
| 20 const JavaParamRef<jobject>& obj, | |
| 21 jint data_type, | |
| 22 jint pref_type_int) | |
| 21 : jobject_(obj) { | 23 : jobject_(obj) { |
| 22 DCHECK_GE(data_type, 0); | 24 DCHECK_GE(data_type, 0); |
| 23 DCHECK_LT(data_type, browsing_data::NUM_TYPES); | 25 DCHECK_LT(data_type, browsing_data::NUM_TYPES); |
|
msramek
2017/02/08 10:55:56
While you're here, can you please change this enum
dullweber
2017/02/08 23:03:18
I changed BrowsingDataType and also TimePeriod to
| |
| 26 DCHECK_GE(pref_type_int, 0); | |
|
msramek
2017/02/08 10:55:56
Please also add the other DCHECK.
dullweber
2017/02/08 23:03:18
Done.
| |
| 27 | |
| 28 pref_type_ = static_cast<browsing_data::ClearBrowsingDataPreferenceType>( | |
| 29 pref_type_int); | |
| 24 | 30 |
| 25 std::string pref; | 31 std::string pref; |
| 26 if (!browsing_data::GetDeletionPreferenceFromDataType( | 32 if (!browsing_data::GetDeletionPreferenceFromDataType( |
| 27 static_cast<browsing_data::BrowsingDataType>(data_type), &pref)) { | 33 static_cast<browsing_data::BrowsingDataType>(data_type), pref_type_, |
| 34 &pref)) { | |
| 28 return; | 35 return; |
| 29 } | 36 } |
| 30 | 37 |
| 31 Profile* profile = | 38 Profile* profile = |
| 32 ProfileManager::GetActiveUserProfile()->GetOriginalProfile(); | 39 ProfileManager::GetActiveUserProfile()->GetOriginalProfile(); |
| 33 counter_ = BrowsingDataCounterFactory::GetForProfileAndPref(profile, pref); | 40 counter_ = BrowsingDataCounterFactory::GetForProfileAndPref(profile, pref); |
| 34 | 41 |
| 35 if (!counter_) | 42 if (!counter_) |
| 36 return; | 43 return; |
| 37 | 44 |
| 38 counter_->Init(profile->GetPrefs(), | 45 counter_->Init(profile->GetPrefs(), pref_type_, |
| 39 base::Bind(&BrowsingDataCounterBridge::onCounterFinished, | 46 base::Bind(&BrowsingDataCounterBridge::onCounterFinished, |
| 40 base::Unretained(this))); | 47 base::Unretained(this))); |
| 41 counter_->Restart(); | 48 counter_->Restart(); |
| 42 } | 49 } |
| 43 | 50 |
| 44 BrowsingDataCounterBridge::~BrowsingDataCounterBridge() { | 51 BrowsingDataCounterBridge::~BrowsingDataCounterBridge() { |
| 45 } | 52 } |
| 46 | 53 |
| 47 void BrowsingDataCounterBridge::Destroy(JNIEnv* env, | 54 void BrowsingDataCounterBridge::Destroy(JNIEnv* env, |
| 48 const JavaParamRef<jobject>& obj) { | 55 const JavaParamRef<jobject>& obj) { |
| 49 delete this; | 56 delete this; |
| 50 } | 57 } |
| 51 | 58 |
| 52 // static | 59 // static |
| 53 bool BrowsingDataCounterBridge::Register(JNIEnv* env) { | 60 bool BrowsingDataCounterBridge::Register(JNIEnv* env) { |
| 54 return RegisterNativesImpl(env); | 61 return RegisterNativesImpl(env); |
| 55 } | 62 } |
| 56 | 63 |
| 57 void BrowsingDataCounterBridge::onCounterFinished( | 64 void BrowsingDataCounterBridge::onCounterFinished( |
| 58 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { | 65 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
| 59 JNIEnv* env = base::android::AttachCurrentThread(); | 66 JNIEnv* env = base::android::AttachCurrentThread(); |
| 60 ScopedJavaLocalRef<jstring> result_string = | 67 ScopedJavaLocalRef<jstring> result_string = |
| 61 base::android::ConvertUTF16ToJavaString( | 68 base::android::ConvertUTF16ToJavaString( |
| 62 env, GetChromeCounterTextFromResult(result.get())); | 69 env, GetChromeCounterTextFromResult(result.get())); |
| 63 Java_BrowsingDataCounterBridge_onBrowsingDataCounterFinished(env, jobject_, | 70 Java_BrowsingDataCounterBridge_onBrowsingDataCounterFinished(env, jobject_, |
| 64 result_string); | 71 result_string); |
| 65 } | 72 } |
| 66 | 73 |
| 67 static jlong Init( | 74 static jlong Init(JNIEnv* env, |
| 68 JNIEnv* env, const JavaParamRef<jobject>& obj, int data_type) { | 75 const JavaParamRef<jobject>& obj, |
| 76 jint data_type, | |
| 77 jint pref_type) { | |
| 69 return reinterpret_cast<intptr_t>( | 78 return reinterpret_cast<intptr_t>( |
| 70 new BrowsingDataCounterBridge(env, obj, data_type)); | 79 new BrowsingDataCounterBridge(env, obj, data_type, pref_type)); |
| 71 } | 80 } |
| OLD | NEW |