forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skeleton implementation of the V4LocalDatabaseManager
TODOs: Tests, fill in skeleton implementation, instantiate in SBService. BUG=543161 Review URL: https://codereview.chromium.org/1858923002 Cr-Commit-Position: refs/heads/master@{#386133}
- Loading branch information
Showing
4 changed files
with
273 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
components/safe_browsing_db/v4_local_database_manager.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "components/safe_browsing_db/v4_local_database_manager.h" | ||
|
||
#include <vector> | ||
|
||
#include "content/public/browser/browser_thread.h" | ||
|
||
using content::BrowserThread; | ||
|
||
namespace safe_browsing { | ||
|
||
V4LocalDatabaseManager::V4LocalDatabaseManager() : enabled_(false) {} | ||
|
||
V4LocalDatabaseManager::~V4LocalDatabaseManager() { | ||
DCHECK(!enabled_); | ||
} | ||
|
||
bool V4LocalDatabaseManager::IsSupported() const { | ||
return true; | ||
} | ||
|
||
safe_browsing::ThreatSource V4LocalDatabaseManager::GetThreatSource() const { | ||
return safe_browsing::ThreatSource::LOCAL_PVER4; | ||
} | ||
|
||
bool V4LocalDatabaseManager::ChecksAreAlwaysAsync() const { | ||
return false; | ||
} | ||
|
||
bool V4LocalDatabaseManager::CanCheckResourceType( | ||
content::ResourceType resource_type) const { | ||
// We check all types since most checks are fast. | ||
return true; | ||
} | ||
|
||
bool V4LocalDatabaseManager::CanCheckUrl(const GURL& url) const { | ||
return url.SchemeIs(url::kHttpsScheme) || url.SchemeIs(url::kHttpScheme) || | ||
url.SchemeIs(url::kFtpScheme); | ||
} | ||
|
||
bool V4LocalDatabaseManager::IsDownloadProtectionEnabled() const { | ||
// TODO(vakh): Investigate the possibility of using a command line switch for | ||
// this instead. | ||
return true; | ||
} | ||
|
||
bool V4LocalDatabaseManager::CheckDownloadUrl( | ||
const std::vector<GURL>& url_chain, | ||
Client* client) { | ||
DCHECK_CURRENTLY_ON(BrowserThread::IO); | ||
// TODO(vakh): Implement this skeleton. | ||
return true; | ||
} | ||
|
||
bool V4LocalDatabaseManager::CheckExtensionIDs( | ||
const std::set<std::string>& extension_ids, | ||
Client* client) { | ||
// TODO(vakh): Implement this skeleton. | ||
DCHECK_CURRENTLY_ON(BrowserThread::IO); | ||
return true; | ||
} | ||
|
||
bool V4LocalDatabaseManager::MatchMalwareIP(const std::string& ip_address) { | ||
// TODO(vakh): Implement this skeleton. | ||
DCHECK_CURRENTLY_ON(BrowserThread::IO); | ||
return false; | ||
} | ||
|
||
bool V4LocalDatabaseManager::MatchCsdWhitelistUrl(const GURL& url) { | ||
// TODO(vakh): Implement this skeleton. | ||
DCHECK_CURRENTLY_ON(BrowserThread::IO); | ||
return true; | ||
} | ||
|
||
bool V4LocalDatabaseManager::MatchDownloadWhitelistUrl(const GURL& url) { | ||
// TODO(vakh): Implement this skeleton. | ||
DCHECK_CURRENTLY_ON(BrowserThread::IO); | ||
return true; | ||
} | ||
|
||
bool V4LocalDatabaseManager::MatchDownloadWhitelistString( | ||
const std::string& str) { | ||
// TODO(vakh): Implement this skeleton. | ||
DCHECK_CURRENTLY_ON(BrowserThread::IO); | ||
return true; | ||
} | ||
|
||
bool V4LocalDatabaseManager::MatchInclusionWhitelistUrl(const GURL& url) { | ||
// TODO(vakh): Implement this skeleton. | ||
DCHECK_CURRENTLY_ON(BrowserThread::IO); | ||
return true; | ||
} | ||
|
||
bool V4LocalDatabaseManager::MatchModuleWhitelistString( | ||
const std::string& str) { | ||
// TODO(vakh): Implement this skeleton. | ||
DCHECK_CURRENTLY_ON(BrowserThread::IO); | ||
return true; | ||
} | ||
|
||
bool V4LocalDatabaseManager::CheckResourceUrl(const GURL& url, Client* client) { | ||
// TODO(vakh): Implement this skeleton. | ||
DCHECK_CURRENTLY_ON(BrowserThread::IO); | ||
return true; | ||
} | ||
|
||
bool V4LocalDatabaseManager::IsMalwareKillSwitchOn() { | ||
// TODO(vakh): Implement this skeleton. | ||
DCHECK_CURRENTLY_ON(BrowserThread::IO); | ||
return true; | ||
} | ||
|
||
bool V4LocalDatabaseManager::IsCsdWhitelistKillSwitchOn() { | ||
// TODO(vakh): Implement this skeleton. | ||
DCHECK_CURRENTLY_ON(BrowserThread::IO); | ||
return true; | ||
} | ||
|
||
bool V4LocalDatabaseManager::CheckBrowseUrl(const GURL& url, Client* client) { | ||
// TODO(vakh): Implement this skeleton. | ||
DCHECK_CURRENTLY_ON(BrowserThread::IO); | ||
if (!enabled_) | ||
return true; | ||
|
||
// Don't defer the resource load. | ||
return true; | ||
} | ||
|
||
void V4LocalDatabaseManager::CancelCheck(Client* client) { | ||
// TODO(vakh): Implement this skeleton. | ||
DCHECK_CURRENTLY_ON(BrowserThread::IO); | ||
DCHECK(enabled_); | ||
} | ||
|
||
void V4LocalDatabaseManager::StartOnIOThread( | ||
net::URLRequestContextGetter* request_context_getter, | ||
const V4ProtocolConfig& config) { | ||
// TODO(vakh): Implement this skeleton. | ||
VLOG(1) << "V4LocalDatabaseManager starting"; | ||
SafeBrowsingDatabaseManager::StartOnIOThread(request_context_getter, config); | ||
|
||
V4UpdateCallback callback = base::Bind( | ||
&V4LocalDatabaseManager::UpdateRequestCompleted, base::Unretained(this)); | ||
v4_update_protocol_manager_ = V4UpdateProtocolManager::Create( | ||
request_context_getter, config, current_list_states_, callback); | ||
|
||
enabled_ = true; | ||
} | ||
|
||
void V4LocalDatabaseManager::StopOnIOThread(bool shutdown) { | ||
DCHECK_CURRENTLY_ON(BrowserThread::IO); | ||
DVLOG(1) << "V4LocalDatabaseManager stopping"; | ||
|
||
// Delete the V4UpdateProtocolManager. | ||
// This cancels any in-flight update request. | ||
if (v4_update_protocol_manager_.get()) { | ||
v4_update_protocol_manager_.reset(); | ||
} | ||
|
||
enabled_ = false; | ||
SafeBrowsingDatabaseManager::StopOnIOThread(shutdown); | ||
} | ||
|
||
void V4LocalDatabaseManager::UpdateRequestCompleted( | ||
const std::vector<ListUpdateResponse>& responses) { | ||
// TODO(vakh): Updates downloaded. Store them on disk and record new state. | ||
} | ||
|
||
} // namespace safe_browsing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ | ||
#define COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ | ||
|
||
// A class that provides the interface between the SafeBrowsing protocol manager | ||
// and database that holds the downloaded updates. | ||
|
||
#include "components/safe_browsing_db/database_manager.h" | ||
#include "components/safe_browsing_db/hit_report.h" | ||
#include "components/safe_browsing_db/v4_protocol_manager_util.h" | ||
#include "components/safe_browsing_db/v4_update_protocol_manager.h" | ||
#include "url/gurl.h" | ||
|
||
using content::ResourceType; | ||
|
||
namespace safe_browsing { | ||
|
||
// Manages the local, on-disk database of updates downloaded from the | ||
// SafeBrowsing service and interfaces with the protocol manager. | ||
class V4LocalDatabaseManager : public SafeBrowsingDatabaseManager { | ||
public: | ||
// Construct V4LocalDatabaseManager. | ||
// Must be initialized by calling StartOnIOThread() before using. | ||
V4LocalDatabaseManager(); | ||
|
||
// | ||
// SafeBrowsingDatabaseManager implementation | ||
// | ||
|
||
bool IsSupported() const override; | ||
safe_browsing::ThreatSource GetThreatSource() const override; | ||
bool ChecksAreAlwaysAsync() const override; | ||
bool CanCheckResourceType(content::ResourceType resource_type) const override; | ||
bool CanCheckUrl(const GURL& url) const override; | ||
bool IsDownloadProtectionEnabled() const override; | ||
bool CheckBrowseUrl(const GURL& url, Client* client) override; | ||
void CancelCheck(Client* client) override; | ||
void StartOnIOThread( | ||
net::URLRequestContextGetter* request_context_getter, | ||
const V4ProtocolConfig& config) override; | ||
void StopOnIOThread(bool shutdown) override; | ||
bool CheckDownloadUrl(const std::vector<GURL>& url_chain, | ||
Client* client) override; | ||
bool CheckExtensionIDs(const std::set<std::string>& extension_ids, | ||
Client* client) override; | ||
bool MatchCsdWhitelistUrl(const GURL& url) override; | ||
bool MatchMalwareIP(const std::string& ip_address) override; | ||
bool MatchDownloadWhitelistUrl(const GURL& url) override; | ||
bool MatchDownloadWhitelistString(const std::string& str) override; | ||
bool MatchInclusionWhitelistUrl(const GURL& url) override; | ||
bool MatchModuleWhitelistString(const std::string& str) override; | ||
bool CheckResourceUrl(const GURL& url, Client* client) override; | ||
bool IsMalwareKillSwitchOn() override; | ||
bool IsCsdWhitelistKillSwitchOn() override; | ||
|
||
private: | ||
~V4LocalDatabaseManager() override; | ||
|
||
// The callback called each time the protocol manager downloads updates | ||
// successfully. | ||
void UpdateRequestCompleted(const std::vector<ListUpdateResponse>& responses); | ||
|
||
bool enabled_; | ||
|
||
// Stores the current status of the lists to download from the SafeBrowsing | ||
// servers. | ||
base::hash_map<UpdateListIdentifier, std::string> current_list_states_; | ||
|
||
// The protocol manager that downloads the hash prefix updates. | ||
scoped_ptr<V4UpdateProtocolManager> v4_update_protocol_manager_; | ||
|
||
friend class base::RefCountedThreadSafe<V4LocalDatabaseManager>; | ||
DISALLOW_COPY_AND_ASSIGN(V4LocalDatabaseManager); | ||
}; // class V4LocalDatabaseManager | ||
|
||
} // namespace safe_browsing | ||
|
||
#endif // COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ |