Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / policy / cloud / user_cloud_policy_invalidator.cc
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/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"
15
16 namespace policy {
17
18 UserCloudPolicyInvalidator::UserCloudPolicyInvalidator(
19     Profile* profile,
20     CloudPolicyManager* policy_manager)
21     : CloudPolicyInvalidator(
22           policy_manager->core(),
23           base::MessageLoopProxy::current(),
24           scoped_ptr<base::Clock>(new base::DefaultClock())),
25       profile_(profile) {
26   DCHECK(profile);
27
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
34   // bug 286209.
35   registrar_.Add(this,
36                  chrome::NOTIFICATION_PROFILE_ADDED,
37                  content::Source<Profile>(profile));
38 }
39
40 void UserCloudPolicyInvalidator::Shutdown() {
41   CloudPolicyInvalidator::Shutdown();
42 }
43
44 void UserCloudPolicyInvalidator::Observe(
45     int type,
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);
55 }
56
57 }  // namespace policy