summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history/top_sites_factory.h
blob: 3978dbe6baf759113d50f99e3daf8caa8b60c50e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2015 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 CHROME_BROWSER_HISTORY_TOP_SITES_FACTORY_H_
#define CHROME_BROWSER_HISTORY_TOP_SITES_FACTORY_H_

#include <vector>

#include "base/memory/ref_counted.h"
#include "components/keyed_service/content/refcounted_browser_context_keyed_service_factory.h"

class Profile;

template <typename T>
struct DefaultSingletonTraits;

namespace history {
struct PrepopulatedPage;
class TopSites;
}

class Profile;

// Used for creating and fetching a per-profile instance of the
// TopSites.
class TopSitesFactory : public RefcountedBrowserContextKeyedServiceFactory {
 public:
  // Get the TopSites service for |profile|, creating one if needed.
  static scoped_refptr<history::TopSites> GetForProfile(Profile* profile);

  // Get the TopSites service for |profile|, but do not create it if it doesn't
  // exist.
  static scoped_refptr<history::TopSites> GetForProfileIfExists(
      Profile* profile);

  // Get the singleton instance of the factory.
  static TopSitesFactory* GetInstance();

  // Creates a TopSites service for |context| with |prepopulated_page_list|.
  // Public for testing.
  static scoped_refptr<history::TopSites> BuildTopSites(
      content::BrowserContext* context,
      const std::vector<history::PrepopulatedPage>& prepopulated_page_list);

 private:
  friend struct DefaultSingletonTraits<TopSitesFactory>;

  TopSitesFactory();
  ~TopSitesFactory() override;

  // Overridden from BrowserContextKeyedServiceFactory.
  scoped_refptr<RefcountedKeyedService> BuildServiceInstanceFor(
      content::BrowserContext* context) const override;
  bool ServiceIsNULLWhileTesting() const override;

  DISALLOW_COPY_AND_ASSIGN(TopSitesFactory);
};

#endif  // CHROME_BROWSER_HISTORY_TOP_SITES_FACTORY_H_