 Chromium Code Reviews
 Chromium Code Reviews Issue 5562002:
  Refactor FileBasedPolicyProvider, introduce AsynchronousPolicyProvider.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 5562002:
  Refactor FileBasedPolicyProvider, introduce AsynchronousPolicyProvider.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| Index: chrome/browser/policy/asynchronous_policy_provider.h | 
| diff --git a/chrome/browser/policy/asynchronous_policy_provider.h b/chrome/browser/policy/asynchronous_policy_provider.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..1a1fd2bd9cc98ec1419f67cae532690becf0513d | 
| --- /dev/null | 
| +++ b/chrome/browser/policy/asynchronous_policy_provider.h | 
| @@ -0,0 +1,99 @@ | 
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#ifndef CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_PROVIDER_H_ | 
| +#define CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_PROVIDER_H_ | 
| +#pragma once | 
| + | 
| +#include "base/ref_counted.h" | 
| +#include "base/time.h" | 
| +#include "base/weak_ptr.h" | 
| +#include "chrome/browser/policy/configuration_policy_provider.h" | 
| + | 
| +class CancelableTask; | 
| +class MessageLoop; | 
| + | 
| +namespace policy { | 
| + | 
| +class AsynchronousPolicyLoader; | 
| + | 
| +// Policy provider that loads policy asynchronously. Providers subclass should | 
| +// subclass from this class if loading the policy requires disk access or must | 
| 
Mattias Nissler (ping if slow)
2010/12/02 18:16:00
subclass should subclass?
 
danno
2010/12/03 17:05:38
Done.
 | 
| +// for some other reason be performed on the file thread. The actual logic for | 
| +// loading policy is handled by a delegate passed at construction time. | 
| +class AsynchronousPolicyProvider | 
| + : public ConfigurationPolicyProvider, | 
| + public base::SupportsWeakPtr<AsynchronousPolicyProvider> { | 
| + public: | 
| + class PolicyChangeObserver; | 
| + | 
| + // Must be implemented by subclasses of the asynchronous policy provider to | 
| + // provide the implementation details of when and how policy is loaded. | 
| + class Delegate { | 
| + public: | 
| + Delegate() {} | 
| + virtual ~Delegate() {} | 
| + | 
| + // Called on the ui thread to provide the back channel with which delegates | 
| + // notify the provider that policy has changed and should be reloaded. | 
| + // The delegate assumes ownership of |observer|. | 
| + virtual void Init(PolicyChangeObserver* observer) = 0; | 
| + | 
| + // Called on the ui thread by the provider to indicate that the delegate | 
| + // should stop providing policy. The delegate must delete the observer that | 
| + // it was passed during Init at the very latest during this call. | 
| + virtual void Stop() = 0; | 
| + | 
| + // Load policies, returning a dictionary of the policy to value | 
| + // mappings. Will always be called on the file thread. | 
| + virtual DictionaryValue* Load() = 0; | 
| + | 
| + // Checks whether policy information is safe to read. If not, returns | 
| + // false and the delay until it is considered safe to reload in |delay|. | 
| + // Will always be called on the file thread. | 
| + virtual bool IsSafeToReloadPolicy(const base::Time& now, | 
| + base::TimeDelta* delay) = 0; | 
| + | 
| + private: | 
| + DISALLOW_COPY_AND_ASSIGN(Delegate); | 
| + }; | 
| + | 
| + // Assumes ownership of |delegate|. | 
| + AsynchronousPolicyProvider( | 
| + const PolicyDefinitionList* policy_list, | 
| 
Mattias Nissler (ping if slow)
2010/12/02 18:16:00
fits previous line?
 
danno
2010/12/03 17:05:38
Done.
 | 
| + Delegate* delegate); | 
| + virtual ~AsynchronousPolicyProvider(); | 
| + | 
| + // ConfigurationPolicyProvider implementation. | 
| + virtual bool Provide(ConfigurationPolicyStoreInterface* store); | 
| + | 
| + private: | 
| + // The loader object used internally. | 
| + scoped_refptr<AsynchronousPolicyLoader> loader_; | 
| + | 
| + // The policy provider delegate. | 
| + Delegate* delegate_; // weak, owned by loader | 
| + | 
| + DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyProvider); | 
| +}; | 
| + | 
| +// Observer interface implemented by the asynchronous policy provider and passed | 
| +// to policy provider delegates as a back channel to indicate when policy should | 
| +// be reloaded. | 
| +class AsynchronousPolicyProvider::PolicyChangeObserver { | 
| + public: | 
| + virtual ~PolicyChangeObserver() {} | 
| + | 
| + virtual void OnPolicyChange() = 0; | 
| + | 
| + protected: | 
| + PolicyChangeObserver() {} | 
| + | 
| + private: | 
| + DISALLOW_COPY_AND_ASSIGN(PolicyChangeObserver); | 
| +}; | 
| + | 
| +} // namespace policy | 
| + | 
| +#endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_PROVIDER_H_ |