Chromium Code Reviews| 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/physical_web/physical_web_data_source_android.h " | 5 #include "chrome/browser/android/physical_web/physical_web_data_source_android.h " |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | |
| 10 #include "base/android/jni_string.h" | |
| 9 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 10 #include "base/values.h" | 12 #include "base/values.h" |
| 11 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 12 #include "jni/UrlManager_jni.h" | 14 #include "jni/UrlManager_jni.h" |
| 13 | 15 |
| 14 using base::android::AttachCurrentThread; | 16 using base::android::AttachCurrentThread; |
| 17 using base::android::ConvertJavaStringToUTF8; | |
| 15 using base::android::JavaParamRef; | 18 using base::android::JavaParamRef; |
| 16 using base::android::ScopedJavaLocalRef; | 19 using base::android::ScopedJavaLocalRef; |
| 17 | 20 |
| 21 PhysicalWebCollection::PhysicalWebCollection() | |
| 22 : metadata_list_(base::MakeUnique<base::ListValue>()) {} | |
| 23 | |
| 24 PhysicalWebCollection::~PhysicalWebCollection() {} | |
| 25 | |
| 26 void PhysicalWebCollection::AppendMetadataItem( | |
| 27 JNIEnv* env, | |
| 28 const JavaParamRef<jobject>& obj, | |
| 29 const JavaParamRef<jstring>& j_request_url, | |
| 30 jdouble distance_estimate, | |
| 31 jint scan_timestamp, | |
| 32 const JavaParamRef<jstring>& j_site_url, | |
| 33 const JavaParamRef<jstring>& j_icon_url, | |
| 34 const JavaParamRef<jstring>& j_title, | |
| 35 const JavaParamRef<jstring>& j_description, | |
| 36 const JavaParamRef<jstring>& j_group_id) { | |
| 37 auto metadata_item = new base::DictionaryValue(); | |
| 38 metadata_item->SetString("scannedUrl", | |
|
gone
2016/10/24 16:35:35
Are these key constants referenced anywhere else?
mattreynolds
2016/10/24 22:39:52
Done. They are also hard-coded in the WebUI HTML b
| |
| 39 ConvertJavaStringToUTF8(j_request_url)); | |
| 40 metadata_item->SetDouble("distanceEstimate", distance_estimate); | |
| 41 metadata_item->SetInteger("scanTimestamp", scan_timestamp); | |
| 42 metadata_item->SetString("resolvedUrl", ConvertJavaStringToUTF8(j_site_url)); | |
| 43 metadata_item->SetString("icon", ConvertJavaStringToUTF8(j_icon_url)); | |
| 44 metadata_item->SetString("title", ConvertJavaStringToUTF8(j_title)); | |
| 45 metadata_item->SetString("description", | |
| 46 ConvertJavaStringToUTF8(j_description)); | |
| 47 metadata_item->SetString("groupId", ConvertJavaStringToUTF8(j_group_id)); | |
| 48 metadata_list_->Append(std::move(metadata_item)); | |
| 49 } | |
| 50 | |
| 51 std::unique_ptr<base::ListValue> PhysicalWebCollection::GetMetadataList() { | |
| 52 return std::move(metadata_list_); | |
| 53 } | |
| 54 | |
| 18 PhysicalWebDataSourceAndroid::PhysicalWebDataSourceAndroid() { | 55 PhysicalWebDataSourceAndroid::PhysicalWebDataSourceAndroid() { |
| 19 Initialize(); | 56 Initialize(); |
| 20 } | 57 } |
| 21 | 58 |
| 22 PhysicalWebDataSourceAndroid::~PhysicalWebDataSourceAndroid() {} | 59 PhysicalWebDataSourceAndroid::~PhysicalWebDataSourceAndroid() {} |
| 23 | 60 |
| 24 void PhysicalWebDataSourceAndroid::Initialize() { | 61 void PhysicalWebDataSourceAndroid::Initialize() { |
| 25 JNIEnv* env = AttachCurrentThread(); | 62 JNIEnv* env = AttachCurrentThread(); |
| 26 | 63 |
| 27 // Cache a reference to the singleton instance of UrlManager. | 64 // Cache a reference to the singleton instance of UrlManager. |
| 28 url_manager_.Reset(Java_UrlManager_getInstance(env)); | 65 url_manager_.Reset(Java_UrlManager_getInstance(env)); |
| 29 DCHECK(url_manager_.obj()); | 66 DCHECK(url_manager_.obj()); |
| 30 } | 67 } |
| 31 | 68 |
| 32 void PhysicalWebDataSourceAndroid::StartDiscovery( | 69 void PhysicalWebDataSourceAndroid::StartDiscovery( |
| 33 bool network_request_enabled) { | 70 bool network_request_enabled) { |
| 34 // On Android, scanning is started and stopped through the Java layer. | 71 // On Android, scanning is started and stopped through the Java layer. |
| 35 NOTREACHED(); | 72 NOTREACHED(); |
| 36 } | 73 } |
| 37 | 74 |
| 38 void PhysicalWebDataSourceAndroid::StopDiscovery() { | 75 void PhysicalWebDataSourceAndroid::StopDiscovery() { |
| 39 // On Android, scanning is started and stopped through the Java layer. | 76 // On Android, scanning is started and stopped through the Java layer. |
| 40 NOTREACHED(); | 77 NOTREACHED(); |
| 41 } | 78 } |
| 42 | 79 |
| 43 std::unique_ptr<base::ListValue> PhysicalWebDataSourceAndroid::GetMetadata() { | 80 std::unique_ptr<base::ListValue> PhysicalWebDataSourceAndroid::GetMetadata() { |
| 44 // TODO(mattreynolds): get the metadata from the Java layer | 81 JNIEnv* env = AttachCurrentThread(); |
| 45 return base::MakeUnique<base::ListValue>(); | 82 |
| 83 auto pw_collection = base::MakeUnique<PhysicalWebCollection>(); | |
| 84 Java_UrlManager_getPwCollection(env, url_manager_.obj(), | |
| 85 (long)pw_collection.get()); | |
| 86 | |
| 87 return pw_collection->GetMetadataList(); | |
| 46 } | 88 } |
| 47 | 89 |
| 48 bool PhysicalWebDataSourceAndroid::HasUnresolvedDiscoveries() { | 90 bool PhysicalWebDataSourceAndroid::HasUnresolvedDiscoveries() { |
| 49 NOTIMPLEMENTED(); | 91 NOTIMPLEMENTED(); |
| 50 return false; | 92 return false; |
| 51 } | 93 } |
| 52 | 94 |
| 53 // static | 95 // static |
| 54 bool PhysicalWebDataSourceAndroid::RegisterPhysicalWebDataSource(JNIEnv* env) { | 96 bool PhysicalWebDataSourceAndroid::RegisterPhysicalWebDataSource(JNIEnv* env) { |
| 55 return RegisterNativesImpl(env); | 97 return RegisterNativesImpl(env); |
| 56 } | 98 } |
| 57 | 99 |
| 58 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 100 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 59 PhysicalWebDataSource* data_source = | 101 PhysicalWebDataSource* data_source = |
| 60 g_browser_process->GetPhysicalWebDataSource(); | 102 g_browser_process->GetPhysicalWebDataSource(); |
| 61 return reinterpret_cast<intptr_t>(data_source); | 103 return reinterpret_cast<intptr_t>(data_source); |
| 62 } | 104 } |
| OLD | NEW |