| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 // Copyright 2015 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. | 
|  | 4 | 
|  | 5 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" | 
|  | 6 | 
|  | 7 #include <string> | 
|  | 8 | 
|  | 9 #include "base/bind.h" | 
|  | 10 #include "base/memory/singleton.h" | 
|  | 11 #include "chrome/browser/policy/profile_policy_connector.h" | 
|  | 12 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 
|  | 13 #include "chrome/browser/profiles/incognito_helpers.h" | 
|  | 14 #include "chrome/browser/profiles/profile.h" | 
|  | 15 #include "components/bookmarks/managed/managed_bookmark_service.h" | 
|  | 16 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 
|  | 17 #include "policy/policy_constants.h" | 
|  | 18 | 
|  | 19 namespace { | 
|  | 20 | 
|  | 21 std::string GetManagedBookmarksDomain(Profile* profile) { | 
|  | 22   policy::ProfilePolicyConnector* connector = | 
|  | 23       policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile); | 
|  | 24   if (connector->IsPolicyFromCloudPolicy(policy::key::kManagedBookmarks)) | 
|  | 25     return connector->GetManagementDomain(); | 
|  | 26   return std::string(); | 
|  | 27 } | 
|  | 28 | 
|  | 29 scoped_ptr<KeyedService> BuildManagedBookmarkService( | 
|  | 30     content::BrowserContext* context) { | 
|  | 31   Profile* profile = Profile::FromBrowserContext(context); | 
|  | 32   return make_scoped_ptr(new bookmarks::ManagedBookmarkService( | 
|  | 33       profile->GetPrefs(), | 
|  | 34       base::Bind(&GetManagedBookmarksDomain, base::Unretained(profile)))); | 
|  | 35 } | 
|  | 36 | 
|  | 37 }  // namespace | 
|  | 38 | 
|  | 39 // static | 
|  | 40 bookmarks::ManagedBookmarkService* ManagedBookmarkServiceFactory::GetForProfile( | 
|  | 41     Profile* profile) { | 
|  | 42   return static_cast<bookmarks::ManagedBookmarkService*>( | 
|  | 43       GetInstance()->GetServiceForBrowserContext(profile, true)); | 
|  | 44 } | 
|  | 45 | 
|  | 46 // static | 
|  | 47 ManagedBookmarkServiceFactory* ManagedBookmarkServiceFactory::GetInstance() { | 
|  | 48   return Singleton<ManagedBookmarkServiceFactory>::get(); | 
|  | 49 } | 
|  | 50 | 
|  | 51 // static | 
|  | 52 BrowserContextKeyedServiceFactory::TestingFactoryFunction | 
|  | 53 ManagedBookmarkServiceFactory::GetDefaultFactory() { | 
|  | 54   return &BuildManagedBookmarkService; | 
|  | 55 } | 
|  | 56 | 
|  | 57 ManagedBookmarkServiceFactory::ManagedBookmarkServiceFactory() | 
|  | 58     : BrowserContextKeyedServiceFactory( | 
|  | 59           "ManagedBookmarkService", | 
|  | 60           BrowserContextDependencyManager::GetInstance()) { | 
|  | 61   DependsOn(policy::ProfilePolicyConnectorFactory::GetInstance()); | 
|  | 62 } | 
|  | 63 | 
|  | 64 ManagedBookmarkServiceFactory::~ManagedBookmarkServiceFactory() { | 
|  | 65 } | 
|  | 66 | 
|  | 67 KeyedService* ManagedBookmarkServiceFactory::BuildServiceInstanceFor( | 
|  | 68     content::BrowserContext* context) const { | 
|  | 69   return BuildManagedBookmarkService(context).release(); | 
|  | 70 } | 
|  | 71 | 
|  | 72 content::BrowserContext* ManagedBookmarkServiceFactory::GetBrowserContextToUse( | 
|  | 73     content::BrowserContext* context) const { | 
|  | 74   return chrome::GetBrowserContextRedirectedInIncognito(context); | 
|  | 75 } | 
|  | 76 | 
|  | 77 bool ManagedBookmarkServiceFactory::ServiceIsNULLWhileTesting() const { | 
|  | 78   return true; | 
|  | 79 } | 
| OLD | NEW | 
|---|