Chromium Code Reviews| Index: chrome/browser/android/browsing_data/browsing_data_counter_bridge.cc |
| diff --git a/chrome/browser/android/browsing_data/browsing_data_counter_bridge.cc b/chrome/browser/android/browsing_data/browsing_data_counter_bridge.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c936998b9c282757301aa6643c2b6f7d7baf06fb |
| --- /dev/null |
| +++ b/chrome/browser/android/browsing_data/browsing_data_counter_bridge.cc |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/android/browsing_data/browsing_data_counter_bridge.h" |
| + |
| +#include "base/android/jni_string.h" |
| +#include "chrome/browser/browsing_data/browsing_data_counter_utils.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "jni/BrowsingDataCounterBridge_jni.h" |
| + |
| +BrowsingDataCounterBridge::BrowsingDataCounterBridge( |
| + JNIEnv* env, const JavaParamRef<jobject>& obj, jint data_type) |
| + : jobject_(obj) { |
| + DCHECK_GE(data_type, 0); |
| + DCHECK_LE(data_type, ClankBrowsingDataType::NUM_TYPES); |
| + |
| + std::string pref; |
| + if (!GetDeletionPreferenceFromDataType( |
| + static_cast<ClankBrowsingDataType>(data_type), &pref)) { |
| + return; |
| + } |
| + |
| + counter_.reset(CreateCounterForPreference(pref)); |
| + |
| + if (!counter_) |
| + return; |
| + |
| + counter_->Init( |
| + ProfileManager::GetActiveUserProfile()->GetOriginalProfile(), |
| + base::Bind(&BrowsingDataCounterBridge::Callback, |
| + base::Unretained(this))); |
| + counter_->Restart(); |
| +} |
| + |
| +BrowsingDataCounterBridge::~BrowsingDataCounterBridge() { |
| +} |
| + |
| +void BrowsingDataCounterBridge::Destroy(JNIEnv* env, |
| + const JavaParamRef<jobject>& obj) { |
| + delete this; |
| +} |
| + |
| +void BrowsingDataCounterBridge::Callback( |
| + scoped_ptr<BrowsingDataCounter::Result> result) { |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + ScopedJavaLocalRef<jstring> resultString = |
|
newt (away)
2016/01/12 18:55:26
s/resultString/result_string/
msramek
2016/01/13 15:27:53
Done.
|
| + base::android::ConvertUTF16ToJavaString( |
| + env, GetCounterTextFromResult(result.get())); |
| + Java_BrowsingDataCounterBridge_onBrowsingDataCounterFinished( |
| + env, jobject_.obj(), resultString.obj()); |
| +} |
| + |
| +static jlong Init( |
| + JNIEnv* env, const JavaParamRef<jobject>& obj, int data_type) { |
| + return reinterpret_cast<intptr_t>( |
| + new BrowsingDataCounterBridge(env, obj, data_type)); |
| +} |
| + |
| +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
|
| + return RegisterNativesImpl(env); |
| +} |