Chromium Code Reviews| 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_LE(data_type, ClankBrowsingDataType::NUM_TYPES); | |
| 18 | |
| 19 std::string pref; | |
| 20 if (!GetDeletionPreferenceFromDataType( | |
| 21 static_cast<ClankBrowsingDataType>(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::Callback, | |
| 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 void BrowsingDataCounterBridge::Callback( | |
| 46 scoped_ptr<BrowsingDataCounter::Result> result) { | |
| 47 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 48 ScopedJavaLocalRef<jstring> resultString = | |
|
newt (away)
2016/01/12 18:55:26
s/resultString/result_string/
msramek
2016/01/13 15:27:53
Done.
| |
| 49 base::android::ConvertUTF16ToJavaString( | |
| 50 env, GetCounterTextFromResult(result.get())); | |
| 51 Java_BrowsingDataCounterBridge_onBrowsingDataCounterFinished( | |
| 52 env, jobject_.obj(), resultString.obj()); | |
| 53 } | |
| 54 | |
| 55 static jlong Init( | |
| 56 JNIEnv* env, const JavaParamRef<jobject>& obj, int data_type) { | |
| 57 return reinterpret_cast<intptr_t>( | |
| 58 new BrowsingDataCounterBridge(env, obj, data_type)); | |
| 59 } | |
| 60 | |
| 61 bool RegisterBrowsingDataCounterBridge(JNIEnv* env) { | |
|
newt (away)
2016/01/12 18:55:26
add a "// static" comment above this method
msramek
2016/01/13 15:27:53
This actually wasn't a static class member, but a
| |
| 62 return RegisterNativesImpl(env); | |
| 63 } | |
| OLD | NEW |