| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/policy/device_management_policy_provider.h" | 5 #include "chrome/browser/policy/device_management_policy_provider.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "chrome/browser/browser_thread.h" | 12 #include "chrome/browser/browser_thread.h" |
| 13 #include "chrome/browser/profile.h" |
| 13 #include "chrome/browser/policy/device_management_backend.h" | 14 #include "chrome/browser/policy/device_management_backend.h" |
| 14 #include "chrome/browser/policy/device_management_backend_impl.h" | 15 #include "chrome/browser/policy/device_management_backend_impl.h" |
| 15 #include "chrome/browser/policy/device_management_policy_cache.h" | 16 #include "chrome/browser/policy/device_management_policy_cache.h" |
| 16 #include "chrome/browser/policy/device_token_fetcher.h" | 17 #include "chrome/browser/policy/device_token_fetcher.h" |
| 17 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/notification_service.h" | 20 #include "chrome/common/notification_service.h" |
| 20 #include "chrome/common/notification_type.h" | 21 #include "chrome/common/notification_type.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 49 provider->InitializeAfterIOThreadExists(); | 50 provider->InitializeAfterIOThreadExists(); |
| 50 } | 51 } |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 base::WeakPtr<DeviceManagementPolicyProvider> provider_; | 54 base::WeakPtr<DeviceManagementPolicyProvider> provider_; |
| 54 }; | 55 }; |
| 55 | 56 |
| 56 DeviceManagementPolicyProvider::DeviceManagementPolicyProvider( | 57 DeviceManagementPolicyProvider::DeviceManagementPolicyProvider( |
| 57 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list, | 58 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list, |
| 58 DeviceManagementBackend* backend, | 59 DeviceManagementBackend* backend, |
| 59 TokenService* token_service, | 60 Profile* profile) |
| 60 const FilePath& storage_dir) | |
| 61 : ConfigurationPolicyProvider(policy_list), | 61 : ConfigurationPolicyProvider(policy_list), |
| 62 backend_(backend), | 62 backend_(backend), |
| 63 token_service_(token_service), | 63 profile_(profile), |
| 64 storage_dir_(GetOrCreateDeviceManagementDir(storage_dir)), | 64 storage_dir_(GetOrCreateDeviceManagementDir(profile_->GetPath())), |
| 65 policy_request_pending_(false) { | 65 policy_request_pending_(false) { |
| 66 Initialize(); | 66 Initialize(); |
| 67 } | 67 } |
| 68 |
| 69 DeviceManagementPolicyProvider::DeviceManagementPolicyProvider( |
| 70 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list, |
| 71 DeviceManagementBackend* backend, |
| 72 Profile* profile, |
| 73 DeviceTokenFetcher* token_fetcher) |
| 74 : ConfigurationPolicyProvider(policy_list), |
| 75 backend_(backend), |
| 76 profile_(profile), |
| 77 token_fetcher_(token_fetcher), |
| 78 storage_dir_(GetOrCreateDeviceManagementDir(profile_->GetPath())), |
| 79 policy_request_pending_(false) { |
| 80 Initialize(); |
| 81 } |
| 68 | 82 |
| 69 DeviceManagementPolicyProvider::~DeviceManagementPolicyProvider() {} | 83 DeviceManagementPolicyProvider::~DeviceManagementPolicyProvider() {} |
| 70 | 84 |
| 71 bool DeviceManagementPolicyProvider::Provide( | 85 bool DeviceManagementPolicyProvider::Provide( |
| 72 ConfigurationPolicyStoreInterface* policy_store) { | 86 ConfigurationPolicyStoreInterface* policy_store) { |
| 73 scoped_ptr<DictionaryValue> policies(cache_->GetPolicy()); | 87 scoped_ptr<DictionaryValue> policies(cache_->GetPolicy()); |
| 74 DecodePolicyValueTree(policies.get(), policy_store); | 88 DecodePolicyValueTree(policies.get(), policy_store); |
| 75 return true; | 89 return true; |
| 76 } | 90 } |
| 77 | 91 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 99 | 113 |
| 100 void DeviceManagementPolicyProvider::OnError( | 114 void DeviceManagementPolicyProvider::OnError( |
| 101 DeviceManagementBackend::ErrorCode code) { | 115 DeviceManagementBackend::ErrorCode code) { |
| 102 LOG(WARNING) << "could not provide policy from the device manager (error = " | 116 LOG(WARNING) << "could not provide policy from the device manager (error = " |
| 103 << code << ")"; | 117 << code << ")"; |
| 104 policy_request_pending_ = false; | 118 policy_request_pending_ = false; |
| 105 // TODO(danno): do something sensible in the error case, perhaps retry later? | 119 // TODO(danno): do something sensible in the error case, perhaps retry later? |
| 106 } | 120 } |
| 107 | 121 |
| 108 void DeviceManagementPolicyProvider::Shutdown() { | 122 void DeviceManagementPolicyProvider::Shutdown() { |
| 109 token_service_ = NULL; | 123 profile_ = NULL; |
| 110 if (token_fetcher_) | 124 if (token_fetcher_) |
| 111 token_fetcher_->Shutdown(); | 125 token_fetcher_->Shutdown(); |
| 112 } | 126 } |
| 113 | 127 |
| 114 DeviceManagementBackend* DeviceManagementPolicyProvider::GetBackend() { | 128 DeviceManagementBackend* DeviceManagementPolicyProvider::GetBackend() { |
| 115 if (!backend_.get()) { | 129 if (!backend_.get()) { |
| 116 backend_.reset(new DeviceManagementBackendImpl( | 130 backend_.reset(new DeviceManagementBackendImpl( |
| 117 GetDeviceManagementURL())); | 131 GetDeviceManagementURL())); |
| 118 } | 132 } |
| 119 return backend_.get(); | 133 return backend_.get(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 131 | 145 |
| 132 // Defer initialization that requires the IOThread until after the IOThread | 146 // Defer initialization that requires the IOThread until after the IOThread |
| 133 // has been initialized. | 147 // has been initialized. |
| 134 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 148 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 135 new InitializeAfterIOThreadExistsTask(AsWeakPtr())); | 149 new InitializeAfterIOThreadExistsTask(AsWeakPtr())); |
| 136 } | 150 } |
| 137 | 151 |
| 138 void DeviceManagementPolicyProvider::InitializeAfterIOThreadExists() { | 152 void DeviceManagementPolicyProvider::InitializeAfterIOThreadExists() { |
| 139 const FilePath token_path = storage_dir_.Append( | 153 const FilePath token_path = storage_dir_.Append( |
| 140 FILE_PATH_LITERAL("Token")); | 154 FILE_PATH_LITERAL("Token")); |
| 141 if (token_service_) { | 155 if (profile_) { |
| 142 token_fetcher_ = | 156 if (!token_fetcher_) { |
| 143 new DeviceTokenFetcher(GetBackend(), token_service_, token_path); | 157 token_fetcher_ = |
| 158 new DeviceTokenFetcher(GetBackend(), profile_, token_path); |
| 159 } |
| 144 token_fetcher_->StartFetching(); | 160 token_fetcher_->StartFetching(); |
| 145 } | 161 } |
| 146 } | 162 } |
| 147 | 163 |
| 148 void DeviceManagementPolicyProvider::SendPolicyRequest() { | 164 void DeviceManagementPolicyProvider::SendPolicyRequest() { |
| 149 if (!policy_request_pending_) { | 165 if (!policy_request_pending_) { |
| 150 em::DevicePolicyRequest policy_request; | 166 em::DevicePolicyRequest policy_request; |
| 151 policy_request.set_policy_scope(kChromePolicyScope); | 167 policy_request.set_policy_scope(kChromePolicyScope); |
| 152 em::DevicePolicySettingRequest* setting = | 168 em::DevicePolicySettingRequest* setting = |
| 153 policy_request.add_setting_request(); | 169 policy_request.add_setting_request(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 181 const FilePath device_management_dir = user_data_dir.Append( | 197 const FilePath device_management_dir = user_data_dir.Append( |
| 182 FILE_PATH_LITERAL("Device Management")); | 198 FILE_PATH_LITERAL("Device Management")); |
| 183 if (!file_util::DirectoryExists(device_management_dir)) { | 199 if (!file_util::DirectoryExists(device_management_dir)) { |
| 184 if (!file_util::CreateDirectory(device_management_dir)) | 200 if (!file_util::CreateDirectory(device_management_dir)) |
| 185 NOTREACHED(); | 201 NOTREACHED(); |
| 186 } | 202 } |
| 187 return device_management_dir; | 203 return device_management_dir; |
| 188 } | 204 } |
| 189 | 205 |
| 190 } // namespace policy | 206 } // namespace policy |
| OLD | NEW |