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_ = new BrowsingHistoryService(profile, this); | |
26 env_ = env; | |
27 j_history_service_obj_.Reset(env, obj); | |
28 } | |
29 | |
30 BrowsingHistoryBridge::~BrowsingHistoryBridge() {} | |
gone
2016/12/02 19:34:37
Do you need to destroy the browsing_history_servic
Theresa
2016/12/02 20:49:33
Done. I made it a unique_ptr<>.
| |
31 | |
32 void BrowsingHistoryBridge::Destroy(JNIEnv*, const JavaParamRef<jobject>&) { | |
33 delete this; | |
34 } | |
35 | |
36 void BrowsingHistoryBridge::QueryHistory( | |
37 JNIEnv* env, | |
38 const JavaParamRef<jobject>& obj, | |
39 const JavaParamRef<jobject>& j_result_obj, | |
40 jstring j_query, | |
41 int64_t j_query_end_time) { | |
gone
2016/12/02 19:34:37
nit: remove newline?
Theresa
2016/12/02 20:49:33
Done.
| |
42 | |
43 j_query_result_obj_.Reset(env, j_result_obj); | |
44 | |
45 history::QueryOptions options; | |
46 options.max_count = kMaxQueryCount; | |
47 options.end_time = base::Time::FromJavaTime(j_query_end_time); | |
48 options.duplicate_policy = history::QueryOptions::REMOVE_DUPLICATES_PER_DAY; | |
49 | |
50 browsing_history_service_->QueryHistory( | |
51 base::android::ConvertJavaStringToUTF16(env, j_query), options); | |
52 } | |
53 | |
54 // BrowsingHistoryServiceHandler implementation | |
55 void BrowsingHistoryBridge::OnQueryComplete( | |
56 std::vector<BrowsingHistoryService::HistoryEntry>* results, | |
57 BrowsingHistoryService::QueryResultsInfo* query_results_info) { | |
gone
2016/12/02 19:34:37
Given the asyncedness, do you need to check if the
Theresa
2016/12/02 20:49:33
I don't think so. The bridge gets destroyed when t
| |
58 for (std::vector<BrowsingHistoryService::HistoryEntry>::iterator it = | |
gone
2016/12/02 19:34:37
Is this something you could use "auto" for?
Theresa
2016/12/02 20:49:33
Done.
| |
59 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 |