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

Unified Diff: chrome/browser/extensions/activity_log/hashed_ad_network_database.cc

Issue 263953003: Re-enable ActivityLog AdNetworkDatabase unittest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/activity_log/hashed_ad_network_database.cc
diff --git a/chrome/browser/extensions/activity_log/ad_network_database.cc b/chrome/browser/extensions/activity_log/hashed_ad_network_database.cc
similarity index 54%
copy from chrome/browser/extensions/activity_log/ad_network_database.cc
copy to chrome/browser/extensions/activity_log/hashed_ad_network_database.cc
index 3ca6700e1e6c2c57dade37d20e85822d6948a4be..3e6f7ce4c26b85cd5eae063a0de87f3d09ec719d 100644
--- a/chrome/browser/extensions/activity_log/ad_network_database.cc
+++ b/chrome/browser/extensions/activity_log/hashed_ad_network_database.cc
@@ -2,15 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/extensions/activity_log/ad_network_database.h"
+#include "chrome/browser/extensions/activity_log/hashed_ad_network_database.h"
#include "base/basictypes.h"
-#include "base/lazy_instance.h"
+#include "base/logging.h"
#include "base/memory/ref_counted_memory.h"
#include "crypto/secure_hash.h"
#include "crypto/sha2.h"
-#include "grit/browser_resources.h"
-#include "ui/base/resource/resource_bundle.h"
#include "url/gurl.h"
namespace extensions {
@@ -30,33 +28,10 @@ COMPILE_ASSERT(kUrlHashSize <= sizeof(int64), url_hashes_must_fit_into_a_int64);
const size_t kChecksumHashSize = 32u;
-class AdNetworkDatabaseImpl : public AdNetworkDatabase {
- public:
- AdNetworkDatabaseImpl();
- virtual ~AdNetworkDatabaseImpl();
-
- private:
- virtual bool IsAdNetwork(const GURL& url) const OVERRIDE;
-
- // Initialize the AdNetworkDatabase. This means initializing the set of
- // hashes from the shared memory.
- void Init();
-
- // The set of partial hashes for known ad networks.
- base::hash_set<int64> entries_;
-};
-
-AdNetworkDatabaseImpl::AdNetworkDatabaseImpl() {
- Init();
-}
-
-AdNetworkDatabaseImpl::~AdNetworkDatabaseImpl() {}
-
-void AdNetworkDatabaseImpl::Init() {
- base::RefCountedStaticMemory* entries_memory =
- ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
- IDR_AD_NETWORK_HASHES);
+} // namespace
+HashedAdNetworkDatabase::HashedAdNetworkDatabase(
+ scoped_refptr<base::RefCountedStaticMemory> entries_memory) {
// This can legitimately happen in unit tests.
if (!entries_memory)
return;
@@ -94,7 +69,9 @@ void AdNetworkDatabaseImpl::Init() {
}
}
-bool AdNetworkDatabaseImpl::IsAdNetwork(const GURL& url) const {
+HashedAdNetworkDatabase::~HashedAdNetworkDatabase() {}
+
+bool HashedAdNetworkDatabase::IsAdNetwork(const GURL& url) const {
int64 hash = 0;
crypto::SHA256HashString(url.host(), &hash, sizeof(hash));
// If initialization failed (most likely because this is a unittest), then
@@ -103,49 +80,4 @@ bool AdNetworkDatabaseImpl::IsAdNetwork(const GURL& url) const {
return entries_.count(hash) != 0;
}
-class AdNetworkDatabaseFactory {
- public:
- AdNetworkDatabaseFactory();
- ~AdNetworkDatabaseFactory();
-
- const AdNetworkDatabase* GetDatabase();
- void SetDatabase(scoped_ptr<AdNetworkDatabase> database);
-
- private:
- scoped_ptr<AdNetworkDatabase> database_;
-};
-
-AdNetworkDatabaseFactory::AdNetworkDatabaseFactory() {}
-AdNetworkDatabaseFactory::~AdNetworkDatabaseFactory() {}
-
-const AdNetworkDatabase* AdNetworkDatabaseFactory::GetDatabase() {
- // Construct a new database, if we don't have one.
- if (!database_.get())
- database_.reset(new AdNetworkDatabaseImpl());
-
- return database_.get();
-}
-
-void AdNetworkDatabaseFactory::SetDatabase(
- scoped_ptr<AdNetworkDatabase> database) {
- database_.reset(database.release());
-}
-
-base::LazyInstance<AdNetworkDatabaseFactory> g_factory =
- LAZY_INSTANCE_INITIALIZER;
-
-} // namespace
-
-AdNetworkDatabase::~AdNetworkDatabase() {}
-
-// static
-const AdNetworkDatabase* AdNetworkDatabase::Get() {
- return g_factory.Get().GetDatabase();
-}
-
-// static
-void AdNetworkDatabase::SetForTesting(scoped_ptr<AdNetworkDatabase> database) {
- g_factory.Get().SetDatabase(database.Pass());
-}
-
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698