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 "base/memory/scoped_ptr.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::StartURLCheck( | |
27 const URLCheckCallback& callback, | |
28 const GURL& url, | |
29 const std::vector<SBThreatType>& threat_types) { | |
30 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
31 | |
32 // Make copy of the callback to add a ref to it. OnURLCheckDone() | |
33 // will delete this ptr, thus releasing the internal ref. | |
mattm
2015/05/08 02:17:26
Stale comment? Also not sure talking about refs he
Nathan Parker
2015/05/12 01:04:01
Done.
| |
34 URLCheckCallback* callback_ptr = new URLCheckCallback(callback); | |
35 intptr_t callback_id_int = reinterpret_cast<intptr_t>(callback_ptr); | |
36 jlong callback_id = static_cast<jlong>(callback_id_int); | |
37 | |
38 // TODO(nparker): Reduce logging before launch of this feature. | |
39 VLOG(1) << "Starting check " << callback_id << " for URL " << url; | |
40 | |
41 // TODO(nparker): Implement this. | |
42 // Convert threat types to API's enums. | |
43 // Call JNI method. | |
44 | |
45 // Until we have the Java implementation, just invoke the callback in 500ms | |
46 // for testing. | |
47 return BrowserThread::PostDelayedTask( | |
48 BrowserThread::IO, FROM_HERE, | |
49 base::Bind(&OnURLCheckDone, callback_id, true, jstring()), | |
50 base::TimeDelta::FromMilliseconds(500)); | |
51 } | |
52 | |
53 // Static. | |
mattm
2015/05/08 02:17:26
nit: In chrome I've only ever seen these comments
Nathan Parker
2015/05/12 01:04:01
Done.
| |
54 void AndroidSafeBrowsingAPIHandler::OnURLCheckDone(jlong callback_id, | |
55 jboolean isSuccessful, | |
56 jstring metadata) { | |
57 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
58 if (!callback_id) { | |
59 DCHECK(false) << "Bad callback_id"; | |
60 return; | |
mattm
2015/05/08 02:17:26
I don't think you should try to handle this failur
Nathan Parker
2015/05/12 01:04:01
Interesting. I may do that in a few other places
| |
61 } | |
62 VLOG(1) << "URLCheckDone invoked for check " << callback_id; | |
63 | |
64 // Convert java long long int to c++ pointer, take ownership. | |
65 scoped_ptr<URLCheckCallback> callback( | |
66 reinterpret_cast<URLCheckCallback*>(callback_id)); | |
67 | |
68 // TODO(nparker): | |
69 // 1) Convert metadata to binary proto of MalwarePatternType so | |
70 // SafeBrowsingUIManager::DisplayBlockingPage() can unmarshal it. | |
71 // 2) Pick the "worst" threat type from metadata and map to SBThreatType. | |
72 | |
73 callback->Run(SB_THREAT_TYPE_SAFE, std::string()); | |
74 VLOG(1) << "Done with check " << callback_id; | |
75 } | |
OLD | NEW |