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" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "jni/UrlManager_jni.h" | 14 #include "jni/UrlManager_jni.h" |
| 15 | 15 |
| 16 using base::android::AttachCurrentThread; | 16 using base::android::AttachCurrentThread; |
| 17 using base::android::ConvertJavaStringToUTF8; | 17 using base::android::ConvertJavaStringToUTF8; |
| 18 using base::android::JavaParamRef; | 18 using base::android::JavaParamRef; |
| 19 using base::android::ScopedJavaLocalRef; | 19 using base::android::ScopedJavaLocalRef; |
| 20 | 20 |
| 21 PhysicalWebCollection::PhysicalWebCollection() | 21 PhysicalWebCollection::PhysicalWebCollection() |
| 22 : metadata_list_(base::MakeUnique<base::ListValue>()), | 22 : dictionary_value_list_(base::MakeUnique<base::ListValue>()), |
| 23 metadata_list_(base::MakeUnique<physical_web::MetadataList>()), | |
| 23 accessed_once_(false) {} | 24 accessed_once_(false) {} |
| 24 | 25 |
| 25 PhysicalWebCollection::~PhysicalWebCollection() {} | 26 PhysicalWebCollection::~PhysicalWebCollection() {} |
| 26 | 27 |
| 27 void PhysicalWebCollection::AppendMetadataItem( | 28 void PhysicalWebCollection::AppendMetadataItem( |
| 28 JNIEnv* env, | 29 JNIEnv* env, |
| 29 const JavaParamRef<jobject>& obj, | 30 const JavaParamRef<jobject>& obj, |
| 30 const JavaParamRef<jstring>& j_request_url, | 31 const JavaParamRef<jstring>& j_request_url, |
| 31 jdouble distance_estimate, | 32 jdouble distance_estimate, |
| 32 jint scan_timestamp, | 33 jlong scan_timestamp, |
| 33 const JavaParamRef<jstring>& j_site_url, | 34 const JavaParamRef<jstring>& j_site_url, |
| 34 const JavaParamRef<jstring>& j_icon_url, | 35 const JavaParamRef<jstring>& j_icon_url, |
| 35 const JavaParamRef<jstring>& j_title, | 36 const JavaParamRef<jstring>& j_title, |
| 36 const JavaParamRef<jstring>& j_description, | 37 const JavaParamRef<jstring>& j_description, |
| 37 const JavaParamRef<jstring>& j_group_id) { | 38 const JavaParamRef<jstring>& j_group_id) { |
| 38 auto metadata_item = new base::DictionaryValue(); | 39 auto dictionary_value = new base::DictionaryValue(); |
|
mattreynolds
2016/12/07 19:55:31
This should be:
auto dictionary_value = base::Mak
cco3
2016/12/08 23:52:50
Done.
| |
| 39 metadata_item->SetString(physical_web::kScannedUrlKey, | 40 dictionary_value->SetString(physical_web::kScannedUrlKey, |
| 40 ConvertJavaStringToUTF8(j_request_url)); | 41 ConvertJavaStringToUTF8(j_request_url)); |
| 41 metadata_item->SetDouble(physical_web::kDistanceEstimateKey, | 42 dictionary_value->SetDouble(physical_web::kDistanceEstimateKey, |
| 42 distance_estimate); | 43 distance_estimate); |
| 43 metadata_item->SetInteger(physical_web::kScanTimestampKey, scan_timestamp); | 44 dictionary_value->SetInteger(physical_web::kScanTimestampKey, scan_timestamp); |
|
vitaliii
2016/12/07 10:14:04
Probably add a comment that this does not work and
cco3
2016/12/08 23:52:50
Done.
| |
| 44 metadata_item->SetString(physical_web::kResolvedUrlKey, | 45 dictionary_value->SetString(physical_web::kResolvedUrlKey, |
| 45 ConvertJavaStringToUTF8(j_site_url)); | 46 ConvertJavaStringToUTF8(j_site_url)); |
| 46 metadata_item->SetString(physical_web::kIconUrlKey, | 47 dictionary_value->SetString(physical_web::kIconUrlKey, |
| 47 ConvertJavaStringToUTF8(j_icon_url)); | 48 ConvertJavaStringToUTF8(j_icon_url)); |
| 48 metadata_item->SetString(physical_web::kTitleKey, | 49 dictionary_value->SetString(physical_web::kTitleKey, |
| 49 ConvertJavaStringToUTF8(j_title)); | 50 ConvertJavaStringToUTF8(j_title)); |
| 50 metadata_item->SetString(physical_web::kDescriptionKey, | 51 dictionary_value->SetString(physical_web::kDescriptionKey, |
| 51 ConvertJavaStringToUTF8(j_description)); | 52 ConvertJavaStringToUTF8(j_description)); |
| 52 metadata_item->SetString(physical_web::kGroupIdKey, | 53 dictionary_value->SetString(physical_web::kGroupIdKey, |
| 53 ConvertJavaStringToUTF8(j_group_id)); | 54 ConvertJavaStringToUTF8(j_group_id)); |
| 54 metadata_list_->Append(std::move(metadata_item)); | 55 dictionary_value_list_->Append(std::move(dictionary_value)); |
| 56 | |
| 57 physical_web::Metadata metadata_item; | |
| 58 metadata_item.scanned_url = ConvertJavaStringToUTF8(j_request_url); | |
| 59 metadata_item.resolved_url = ConvertJavaStringToUTF8(j_site_url); | |
| 60 metadata_item.icon_url = ConvertJavaStringToUTF8(j_icon_url); | |
| 61 metadata_item.title = ConvertJavaStringToUTF8(j_title); | |
| 62 metadata_item.description = ConvertJavaStringToUTF8(j_description); | |
| 63 metadata_item.group_id = ConvertJavaStringToUTF8(j_group_id); | |
| 64 metadata_item.distance_estimate = distance_estimate; | |
| 65 metadata_item.scan_timestamp = scan_timestamp; | |
| 66 metadata_list_->push_back(std::move(metadata_item)); | |
| 55 } | 67 } |
| 56 | 68 |
| 57 std::unique_ptr<base::ListValue> PhysicalWebCollection::GetMetadataList() { | 69 std::unique_ptr<physical_web::MetadataList> |
| 70 PhysicalWebCollection::GetMetadataList() { | |
| 58 DCHECK(!accessed_once_); | 71 DCHECK(!accessed_once_); |
| 59 accessed_once_ = true; | 72 accessed_once_ = true; |
| 60 return std::move(metadata_list_); | 73 return std::move(metadata_list_); |
| 61 } | 74 } |
| 62 | 75 |
| 76 std::unique_ptr<base::ListValue> | |
| 77 PhysicalWebCollection::GetMetadataListValue() { | |
| 78 DCHECK(!accessed_once_); | |
| 79 accessed_once_ = true; | |
| 80 return std::move(dictionary_value_list_); | |
| 81 } | |
| 82 | |
| 63 PhysicalWebDataSourceAndroid::PhysicalWebDataSourceAndroid() { | 83 PhysicalWebDataSourceAndroid::PhysicalWebDataSourceAndroid() { |
| 64 Initialize(); | 84 Initialize(); |
| 65 } | 85 } |
| 66 | 86 |
| 67 PhysicalWebDataSourceAndroid::~PhysicalWebDataSourceAndroid() {} | 87 PhysicalWebDataSourceAndroid::~PhysicalWebDataSourceAndroid() {} |
| 68 | 88 |
| 69 void PhysicalWebDataSourceAndroid::Initialize() { | 89 void PhysicalWebDataSourceAndroid::Initialize() { |
| 70 JNIEnv* env = AttachCurrentThread(); | 90 JNIEnv* env = AttachCurrentThread(); |
| 71 | 91 |
| 72 // Cache a reference to the singleton instance of UrlManager. | 92 // Cache a reference to the singleton instance of UrlManager. |
| 73 url_manager_.Reset(Java_UrlManager_getInstance(env)); | 93 url_manager_.Reset(Java_UrlManager_getInstance(env)); |
| 74 DCHECK(url_manager_.obj()); | 94 DCHECK(url_manager_.obj()); |
| 75 } | 95 } |
| 76 | 96 |
| 77 void PhysicalWebDataSourceAndroid::StartDiscovery( | 97 void PhysicalWebDataSourceAndroid::StartDiscovery( |
| 78 bool network_request_enabled) { | 98 bool network_request_enabled) { |
| 79 // On Android, scanning is started and stopped through the Java layer. | 99 // On Android, scanning is started and stopped through the Java layer. |
| 80 NOTREACHED(); | 100 NOTREACHED(); |
| 81 } | 101 } |
| 82 | 102 |
| 83 void PhysicalWebDataSourceAndroid::StopDiscovery() { | 103 void PhysicalWebDataSourceAndroid::StopDiscovery() { |
| 84 // On Android, scanning is started and stopped through the Java layer. | 104 // On Android, scanning is started and stopped through the Java layer. |
| 85 NOTREACHED(); | 105 NOTREACHED(); |
| 86 } | 106 } |
| 87 | 107 |
| 88 std::unique_ptr<base::ListValue> PhysicalWebDataSourceAndroid::GetMetadata() { | 108 std::unique_ptr<physical_web::MetadataList> |
| 109 PhysicalWebDataSourceAndroid::GetMetadata() { | |
| 89 JNIEnv* env = AttachCurrentThread(); | 110 JNIEnv* env = AttachCurrentThread(); |
| 90 | 111 |
| 91 auto pw_collection = base::MakeUnique<PhysicalWebCollection>(); | 112 auto pw_collection = base::MakeUnique<PhysicalWebCollection>(); |
| 92 Java_UrlManager_getPwCollection(env, url_manager_.obj(), | 113 Java_UrlManager_getPwCollection(env, url_manager_.obj(), |
| 93 (long)pw_collection.get()); | 114 (long)pw_collection.get()); |
| 94 | 115 |
| 95 return pw_collection->GetMetadataList(); | 116 return pw_collection->GetMetadataList(); |
| 96 } | 117 } |
| 97 | 118 |
| 119 std::unique_ptr<base::ListValue> | |
| 120 PhysicalWebDataSourceAndroid::GetMetadataListValue() { | |
| 121 JNIEnv* env = AttachCurrentThread(); | |
| 122 | |
| 123 auto pw_collection = base::MakeUnique<PhysicalWebCollection>(); | |
| 124 Java_UrlManager_getPwCollection(env, url_manager_.obj(), | |
| 125 (long)pw_collection.get()); | |
| 126 | |
| 127 return pw_collection->GetMetadataListValue(); | |
| 128 } | |
| 129 | |
| 98 bool PhysicalWebDataSourceAndroid::HasUnresolvedDiscoveries() { | 130 bool PhysicalWebDataSourceAndroid::HasUnresolvedDiscoveries() { |
| 99 NOTIMPLEMENTED(); | 131 NOTIMPLEMENTED(); |
| 100 return false; | 132 return false; |
| 101 } | 133 } |
| 102 | 134 |
| 103 void PhysicalWebDataSourceAndroid::OnFound( | 135 void PhysicalWebDataSourceAndroid::OnFound( |
| 104 JNIEnv* env, | 136 JNIEnv* env, |
| 105 const base::android::JavaParamRef<jobject>& obj, | 137 const base::android::JavaParamRef<jobject>& obj, |
| 106 const base::android::JavaParamRef<jstring>& j_url) { | 138 const base::android::JavaParamRef<jstring>& j_url) { |
| 107 std::string url = ConvertJavaStringToUTF8(env, j_url); | 139 std::string url = ConvertJavaStringToUTF8(env, j_url); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 128 // static | 160 // static |
| 129 bool PhysicalWebDataSourceAndroid::RegisterPhysicalWebDataSource(JNIEnv* env) { | 161 bool PhysicalWebDataSourceAndroid::RegisterPhysicalWebDataSource(JNIEnv* env) { |
| 130 return RegisterNativesImpl(env); | 162 return RegisterNativesImpl(env); |
| 131 } | 163 } |
| 132 | 164 |
| 133 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 165 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 134 physical_web::PhysicalWebDataSource* data_source = | 166 physical_web::PhysicalWebDataSource* data_source = |
| 135 g_browser_process->GetPhysicalWebDataSource(); | 167 g_browser_process->GetPhysicalWebDataSource(); |
| 136 return reinterpret_cast<intptr_t>(data_source); | 168 return reinterpret_cast<intptr_t>(data_source); |
| 137 } | 169 } |
| OLD | NEW |