summaryrefslogtreecommitdiffstats
path: root/chrome/browser/bookmarks/bookmark_model_factory.cc
blob: efa8779fb48cf4585c17816b1a094824e82d94c2 (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
// Copyright (c) 2012 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 "chrome/browser/bookmarks/bookmark_model_factory.h"

#include "base/memory/singleton.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
#include "chrome/common/pref_names.h"

// static
BookmarkModel* BookmarkModelFactory::GetForProfile(Profile* profile) {
  return static_cast<BookmarkModel*>(
      GetInstance()->GetServiceForProfile(profile, true));
}

BookmarkModel* BookmarkModelFactory::GetForProfileIfExists(Profile* profile) {
  return static_cast<BookmarkModel*>(
      GetInstance()->GetServiceForProfile(profile, false));
}

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

BookmarkModelFactory::BookmarkModelFactory()
    : ProfileKeyedServiceFactory("BookmarkModel",
                                 ProfileDependencyManager::GetInstance()) {
}

BookmarkModelFactory::~BookmarkModelFactory() {}

ProfileKeyedService* BookmarkModelFactory::BuildServiceInstanceFor(
    Profile* profile) const {
  BookmarkModel* bookmark_model = new BookmarkModel(profile);
  bookmark_model->Load();
  return bookmark_model;
}

void BookmarkModelFactory::RegisterUserPrefs(PrefService* prefs) {
  // Don't sync this, as otherwise, due to a limitation in sync, it
  // will cause a deadlock (see http://crbug.com/97955).  If we truly
  // want to sync the expanded state of folders, it should be part of
  // bookmark sync itself (i.e., a property of the sync folder nodes).
  prefs->RegisterListPref(prefs::kBookmarkEditorExpandedNodes, new ListValue,
                          PrefService::UNSYNCABLE_PREF);
}

bool BookmarkModelFactory::ServiceRedirectedInIncognito() const {
  return true;
}

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