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

Unified Diff: remoting/host/policy_watcher.h

Issue 2710023003: Refactor PolicyWatcher to allow mocking (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | remoting/host/policy_watcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/policy_watcher.h
diff --git a/remoting/host/policy_watcher.h b/remoting/host/policy_watcher.h
index e3f54f6916bfd80c6a5dbdfc74722198e76472a8..facf7f31711e8f58ef0c52d5d6b10b55fa679c89 100644
--- a/remoting/host/policy_watcher.h
+++ b/remoting/host/policy_watcher.h
@@ -20,16 +20,13 @@ class SingleThreadTaskRunner;
namespace policy {
class AsyncPolicyLoader;
-class ConfigurationPolicyProvider;
class Schema;
-class SchemaRegistry;
} // namespace policy
namespace remoting {
// Watches for changes to the managed remote access host policies.
-class PolicyWatcher : public policy::PolicyService::Observer,
- public base::NonThreadSafe {
+class PolicyWatcher : public base::NonThreadSafe {
public:
// Called first with all policies, and subsequently with any changed policies.
typedef base::Callback<void(std::unique_ptr<base::DictionaryValue>)>
@@ -38,7 +35,7 @@ class PolicyWatcher : public policy::PolicyService::Observer,
// Called after detecting malformed policies.
typedef base::Callback<void()> PolicyErrorCallback;
- ~PolicyWatcher() override;
+ virtual ~PolicyWatcher() = 0;
Sergey Ulanov 2017/02/23 19:18:55 s/=0/{}/ I didn't know destructor can be pure virt
rkjnsn 2017/02/23 22:28:10 Pure virtual destructors are interesting beasts. U
// This guarantees that the |policy_updated_callback| is called at least once
// with the current policies. After that, |policy_updated_callback| will be
@@ -57,7 +54,7 @@ class PolicyWatcher : public policy::PolicyService::Observer,
// found.
virtual void StartWatching(
const PolicyUpdatedCallback& policy_updated_callback,
- const PolicyErrorCallback& policy_error_callback);
+ const PolicyErrorCallback& policy_error_callback) = 0;
// Specify a |policy_service| to borrow (on Chrome OS, from the browser
// process) or specify nullptr to internally construct and use a new
@@ -78,35 +75,12 @@ class PolicyWatcher : public policy::PolicyService::Observer,
policy::PolicyService* policy_service,
const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner);
+ protected:
+ PolicyWatcher();
Sergey Ulanov 2017/02/23 19:18:55 Usually for interfaces the constructor should have
rkjnsn 2017/02/23 22:28:10 Okay, I'll move it inline.
+
private:
friend class PolicyWatcherTest;
- // Gets Chromoting schema stored inside |owned_schema_registry_|.
- const policy::Schema* GetPolicySchema() const;
-
- // Simplifying wrapper around Schema::Normalize.
- // - Returns false if |dict| is invalid (i.e. contains mistyped policy
- // values).
- // - Returns true if |dict| was valid or got normalized.
- bool NormalizePolicies(base::DictionaryValue* dict);
-
- // Stores |new_policies| into |old_policies_|. Returns dictionary with items
- // from |new_policies| that are different from the old |old_policies_|.
- std::unique_ptr<base::DictionaryValue> StoreNewAndReturnChangedPolicies(
- std::unique_ptr<base::DictionaryValue> new_policies);
-
- // Signals policy error to the registered |PolicyErrorCallback|.
- void SignalPolicyError();
-
- // |policy_service_task_runner| is the task runner where it is safe
- // to call |policy_service_| methods and where we expect to get callbacks
- // from |policy_service_|.
- PolicyWatcher(policy::PolicyService* policy_service,
- std::unique_ptr<policy::PolicyService> owned_policy_service,
- std::unique_ptr<policy::ConfigurationPolicyProvider>
- owned_policy_provider,
- std::unique_ptr<policy::SchemaRegistry> owned_schema_registry);
-
// Creates PolicyWatcher that wraps the owned |async_policy_loader| with an
// appropriate PolicySchema.
//
@@ -115,27 +89,11 @@ class PolicyWatcher : public policy::PolicyService::Observer,
static std::unique_ptr<PolicyWatcher> CreateFromPolicyLoader(
std::unique_ptr<policy::AsyncPolicyLoader> async_policy_loader);
- // PolicyService::Observer interface.
- void OnPolicyUpdated(const policy::PolicyNamespace& ns,
- const policy::PolicyMap& previous,
- const policy::PolicyMap& current) override;
- void OnPolicyServiceInitialized(policy::PolicyDomain domain) override;
-
- PolicyUpdatedCallback policy_updated_callback_;
- PolicyErrorCallback policy_error_callback_;
-
- std::unique_ptr<base::DictionaryValue> old_policies_;
- std::unique_ptr<base::DictionaryValue> default_values_;
-
- policy::PolicyService* policy_service_;
+ // Gets Chromoting schema stored inside |owned_schema_registry_|.
+ virtual const policy::Schema* GetPolicySchema() const = 0;
- // Order of fields below is important to ensure destruction takes object
- // dependencies into account:
- // - |owned_policy_service_| uses |owned_policy_provider_|
- // - |owned_policy_provider_| uses |owned_schema_registry_|
- std::unique_ptr<policy::SchemaRegistry> owned_schema_registry_;
- std::unique_ptr<policy::ConfigurationPolicyProvider> owned_policy_provider_;
- std::unique_ptr<policy::PolicyService> owned_policy_service_;
+ // Gets default policy values.
+ virtual const base::DictionaryValue* GetDefaultValues() const = 0;
Sergey Ulanov 2017/02/23 19:18:55 I don't think these private methods need to be her
DISALLOW_COPY_AND_ASSIGN(PolicyWatcher);
};
« no previous file with comments | « no previous file | remoting/host/policy_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698