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