Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_ | |
| 6 #define CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/ref_counted.h" | |
| 10 #include "base/values.h" | |
| 11 #include "chrome/browser/policy/asynchronous_policy_provider.h" | |
| 12 | |
| 13 namespace policy { | |
| 14 | |
| 15 class ConfigurationPolicyProvider; | |
| 16 | |
| 17 // Used by the implementation of asynchronous policy provider to managed the | |
|
Mattias Nissler (ping if slow)
2010/12/06 10:26:20
to manage
danno
2010/12/06 14:05:12
Done.
| |
| 18 // tasks on the file thread that do the heavy lifting of loading policies on the | |
|
Mattias Nissler (ping if slow)
2010/12/06 10:26:20
"on the file thread" twice?
danno
2010/12/06 14:05:12
Done.
| |
| 19 // file thread. | |
| 20 class AsynchronousPolicyLoader | |
| 21 : public base::RefCountedThreadSafe<AsynchronousPolicyLoader> { | |
| 22 public: | |
| 23 explicit AsynchronousPolicyLoader( | |
| 24 AsynchronousPolicyProvider::Delegate* delegate); | |
| 25 | |
| 26 // Triggers initial policy load and schedules fallback reload. | |
|
Mattias Nissler (ping if slow)
2010/12/06 10:26:20
In the base implementation, it doesn't schedule fa
danno
2010/12/06 14:05:12
Done.
| |
| 27 virtual void Init(); | |
| 28 | |
| 29 // Reloads policy, sending notification of changes if necessary. Must be | |
| 30 // called on the file thread. | |
| 31 virtual void Reload(); | |
| 32 | |
| 33 // Stops any pending reload tasks. | |
| 34 virtual void Stop(); | |
| 35 | |
| 36 // Associates a provider with the loader to allow the loader to notify the | |
| 37 // provider when policy changes. | |
| 38 void SetProvider(base::WeakPtr<AsynchronousPolicyProvider> provider); | |
|
Mattias Nissler (ping if slow)
2010/12/06 10:26:20
If there is SetProvider(), you don't need to pass
danno
2010/12/06 14:05:12
Done. TODO already in .cc file.
| |
| 39 | |
| 40 const DictionaryValue* policy() const { return policy_.get(); } | |
| 41 | |
| 42 protected: | |
| 43 friend class UpdatePolicyTask; | |
| 44 | |
| 45 // AsynchronousPolicyLoader objects should only be deleted by | |
| 46 // RefCountedThreadSafe. | |
| 47 friend class base::RefCountedThreadSafe<AsynchronousPolicyLoader>; | |
| 48 virtual ~AsynchronousPolicyLoader() {} | |
| 49 | |
| 50 // Schedules a call to UpdatePolicy on the ui thread. Must be called on the | |
| 51 // FILE thread. | |
| 52 void PostUpdatePolicyTask(DictionaryValue* new_policy); | |
| 53 | |
| 54 // Replaces the existing policy to value map with a new once, sending | |
|
Mattias Nissler (ping if slow)
2010/12/06 10:26:20
s/once/one/
danno
2010/12/06 14:05:12
Done.
| |
| 55 // notification to the provider if there is a policy change. Must be called on | |
| 56 // the ui thread. | |
|
Mattias Nissler (ping if slow)
2010/12/06 10:26:20
s/ui/UI/ (you say FILE thread above)
danno
2010/12/06 14:05:12
Done.
| |
| 57 void UpdatePolicy(DictionaryValue* new_policy); | |
| 58 | |
| 59 AsynchronousPolicyProvider::Delegate* delegate() { | |
| 60 return delegate_.get(); | |
| 61 } | |
| 62 | |
| 63 private: | |
| 64 friend class AsynchronousPolicyLoaderTest; | |
| 65 | |
| 66 // Provides the low-level mechanics for loading policy. | |
| 67 scoped_ptr<AsynchronousPolicyProvider::Delegate> delegate_; | |
| 68 | |
| 69 // Current policy. | |
| 70 scoped_ptr<DictionaryValue> policy_; | |
| 71 | |
| 72 // The provider this loader is associated with. Access only on the thread that | |
| 73 // called the constructor. See |origin_loop_| below. | |
| 74 base::WeakPtr<AsynchronousPolicyProvider> provider_; | |
| 75 | |
| 76 // The message loop on which this object was constructed and |provider_| | |
| 77 // received on. Recorded so we can call back into the non thread safe provider | |
| 78 // to fire the notification. | |
| 79 MessageLoop* origin_loop_; | |
|
Mattias Nissler (ping if slow)
2010/12/06 10:26:20
Do we still need this? If yes, the comment above c
danno
2010/12/06 14:05:12
Done.
| |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyLoader); | |
| 82 }; | |
| 83 | |
| 84 } // namespace policy | |
| 85 | |
| 86 #endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_ | |
| OLD | NEW |