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

Unified Diff: chrome/browser/policy/cloud_policy_identity_strategy.h

Issue 6520008: Device policy infrastructure (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address Mattias' comments Created 9 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
Index: chrome/browser/policy/cloud_policy_identity_strategy.h
diff --git a/chrome/browser/policy/cloud_policy_identity_strategy.h b/chrome/browser/policy/cloud_policy_identity_strategy.h
new file mode 100644
index 0000000000000000000000000000000000000000..681d80acd21f9884f36bc3e1be3b0c80d20f4310
--- /dev/null
+++ b/chrome/browser/policy/cloud_policy_identity_strategy.h
@@ -0,0 +1,83 @@
+// Copyright (c) 2011 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_CLOUD_POLICY_IDENTITY_STRATEGY_H_
+#define CHROME_BROWSER_POLICY_CLOUD_POLICY_IDENTITY_STRATEGY_H_
+#pragma once
+
+#include <string>
+
+#include "base/observer_list.h"
+
+namespace policy {
+
+// Manages a device management token, i.e. an identifier that represents a
+// registration with the device management service, and the associated
+// credentials. Responsibilities include storing and loading the token from
+// disk, observing and triggering relevant notifications.
+class CloudPolicyIdentityStrategy {
+ public:
+ class Observer {
+ public:
+ virtual ~Observer() {}
+
+ // Notifies observers that the effective token for fetching policy has
+ // changed. The token can be queried by calling GetDeviceToken().
+ virtual void OnDeviceTokenChanged() = 0;
+
+ // Authentication credentials for talking to the device management service
+ // changed. New auth data is available through GetCredentials().
+ virtual void OnCredentialsChanged() = 0;
+ };
+
+ CloudPolicyIdentityStrategy() {}
+ virtual ~CloudPolicyIdentityStrategy() {}
+
+ void AddObserver(Observer* obs) {
+ observer_list_.AddObserver(obs);
+ }
+
+ void RemoveObserver(Observer* obs) {
+ observer_list_.RemoveObserver(obs);
+ }
+
+ // Returns the device management token, if available. Returns the empty string
+ // if the device token is currently unavailable.
+ virtual std::string GetDeviceToken() = 0;
+
+ // Returns the device ID for this device.
+ virtual std::string GetDeviceID() = 0;
+
+ // Retrieves authentication credentials to use when talking to the device
+ // management service. Returns true if the data is available and writes the
+ // values to the provided pointers.
+ virtual bool GetCredentials(std::string* username,
+ std::string* auth_token) = 0;
+
+ // Notifies the identity strategy that a new token has been fetched. It is up
+ // to the identity strategy to store the token, decide whether it is going
+ // to be used, send out an appropriate OnDeviceTokenChanged() notification
+ // and return the new token in GetDeviceToken() calls.
+ virtual void OnDeviceTokenAvailable(const std::string& token) = 0;
+
+ protected:
+ // Notify observers that the effective token has changed.
+ void NotifyDeviceTokenChanged() {
+ FOR_EACH_OBSERVER(Observer, observer_list_, OnDeviceTokenChanged());
+ }
+
+ // Notify observers about authentication data change.
+ void NotifyAuthChanged() {
+ FOR_EACH_OBSERVER(Observer, observer_list_, OnCredentialsChanged());
+ }
+
+ private:
+ ObserverList<Observer, true> observer_list_;
+
+ DISALLOW_COPY_AND_ASSIGN(CloudPolicyIdentityStrategy);
+};
+
+} // namespace policy
+
+#endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_IDENTITY_STRATEGY_H_

Powered by Google App Engine
This is Rietveld 408576698