1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/activity_log/ad_network_database.h"
7 #include "base/lazy_instance.h"
8 #include "chrome/browser/extensions/activity_log/hashed_ad_network_database.h"
10 namespace extensions
{
14 class AdNetworkDatabaseFactory
{
16 AdNetworkDatabaseFactory();
17 ~AdNetworkDatabaseFactory();
19 const AdNetworkDatabase
* GetDatabase();
20 void SetDatabase(scoped_ptr
<AdNetworkDatabase
> database
);
23 scoped_ptr
<AdNetworkDatabase
> database_
;
26 AdNetworkDatabaseFactory::AdNetworkDatabaseFactory() {}
27 AdNetworkDatabaseFactory::~AdNetworkDatabaseFactory() {}
29 const AdNetworkDatabase
* AdNetworkDatabaseFactory::GetDatabase() {
30 // Construct a new database, if we don't have one.
32 database_
.reset(new HashedAdNetworkDatabase());
34 return database_
.get();
37 void AdNetworkDatabaseFactory::SetDatabase(
38 scoped_ptr
<AdNetworkDatabase
> database
) {
39 database_
.reset(database
.release());
42 base::LazyInstance
<AdNetworkDatabaseFactory
> g_factory
=
43 LAZY_INSTANCE_INITIALIZER
;
47 AdNetworkDatabase::~AdNetworkDatabase() {}
50 const AdNetworkDatabase
* AdNetworkDatabase::Get() {
51 return g_factory
.Get().GetDatabase();
55 void AdNetworkDatabase::SetForTesting(scoped_ptr
<AdNetworkDatabase
> database
) {
56 g_factory
.Get().SetDatabase(database
.Pass());
59 } // namespace extensions