Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / activity_log / ad_network_database.cc
blob1dde3e25361bcdf3b9735c2019633cb173914906
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 {
12 namespace {
14 class AdNetworkDatabaseFactory {
15 public:
16 AdNetworkDatabaseFactory();
17 ~AdNetworkDatabaseFactory();
19 const AdNetworkDatabase* GetDatabase();
20 void SetDatabase(scoped_ptr<AdNetworkDatabase> database);
22 private:
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.
31 if (!database_.get())
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;
45 } // namespace
47 AdNetworkDatabase::~AdNetworkDatabase() {}
49 // static
50 const AdNetworkDatabase* AdNetworkDatabase::Get() {
51 return g_factory.Get().GetDatabase();
54 // static
55 void AdNetworkDatabase::SetForTesting(scoped_ptr<AdNetworkDatabase> database) {
56 g_factory.Get().SetDatabase(database.Pass());
59 } // namespace extensions