user_cloud_policy_invalidator.cc revision a36e5920737c6adbddd3e43b760e5de8431db6e0
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.
4
5#include "chrome/browser/policy/cloud/user_cloud_policy_invalidator.h"
6
7#include "base/bind.h"
8#include "base/message_loop/message_loop_proxy.h"
9#include "chrome/browser/chrome_notification_types.h"
10#include "chrome/browser/policy/cloud/cloud_policy_core.h"
11#include "chrome/browser/policy/cloud/cloud_policy_manager.h"
12#include "content/public/browser/notification_source.h"
13
14namespace policy {
15
16UserCloudPolicyInvalidator::UserCloudPolicyInvalidator(
17    Profile* profile,
18    CloudPolicyManager* policy_manager)
19    : CloudPolicyInvalidator(
20          policy_manager,
21          policy_manager->core()->store(),
22          base::MessageLoopProxy::current()),
23      profile_(profile),
24      policy_manager_(policy_manager) {
25  DCHECK(profile);
26
27  // Register for notification that profile creation is complete.
28  registrar_.Add(this,
29                 chrome::NOTIFICATION_PROFILE_ADDED,
30                 content::Source<Profile>(profile));
31}
32
33void UserCloudPolicyInvalidator::Shutdown() {
34  CloudPolicyInvalidator::Shutdown();
35}
36
37void UserCloudPolicyInvalidator::Observe(
38    int type,
39    const content::NotificationSource& source,
40    const content::NotificationDetails& details) {
41  // Enable invalidations now that profile creation is complete.
42  DCHECK(type == chrome::NOTIFICATION_PROFILE_ADDED);
43  policy_manager_->EnableInvalidations(
44      base::Bind(
45          &CloudPolicyInvalidator::InitializeWithProfile,
46          GetWeakPtr(),
47          base::Unretained(profile_)));
48}
49
50}  // namespace policy
51