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

Unified Diff: chrome/browser/doodle/doodle_service_factory.cc

Issue 2752563003: [Doodle] Make DoodleService a KeyedService and add a factory (Closed)
Patch Set: Move factory to c/b/doodle Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/doodle/doodle_service_factory.h ('k') | components/doodle/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/doodle/doodle_service_factory.cc
diff --git a/chrome/browser/doodle/doodle_service_factory.cc b/chrome/browser/doodle/doodle_service_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..159c65f69adb9f286d7d4e84ce348d8ca916eec4
--- /dev/null
+++ b/chrome/browser/doodle/doodle_service_factory.cc
@@ -0,0 +1,55 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/doodle/doodle_service_factory.h"
+
+#include <memory>
+#include <utility>
+
+#include "base/memory/ptr_util.h"
+#include "base/time/default_clock.h"
+#include "base/timer/timer.h"
+#include "chrome/browser/google/google_url_tracker_factory.h"
+#include "chrome/browser/profiles/profile.h"
+#include "components/doodle/doodle_fetcher.h"
+#include "components/doodle/doodle_fetcher_impl.h"
+#include "components/doodle/doodle_service.h"
+#include "components/keyed_service/content/browser_context_dependency_manager.h"
+#include "components/prefs/pref_service.h"
+#include "components/safe_json/safe_json_parser.h"
+
+// static
+DoodleServiceFactory* DoodleServiceFactory::GetInstance() {
+ return base::Singleton<DoodleServiceFactory>::get();
+}
+
+// static
+doodle::DoodleService* DoodleServiceFactory::GetForProfile(Profile* profile) {
+ return static_cast<doodle::DoodleService*>(
+ GetInstance()->GetServiceForBrowserContext(profile, /*create=*/true));
+}
+
+DoodleServiceFactory::DoodleServiceFactory()
+ : BrowserContextKeyedServiceFactory(
+ "DoodleService",
+ BrowserContextDependencyManager::GetInstance()) {
+ DependsOn(GoogleURLTrackerFactory::GetInstance());
+}
+
+DoodleServiceFactory::~DoodleServiceFactory() = default;
+
+KeyedService* DoodleServiceFactory::BuildServiceInstanceFor(
+ content::BrowserContext* context) const {
+ Profile* profile = static_cast<Profile*>(context);
+ // We don't show doodles in incognito profiles (for now?).
+ DCHECK(!profile->IsOffTheRecord());
+
+ auto fetcher = base::MakeUnique<doodle::DoodleFetcherImpl>(
+ profile->GetRequestContext(),
+ GoogleURLTrackerFactory::GetForProfile(profile),
+ base::Bind(&safe_json::SafeJsonParser::Parse));
+ return new doodle::DoodleService(profile->GetPrefs(), std::move(fetcher),
+ base::MakeUnique<base::OneShotTimer>(),
+ base::MakeUnique<base::DefaultClock>());
+}
« no previous file with comments | « chrome/browser/doodle/doodle_service_factory.h ('k') | components/doodle/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698