| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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/doodle/doodle_service_factory.h" |
| 6 |
| 7 #include <memory> |
| 8 #include <utility> |
| 9 |
| 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/time/default_clock.h" |
| 12 #include "base/timer/timer.h" |
| 13 #include "chrome/browser/google/google_url_tracker_factory.h" |
| 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "components/doodle/doodle_fetcher.h" |
| 16 #include "components/doodle/doodle_fetcher_impl.h" |
| 17 #include "components/doodle/doodle_service.h" |
| 18 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 19 #include "components/prefs/pref_service.h" |
| 20 #include "components/safe_json/safe_json_parser.h" |
| 21 |
| 22 // static |
| 23 DoodleServiceFactory* DoodleServiceFactory::GetInstance() { |
| 24 return base::Singleton<DoodleServiceFactory>::get(); |
| 25 } |
| 26 |
| 27 // static |
| 28 doodle::DoodleService* DoodleServiceFactory::GetForProfile(Profile* profile) { |
| 29 return static_cast<doodle::DoodleService*>( |
| 30 GetInstance()->GetServiceForBrowserContext(profile, /*create=*/true)); |
| 31 } |
| 32 |
| 33 DoodleServiceFactory::DoodleServiceFactory() |
| 34 : BrowserContextKeyedServiceFactory( |
| 35 "DoodleService", |
| 36 BrowserContextDependencyManager::GetInstance()) { |
| 37 DependsOn(GoogleURLTrackerFactory::GetInstance()); |
| 38 } |
| 39 |
| 40 DoodleServiceFactory::~DoodleServiceFactory() = default; |
| 41 |
| 42 KeyedService* DoodleServiceFactory::BuildServiceInstanceFor( |
| 43 content::BrowserContext* context) const { |
| 44 Profile* profile = static_cast<Profile*>(context); |
| 45 // We don't show doodles in incognito profiles (for now?). |
| 46 DCHECK(!profile->IsOffTheRecord()); |
| 47 |
| 48 auto fetcher = base::MakeUnique<doodle::DoodleFetcherImpl>( |
| 49 profile->GetRequestContext(), |
| 50 GoogleURLTrackerFactory::GetForProfile(profile), |
| 51 base::Bind(&safe_json::SafeJsonParser::Parse)); |
| 52 return new doodle::DoodleService(profile->GetPrefs(), std::move(fetcher), |
| 53 base::MakeUnique<base::OneShotTimer>(), |
| 54 base::MakeUnique<base::DefaultClock>()); |
| 55 } |
| OLD | NEW |