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/message_loop/message_loop_proxy.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/invalidation/invalidation_service_factory.h"
11 #include "components/policy/core/common/cloud/cloud_policy_manager.h"
12 #include "content/public/browser/notification_source.h"
16 UserCloudPolicyInvalidator::UserCloudPolicyInvalidator(
18 CloudPolicyManager
* policy_manager
)
19 : CloudPolicyInvalidator(
20 policy_manager
->core(),
21 base::MessageLoopProxy::current()),
25 // Register for notification that profile creation is complete. The
26 // invalidator must not be initialized before then because the invalidation
27 // service cannot be started because it depends on components initialized
28 // after this object is instantiated.
29 // TODO(stepco): Delayed initialization can be removed once the request
30 // context can be accessed during profile-keyed service creation. Tracked by
33 chrome::NOTIFICATION_PROFILE_ADDED
,
34 content::Source
<Profile
>(profile
));
37 void UserCloudPolicyInvalidator::Shutdown() {
38 CloudPolicyInvalidator::Shutdown();
41 void UserCloudPolicyInvalidator::Observe(
43 const content::NotificationSource
& source
,
44 const content::NotificationDetails
& details
) {
45 // Initialize now that profile creation is complete and the invalidation
46 // service can safely be initialized.
47 DCHECK(type
== chrome::NOTIFICATION_PROFILE_ADDED
);
48 invalidation::InvalidationService
* invalidation_service
=
49 invalidation::InvalidationServiceFactory::GetForProfile(profile_
);
50 if (invalidation_service
)
51 Initialize(invalidation_service
);