Commit 9818134c authored by bryner@chromium.org's avatar bryner@chromium.org

Remove thumbnails from the ClientSideDetectionService.

BUG=none
TEST=ClientSideDetectionServiceTest

Review URL: http://codereview.chromium.org/6277002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71503 0039d316-1c4b-4281-b951-d872f2087c98
parent 463194fe
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/platform_file.h" #include "base/platform_file.h"
#include "base/ref_counted_memory.h"
#include "base/scoped_ptr.h" #include "base/scoped_ptr.h"
#include "base/stl_util-inl.h" #include "base/stl_util-inl.h"
#include "base/task.h" #include "base/task.h"
...@@ -19,11 +18,9 @@ ...@@ -19,11 +18,9 @@
#include "chrome/common/net/http_return.h" #include "chrome/common/net/http_return.h"
#include "chrome/common/net/url_fetcher.h" #include "chrome/common/net/url_fetcher.h"
#include "chrome/common/net/url_request_context_getter.h" #include "chrome/common/net/url_request_context_getter.h"
#include "gfx/codec/png_codec.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
#include "net/url_request/url_request_status.h" #include "net/url_request/url_request_status.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace safe_browsing { namespace safe_browsing {
...@@ -92,14 +89,13 @@ void ClientSideDetectionService::GetModelFile(OpenModelDoneCallback* callback) { ...@@ -92,14 +89,13 @@ void ClientSideDetectionService::GetModelFile(OpenModelDoneCallback* callback) {
void ClientSideDetectionService::SendClientReportPhishingRequest( void ClientSideDetectionService::SendClientReportPhishingRequest(
const GURL& phishing_url, const GURL& phishing_url,
double score, double score,
SkBitmap thumbnail,
ClientReportPhishingRequestCallback* callback) { ClientReportPhishingRequestCallback* callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
MessageLoop::current()->PostTask( MessageLoop::current()->PostTask(
FROM_HERE, FROM_HERE,
method_factory_.NewRunnableMethod( method_factory_.NewRunnableMethod(
&ClientSideDetectionService::StartClientReportPhishingRequest, &ClientSideDetectionService::StartClientReportPhishingRequest,
phishing_url, score, thumbnail, callback)); phishing_url, score, callback));
} }
void ClientSideDetectionService::OnURLFetchComplete( void ClientSideDetectionService::OnURLFetchComplete(
...@@ -226,26 +222,13 @@ void ClientSideDetectionService::StartGetModelFile( ...@@ -226,26 +222,13 @@ void ClientSideDetectionService::StartGetModelFile(
void ClientSideDetectionService::StartClientReportPhishingRequest( void ClientSideDetectionService::StartClientReportPhishingRequest(
const GURL& phishing_url, const GURL& phishing_url,
double score, double score,
SkBitmap thumbnail,
ClientReportPhishingRequestCallback* callback) { ClientReportPhishingRequestCallback* callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
scoped_ptr<ClientReportPhishingRequestCallback> cb(callback); scoped_ptr<ClientReportPhishingRequestCallback> cb(callback);
// The server expects an encoded PNG image.
scoped_refptr<RefCountedBytes> thumbnail_data(new RefCountedBytes);
SkAutoLockPixels lock(thumbnail);
if (!thumbnail.readyToDraw() ||
!gfx::PNGCodec::EncodeBGRASkBitmap(thumbnail,
true /* discard_transparency */,
&thumbnail_data->data)) {
cb->Run(phishing_url, false);
return;
}
ClientPhishingRequest request; ClientPhishingRequest request;
request.set_url(phishing_url.spec()); request.set_url(phishing_url.spec());
request.set_client_score(static_cast<float>(score)); request.set_client_score(static_cast<float>(score));
request.set_snapshot(reinterpret_cast<const char*>(thumbnail_data->front()),
thumbnail_data->size());
std::string request_data; std::string request_data;
if (!request.SerializeToString(&request_data)) { if (!request.SerializeToString(&request_data)) {
// For consistency, we always call the callback asynchronously, rather than // For consistency, we always call the callback asynchronously, rather than
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "chrome/common/net/url_fetcher.h" #include "chrome/common/net/url_fetcher.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
class SkBitmap;
class URLRequestContextGetter; class URLRequestContextGetter;
namespace net { namespace net {
...@@ -75,17 +74,15 @@ class ClientSideDetectionService : public URLFetcher::Delegate { ...@@ -75,17 +74,15 @@ class ClientSideDetectionService : public URLFetcher::Delegate {
void GetModelFile(OpenModelDoneCallback* callback); void GetModelFile(OpenModelDoneCallback* callback);
// Sends a request to the SafeBrowsing servers with the potentially phishing // Sends a request to the SafeBrowsing servers with the potentially phishing
// URL, the client-side phishing score, and a low resolution thumbnail. The // URL and the client-side phishing score. The |phishing_url| scheme should
// |phishing_url| scheme should be HTTP. This method takes ownership of the // be HTTP. This method takes ownership of the |callback| and calls it once
// |callback| and calls it once the result has come back from the server or // the result has come back from the server or if an error occurs during the
// if an error occurs during the fetch. If an error occurs the phishing // fetch. If an error occurs the phishing verdict will always be false. The
// verdict will always be false. The callback is always called after // callback is always called after SendClientReportPhishingRequest() returns
// SendClientReportPhishingRequest() returns and on the same thread as // and on the same thread as SendClientReportPhishingRequest() was called.
// SendClientReportPhishingRequest() was called.
void SendClientReportPhishingRequest( void SendClientReportPhishingRequest(
const GURL& phishing_url, const GURL& phishing_url,
double score, double score,
SkBitmap thumbnail,
ClientReportPhishingRequestCallback* callback); ClientReportPhishingRequestCallback* callback);
private: private:
...@@ -142,7 +139,6 @@ class ClientSideDetectionService : public URLFetcher::Delegate { ...@@ -142,7 +139,6 @@ class ClientSideDetectionService : public URLFetcher::Delegate {
void StartClientReportPhishingRequest( void StartClientReportPhishingRequest(
const GURL& phishing_url, const GURL& phishing_url,
double score, double score,
SkBitmap thumbnail,
ClientReportPhishingRequestCallback* callback); ClientReportPhishingRequestCallback* callback);
// Starts getting the model file. // Starts getting the model file.
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "chrome/common/net/url_fetcher.h" #include "chrome/common/net/url_fetcher.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "net/url_request/url_request_status.h" #include "net/url_request/url_request_status.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace safe_browsing { namespace safe_browsing {
...@@ -63,12 +62,10 @@ class ClientSideDetectionServiceTest : public testing::Test { ...@@ -63,12 +62,10 @@ class ClientSideDetectionServiceTest : public testing::Test {
} }
bool SendClientReportPhishingRequest(const GURL& phishing_url, bool SendClientReportPhishingRequest(const GURL& phishing_url,
double score, double score) {
SkBitmap thumbnail) {
csd_service_->SendClientReportPhishingRequest( csd_service_->SendClientReportPhishingRequest(
phishing_url, phishing_url,
score, score,
thumbnail,
NewCallback(this, &ClientSideDetectionServiceTest::SendRequestDone)); NewCallback(this, &ClientSideDetectionServiceTest::SendRequestDone));
phishing_url_ = phishing_url; phishing_url_ = phishing_url;
msg_loop_.Run(); // Waits until callback is called. msg_loop_.Run(); // Waits until callback is called.
...@@ -166,33 +163,23 @@ TEST_F(ClientSideDetectionServiceTest, SendClientReportPhishingRequest) { ...@@ -166,33 +163,23 @@ TEST_F(ClientSideDetectionServiceTest, SendClientReportPhishingRequest) {
csd_service_.reset(ClientSideDetectionService::Create( csd_service_.reset(ClientSideDetectionService::Create(
tmp_dir.path().AppendASCII("model"), NULL)); tmp_dir.path().AppendASCII("model"), NULL));
// Invalid thumbnail.
SkBitmap thumbnail;
GURL url("http://a.com/"); GURL url("http://a.com/");
double score = 0.4; // Some random client score. double score = 0.4; // Some random client score.
EXPECT_FALSE(SendClientReportPhishingRequest(url, score, thumbnail));
// Valid thumbnail but the server returns an error.
thumbnail.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
ASSERT_TRUE(thumbnail.allocPixels());
thumbnail.eraseRGB(255, 0, 0);
SetClientReportPhishingResponse("", false /* fail */);
EXPECT_FALSE(SendClientReportPhishingRequest(url, score, thumbnail));
// Invalid response body from the server. // Invalid response body from the server.
SetClientReportPhishingResponse("invalid proto response", true /* success */); SetClientReportPhishingResponse("invalid proto response", true /* success */);
EXPECT_FALSE(SendClientReportPhishingRequest(url, score, thumbnail)); EXPECT_FALSE(SendClientReportPhishingRequest(url, score));
// Normal behavior. // Normal behavior.
ClientPhishingResponse response; ClientPhishingResponse response;
response.set_phishy(true); response.set_phishy(true);
SetClientReportPhishingResponse(response.SerializeAsString(), SetClientReportPhishingResponse(response.SerializeAsString(),
true /* success */); true /* success */);
EXPECT_TRUE(SendClientReportPhishingRequest(url, score, thumbnail)); EXPECT_TRUE(SendClientReportPhishingRequest(url, score));
response.set_phishy(false); response.set_phishy(false);
SetClientReportPhishingResponse(response.SerializeAsString(), SetClientReportPhishingResponse(response.SerializeAsString(),
true /* success */); true /* success */);
EXPECT_FALSE(SendClientReportPhishingRequest(url, score, thumbnail)); EXPECT_FALSE(SendClientReportPhishingRequest(url, score));
} }
} // namespace safe_browsing } // namespace safe_browsing
...@@ -23,10 +23,6 @@ message ClientPhishingRequest { ...@@ -23,10 +23,6 @@ message ClientPhishingRequest {
// Score that was computed on the client. Value is between 0.0 and 1.0. // Score that was computed on the client. Value is between 0.0 and 1.0.
// The larger the value the more likely the url is phishing. // The larger the value the more likely the url is phishing.
required float client_score = 2; required float client_score = 2;
// Thumbnail from the client. Supports all typical image formats (png, jpg
// etc.).
required bytes snapshot = 3;
} }
message ClientPhishingResponse { message ClientPhishingResponse {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment