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

Side by Side Diff: chrome/browser/policy/cloud_policy_refresh_scheduler.cc

Issue 11414083: Remove PrefObserver usage, batch 9. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to sort-of good revision (r169014). Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_policy_refresh_scheduler.h" 5 #include "chrome/browser/policy/cloud_policy_refresh_scheduler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/task_runner.h" 9 #include "base/task_runner.h"
10 #include "chrome/browser/policy/cloud_policy_constants.h" 10 #include "chrome/browser/policy/cloud_policy_constants.h"
(...skipping 19 matching lines...) Expand all
30 const std::string& refresh_pref, 30 const std::string& refresh_pref,
31 const scoped_refptr<base::TaskRunner>& task_runner) 31 const scoped_refptr<base::TaskRunner>& task_runner)
32 : client_(client), 32 : client_(client),
33 store_(store), 33 store_(store),
34 task_runner_(task_runner), 34 task_runner_(task_runner),
35 error_retry_delay_ms_(kInitialErrorRetryDelayMs) { 35 error_retry_delay_ms_(kInitialErrorRetryDelayMs) {
36 client_->AddObserver(this); 36 client_->AddObserver(this);
37 store_->AddObserver(this); 37 store_->AddObserver(this);
38 net::NetworkChangeNotifier::AddIPAddressObserver(this); 38 net::NetworkChangeNotifier::AddIPAddressObserver(this);
39 39
40 refresh_delay_.Init(refresh_pref.c_str(), prefs, this); 40 refresh_delay_.Init(
41 refresh_pref.c_str(), prefs,
42 base::Bind(&CloudPolicyRefreshScheduler::ScheduleRefresh,
43 base::Unretained(this)));
41 44
42 UpdateLastRefreshFromPolicy(); 45 UpdateLastRefreshFromPolicy();
43 ScheduleRefresh(); 46 ScheduleRefresh();
44 } 47 }
45 48
46 CloudPolicyRefreshScheduler::~CloudPolicyRefreshScheduler() { 49 CloudPolicyRefreshScheduler::~CloudPolicyRefreshScheduler() {
47 store_->RemoveObserver(this); 50 store_->RemoveObserver(this);
48 client_->RemoveObserver(this); 51 client_->RemoveObserver(this);
49 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 52 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
50 } 53 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 ScheduleRefresh(); 95 ScheduleRefresh();
93 } 96 }
94 97
95 void CloudPolicyRefreshScheduler::OnStoreError(CloudPolicyStore* store) { 98 void CloudPolicyRefreshScheduler::OnStoreError(CloudPolicyStore* store) {
96 // If |store_| fails, the is_managed bit that it provides may become stale. 99 // If |store_| fails, the is_managed bit that it provides may become stale.
97 // The best guess in that situation is to assume is_managed didn't change and 100 // The best guess in that situation is to assume is_managed didn't change and
98 // continue using the stale information. Thus, no specific response to a store 101 // continue using the stale information. Thus, no specific response to a store
99 // error is required. NB: Changes to is_managed fire OnStoreLoaded(). 102 // error is required. NB: Changes to is_managed fire OnStoreLoaded().
100 } 103 }
101 104
102 void CloudPolicyRefreshScheduler::OnPreferenceChanged(
103 PrefServiceBase* service,
104 const std::string& pref_name) {
105 DCHECK_EQ(refresh_delay_.GetPrefName(), pref_name);
106
107 ScheduleRefresh();
108 }
109
110 void CloudPolicyRefreshScheduler::OnIPAddressChanged() { 105 void CloudPolicyRefreshScheduler::OnIPAddressChanged() {
111 if (client_->status() == DM_STATUS_REQUEST_FAILED) 106 if (client_->status() == DM_STATUS_REQUEST_FAILED)
112 RefreshAfter(0); 107 RefreshAfter(0);
113 } 108 }
114 109
115 void CloudPolicyRefreshScheduler::UpdateLastRefreshFromPolicy() { 110 void CloudPolicyRefreshScheduler::UpdateLastRefreshFromPolicy() {
116 if (!last_refresh_.is_null()) 111 if (!last_refresh_.is_null())
117 return; 112 return;
118 113
119 // If the client has already fetched policy, assume that happened recently. If 114 // If the client has already fetched policy, assume that happened recently. If
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 task_runner_->PostDelayedTask(FROM_HERE, refresh_callback_.callback(), delay); 202 task_runner_->PostDelayedTask(FROM_HERE, refresh_callback_.callback(), delay);
208 } 203 }
209 204
210 int64 CloudPolicyRefreshScheduler::GetRefreshDelay() { 205 int64 CloudPolicyRefreshScheduler::GetRefreshDelay() {
211 return std::min(std::max<int64>(refresh_delay_.GetValue(), 206 return std::min(std::max<int64>(refresh_delay_.GetValue(),
212 kRefreshDelayMinMs), 207 kRefreshDelayMinMs),
213 kRefreshDelayMaxMs); 208 kRefreshDelayMaxMs);
214 } 209 }
215 210
216 } // namespace policy 211 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_refresh_scheduler.h ('k') | chrome/browser/policy/cloud_policy_subsystem.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698