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

Side by Side Diff: chrome/browser/policy/cloud/user_cloud_policy_invalidator.cc

Issue 23592017: Fix policy invalidator lifecycle bugs for Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/policy/cloud/user_cloud_policy_invalidator.h" 5 #include "chrome/browser/policy/cloud/user_cloud_policy_invalidator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/invalidation/invalidation_service_factory.h"
10 #include "chrome/browser/policy/cloud/cloud_policy_core.h" 11 #include "chrome/browser/policy/cloud/cloud_policy_core.h"
11 #include "chrome/browser/policy/cloud/cloud_policy_manager.h" 12 #include "chrome/browser/policy/cloud/cloud_policy_manager.h"
12 #include "content/public/browser/notification_source.h" 13 #include "content/public/browser/notification_source.h"
13 14
14 namespace policy { 15 namespace policy {
15 16
16 UserCloudPolicyInvalidator::UserCloudPolicyInvalidator( 17 UserCloudPolicyInvalidator::UserCloudPolicyInvalidator(
17 Profile* profile, 18 Profile* profile,
18 CloudPolicyManager* policy_manager) 19 CloudPolicyManager* policy_manager)
19 : CloudPolicyInvalidator( 20 : CloudPolicyInvalidator(
21 base::Bind(
22 &invalidation::InvalidationServiceFactory::GetForProfile,
23 base::Unretained(profile)),
20 policy_manager, 24 policy_manager,
21 policy_manager->core()->store(), 25 policy_manager->core()->store(),
22 base::MessageLoopProxy::current()), 26 base::MessageLoopProxy::current()),
23 profile_(profile), 27 policy_manager_(policy_manager),
24 policy_manager_(policy_manager) { 28 weak_factory_(this) {
25 DCHECK(profile); 29 DCHECK(profile);
26 30
27 // Register for notification that profile creation is complete. 31 // Register for notification that profile creation is complete. The
32 // invalidator must not be started before then because the invalidation
33 // service cannot be started because it depends on components initialized
34 // after this object is instantiated.
28 registrar_.Add(this, 35 registrar_.Add(this,
29 chrome::NOTIFICATION_PROFILE_ADDED, 36 chrome::NOTIFICATION_PROFILE_ADDED,
30 content::Source<Profile>(profile)); 37 content::Source<Profile>(profile));
31 } 38 }
32 39
40 UserCloudPolicyInvalidator::~UserCloudPolicyInvalidator() {}
41
33 void UserCloudPolicyInvalidator::Shutdown() { 42 void UserCloudPolicyInvalidator::Shutdown() {
43 weak_factory_.InvalidateWeakPtrs();
34 CloudPolicyInvalidator::Shutdown(); 44 CloudPolicyInvalidator::Shutdown();
35 } 45 }
36 46
37 void UserCloudPolicyInvalidator::Observe( 47 void UserCloudPolicyInvalidator::Observe(
38 int type, 48 int type,
39 const content::NotificationSource& source, 49 const content::NotificationSource& source,
40 const content::NotificationDetails& details) { 50 const content::NotificationDetails& details) {
41 // Enable invalidations now that profile creation is complete.
42 DCHECK(type == chrome::NOTIFICATION_PROFILE_ADDED); 51 DCHECK(type == chrome::NOTIFICATION_PROFILE_ADDED);
43 policy_manager_->EnableInvalidations( 52 // Pass a reference to the invalidator to the policy manager, which handles
44 base::Bind( 53 // starting and stopping the invalidator.
45 &CloudPolicyInvalidator::InitializeWithProfile, 54 policy_manager_->SetInvalidator(weak_factory_.GetWeakPtr());
46 GetWeakPtr(),
47 base::Unretained(profile_)));
48 } 55 }
49 56
50 } // namespace policy 57 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698