Chromium Code Reviews| Index: components/safe_browsing/base_safe_browsing_service.cc |
| diff --git a/components/safe_browsing/base_safe_browsing_service.cc b/components/safe_browsing/base_safe_browsing_service.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f0f883ea143e3cd6adc0615d72b05c37687cac48 |
| --- /dev/null |
| +++ b/components/safe_browsing/base_safe_browsing_service.cc |
| @@ -0,0 +1,151 @@ |
| +// Copyright (c) 2012 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/base_safe_browsing_service.h" |
| + |
| +#include <stddef.h> |
| + |
| +#include "base/bind.h" |
| +#include "base/macros.h" |
| +#include "base/path_service.h" |
| +#include "components/safe_browsing/base_ui_manager.h" |
| +#include "components/safe_browsing/common/safebrowsing_constants.h" |
| +#include "components/safe_browsing_db/database_manager.h" |
| +#include "components/safe_browsing_db/safe_browsing_prefs.h" |
| +#include "components/safe_browsing_db/v4_feature_list.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/resource_request_info.h" |
| +#include "google_apis/google_api_keys.h" |
| +#include "net/url_request/url_request_context.h" |
| +#include "net/url_request/url_request_context_getter.h" |
| + |
| +#if defined(SAFE_BROWSING_DB_REMOTE) |
| +#include "components/safe_browsing_db/remote_database_manager.h" |
| +#endif |
| + |
| +using content::BrowserThread; |
| + |
| +namespace safe_browsing { |
| + |
| +BaseSafeBrowsingService::BaseSafeBrowsingService() |
| + : enabled_(false), |
| + enabled_by_prefs_(false), |
| + enabled_v4_only_(safe_browsing::V4FeatureList::IsV4OnlyEnabled()) {} |
| + |
| +BaseSafeBrowsingService::~BaseSafeBrowsingService() { |
| + // We should have already been shut down. If we're still enabled, then the |
| + // database isn't going to be closed properly, which could lead to corruption. |
| + DCHECK(!enabled_); |
| +} |
| + |
| +void BaseSafeBrowsingService::Initialize() { |
| + // TODO(ntfschr): initialize ui_manager_ once CreateUIManager is componentized |
|
Jialiu Lin
2016/12/29 17:41:37
CreateUIManager can simply return a BaseUIManager
Nate Fischer
2017/01/03 22:39:53
This is tricky, since other files (e.g. permission
Jialiu Lin
2017/01/04 01:36:34
Ah, I see. Thanks for your explanation.
|
| + |
| + if (!enabled_v4_only_) { |
| + database_manager_ = CreateDatabaseManager(); |
| + } |
| +} |
| + |
| +void BaseSafeBrowsingService::ShutDown() { |
| + return; |
| +} |
| + |
| +scoped_refptr<net::URLRequestContextGetter> |
| +BaseSafeBrowsingService::url_request_context() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + return nullptr; |
| +} |
| + |
| +const scoped_refptr<SafeBrowsingDatabaseManager>& |
| +BaseSafeBrowsingService::database_manager() const { |
| + return database_manager_; |
| +} |
| + |
| +void BaseSafeBrowsingService::OnResourceRequest( |
| + const net::URLRequest* request) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| +} |
| + |
| +SafeBrowsingDatabaseManager* BaseSafeBrowsingService::CreateDatabaseManager() { |
| +#if defined(SAFE_BROWSING_DB_REMOTE) |
| + return new RemoteSafeBrowsingDatabaseManager(); |
| +#else |
| + return NULL; |
| +#endif |
| +} |
| + |
| +std::string BaseSafeBrowsingService::GetProtocolConfigClientName() const { |
|
Jialiu Lin
2016/12/29 17:41:37
Since this function is not called in the base clas
Nate Fischer
2017/01/03 22:39:52
Done
|
| + std::string client_name; |
| +// On Windows, get the safe browsing client name from the browser |
| +// distribution classes in installer util. These classes don't yet have |
| +// an analog on non-Windows builds so just keep the name specified here. |
| +#if defined(OS_WIN) |
| + BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| + client_name = dist->GetSafeBrowsingName(); |
| +#else |
| +#if defined(GOOGLE_CHROME_BUILD) |
| + client_name = "googlechrome"; |
| +#else |
| + client_name = "chromium"; |
| +#endif |
| + |
| +// Mark client string to allow server to differentiate mobile. |
| +#if defined(OS_ANDROID) |
| + client_name.append("-a"); |
| +#endif |
| + |
| +#endif // defined(OS_WIN) |
| + |
| + return client_name; |
| +} |
| + |
| +void BaseSafeBrowsingService::StartOnIOThread( |
| + net::URLRequestContextGetter* url_request_context_getter) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + if (enabled_) |
| + return; |
| + enabled_ = true; |
| + return; |
| +} |
| + |
| +void BaseSafeBrowsingService::StopOnIOThread(bool shutdown) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + return; |
| +} |
| + |
| +void BaseSafeBrowsingService::Start() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + return; |
| +} |
| + |
| +void BaseSafeBrowsingService::Stop(bool shutdown) { |
| + return; |
| +} |
| + |
| +void BaseSafeBrowsingService::Observe( |
| + int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + return; |
| +} |
| + |
| +std::unique_ptr<BaseSafeBrowsingService::StateSubscription> |
| +BaseSafeBrowsingService::RegisterStateCallback( |
| + const base::Callback<void(void)>& callback) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + return state_callback_list_.Add(callback); |
| +} |
| + |
| +void BaseSafeBrowsingService::RefreshState() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + return; |
| +} |
| + |
| +void BaseSafeBrowsingService::ProcessResourceRequest( |
| + const ResourceRequestInfo& request) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + return; |
| +} |
| + |
| +} // namespace safe_browsing |