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

Unified Diff: chrome/browser/chromeos/policy/consumer_management_notifier_factory.cc

Issue 733613005: Move the notification part out of ConsumerEnrollmentHandler so that it can be reused for unenrollme… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@enroll
Patch Set: Added a check for UserManager. Created 6 years, 1 month 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
Index: chrome/browser/chromeos/policy/consumer_management_notifier_factory.cc
diff --git a/chrome/browser/chromeos/policy/consumer_management_notifier_factory.cc b/chrome/browser/chromeos/policy/consumer_management_notifier_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a63c772a97f0c2ac043736d26c57b656e4b8bfa8
--- /dev/null
+++ b/chrome/browser/chromeos/policy/consumer_management_notifier_factory.cc
@@ -0,0 +1,67 @@
+// Copyright 2014 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/chromeos/policy/consumer_management_notifier_factory.h"
+
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/browser_process_platform_part.h"
+#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
+#include "chrome/browser/chromeos/policy/consumer_management_notifier.h"
+#include "chrome/browser/chromeos/profiles/profile_helper.h"
+#include "chrome/browser/profiles/profile.h"
+#include "components/keyed_service/content/browser_context_dependency_manager.h"
+#include "components/user_manager/user_manager.h"
+
+namespace policy {
+
+// static
+ConsumerManagementNotifier*
+ConsumerManagementNotifierFactory::GetForBrowserContext(
+ content::BrowserContext* context) {
+ return static_cast<ConsumerManagementNotifier*>(
+ GetInstance()->GetServiceForBrowserContext(context, true));
+}
+
+// static
+ConsumerManagementNotifierFactory*
+ConsumerManagementNotifierFactory::GetInstance() {
+ return Singleton<ConsumerManagementNotifierFactory>::get();
+}
+
+ConsumerManagementNotifierFactory::ConsumerManagementNotifierFactory()
+ : BrowserContextKeyedServiceFactory(
+ "ConsumerManagementNotifier",
+ BrowserContextDependencyManager::GetInstance()) {
+}
+
+ConsumerManagementNotifierFactory::~ConsumerManagementNotifierFactory() {
+}
+
+KeyedService* ConsumerManagementNotifierFactory::BuildServiceInstanceFor(
+ content::BrowserContext* context) const {
+ // Some tests don't have a user manager and may crash at IsOwnerProfile().
+ if (!user_manager::UserManager::IsInitialized())
+ return nullptr;
+
+ // On a fresh device, the first time the owner signs in, IsOwnerProfile()
+ // will return false. But it is okay since there's no notification to show.
+ Profile* profile = Profile::FromBrowserContext(context);
+ if (!chromeos::ProfileHelper::IsOwnerProfile(profile))
+ return nullptr;
+
+ ConsumerManagementService* service =
+ g_browser_process->platform_part()->browser_policy_connector_chromeos()->
+ GetConsumerManagementService();
+ if (!service)
+ return nullptr;
+
+ return new ConsumerManagementNotifier(profile, service);
+}
+
+bool ConsumerManagementNotifierFactory::ServiceIsCreatedWithBrowserContext()
+ const {
+ return true;
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698