OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 | |
6 #include "chrome/browser/safe_browsing/android_safe_browsing_api_handler.h" | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/android/jni_android.h" | |
11 #include "chrome/browser/safe_browsing/local_database_manager.h" | |
12 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | |
13 #include "content/public/browser/browser_thread.h" | |
14 // TODO(nparker): Include JNI-generated file | |
15 | |
16 using content::BrowserThread; | |
17 | |
18 AndroidSafeBrowsingAPIHandler::AndroidSafeBrowsingAPIHandler() { | |
19 j_context_ = base::android::GetApplicationContext(); | |
20 DCHECK(j_context_); | |
21 | |
22 // TODO(nparker): Fetch API key pertaining to Chrome. | |
23 api_key_ = "<todo-get-appropriate-api-key>"; | |
24 } | |
25 | |
26 bool AndroidSafeBrowsingAPIHandler::StartRequest( | |
27 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
| |
28 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
29 // TODO(nparker): Implement this. | |
30 // jlong client_req_id = static_cast<jlong>(client_request); | |
31 // Convert threat types to API's enums. | |
32 // Call JNI method. | |
33 | |
34 return false; | |
35 } | |
36 | |
37 // Static. | |
38 void AndroidSafeBrowsingAPIHandler::OnRequestDone(jlong client_req_id, | |
39 jboolean isSuccessful, | |
40 jstring metadata) { | |
41 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
42 if (!client_req_id) { | |
43 DCHECK(false) << "Bad client_req_id"; | |
44 return; | |
45 } | |
46 | |
47 // Convert java long long int to c++ pointer, take ownership. | |
48 scoped_ptr<RemoteSafeBrowsingDatabaseManager::ClientRequest> client_req( | |
49 reinterpret_cast<RemoteSafeBrowsingDatabaseManager::ClientRequest*>( | |
50 client_req_id)); | |
51 | |
52 SafeBrowsingDatabaseManager::Client* client = client_req->client; | |
53 if (!client) { | |
54 // Previously canceled. | |
55 return; | |
56 } | |
57 | |
58 // TODO(nparker): | |
59 // 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.
| |
60 // so SafeBrowsingUIManager::DisplayBlockingPage() can parse it. | |
61 // Might need base::android::ConvertJavaStringToUTF8(). | |
62 // 2) Pick the "worst" threat type from metadata and map to SBThreatType. | |
63 | |
64 SBThreatType sb_threat_type = SB_THREAT_TYPE_SAFE; | |
65 client->OnCheckBrowseUrlResult(client_req->url, sb_threat_type, | |
66 std::string()); | |
67 | |
68 DCHECK(client_req->db_manager); | |
69 if (client_req->db_manager) { | |
70 client_req->db_manager->CancelCheck(client); | |
71 } | |
72 } | |
OLD | NEW |