Commit bd4bd0f2 authored by atwilson@chromium.org's avatar atwilson@chromium.org

Added UserCloudPolicyManager::ShutdownAndRemovePolicy()

BUG=143272
TEST=Sign out, see policy disappear.


Review URL: https://chromiumcodereview.appspot.com/10854213

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152383 0039d316-1c4b-4281-b951-d872f2087c98
parent e02c1e73
...@@ -15,6 +15,13 @@ CloudPolicyStore::CloudPolicyStore() ...@@ -15,6 +15,13 @@ CloudPolicyStore::CloudPolicyStore()
CloudPolicyStore::~CloudPolicyStore() {} CloudPolicyStore::~CloudPolicyStore() {}
void CloudPolicyStore::Clear() {
RemoveStoredPolicy();
policy_.reset();
policy_map_.Clear();
NotifyStoreLoaded();
}
void CloudPolicyStore::AddObserver(CloudPolicyStore::Observer* observer) { void CloudPolicyStore::AddObserver(CloudPolicyStore::Observer* observer) {
observers_.AddObserver(observer); observers_.AddObserver(observer);
} }
......
...@@ -87,6 +87,10 @@ class CloudPolicyStore { ...@@ -87,6 +87,10 @@ class CloudPolicyStore {
// failure. // failure.
virtual void Load() = 0; virtual void Load() = 0;
// Deletes any existing policy blob and notifies observers via OnStoreLoaded()
// that the blob has changed. Virtual for mocks.
virtual void Clear();
// Registers an observer to be notified when policy changes. // Registers an observer to be notified when policy changes.
void AddObserver(Observer* observer); void AddObserver(Observer* observer);
...@@ -104,6 +108,9 @@ class CloudPolicyStore { ...@@ -104,6 +108,9 @@ class CloudPolicyStore {
void NotifyStoreLoaded(); void NotifyStoreLoaded();
void NotifyStoreError(); void NotifyStoreError();
// Invoked by Clear() to remove stored policy.
virtual void RemoveStoredPolicy() = 0;
// Decoded version of the currently effective policy. // Decoded version of the currently effective policy.
PolicyMap policy_map_; PolicyMap policy_map_;
......
...@@ -17,6 +17,8 @@ class MockCloudPolicyStore : public CloudPolicyStore { ...@@ -17,6 +17,8 @@ class MockCloudPolicyStore : public CloudPolicyStore {
MOCK_METHOD1(Store, void(const enterprise_management::PolicyFetchResponse&)); MOCK_METHOD1(Store, void(const enterprise_management::PolicyFetchResponse&));
MOCK_METHOD0(Load, void(void)); MOCK_METHOD0(Load, void(void));
MOCK_METHOD0(Clear, void(void));
MOCK_METHOD0(RemoveStoredPolicy, void(void));
// Publish the protected members. // Publish the protected members.
using CloudPolicyStore::NotifyStoreLoaded; using CloudPolicyStore::NotifyStoreLoaded;
......
...@@ -95,12 +95,9 @@ void UserCloudPolicyManager::Initialize(PrefService* prefs, ...@@ -95,12 +95,9 @@ void UserCloudPolicyManager::Initialize(PrefService* prefs,
} }
} }
void UserCloudPolicyManager::Shutdown() { void UserCloudPolicyManager::ShutdownAndRemovePolicy() {
refresh_scheduler_.reset(); Shutdown();
if (service_.get()) store_->Clear();
service_->client()->RemoveObserver(this);
service_.reset();
prefs_ = NULL;
} }
void UserCloudPolicyManager::CancelWaitForPolicyFetch() { void UserCloudPolicyManager::CancelWaitForPolicyFetch() {
...@@ -196,4 +193,12 @@ void UserCloudPolicyManager::OnRefreshComplete() { ...@@ -196,4 +193,12 @@ void UserCloudPolicyManager::OnRefreshComplete() {
CheckAndPublishPolicy(); CheckAndPublishPolicy();
} }
void UserCloudPolicyManager::Shutdown() {
refresh_scheduler_.reset();
if (service_.get())
service_->client()->RemoveObserver(this);
service_.reset();
prefs_ = NULL;
}
} // namespace policy } // namespace policy
...@@ -40,13 +40,17 @@ class UserCloudPolicyManager : public ConfigurationPolicyProvider, ...@@ -40,13 +40,17 @@ class UserCloudPolicyManager : public ConfigurationPolicyProvider,
bool wait_for_policy_fetch); bool wait_for_policy_fetch);
// Initializes the cloud connection. |local_prefs| and |service| must stay // Initializes the cloud connection. |local_prefs| and |service| must stay
// valid until Shutdown() gets called. Virtual for mocking. // valid until this object is deleted or ShutdownAndRemovePolicy() gets
// called. Virtual for mocking.
virtual void Initialize(PrefService* local_prefs, virtual void Initialize(PrefService* local_prefs,
DeviceManagementService* service, DeviceManagementService* service,
UserAffiliation user_affiliation); UserAffiliation user_affiliation);
// Virtual for mocks. // Shuts down the UserCloudPolicyManager (removes and stops refreshing the
virtual void Shutdown(); // cached cloud policy). This is typically called when a profile is being
// disassociated from a given user (e.g. during signout). No policy will be
// provided by this object until the next time Initialize() is invoked.
void ShutdownAndRemovePolicy();
// Cancels waiting for the policy fetch and flags the // Cancels waiting for the policy fetch and flags the
// ConfigurationPolicyProvider ready (assuming all other initialization tasks // ConfigurationPolicyProvider ready (assuming all other initialization tasks
...@@ -87,6 +91,10 @@ class UserCloudPolicyManager : public ConfigurationPolicyProvider, ...@@ -87,6 +91,10 @@ class UserCloudPolicyManager : public ConfigurationPolicyProvider,
// Completion handler for policy refresh operations. // Completion handler for policy refresh operations.
void OnRefreshComplete(); void OnRefreshComplete();
// Frees the CloudPolicyService and stops refreshing policy. Any previously
// cached policy will continue to be served.
void Shutdown();
// Whether to wait for a policy fetch to complete before reporting // Whether to wait for a policy fetch to complete before reporting
// IsInitializationComplete(). // IsInitializationComplete().
bool wait_for_policy_fetch_; bool wait_for_policy_fetch_;
......
...@@ -209,6 +209,19 @@ TEST_F(UserCloudPolicyManagerTest, Init) { ...@@ -209,6 +209,19 @@ TEST_F(UserCloudPolicyManagerTest, Init) {
EXPECT_TRUE(manager_->IsInitializationComplete()); EXPECT_TRUE(manager_->IsInitializationComplete());
} }
TEST_F(UserCloudPolicyManagerTest, ShutdownAndRemovePolicy) {
// Load policy, make sure it goes away when ShutdownAndRemove() is called.
CreateManager(false);
store_->policy_map_.CopyFrom(policy_map_);
EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get()));
store_->NotifyStoreLoaded();
EXPECT_TRUE(expected_bundle_.Equals(manager_->policies()));
EXPECT_TRUE(manager_->IsInitializationComplete());
EXPECT_CALL(*store_, Clear());
manager_->ShutdownAndRemovePolicy();
EXPECT_FALSE(manager_->cloud_policy_service());
}
TEST_F(UserCloudPolicyManagerTest, Update) { TEST_F(UserCloudPolicyManagerTest, Update) {
CreateManager(false); CreateManager(false);
EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get()));
......
...@@ -28,6 +28,10 @@ void UserCloudPolicyStore::Load() { ...@@ -28,6 +28,10 @@ void UserCloudPolicyStore::Load() {
NotifyStoreLoaded(); NotifyStoreLoaded();
} }
void UserCloudPolicyStore::RemoveStoredPolicy() {
// TODO(atwilson): Remove policy from disk.
}
void UserCloudPolicyStore::Store( void UserCloudPolicyStore::Store(
const enterprise_management::PolicyFetchResponse& policy) { const enterprise_management::PolicyFetchResponse& policy) {
// Stop any pending requests to store policy, then validate the new policy // Stop any pending requests to store policy, then validate the new policy
......
...@@ -29,6 +29,9 @@ class UserCloudPolicyStore : public UserCloudPolicyStoreBase { ...@@ -29,6 +29,9 @@ class UserCloudPolicyStore : public UserCloudPolicyStoreBase {
virtual void Store( virtual void Store(
const enterprise_management::PolicyFetchResponse& policy) OVERRIDE; const enterprise_management::PolicyFetchResponse& policy) OVERRIDE;
protected:
virtual void RemoveStoredPolicy() OVERRIDE;
private: private:
// Starts policy blob validation. |callback| is invoked once validation is // Starts policy blob validation. |callback| is invoked once validation is
// complete. // complete.
......
...@@ -182,6 +182,13 @@ void UserCloudPolicyStoreChromeOS::Load() { ...@@ -182,6 +182,13 @@ void UserCloudPolicyStoreChromeOS::Load() {
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
void UserCloudPolicyStoreChromeOS::RemoveStoredPolicy() {
// This should never be called on ChromeOS since it is not possible to sign
// out of a Profile. The underlying policy store is only removed if the
// Profile itself is deleted.
NOTREACHED();
}
void UserCloudPolicyStoreChromeOS::OnPolicyRetrieved( void UserCloudPolicyStoreChromeOS::OnPolicyRetrieved(
const std::string& policy_blob) { const std::string& policy_blob) {
if (policy_blob.empty()) { if (policy_blob.empty()) {
......
...@@ -47,6 +47,9 @@ class UserCloudPolicyStoreChromeOS : public UserCloudPolicyStoreBase { ...@@ -47,6 +47,9 @@ class UserCloudPolicyStoreChromeOS : public UserCloudPolicyStoreBase {
const enterprise_management::PolicyFetchResponse& policy) OVERRIDE; const enterprise_management::PolicyFetchResponse& policy) OVERRIDE;
virtual void Load() OVERRIDE; virtual void Load() OVERRIDE;
protected:
virtual void RemoveStoredPolicy() OVERRIDE;
private: private:
// Called back from SessionManagerClient for policy load operations. // Called back from SessionManagerClient for policy load operations.
void OnPolicyRetrieved(const std::string& policy_blob); void OnPolicyRetrieved(const std::string& policy_blob);
......
...@@ -107,7 +107,7 @@ void UserPolicySigninService::ConfigureUserCloudPolicyManager() { ...@@ -107,7 +107,7 @@ void UserPolicySigninService::ConfigureUserCloudPolicyManager() {
SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile_); SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile_);
if (signin_manager->GetAuthenticatedUsername().empty()) { if (signin_manager->GetAuthenticatedUsername().empty()) {
manager_->Shutdown(); manager_->ShutdownAndRemovePolicy();
} else { } else {
if (!manager_->cloud_policy_service()) { if (!manager_->cloud_policy_service()) {
// Make sure we've initialized the DeviceManagementService. It's OK to // Make sure we've initialized the DeviceManagementService. It's OK to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment