Index: chrome/browser/chromeos/policy/active_directory_policy_manager.cc |
diff --git a/chrome/browser/chromeos/policy/active_directory_policy_manager.cc b/chrome/browser/chromeos/policy/active_directory_policy_manager.cc |
index 5b3ca717429139fb5a260f5da5227545c5f91f3d..23c19e9e48f65335601f36479d7f2de07a63589c 100644 |
--- a/chrome/browser/chromeos/policy/active_directory_policy_manager.cc |
+++ b/chrome/browser/chromeos/policy/active_directory_policy_manager.cc |
@@ -9,7 +9,6 @@ |
#include "base/logging.h" |
#include "base/memory/ptr_util.h" |
-#include "base/threading/thread_task_runner_handle.h" |
#include "chromeos/dbus/auth_policy_client.h" |
#include "chromeos/dbus/dbus_thread_manager.h" |
#include "components/policy/core/common/policy_bundle.h" |
@@ -22,9 +21,6 @@ namespace { |
// https://technet.microsoft.com/en-us/library/cc940895.aspx |
constexpr base::TimeDelta kRefreshInterval = base::TimeDelta::FromMinutes(90); |
-// Retry delay in case of |refresh_in_progress_|. |
-constexpr base::TimeDelta kBusyRetryInterval = base::TimeDelta::FromSeconds(1); |
- |
} // namespace |
namespace policy { |
@@ -59,7 +55,12 @@ void ActiveDirectoryPolicyManager::Init(SchemaRegistry* registry) { |
// Does nothing if |store_| hasn't yet initialized. |
PublishPolicy(); |
- ScheduleAutomaticRefresh(); |
+ scheduler_ = base::MakeUnique<PolicyScheduler>( |
+ base::BindRepeating(&ActiveDirectoryPolicyManager::DoRefresh, |
+ weak_ptr_factory_.GetWeakPtr()), |
+ base::BindRepeating(&ActiveDirectoryPolicyManager::OnPolicyRefreshed, |
+ weak_ptr_factory_.GetWeakPtr()), |
+ kRefreshInterval); |
} |
void ActiveDirectoryPolicyManager::Shutdown() { |
@@ -76,7 +77,7 @@ bool ActiveDirectoryPolicyManager::IsInitializationComplete( |
} |
void ActiveDirectoryPolicyManager::RefreshPolicies() { |
- ScheduleRefresh(base::TimeDelta()); |
+ scheduler_->ScheduleTaskNow(); |
} |
void ActiveDirectoryPolicyManager::OnStoreLoaded( |
@@ -97,9 +98,7 @@ void ActiveDirectoryPolicyManager::OnStoreError( |
ActiveDirectoryPolicyManager::ActiveDirectoryPolicyManager( |
const AccountId& account_id, |
std::unique_ptr<CloudPolicyStore> store) |
- : account_id_(account_id), |
- store_(std::move(store)), |
- weak_ptr_factory_(this) {} |
+ : account_id_(account_id), store_(std::move(store)) {} |
void ActiveDirectoryPolicyManager::PublishPolicy() { |
if (!store_->is_initialized()) { |
@@ -118,61 +117,8 @@ void ActiveDirectoryPolicyManager::PublishPolicy() { |
UpdatePolicy(std::move(bundle)); |
} |
-void ActiveDirectoryPolicyManager::OnPolicyRefreshed(bool success) { |
- if (!success) { |
- LOG(ERROR) << "Active Directory policy refresh failed."; |
- } |
- // Load independently of success or failure to keep up to date with whatever |
- // has happened on the authpolicyd / session manager side. |
- store_->Load(); |
- |
- refresh_in_progress_ = false; |
- last_refresh_ = base::TimeTicks::Now(); |
- ScheduleAutomaticRefresh(); |
-} |
- |
-void ActiveDirectoryPolicyManager::ScheduleRefresh(base::TimeDelta delay) { |
- if (refresh_task_) { |
- refresh_task_->Cancel(); |
- } |
- refresh_task_ = base::MakeUnique<base::CancelableClosure>( |
- base::Bind(&ActiveDirectoryPolicyManager::RunScheduledRefresh, |
- weak_ptr_factory_.GetWeakPtr())); |
- base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
- FROM_HERE, refresh_task_->callback(), delay); |
-} |
- |
-void ActiveDirectoryPolicyManager::ScheduleAutomaticRefresh() { |
- base::TimeTicks baseline; |
- base::TimeDelta interval; |
- if (retry_refresh_) { |
- baseline = last_refresh_; |
- interval = kBusyRetryInterval; |
- } else if (last_refresh_ == base::TimeTicks()) { |
- baseline = startup_; |
- interval = base::TimeDelta(); |
- } else { |
- baseline = last_refresh_; |
- interval = kRefreshInterval; |
- } |
- base::TimeDelta delay; |
- const base::TimeTicks now(base::TimeTicks::Now()); |
- if (now < baseline + interval) { |
- delay = baseline + interval - now; |
- } |
- ScheduleRefresh(delay); |
-} |
- |
-void ActiveDirectoryPolicyManager::RunScheduledRefresh() { |
- // Abort if a refresh is currently in progress (to avoid D-Bus jobs piling up |
- // behind each other). |
- if (refresh_in_progress_) { |
- retry_refresh_ = true; |
- return; |
- } |
- |
- retry_refresh_ = false; |
- refresh_in_progress_ = true; |
+void ActiveDirectoryPolicyManager::DoRefresh( |
+ base::OnceCallback<void(bool success)> callback) { |
chromeos::DBusThreadManager* thread_manager = |
chromeos::DBusThreadManager::Get(); |
DCHECK(thread_manager); |
@@ -180,15 +126,19 @@ void ActiveDirectoryPolicyManager::RunScheduledRefresh() { |
thread_manager->GetAuthPolicyClient(); |
DCHECK(auth_policy_client); |
if (account_id_ == EmptyAccountId()) { |
- auth_policy_client->RefreshDevicePolicy( |
- base::Bind(&ActiveDirectoryPolicyManager::OnPolicyRefreshed, |
- weak_ptr_factory_.GetWeakPtr())); |
+ auth_policy_client->RefreshDevicePolicy(std::move(callback)); |
} else { |
- auth_policy_client->RefreshUserPolicy( |
- account_id_, |
- base::Bind(&ActiveDirectoryPolicyManager::OnPolicyRefreshed, |
- weak_ptr_factory_.GetWeakPtr())); |
+ auth_policy_client->RefreshUserPolicy(account_id_, std::move(callback)); |
} |
} |
+void ActiveDirectoryPolicyManager::OnPolicyRefreshed(bool success) { |
+ if (!success) { |
+ LOG(ERROR) << "Active Directory policy refresh failed."; |
+ } |
+ // Load independently of success or failure to keep up to date with whatever |
+ // has happened on the authpolicyd / session manager side. |
+ store_->Load(); |
+} |
+ |
} // namespace policy |