OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/history/browsing_history_bridge.h" |
| 6 |
| 7 #include <jni.h> |
| 8 |
| 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/time/time.h" |
| 14 #include "chrome/browser/profiles/profile_android.h" |
| 15 #include "components/url_formatter/url_formatter.h" |
| 16 #include "jni/BrowsingHistoryBridge_jni.h" |
| 17 |
| 18 const int kMaxQueryCount = 100; |
| 19 |
| 20 BrowsingHistoryBridge::BrowsingHistoryBridge( |
| 21 JNIEnv* env, |
| 22 const JavaParamRef<jobject>& obj, |
| 23 jobject j_profile) { |
| 24 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); |
| 25 browsing_history_service_.reset(new BrowsingHistoryService(profile, this)); |
| 26 j_history_service_obj_.Reset(env, obj); |
| 27 } |
| 28 |
| 29 BrowsingHistoryBridge::~BrowsingHistoryBridge() {} |
| 30 |
| 31 void BrowsingHistoryBridge::Destroy(JNIEnv*, const JavaParamRef<jobject>&) { |
| 32 delete this; |
| 33 } |
| 34 |
| 35 void BrowsingHistoryBridge::QueryHistory( |
| 36 JNIEnv* env, |
| 37 const JavaParamRef<jobject>& obj, |
| 38 const JavaParamRef<jobject>& j_result_obj, |
| 39 jstring j_query, |
| 40 int64_t j_query_end_time) { |
| 41 j_query_result_obj_.Reset(env, j_result_obj); |
| 42 |
| 43 history::QueryOptions options; |
| 44 options.max_count = kMaxQueryCount; |
| 45 options.end_time = base::Time::FromJavaTime(j_query_end_time); |
| 46 options.duplicate_policy = history::QueryOptions::REMOVE_DUPLICATES_PER_DAY; |
| 47 |
| 48 browsing_history_service_->QueryHistory( |
| 49 base::android::ConvertJavaStringToUTF16(env, j_query), options); |
| 50 } |
| 51 |
| 52 // BrowsingHistoryServiceHandler implementation |
| 53 void BrowsingHistoryBridge::OnQueryComplete( |
| 54 std::vector<BrowsingHistoryService::HistoryEntry>* results, |
| 55 BrowsingHistoryService::QueryResultsInfo* query_results_info) { |
| 56 |
| 57 JNIEnv* env = base::android::AttachCurrentThread(); |
| 58 |
| 59 for (auto it = results->begin(); it != results->end(); ++it) { |
| 60 |
| 61 // TODO(twellington): move the domain logic to BrowsingHistoryServce so it |
| 62 // can be shared with BrowsingHistoryHandler. |
| 63 base::string16 domain = url_formatter::IDNToUnicode(it->url.host()); |
| 64 // When the domain is empty, use the scheme instead. This allows for a |
| 65 // sensible treatment of e.g. file: URLs when group by domain is on. |
| 66 if (domain.empty()) |
| 67 domain = base::UTF8ToUTF16(it->url.scheme() + ":"); |
| 68 |
| 69 Java_BrowsingHistoryBridge_createHistoryItemAndAddToList( |
| 70 env, |
| 71 j_query_result_obj_.obj(), |
| 72 base::android::ConvertUTF8ToJavaString(env, it->url.spec()), |
| 73 base::android::ConvertUTF16ToJavaString(env, domain), |
| 74 base::android::ConvertUTF16ToJavaString(env, it->title), |
| 75 it->time.ToJavaTime()); |
| 76 } |
| 77 |
| 78 Java_BrowsingHistoryBridge_onQueryHistoryComplete( |
| 79 env, |
| 80 j_history_service_obj_.obj(), |
| 81 j_query_result_obj_.obj()); |
| 82 |
| 83 j_query_result_obj_.Release(); |
| 84 } |
| 85 |
| 86 void BrowsingHistoryBridge::OnRemoveVisitsComplete() { |
| 87 // TODO(twellington): implement |
| 88 } |
| 89 |
| 90 void BrowsingHistoryBridge::OnRemoveVisitsFailed() { |
| 91 // TODO(twellington): implement |
| 92 } |
| 93 |
| 94 void BrowsingHistoryBridge::HistoryDeleted() { |
| 95 // TODO(twellington): implement |
| 96 } |
| 97 |
| 98 void BrowsingHistoryBridge::HasOtherFormsOfBrowsingHistory( |
| 99 bool has_other_forms, bool has_synced_results) { |
| 100 // TODO(twellington): implement |
| 101 } |
| 102 |
| 103 bool RegisterBrowsingHistoryBridge(JNIEnv* env) { |
| 104 return RegisterNativesImpl(env); |
| 105 } |
| 106 |
| 107 static jlong Init(JNIEnv* env, |
| 108 const JavaParamRef<jobject>& obj, |
| 109 const JavaParamRef<jobject>& j_profile) { |
| 110 BrowsingHistoryBridge* bridge = |
| 111 new BrowsingHistoryBridge(env, obj, j_profile); |
| 112 return reinterpret_cast<intptr_t>(bridge); |
| 113 } |
OLD | NEW |