| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 5 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/deferred_sequenced_task_runner.h" | 8 #include "base/deferred_sequenced_task_runner.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | 12 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" |
| 13 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" | 13 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" |
| 14 #include "chrome/browser/bookmarks/startup_task_runner_service_factory.h" | 14 #include "chrome/browser/bookmarks/startup_task_runner_service_factory.h" |
| 15 #include "chrome/browser/profiles/incognito_helpers.h" | 15 #include "chrome/browser/profiles/incognito_helpers.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/undo/bookmark_undo_service_factory.h" | 17 #include "chrome/browser/undo/bookmark_undo_service_factory.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/features.h" |
| 19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 20 #include "components/bookmarks/browser/bookmark_model.h" | 21 #include "components/bookmarks/browser/bookmark_model.h" |
| 21 #include "components/bookmarks/browser/bookmark_utils.h" | 22 #include "components/bookmarks/browser/bookmark_utils.h" |
| 22 #include "components/bookmarks/browser/startup_task_runner_service.h" | 23 #include "components/bookmarks/browser/startup_task_runner_service.h" |
| 23 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 24 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 24 #include "components/undo/bookmark_undo_service.h" | 25 #include "components/undo/bookmark_undo_service.h" |
| 25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 26 | 27 |
| 27 #if defined(OS_ANDROID) | 28 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 28 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 29 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" |
| 29 #include "components/offline_pages/offline_page_feature.h" | 30 #include "components/offline_pages/offline_page_feature.h" |
| 30 #include "components/offline_pages/offline_page_model.h" | 31 #include "components/offline_pages/offline_page_model.h" |
| 31 #endif // defined(OS_ANDROID) | 32 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 32 | 33 |
| 33 using bookmarks::BookmarkModel; | 34 using bookmarks::BookmarkModel; |
| 34 | 35 |
| 35 // static | 36 // static |
| 36 BookmarkModel* BookmarkModelFactory::GetForProfile(Profile* profile) { | 37 BookmarkModel* BookmarkModelFactory::GetForProfile(Profile* profile) { |
| 37 return static_cast<BookmarkModel*>( | 38 return static_cast<BookmarkModel*>( |
| 38 GetInstance()->GetServiceForBrowserContext(profile, true)); | 39 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 39 } | 40 } |
| 40 | 41 |
| 41 // static | 42 // static |
| 42 BookmarkModel* BookmarkModelFactory::GetForProfileIfExists(Profile* profile) { | 43 BookmarkModel* BookmarkModelFactory::GetForProfileIfExists(Profile* profile) { |
| 43 return static_cast<BookmarkModel*>( | 44 return static_cast<BookmarkModel*>( |
| 44 GetInstance()->GetServiceForBrowserContext(profile, false)); | 45 GetInstance()->GetServiceForBrowserContext(profile, false)); |
| 45 } | 46 } |
| 46 | 47 |
| 47 // static | 48 // static |
| 48 BookmarkModelFactory* BookmarkModelFactory::GetInstance() { | 49 BookmarkModelFactory* BookmarkModelFactory::GetInstance() { |
| 49 return base::Singleton<BookmarkModelFactory>::get(); | 50 return base::Singleton<BookmarkModelFactory>::get(); |
| 50 } | 51 } |
| 51 | 52 |
| 52 BookmarkModelFactory::BookmarkModelFactory() | 53 BookmarkModelFactory::BookmarkModelFactory() |
| 53 : BrowserContextKeyedServiceFactory( | 54 : BrowserContextKeyedServiceFactory( |
| 54 "BookmarkModel", | 55 "BookmarkModel", |
| 55 BrowserContextDependencyManager::GetInstance()) { | 56 BrowserContextDependencyManager::GetInstance()) { |
| 56 DependsOn(BookmarkUndoServiceFactory::GetInstance()); | 57 DependsOn(BookmarkUndoServiceFactory::GetInstance()); |
| 57 DependsOn(ChromeBookmarkClientFactory::GetInstance()); | 58 DependsOn(ChromeBookmarkClientFactory::GetInstance()); |
| 58 DependsOn(StartupTaskRunnerServiceFactory::GetInstance()); | 59 DependsOn(StartupTaskRunnerServiceFactory::GetInstance()); |
| 59 #if defined(OS_ANDROID) | 60 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 60 if (offline_pages::IsOfflinePagesEnabled()) | 61 if (offline_pages::IsOfflinePagesEnabled()) |
| 61 DependsOn(offline_pages::OfflinePageModelFactory::GetInstance()); | 62 DependsOn(offline_pages::OfflinePageModelFactory::GetInstance()); |
| 62 #endif | 63 #endif |
| 63 } | 64 } |
| 64 | 65 |
| 65 BookmarkModelFactory::~BookmarkModelFactory() { | 66 BookmarkModelFactory::~BookmarkModelFactory() { |
| 66 } | 67 } |
| 67 | 68 |
| 68 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor( | 69 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor( |
| 69 content::BrowserContext* context) const { | 70 content::BrowserContext* context) const { |
| 70 Profile* profile = Profile::FromBrowserContext(context); | 71 Profile* profile = Profile::FromBrowserContext(context); |
| 71 ChromeBookmarkClient* bookmark_client = | 72 ChromeBookmarkClient* bookmark_client = |
| 72 ChromeBookmarkClientFactory::GetForProfile(profile); | 73 ChromeBookmarkClientFactory::GetForProfile(profile); |
| 73 BookmarkModel* bookmark_model = new BookmarkModel(bookmark_client); | 74 BookmarkModel* bookmark_model = new BookmarkModel(bookmark_client); |
| 74 bookmark_client->Init(bookmark_model); | 75 bookmark_client->Init(bookmark_model); |
| 75 bookmark_model->Load(profile->GetPrefs(), | 76 bookmark_model->Load(profile->GetPrefs(), |
| 76 profile->GetPrefs()->GetString(prefs::kAcceptLanguages), | 77 profile->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| 77 profile->GetPath(), | 78 profile->GetPath(), |
| 78 StartupTaskRunnerServiceFactory::GetForProfile(profile) | 79 StartupTaskRunnerServiceFactory::GetForProfile(profile) |
| 79 ->GetBookmarkTaskRunner(), | 80 ->GetBookmarkTaskRunner(), |
| 80 content::BrowserThread::GetMessageLoopProxyForThread( | 81 content::BrowserThread::GetMessageLoopProxyForThread( |
| 81 content::BrowserThread::UI)); | 82 content::BrowserThread::UI)); |
| 82 bool register_bookmark_undo_service_as_observer = true; | 83 bool register_bookmark_undo_service_as_observer = true; |
| 83 #if !defined(OS_IOS) && !defined(OS_ANDROID) | 84 #if !defined(OS_IOS) && !BUILDFLAG(ANDROID_JAVA_UI) |
| 84 register_bookmark_undo_service_as_observer = | 85 register_bookmark_undo_service_as_observer = |
| 85 base::CommandLine::ForCurrentProcess()->HasSwitch( | 86 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 86 switches::kEnableBookmarkUndo); | 87 switches::kEnableBookmarkUndo); |
| 87 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) | 88 #endif // !defined(OS_IOS) && !BUILDFLAG(ANDROID_JAVA_UI) |
| 88 if (register_bookmark_undo_service_as_observer) | 89 if (register_bookmark_undo_service_as_observer) |
| 89 BookmarkUndoServiceFactory::GetForProfile(profile)->Start(bookmark_model); | 90 BookmarkUndoServiceFactory::GetForProfile(profile)->Start(bookmark_model); |
| 90 | 91 |
| 91 #if defined(OS_ANDROID) | 92 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 92 if (offline_pages::IsOfflinePagesEnabled()) { | 93 if (offline_pages::IsOfflinePagesEnabled()) { |
| 93 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile)-> | 94 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile)-> |
| 94 Start(bookmark_model); | 95 Start(bookmark_model); |
| 95 } | 96 } |
| 96 #endif // defined(OS_ANDROID) | 97 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 97 | 98 |
| 98 return bookmark_model; | 99 return bookmark_model; |
| 99 } | 100 } |
| 100 | 101 |
| 101 void BookmarkModelFactory::RegisterProfilePrefs( | 102 void BookmarkModelFactory::RegisterProfilePrefs( |
| 102 user_prefs::PrefRegistrySyncable* registry) { | 103 user_prefs::PrefRegistrySyncable* registry) { |
| 103 bookmarks::RegisterProfilePrefs(registry); | 104 bookmarks::RegisterProfilePrefs(registry); |
| 104 } | 105 } |
| 105 | 106 |
| 106 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( | 107 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( |
| 107 content::BrowserContext* context) const { | 108 content::BrowserContext* context) const { |
| 108 return chrome::GetBrowserContextRedirectedInIncognito(context); | 109 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 109 } | 110 } |
| 110 | 111 |
| 111 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { | 112 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { |
| 112 return true; | 113 return true; |
| 113 } | 114 } |
| OLD | NEW |