summaryrefslogtreecommitdiffstats
path: root/ios/chrome/browser/history/top_sites_factory.cc
blob: d2a80b7fe8bb1fabcd36f935a32b64d34aab151d (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
61
62
63
64
65
66
67
// 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.

#include "ios/chrome/browser/history/top_sites_factory.h"

#include "base/memory/singleton.h"
#include "components/history/core/browser/history_constants.h"
#include "components/history/core/browser/top_sites_impl.h"
#include "components/keyed_service/core/refcounted_keyed_service.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/history/history_service_factory.h"
#include "ios/chrome/browser/history/history_utils.h"
#include "ios/web/public/web_thread.h"

namespace ios {

// static
scoped_refptr<history::TopSites> TopSitesFactory::GetForBrowserState(
    ios::ChromeBrowserState* browser_state) {
  return make_scoped_refptr(static_cast<history::TopSites*>(
      GetInstance()->GetServiceForBrowserState(browser_state, true).get()));
}

// static
TopSitesFactory* TopSitesFactory::GetInstance() {
  return base::Singleton<TopSitesFactory>::get();
}

TopSitesFactory::TopSitesFactory()
    : RefcountedBrowserStateKeyedServiceFactory(
          "TopSites",
          BrowserStateDependencyManager::GetInstance()) {
  DependsOn(ios::HistoryServiceFactory::GetInstance());
}

TopSitesFactory::~TopSitesFactory() {
}

scoped_refptr<RefcountedKeyedService> TopSitesFactory::BuildServiceInstanceFor(
    web::BrowserState* context) const {
  ios::ChromeBrowserState* browser_state =
      ios::ChromeBrowserState::FromBrowserState(context);
  scoped_refptr<history::TopSitesImpl> top_sites(new history::TopSitesImpl(
      browser_state->GetPrefs(),
      ios::HistoryServiceFactory::GetForBrowserState(
          browser_state, ServiceAccessType::EXPLICIT_ACCESS),
      history::PrepopulatedPageList(), base::Bind(CanAddURLToHistory)));
  top_sites->Init(
      browser_state->GetStatePath().Append(history::kTopSitesFilename),
      web::WebThread::GetTaskRunnerForThread(web::WebThread::DB));
  return top_sites;
}

void TopSitesFactory::RegisterBrowserStatePrefs(
    user_prefs::PrefRegistrySyncable* registry) {
  history::TopSitesImpl::RegisterPrefs(registry);
}

bool TopSitesFactory::ServiceIsNULLWhileTesting() const {
  return true;
}

}  // namespace ios