| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/search/suggestions/suggestions_service_factory.h" | 5 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "chrome/browser/profiles/incognito_helpers.h" | 9 #include "chrome/browser/profiles/incognito_helpers.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/search/suggestions/blacklist_store.h" | |
| 12 #include "chrome/browser/search/suggestions/image_manager.h" | |
| 13 #include "chrome/browser/search/suggestions/proto/suggestions.pb.h" | |
| 14 #include "chrome/browser/search/suggestions/suggestions_service.h" | |
| 15 #include "chrome/browser/search/suggestions/suggestions_store.h" | |
| 16 #include "chrome/browser/search/suggestions/thumbnail_manager.h" | 11 #include "chrome/browser/search/suggestions/thumbnail_manager.h" |
| 17 #include "chrome/common/pref_names.h" | |
| 18 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 12 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 19 #include "components/leveldb_proto/proto_database.h" | 13 #include "components/leveldb_proto/proto_database.h" |
| 20 #include "components/leveldb_proto/proto_database_impl.h" | 14 #include "components/leveldb_proto/proto_database_impl.h" |
| 21 #include "components/pref_registry/pref_registry_syncable.h" | 15 #include "components/pref_registry/pref_registry_syncable.h" |
| 16 #include "components/suggestions/blacklist_store.h" |
| 17 #include "components/suggestions/image_manager.h" |
| 18 #include "components/suggestions/proto/suggestions.pb.h" |
| 19 #include "components/suggestions/suggestions_service.h" |
| 20 #include "components/suggestions/suggestions_store.h" |
| 22 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 24 | 23 |
| 24 using content::BrowserThread; |
| 25 |
| 25 namespace suggestions { | 26 namespace suggestions { |
| 26 | 27 |
| 27 // static | 28 // static |
| 28 SuggestionsService* SuggestionsServiceFactory::GetForProfile(Profile* profile) { | 29 SuggestionsService* SuggestionsServiceFactory::GetForProfile(Profile* profile) { |
| 29 if (!SuggestionsService::IsEnabled() || profile->IsOffTheRecord()) | 30 if (!SuggestionsService::IsEnabled() || profile->IsOffTheRecord()) |
| 30 return NULL; | 31 return NULL; |
| 31 | 32 |
| 32 return static_cast<SuggestionsService*>( | 33 return static_cast<SuggestionsService*>( |
| 33 GetInstance()->GetServiceForBrowserContext(profile, true)); | 34 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 34 } | 35 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 48 SuggestionsServiceFactory::~SuggestionsServiceFactory() {} | 49 SuggestionsServiceFactory::~SuggestionsServiceFactory() {} |
| 49 | 50 |
| 50 content::BrowserContext* SuggestionsServiceFactory::GetBrowserContextToUse( | 51 content::BrowserContext* SuggestionsServiceFactory::GetBrowserContextToUse( |
| 51 content::BrowserContext* context) const { | 52 content::BrowserContext* context) const { |
| 52 return chrome::GetBrowserContextRedirectedInIncognito(context); | 53 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 53 } | 54 } |
| 54 | 55 |
| 55 KeyedService* SuggestionsServiceFactory::BuildServiceInstanceFor( | 56 KeyedService* SuggestionsServiceFactory::BuildServiceInstanceFor( |
| 56 content::BrowserContext* profile) const { | 57 content::BrowserContext* profile) const { |
| 57 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 58 scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
| 58 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( | 59 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( |
| 59 content::BrowserThread::GetBlockingPool()->GetSequenceToken()); | 60 BrowserThread::GetBlockingPool()->GetSequenceToken()); |
| 60 | 61 |
| 61 Profile* the_profile = static_cast<Profile*>(profile); | 62 Profile* the_profile = static_cast<Profile*>(profile); |
| 62 scoped_ptr<SuggestionsStore> suggestions_store( | 63 scoped_ptr<SuggestionsStore> suggestions_store( |
| 63 new SuggestionsStore(the_profile->GetPrefs())); | 64 new SuggestionsStore(the_profile->GetPrefs())); |
| 64 scoped_ptr<BlacklistStore> blacklist_store( | 65 scoped_ptr<BlacklistStore> blacklist_store( |
| 65 new BlacklistStore(the_profile->GetPrefs())); | 66 new BlacklistStore(the_profile->GetPrefs())); |
| 66 | 67 |
| 67 scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ThumbnailData> > db( | 68 scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ThumbnailData> > db( |
| 68 new leveldb_proto::ProtoDatabaseImpl<ThumbnailData>( | 69 new leveldb_proto::ProtoDatabaseImpl<ThumbnailData>( |
| 69 background_task_runner)); | 70 background_task_runner)); |
| 70 | 71 |
| 71 base::FilePath database_dir( | 72 base::FilePath database_dir( |
| 72 the_profile->GetPath().Append(FILE_PATH_LITERAL("Thumbnails"))); | 73 the_profile->GetPath().Append(FILE_PATH_LITERAL("Thumbnails"))); |
| 73 | 74 |
| 74 scoped_ptr<ThumbnailManager> thumbnail_manager(new ThumbnailManager( | 75 scoped_ptr<ThumbnailManager> thumbnail_manager(new ThumbnailManager( |
| 75 the_profile->GetRequestContext(), | 76 the_profile->GetRequestContext(), |
| 76 db.PassAs<leveldb_proto::ProtoDatabase<ThumbnailData> >(), database_dir)); | 77 db.PassAs<leveldb_proto::ProtoDatabase<ThumbnailData> >(), database_dir)); |
| 77 return new SuggestionsService( | 78 return new SuggestionsService( |
| 78 the_profile->GetRequestContext(), suggestions_store.Pass(), | 79 the_profile->GetRequestContext(), suggestions_store.Pass(), |
| 79 thumbnail_manager.PassAs<ImageManager>(), blacklist_store.Pass()); | 80 thumbnail_manager.PassAs<ImageManager>(), blacklist_store.Pass()); |
| 80 } | 81 } |
| 81 | 82 |
| 82 void SuggestionsServiceFactory::RegisterProfilePrefs( | 83 void SuggestionsServiceFactory::RegisterProfilePrefs( |
| 83 user_prefs::PrefRegistrySyncable* registry) { | 84 user_prefs::PrefRegistrySyncable* registry) { |
| 84 SuggestionsService::RegisterProfilePrefs(registry); | 85 SuggestionsService::RegisterProfilePrefs(registry); |
| 85 } | 86 } |
| 86 | 87 |
| 87 } // namespace suggestions | 88 } // namespace suggestions |
| OLD | NEW |