OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/history/browsing_history_bridge.h" | 5 #include "chrome/browser/android/history/browsing_history_bridge.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | |
10 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "chrome/browser/profiles/profile_android.h" | 15 #include "chrome/browser/profiles/profile_android.h" |
15 #include "components/url_formatter/url_formatter.h" | 16 #include "components/url_formatter/url_formatter.h" |
16 #include "jni/BrowsingHistoryBridge_jni.h" | 17 #include "jni/BrowsingHistoryBridge_jni.h" |
17 | 18 |
18 const int kMaxQueryCount = 100; | 19 const int kMaxQueryCount = 100; |
19 | 20 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 for (auto it = results->begin(); it != results->end(); ++it) { | 60 for (auto it = results->begin(); it != results->end(); ++it) { |
60 | 61 |
61 // TODO(twellington): move the domain logic to BrowsingHistoryServce so it | 62 // TODO(twellington): move the domain logic to BrowsingHistoryServce so it |
62 // can be shared with BrowsingHistoryHandler. | 63 // can be shared with BrowsingHistoryHandler. |
63 base::string16 domain = url_formatter::IDNToUnicode(it->url.host()); | 64 base::string16 domain = url_formatter::IDNToUnicode(it->url.host()); |
64 // When the domain is empty, use the scheme instead. This allows for a | 65 // 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 // sensible treatment of e.g. file: URLs when group by domain is on. |
66 if (domain.empty()) | 67 if (domain.empty()) |
67 domain = base::UTF8ToUTF16(it->url.scheme() + ":"); | 68 domain = base::UTF8ToUTF16(it->url.scheme() + ":"); |
68 | 69 |
70 std::vector<int64_t> timestamps; | |
71 for (auto timestampIt = it->all_timestamps.begin(); | |
72 timestampIt != it->all_timestamps.end(); ++timestampIt) { | |
73 timestamps.push_back( | |
74 base::Time::FromInternalValue(*timestampIt).ToJavaTime()); | |
75 } | |
76 | |
69 Java_BrowsingHistoryBridge_createHistoryItemAndAddToList( | 77 Java_BrowsingHistoryBridge_createHistoryItemAndAddToList( |
70 env, | 78 env, |
71 j_query_result_obj_.obj(), | 79 j_query_result_obj_.obj(), |
72 base::android::ConvertUTF8ToJavaString(env, it->url.spec()), | 80 base::android::ConvertUTF8ToJavaString(env, it->url.spec()), |
73 base::android::ConvertUTF16ToJavaString(env, domain), | 81 base::android::ConvertUTF16ToJavaString(env, domain), |
74 base::android::ConvertUTF16ToJavaString(env, it->title), | 82 base::android::ConvertUTF16ToJavaString(env, it->title), |
75 it->time.ToJavaTime()); | 83 base::android::ToJavaLongArray(env, timestamps)); |
84 | |
85 timestamps.clear(); | |
76 } | 86 } |
77 | 87 |
78 Java_BrowsingHistoryBridge_onQueryHistoryComplete( | 88 Java_BrowsingHistoryBridge_onQueryHistoryComplete( |
79 env, | 89 env, |
80 j_history_service_obj_.obj(), | 90 j_history_service_obj_.obj(), |
81 j_query_result_obj_.obj()); | 91 j_query_result_obj_.obj()); |
82 | 92 |
83 j_query_result_obj_.Release(); | 93 j_query_result_obj_.Release(); |
84 } | 94 } |
85 | 95 |
96 void BrowsingHistoryBridge::MarkItemForRemoval( | |
97 JNIEnv* env, | |
98 const JavaParamRef<jobject>& obj, | |
99 jstring j_url, | |
100 const JavaParamRef<jlongArray>& j_timestamps) { | |
101 std::unique_ptr<BrowsingHistoryService::HistoryEntry> entry( | |
102 new BrowsingHistoryService::HistoryEntry()); | |
gone
2016/12/08 21:21:56
git cl format?
Theresa
2016/12/08 21:51:15
Done.
| |
103 entry->url = GURL(base::android::ConvertJavaStringToUTF16(env, j_url)); | |
104 | |
105 std::vector<int64_t> timestamps; | |
106 base::android::JavaLongArrayToInt64Vector( | |
107 env, j_timestamps.obj(), ×tamps); | |
108 for (auto it = timestamps.begin(); it != timestamps.end(); ++it) { | |
109 base::Time visit_time = base::Time::FromJavaTime(*it); | |
110 entry->all_timestamps.insert(visit_time.ToInternalValue()); | |
111 } | |
112 | |
113 items_to_remove_.push_back(std::move(entry)); | |
114 timestamps.clear(); | |
115 } | |
116 | |
117 void BrowsingHistoryBridge::RemoveItems(JNIEnv* env, | |
118 const JavaParamRef<jobject>& obj) { | |
119 browsing_history_service_->RemoveVisits(&items_to_remove_); | |
120 items_to_remove_.clear(); | |
121 } | |
122 | |
86 void BrowsingHistoryBridge::OnRemoveVisitsComplete() { | 123 void BrowsingHistoryBridge::OnRemoveVisitsComplete() { |
87 // TODO(twellington): implement | 124 JNIEnv* env = base::android::AttachCurrentThread(); |
125 Java_BrowsingHistoryBridge_onRemoveComplete( | |
126 env, j_history_service_obj_.obj()); | |
88 } | 127 } |
89 | 128 |
90 void BrowsingHistoryBridge::OnRemoveVisitsFailed() { | 129 void BrowsingHistoryBridge::OnRemoveVisitsFailed() { |
91 // TODO(twellington): implement | 130 JNIEnv* env = base::android::AttachCurrentThread(); |
131 Java_BrowsingHistoryBridge_onRemoveFailed(env, j_history_service_obj_.obj()); | |
92 } | 132 } |
93 | 133 |
94 void BrowsingHistoryBridge::HistoryDeleted() { | 134 void BrowsingHistoryBridge::HistoryDeleted() { |
95 // TODO(twellington): implement | 135 JNIEnv* env = base::android::AttachCurrentThread(); |
136 Java_BrowsingHistoryBridge_onHistoryDeleted( | |
137 env, j_history_service_obj_.obj()); | |
96 } | 138 } |
97 | 139 |
98 void BrowsingHistoryBridge::HasOtherFormsOfBrowsingHistory( | 140 void BrowsingHistoryBridge::HasOtherFormsOfBrowsingHistory( |
99 bool has_other_forms, bool has_synced_results) { | 141 bool has_other_forms, bool has_synced_results) { |
100 // TODO(twellington): implement | 142 // TODO(twellington): implement |
101 } | 143 } |
102 | 144 |
103 bool RegisterBrowsingHistoryBridge(JNIEnv* env) { | 145 bool RegisterBrowsingHistoryBridge(JNIEnv* env) { |
104 return RegisterNativesImpl(env); | 146 return RegisterNativesImpl(env); |
105 } | 147 } |
106 | 148 |
107 static jlong Init(JNIEnv* env, | 149 static jlong Init(JNIEnv* env, |
108 const JavaParamRef<jobject>& obj, | 150 const JavaParamRef<jobject>& obj, |
109 const JavaParamRef<jobject>& j_profile) { | 151 const JavaParamRef<jobject>& j_profile) { |
110 BrowsingHistoryBridge* bridge = | 152 BrowsingHistoryBridge* bridge = |
111 new BrowsingHistoryBridge(env, obj, j_profile); | 153 new BrowsingHistoryBridge(env, obj, j_profile); |
112 return reinterpret_cast<intptr_t>(bridge); | 154 return reinterpret_cast<intptr_t>(bridge); |
113 } | 155 } |
OLD | NEW |