Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: chrome/browser/safe_browsing/android_safe_browsing_api_handler.cc

Issue 1110723002: Split to SafeBrowsingDatabaseManager into Local* and Remote*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to review. Tweak comments and list initializer. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 #include "chrome/browser/safe_browsing/android_safe_browsing_api_handler.h"
6
7 #include <string>
8
9 #include "base/android/jni_android.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
12 #include "content/public/browser/browser_thread.h"
13 // TODO(nparker): Include JNI-generated file
14
15 using content::BrowserThread;
16
17 AndroidSafeBrowsingAPIHandler::AndroidSafeBrowsingAPIHandler() {
18 j_context_ = base::android::GetApplicationContext();
19 DCHECK(j_context_);
20
21 // TODO(nparker): Fetch API key pertaining to Chrome.
22 api_key_ = "<todo-get-appropriate-api-key>";
23 }
24
25 bool AndroidSafeBrowsingAPIHandler::StartURLCheck(
26 const URLCheckCallback& callback,
27 const GURL& url,
28 const std::vector<SBThreatType>& threat_types) {
29 DCHECK_CURRENTLY_ON(BrowserThread::IO);
30
31 // Make copy on the heap so we can pass the pointer through JNI.
32 URLCheckCallback* callback_ptr = new URLCheckCallback(callback);
33 intptr_t callback_id_int = reinterpret_cast<intptr_t>(callback_ptr);
34 jlong callback_id = static_cast<jlong>(callback_id_int);
35
36 // TODO(nparker): Reduce logging before launch of this feature.
37 VLOG(1) << "Starting check " << callback_id << " for URL " << url;
38
39 // TODO(nparker): Implement this.
40 // Convert threat types to API's enums.
41 // Call JNI method.
42
43 // Until we have the Java implementation, just invoke the callback in 500ms
44 // for testing.
45 return BrowserThread::PostDelayedTask(
46 BrowserThread::IO, FROM_HERE,
47 base::Bind(&OnURLCheckDone, callback_id, true, jstring()),
48 base::TimeDelta::FromMilliseconds(500));
49 }
50
51 // static
52 void AndroidSafeBrowsingAPIHandler::OnURLCheckDone(jlong callback_id,
53 jboolean isSuccessful,
54 jstring metadata) {
55 DCHECK_CURRENTLY_ON(BrowserThread::IO);
56 DCHECK(callback_id);
57
58 VLOG(1) << "URLCheckDone invoked for check " << callback_id;
59
60 // Convert java long long int to c++ pointer, take ownership.
61 scoped_ptr<URLCheckCallback> callback(
62 reinterpret_cast<URLCheckCallback*>(callback_id));
63
64 // TODO(nparker):
65 // 1) Convert metadata to binary proto of MalwarePatternType so
66 // SafeBrowsingUIManager::DisplayBlockingPage() can unmarshal it.
67 // 2) Pick the "worst" threat type from metadata and map to SBThreatType.
68
69 callback->Run(SB_THREAT_TYPE_SAFE, std::string());
70 VLOG(1) << "Done with check " << callback_id;
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698