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

Unified Diff: chrome/browser/safe_browsing/download_protection_service.h

Issue 8400020: Revert 107528 - Collect some histograms about signed binary downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/download_protection_service.h
===================================================================
--- chrome/browser/safe_browsing/download_protection_service.h (revision 107537)
+++ chrome/browser/safe_browsing/download_protection_service.h (working copy)
@@ -9,34 +9,36 @@
#define CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_
#pragma once
-#include <set>
+#include <map>
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/callback.h"
-#include "base/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time.h"
+#include "content/public/common/url_fetcher_delegate.h"
#include "googleurl/src/gurl.h"
namespace net {
class URLRequestContextGetter;
class URLRequestStatus;
} // namespace net
-class DownloadItem;
class SafeBrowsingService;
namespace safe_browsing {
// This class provides an asynchronous API to check whether a particular
// client download is malicious or not.
-class DownloadProtectionService {
+class DownloadProtectionService
+ : public base::RefCountedThreadSafe<DownloadProtectionService>,
+ public content::URLFetcherDelegate {
public:
- // TODO(noelutz): we're missing some fields here: server IPs,
- // tab URL redirect chain, ...
+ // TODO(noelutz): we're missing some fields here: filename to get
+ // the signature, server IPs, tab URL redirect chain, ...
struct DownloadInfo {
- FilePath local_file;
std::vector<GURL> download_url_chain;
GURL referrer_url;
std::string sha256_hash;
@@ -44,9 +46,6 @@
bool user_initiated;
DownloadInfo();
~DownloadInfo();
-
- // Creates a DownloadInfo from a DownloadItem object.
- static DownloadInfo FromDownloadItem(const DownloadItem& item);
};
enum DownloadCheckResult {
@@ -60,25 +59,32 @@
typedef base::Callback<void(DownloadCheckResult)> CheckDownloadCallback;
// Creates a download service. The service is initially disabled. You need
- // to call SetEnabled() to start it. |sb_service| owns this object; we
- // keep a reference to |request_context_getter|.
+ // to call SetEnabled() to start it. We keep scoped references to both of
+ // these objects.
DownloadProtectionService(
SafeBrowsingService* sb_service,
net::URLRequestContextGetter* request_context_getter);
- virtual ~DownloadProtectionService();
+ // From the content::URLFetcherDelegate interface.
+ virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
- // Checks whether the given client download is likely to be malicious or not.
- // The result is delivered asynchronously via the given callback. This
- // method must be called on the UI thread, and the callback will also be
- // invoked on the UI thread.
- virtual void CheckClientDownload(const DownloadInfo& info,
+ // Checks whether the given client download is likely to be
+ // malicious or not. If this method returns true it means the
+ // download is safe or we're unable to tell whether it is safe or
+ // not. In this case the callback will never be called. If this
+ // method returns false we will asynchronously check whether the
+ // download is safe and call the callback when we have the response.
+ // This method should be called on the UI thread. The callback will
+ // be called on the UI thread and will always be called asynchronously.
+ virtual bool CheckClientDownload(const DownloadInfo& info,
const CheckDownloadCallback& callback);
// Enables or disables the service. This is usually called by the
// SafeBrowsingService, which tracks whether any profile uses these services
- // at all. Disabling causes any pending and future requests to have their
- // callbacks called with "SAFE" results.
+ // at all. Disabling cancels any pending requests; existing requests will
+ // have their callbacks called with "SAFE" results. Note: SetEnabled() is
+ // asynchronous because this method is called on the UI thread but most
+ // everything else happens on the IO thread.
void SetEnabled(bool enabled);
bool enabled() const {
@@ -96,12 +102,13 @@
REASON_INVALID_REQUEST_PROTO,
REASON_SERVER_PING_FAILED,
REASON_INVALID_RESPONSE_PROTO,
- REASON_NOT_BINARY_FILE,
REASON_MAX // Always add new values before this one.
};
+ virtual ~DownloadProtectionService();
+
private:
- class CheckClientDownloadRequest; // Per-request state
+ friend class base::RefCountedThreadSafe<DownloadProtectionService>;
friend class DownloadProtectionServiceTest;
FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest,
CheckClientDownloadValidateRequest);
@@ -112,28 +119,35 @@
static const char kDownloadRequestUrl[];
- // Cancels all requests in |download_requests_|, and empties it, releasing
- // the references to the requests.
- void CancelPendingRequests();
+ // Same as above but this method is called on the IO thread after we have
+ // done some basic checks to see whether the download is definitely not
+ // safe.
+ void StartCheckClientDownload(const DownloadInfo& info,
+ const CheckDownloadCallback& callback);
- // Called by a CheckClientDownloadRequest instance when it finishes, to
- // remove it from |download_requests_|.
- void RequestFinished(CheckClientDownloadRequest* request);
+ // This function must run on the UI thread and will invoke the callback
+ // with the given result.
+ void EndCheckClientDownload(DownloadCheckResult result,
+ DownloadCheckResultReason reason,
+ const CheckDownloadCallback& callback);
- static void FillDownloadInfo(const DownloadItem& item,
- DownloadInfo* download_info);
+ void RecordStats(DownloadCheckResultReason reason);
- // This pointer may be NULL if SafeBrowsing is disabled. The
- // SafeBrowsingService owns us, so we don't need to hold a reference to it.
- SafeBrowsingService* sb_service_;
+ // SetEnabled(bool) calls this method on the IO thread.
+ void SetEnabledOnIOThread(bool enableed);
+ // This pointer may be NULL if SafeBrowsing is disabled.
+ scoped_refptr<SafeBrowsingService> sb_service_;
+
// The context we use to issue network requests.
scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
// Map of client download request to the corresponding callback that
// has to be invoked when the request is done. This map contains all
// pending server requests.
- std::set<scoped_refptr<CheckClientDownloadRequest> > download_requests_;
+ typedef std::map<const content::URLFetcher*, CheckDownloadCallback>
+ DownloadRequests;
+ DownloadRequests download_requests_;
// Keeps track of the state of the service.
bool enabled_;

Powered by Google App Engine
This is Rietveld 408576698