1 // Copyright 2013 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.
5 #include "chrome/browser/policy/cloud/user_cloud_policy_invalidator.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/time/default_clock.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/invalidation/invalidation_service_factory.h"
13 #include "components/policy/core/common/cloud/cloud_policy_manager.h"
14 #include "content/public/browser/notification_source.h"
18 UserCloudPolicyInvalidator::UserCloudPolicyInvalidator(
20 CloudPolicyManager* policy_manager)
21 : CloudPolicyInvalidator(
22 policy_manager->core(),
23 base::MessageLoopProxy::current(),
24 scoped_ptr<base::Clock>(new base::DefaultClock())),
28 // Register for notification that profile creation is complete. The
29 // invalidator must not be initialized before then because the invalidation
30 // service cannot be started because it depends on components initialized
31 // after this object is instantiated.
32 // TODO(stepco): Delayed initialization can be removed once the request
33 // context can be accessed during profile-keyed service creation. Tracked by
36 chrome::NOTIFICATION_PROFILE_ADDED,
37 content::Source<Profile>(profile));
40 void UserCloudPolicyInvalidator::Shutdown() {
41 CloudPolicyInvalidator::Shutdown();
44 void UserCloudPolicyInvalidator::Observe(
46 const content::NotificationSource& source,
47 const content::NotificationDetails& details) {
48 // Initialize now that profile creation is complete and the invalidation
49 // service can safely be initialized.
50 DCHECK(type == chrome::NOTIFICATION_PROFILE_ADDED);
51 invalidation::InvalidationService* invalidation_service =
52 invalidation::InvalidationServiceFactory::GetForProfile(profile_);
53 if (invalidation_service)
54 Initialize(invalidation_service);