Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: chrome/browser/doodle/doodle_service_factory.cc

Issue 2798033002: [Doodle] Allow overriding the API URL via a fieldtrial param (Closed)
Patch Set: .name Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | components/doodle/doodle_fetcher_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/metrics/field_trial_params.h"
11 #include "base/time/default_clock.h" 12 #include "base/time/default_clock.h"
12 #include "base/time/default_tick_clock.h" 13 #include "base/time/default_tick_clock.h"
13 #include "base/timer/timer.h" 14 #include "base/timer/timer.h"
14 #include "chrome/browser/google/google_url_tracker_factory.h" 15 #include "chrome/browser/google/google_url_tracker_factory.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "components/doodle/doodle_fetcher.h" 17 #include "components/doodle/doodle_fetcher.h"
17 #include "components/doodle/doodle_fetcher_impl.h" 18 #include "components/doodle/doodle_fetcher_impl.h"
18 #include "components/doodle/doodle_service.h" 19 #include "components/doodle/doodle_service.h"
19 #include "components/keyed_service/content/browser_context_dependency_manager.h" 20 #include "components/keyed_service/content/browser_context_dependency_manager.h"
20 #include "components/prefs/pref_service.h" 21 #include "components/prefs/pref_service.h"
21 #include "components/safe_json/safe_json_parser.h" 22 #include "components/safe_json/safe_json_parser.h"
22 23
23 #if defined(OS_ANDROID) 24 #if defined(OS_ANDROID)
24 #include "chrome/browser/android/chrome_feature_list.h" 25 #include "chrome/browser/android/chrome_feature_list.h"
25 #endif 26 #endif
26 27
28 #if defined(OS_ANDROID)
29 namespace {
30 const char kOverrideUrlParam[] = "doodle_override_url";
31 } // namespace
32 #endif
33
27 // static 34 // static
28 DoodleServiceFactory* DoodleServiceFactory::GetInstance() { 35 DoodleServiceFactory* DoodleServiceFactory::GetInstance() {
29 return base::Singleton<DoodleServiceFactory>::get(); 36 return base::Singleton<DoodleServiceFactory>::get();
30 } 37 }
31 38
32 // static 39 // static
33 doodle::DoodleService* DoodleServiceFactory::GetForProfile(Profile* profile) { 40 doodle::DoodleService* DoodleServiceFactory::GetForProfile(Profile* profile) {
34 return static_cast<doodle::DoodleService*>( 41 return static_cast<doodle::DoodleService*>(
35 GetInstance()->GetServiceForBrowserContext(profile, /*create=*/true)); 42 GetInstance()->GetServiceForBrowserContext(profile, /*create=*/true));
36 } 43 }
37 44
38 DoodleServiceFactory::DoodleServiceFactory() 45 DoodleServiceFactory::DoodleServiceFactory()
39 : BrowserContextKeyedServiceFactory( 46 : BrowserContextKeyedServiceFactory(
40 "DoodleService", 47 "DoodleService",
41 BrowserContextDependencyManager::GetInstance()) { 48 BrowserContextDependencyManager::GetInstance()) {
42 DependsOn(GoogleURLTrackerFactory::GetInstance()); 49 DependsOn(GoogleURLTrackerFactory::GetInstance());
43 } 50 }
44 51
45 DoodleServiceFactory::~DoodleServiceFactory() = default; 52 DoodleServiceFactory::~DoodleServiceFactory() = default;
46 53
47 KeyedService* DoodleServiceFactory::BuildServiceInstanceFor( 54 KeyedService* DoodleServiceFactory::BuildServiceInstanceFor(
48 content::BrowserContext* context) const { 55 content::BrowserContext* context) const {
49 Profile* profile = static_cast<Profile*>(context); 56 Profile* profile = static_cast<Profile*>(context);
50 // We don't show doodles in incognito profiles (for now?). 57 // We don't show doodles in incognito profiles (for now?).
51 DCHECK(!profile->IsOffTheRecord()); 58 DCHECK(!profile->IsOffTheRecord());
52 59
53 bool use_gray_background = false; 60 bool use_gray_background = false;
61 base::Optional<std::string> override_url;
62
54 #if defined(OS_ANDROID) 63 #if defined(OS_ANDROID)
64 DCHECK(base::FeatureList::IsEnabled(chrome::android::kUseNewDoodleApi));
65
55 use_gray_background = 66 use_gray_background =
56 !base::FeatureList::IsEnabled(chrome::android::kChromeHomeFeature); 67 !base::FeatureList::IsEnabled(chrome::android::kChromeHomeFeature);
68
69 std::string override_url_str = base::GetFieldTrialParamValueByFeature(
70 chrome::android::kUseNewDoodleApi, kOverrideUrlParam);
71 // GetFieldTrialParamValueByFeature returns an empty string if the param is
72 // not set.
73 if (!override_url_str.empty()) {
74 override_url = override_url_str;
75 }
57 #endif 76 #endif
77
58 auto fetcher = base::MakeUnique<doodle::DoodleFetcherImpl>( 78 auto fetcher = base::MakeUnique<doodle::DoodleFetcherImpl>(
59 profile->GetRequestContext(), 79 profile->GetRequestContext(),
60 GoogleURLTrackerFactory::GetForProfile(profile), 80 GoogleURLTrackerFactory::GetForProfile(profile),
61 base::Bind(&safe_json::SafeJsonParser::Parse), use_gray_background); 81 base::Bind(&safe_json::SafeJsonParser::Parse), use_gray_background,
82 override_url);
62 return new doodle::DoodleService( 83 return new doodle::DoodleService(
63 profile->GetPrefs(), std::move(fetcher), 84 profile->GetPrefs(), std::move(fetcher),
64 base::MakeUnique<base::OneShotTimer>(), 85 base::MakeUnique<base::OneShotTimer>(),
65 base::MakeUnique<base::DefaultClock>(), 86 base::MakeUnique<base::DefaultClock>(),
66 base::MakeUnique<base::DefaultTickClock>(), 87 base::MakeUnique<base::DefaultTickClock>(),
67 /*override_min_refresh_interval=*/base::nullopt); 88 /*override_min_refresh_interval=*/base::nullopt);
68 } 89 }
OLDNEW
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | components/doodle/doodle_fetcher_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698