Index: chrome/browser/safe_browsing/android_safe_browsing_api_handler.cc |
diff --git a/chrome/browser/safe_browsing/android_safe_browsing_api_handler.cc b/chrome/browser/safe_browsing/android_safe_browsing_api_handler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7113bc91ff00b4a7b718e3da7d47871810e46b27 |
--- /dev/null |
+++ b/chrome/browser/safe_browsing/android_safe_browsing_api_handler.cc |
@@ -0,0 +1,72 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+// |
+ |
+#include "chrome/browser/safe_browsing/android_safe_browsing_api_handler.h" |
+ |
+#include <string> |
+ |
+#include "base/android/jni_android.h" |
+#include "chrome/browser/safe_browsing/local_database_manager.h" |
+#include "chrome/browser/safe_browsing/safe_browsing_util.h" |
+#include "content/public/browser/browser_thread.h" |
+// TODO(nparker): Include JNI-generated file |
+ |
+using content::BrowserThread; |
+ |
+AndroidSafeBrowsingAPIHandler::AndroidSafeBrowsingAPIHandler() { |
+ j_context_ = base::android::GetApplicationContext(); |
+ DCHECK(j_context_); |
+ |
+ // TODO(nparker): Fetch API key pertaining to Chrome. |
+ api_key_ = "<todo-get-appropriate-api-key>"; |
+} |
+ |
+bool AndroidSafeBrowsingAPIHandler::StartRequest( |
+ RemoteSafeBrowsingDatabaseManager::ClientRequest* client_request) { |
mattm
2015/04/29 22:59:59
I find the split of ClientRequests handling being
Nathan Parker
2015/05/04 21:17:18
ok, I've make ClientRequest private and moved all
|
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ // TODO(nparker): Implement this. |
+ // jlong client_req_id = static_cast<jlong>(client_request); |
+ // Convert threat types to API's enums. |
+ // Call JNI method. |
+ |
+ return false; |
+} |
+ |
+// Static. |
+void AndroidSafeBrowsingAPIHandler::OnRequestDone(jlong client_req_id, |
+ jboolean isSuccessful, |
+ jstring metadata) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ if (!client_req_id) { |
+ DCHECK(false) << "Bad client_req_id"; |
+ return; |
+ } |
+ |
+ // Convert java long long int to c++ pointer, take ownership. |
+ scoped_ptr<RemoteSafeBrowsingDatabaseManager::ClientRequest> client_req( |
+ reinterpret_cast<RemoteSafeBrowsingDatabaseManager::ClientRequest*>( |
+ client_req_id)); |
+ |
+ SafeBrowsingDatabaseManager::Client* client = client_req->client; |
+ if (!client) { |
+ // Previously canceled. |
+ return; |
+ } |
+ |
+ // TODO(nparker): |
+ // 1) Convert metadata to be ascii proto of MalwarePatternType |
mattm
2015/04/29 22:59:59
metadata should be encoded protobuf, not ascii. (u
Nathan Parker
2015/05/04 21:17:18
Fixed.
|
+ // so SafeBrowsingUIManager::DisplayBlockingPage() can parse it. |
+ // Might need base::android::ConvertJavaStringToUTF8(). |
+ // 2) Pick the "worst" threat type from metadata and map to SBThreatType. |
+ |
+ SBThreatType sb_threat_type = SB_THREAT_TYPE_SAFE; |
+ client->OnCheckBrowseUrlResult(client_req->url, sb_threat_type, |
+ std::string()); |
+ |
+ DCHECK(client_req->db_manager); |
+ if (client_req->db_manager) { |
+ client_req->db_manager->CancelCheck(client); |
+ } |
+} |