| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/policy/cloud_external_data_manager_base.h" | 5 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 |
| 9 #include <map> | 10 #include <map> |
| 10 #include <string> | 11 #include <string> |
| 11 #include <utility> | 12 #include <utility> |
| 12 #include <vector> | 13 #include <vector> |
| 13 | 14 |
| 14 #include "base/bind.h" | 15 #include "base/bind.h" |
| 15 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
| 16 #include "base/callback.h" | 17 #include "base/callback.h" |
| 17 #include "base/location.h" | 18 #include "base/location.h" |
| 18 #include "base/logging.h" | 19 #include "base/logging.h" |
| 19 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "base/memory/ptr_util.h" |
| 20 #include "base/sequenced_task_runner.h" | 22 #include "base/sequenced_task_runner.h" |
| 21 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 22 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/thread_task_runner_handle.h" | 25 #include "base/thread_task_runner_handle.h" |
| 24 #include "base/values.h" | 26 #include "base/values.h" |
| 25 #include "chrome/browser/chromeos/policy/cloud_external_data_store.h" | 27 #include "chrome/browser/chromeos/policy/cloud_external_data_store.h" |
| 26 #include "components/policy/core/common/cloud/cloud_policy_store.h" | 28 #include "components/policy/core/common/cloud/cloud_policy_store.h" |
| 27 #include "components/policy/core/common/cloud/external_policy_data_fetcher.h" | 29 #include "components/policy/core/common/cloud/external_policy_data_fetcher.h" |
| 28 #include "components/policy/core/common/cloud/external_policy_data_updater.h" | 30 #include "components/policy/core/common/cloud/external_policy_data_updater.h" |
| 29 #include "components/policy/core/common/external_data_fetcher.h" | 31 #include "components/policy/core/common/external_data_fetcher.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 50 // |get_policy_details| is used to determine the maximum size that the | 52 // |get_policy_details| is used to determine the maximum size that the |
| 51 // data referenced by each policy can have. This class can be instantiated on | 53 // data referenced by each policy can have. This class can be instantiated on |
| 52 // any thread but from then on, may be accessed via the |task_runner_| only. | 54 // any thread but from then on, may be accessed via the |task_runner_| only. |
| 53 // All FetchCallbacks will be invoked via |callback_task_runner|. | 55 // All FetchCallbacks will be invoked via |callback_task_runner|. |
| 54 Backend(const GetChromePolicyDetailsCallback& get_policy_details, | 56 Backend(const GetChromePolicyDetailsCallback& get_policy_details, |
| 55 scoped_refptr<base::SequencedTaskRunner> task_runner, | 57 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 56 scoped_refptr<base::SequencedTaskRunner> callback_task_runner); | 58 scoped_refptr<base::SequencedTaskRunner> callback_task_runner); |
| 57 | 59 |
| 58 // Allows downloaded external data to be cached in |external_data_store|. | 60 // Allows downloaded external data to be cached in |external_data_store|. |
| 59 // Ownership of the store is taken. The store can be destroyed by calling | 61 // Ownership of the store is taken. The store can be destroyed by calling |
| 60 // SetExternalDataStore(scoped_ptr<CloudExternalDataStore>()). | 62 // SetExternalDataStore(std::unique_ptr<CloudExternalDataStore>()). |
| 61 void SetExternalDataStore( | 63 void SetExternalDataStore( |
| 62 scoped_ptr<CloudExternalDataStore> external_data_store); | 64 std::unique_ptr<CloudExternalDataStore> external_data_store); |
| 63 | 65 |
| 64 // Allows downloading of external data via the |external_policy_data_fetcher|. | 66 // Allows downloading of external data via the |external_policy_data_fetcher|. |
| 65 void Connect( | 67 void Connect( |
| 66 scoped_ptr<ExternalPolicyDataFetcher> external_policy_data_fetcher); | 68 std::unique_ptr<ExternalPolicyDataFetcher> external_policy_data_fetcher); |
| 67 | 69 |
| 68 // Prevents further external data downloads and aborts any downloads currently | 70 // Prevents further external data downloads and aborts any downloads currently |
| 69 // in progress | 71 // in progress |
| 70 void Disconnect(); | 72 void Disconnect(); |
| 71 | 73 |
| 72 // Called when the external data references that this backend is responsible | 74 // Called when the external data references that this backend is responsible |
| 73 // for change. |metadata| maps from policy names to the metadata specifying | 75 // for change. |metadata| maps from policy names to the metadata specifying |
| 74 // the external data that each of the policies references. | 76 // the external data that each of the policies references. |
| 75 void OnMetadataUpdated(scoped_ptr<Metadata> metadata); | 77 void OnMetadataUpdated(std::unique_ptr<Metadata> metadata); |
| 76 | 78 |
| 77 // Called by the |updater_| when the external |data| referenced by |policy| | 79 // Called by the |updater_| when the external |data| referenced by |policy| |
| 78 // has been successfully downloaded and verified to match |hash|. | 80 // has been successfully downloaded and verified to match |hash|. |
| 79 bool OnDownloadSuccess(const std::string& policy, | 81 bool OnDownloadSuccess(const std::string& policy, |
| 80 const std::string& hash, | 82 const std::string& hash, |
| 81 const std::string& data); | 83 const std::string& data); |
| 82 | 84 |
| 83 // Retrieves the external data referenced by |policy| and invokes |callback| | 85 // Retrieves the external data referenced by |policy| and invokes |callback| |
| 84 // with the result. If |policy| does not reference any external data, the | 86 // with the result. If |policy| does not reference any external data, the |
| 85 // |callback| is invoked with a NULL pointer. Otherwise, the |callback| is | 87 // |callback| is invoked with a NULL pointer. Otherwise, the |callback| is |
| (...skipping 19 matching lines...) Expand all Loading... |
| 105 | 107 |
| 106 // Map from policy names to the lists of callbacks defined above. | 108 // Map from policy names to the lists of callbacks defined above. |
| 107 typedef std::map<std::string, FetchCallbackList> FetchCallbackMap; | 109 typedef std::map<std::string, FetchCallbackList> FetchCallbackMap; |
| 108 | 110 |
| 109 // Looks up the maximum size that the data referenced by |policy| can have. | 111 // Looks up the maximum size that the data referenced by |policy| can have. |
| 110 size_t GetMaxExternalDataSize(const std::string& policy) const; | 112 size_t GetMaxExternalDataSize(const std::string& policy) const; |
| 111 | 113 |
| 112 // Invokes |callback| via the |callback_task_runner_|, passing |data| as a | 114 // Invokes |callback| via the |callback_task_runner_|, passing |data| as a |
| 113 // parameter. | 115 // parameter. |
| 114 void RunCallback(const ExternalDataFetcher::FetchCallback& callback, | 116 void RunCallback(const ExternalDataFetcher::FetchCallback& callback, |
| 115 scoped_ptr<std::string> data) const; | 117 std::unique_ptr<std::string> data) const; |
| 116 | 118 |
| 117 // Tells the |updater_| to download the external data referenced by |policy|. | 119 // Tells the |updater_| to download the external data referenced by |policy|. |
| 118 // If Connect() was not called yet and no |updater_| exists, does nothing. | 120 // If Connect() was not called yet and no |updater_| exists, does nothing. |
| 119 void StartDownload(const std::string& policy); | 121 void StartDownload(const std::string& policy); |
| 120 | 122 |
| 121 // Used to determine the maximum size that the data referenced by each policy | 123 // Used to determine the maximum size that the data referenced by each policy |
| 122 // can have. | 124 // can have. |
| 123 GetChromePolicyDetailsCallback get_policy_details_; | 125 GetChromePolicyDetailsCallback get_policy_details_; |
| 124 | 126 |
| 125 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 127 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 126 scoped_refptr<base::SequencedTaskRunner> callback_task_runner_; | 128 scoped_refptr<base::SequencedTaskRunner> callback_task_runner_; |
| 127 | 129 |
| 128 // Contains the policies for which a download of the referenced external data | 130 // Contains the policies for which a download of the referenced external data |
| 129 // has been requested. Each policy is mapped to a list of callbacks to invoke | 131 // has been requested. Each policy is mapped to a list of callbacks to invoke |
| 130 // when the download completes successfully or fails permanently. If no | 132 // when the download completes successfully or fails permanently. If no |
| 131 // callback needs to be invoked (because the download was requested via | 133 // callback needs to be invoked (because the download was requested via |
| 132 // FetchAll()), a map entry will still exist but the list of callbacks it maps | 134 // FetchAll()), a map entry will still exist but the list of callbacks it maps |
| 133 // to will be empty. | 135 // to will be empty. |
| 134 FetchCallbackMap pending_downloads_; | 136 FetchCallbackMap pending_downloads_; |
| 135 | 137 |
| 136 // Indicates that OnMetadataUpdated() has been called at least once and the | 138 // Indicates that OnMetadataUpdated() has been called at least once and the |
| 137 // contents of |metadata_| is initialized. | 139 // contents of |metadata_| is initialized. |
| 138 bool metadata_set_; | 140 bool metadata_set_; |
| 139 | 141 |
| 140 // Maps from policy names to the metadata specifying the external data that | 142 // Maps from policy names to the metadata specifying the external data that |
| 141 // each of the policies references. | 143 // each of the policies references. |
| 142 Metadata metadata_; | 144 Metadata metadata_; |
| 143 | 145 |
| 144 // Used to cache external data referenced by policies. | 146 // Used to cache external data referenced by policies. |
| 145 scoped_ptr<CloudExternalDataStore> external_data_store_; | 147 std::unique_ptr<CloudExternalDataStore> external_data_store_; |
| 146 | 148 |
| 147 // Used to download external data referenced by policies. | 149 // Used to download external data referenced by policies. |
| 148 scoped_ptr<ExternalPolicyDataUpdater> updater_; | 150 std::unique_ptr<ExternalPolicyDataUpdater> updater_; |
| 149 | 151 |
| 150 DISALLOW_COPY_AND_ASSIGN(Backend); | 152 DISALLOW_COPY_AND_ASSIGN(Backend); |
| 151 }; | 153 }; |
| 152 | 154 |
| 153 CloudExternalDataManagerBase::Backend::Backend( | 155 CloudExternalDataManagerBase::Backend::Backend( |
| 154 const GetChromePolicyDetailsCallback& get_policy_details, | 156 const GetChromePolicyDetailsCallback& get_policy_details, |
| 155 scoped_refptr<base::SequencedTaskRunner> task_runner, | 157 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 156 scoped_refptr<base::SequencedTaskRunner> callback_task_runner) | 158 scoped_refptr<base::SequencedTaskRunner> callback_task_runner) |
| 157 : get_policy_details_(get_policy_details), | 159 : get_policy_details_(get_policy_details), |
| 158 task_runner_(task_runner), | 160 task_runner_(task_runner), |
| 159 callback_task_runner_(callback_task_runner), | 161 callback_task_runner_(callback_task_runner), |
| 160 metadata_set_(false) { | 162 metadata_set_(false) { |
| 161 } | 163 } |
| 162 | 164 |
| 163 void CloudExternalDataManagerBase::Backend::SetExternalDataStore( | 165 void CloudExternalDataManagerBase::Backend::SetExternalDataStore( |
| 164 scoped_ptr<CloudExternalDataStore> external_data_store) { | 166 std::unique_ptr<CloudExternalDataStore> external_data_store) { |
| 165 external_data_store_.reset(external_data_store.release()); | 167 external_data_store_.reset(external_data_store.release()); |
| 166 if (metadata_set_ && external_data_store_) | 168 if (metadata_set_ && external_data_store_) |
| 167 external_data_store_->Prune(metadata_); | 169 external_data_store_->Prune(metadata_); |
| 168 } | 170 } |
| 169 | 171 |
| 170 void CloudExternalDataManagerBase::Backend::Connect( | 172 void CloudExternalDataManagerBase::Backend::Connect( |
| 171 scoped_ptr<ExternalPolicyDataFetcher> external_policy_data_fetcher) { | 173 std::unique_ptr<ExternalPolicyDataFetcher> external_policy_data_fetcher) { |
| 172 DCHECK(!updater_); | 174 DCHECK(!updater_); |
| 173 updater_.reset(new ExternalPolicyDataUpdater( | 175 updater_.reset(new ExternalPolicyDataUpdater( |
| 174 task_runner_, std::move(external_policy_data_fetcher), | 176 task_runner_, std::move(external_policy_data_fetcher), |
| 175 kMaxParallelFetches)); | 177 kMaxParallelFetches)); |
| 176 for (FetchCallbackMap::const_iterator it = pending_downloads_.begin(); | 178 for (FetchCallbackMap::const_iterator it = pending_downloads_.begin(); |
| 177 it != pending_downloads_.end(); ++it) { | 179 it != pending_downloads_.end(); ++it) { |
| 178 StartDownload(it->first); | 180 StartDownload(it->first); |
| 179 } | 181 } |
| 180 } | 182 } |
| 181 | 183 |
| 182 void CloudExternalDataManagerBase::Backend::Disconnect() { | 184 void CloudExternalDataManagerBase::Backend::Disconnect() { |
| 183 updater_.reset(); | 185 updater_.reset(); |
| 184 } | 186 } |
| 185 | 187 |
| 186 void CloudExternalDataManagerBase::Backend::OnMetadataUpdated( | 188 void CloudExternalDataManagerBase::Backend::OnMetadataUpdated( |
| 187 scoped_ptr<Metadata> metadata) { | 189 std::unique_ptr<Metadata> metadata) { |
| 188 metadata_set_ = true; | 190 metadata_set_ = true; |
| 189 Metadata old_metadata; | 191 Metadata old_metadata; |
| 190 metadata_.swap(old_metadata); | 192 metadata_.swap(old_metadata); |
| 191 if (metadata) | 193 if (metadata) |
| 192 metadata_.swap(*metadata); | 194 metadata_.swap(*metadata); |
| 193 | 195 |
| 194 if (external_data_store_) | 196 if (external_data_store_) |
| 195 external_data_store_->Prune(metadata_); | 197 external_data_store_->Prune(metadata_); |
| 196 | 198 |
| 197 for (FetchCallbackMap::iterator it = pending_downloads_.begin(); | 199 for (FetchCallbackMap::iterator it = pending_downloads_.begin(); |
| 198 it != pending_downloads_.end(); ) { | 200 it != pending_downloads_.end(); ) { |
| 199 const std::string policy = it->first; | 201 const std::string policy = it->first; |
| 200 Metadata::const_iterator metadata = metadata_.find(policy); | 202 Metadata::const_iterator metadata = metadata_.find(policy); |
| 201 if (metadata == metadata_.end()) { | 203 if (metadata == metadata_.end()) { |
| 202 // |policy| no longer references external data. | 204 // |policy| no longer references external data. |
| 203 if (updater_) { | 205 if (updater_) { |
| 204 // Cancel the external data download. | 206 // Cancel the external data download. |
| 205 updater_->CancelExternalDataFetch(policy); | 207 updater_->CancelExternalDataFetch(policy); |
| 206 } | 208 } |
| 207 for (FetchCallbackList::const_iterator callback = it->second.begin(); | 209 for (FetchCallbackList::const_iterator callback = it->second.begin(); |
| 208 callback != it->second.end(); ++callback) { | 210 callback != it->second.end(); ++callback) { |
| 209 // Invoke all callbacks for |policy|, indicating permanent failure. | 211 // Invoke all callbacks for |policy|, indicating permanent failure. |
| 210 RunCallback(*callback, scoped_ptr<std::string>()); | 212 RunCallback(*callback, std::unique_ptr<std::string>()); |
| 211 } | 213 } |
| 212 pending_downloads_.erase(it++); | 214 pending_downloads_.erase(it++); |
| 213 continue; | 215 continue; |
| 214 } | 216 } |
| 215 | 217 |
| 216 if (updater_ && metadata->second != old_metadata[policy]) { | 218 if (updater_ && metadata->second != old_metadata[policy]) { |
| 217 // |policy| still references external data but the reference has changed. | 219 // |policy| still references external data but the reference has changed. |
| 218 // Cancel the external data download and start a new one. | 220 // Cancel the external data download and start a new one. |
| 219 updater_->CancelExternalDataFetch(policy); | 221 updater_->CancelExternalDataFetch(policy); |
| 220 StartDownload(policy); | 222 StartDownload(policy); |
| 221 } | 223 } |
| 222 ++it; | 224 ++it; |
| 223 } | 225 } |
| 224 } | 226 } |
| 225 | 227 |
| 226 bool CloudExternalDataManagerBase::Backend::OnDownloadSuccess( | 228 bool CloudExternalDataManagerBase::Backend::OnDownloadSuccess( |
| 227 const std::string& policy, | 229 const std::string& policy, |
| 228 const std::string& hash, | 230 const std::string& hash, |
| 229 const std::string& data) { | 231 const std::string& data) { |
| 230 DCHECK(metadata_.find(policy) != metadata_.end()); | 232 DCHECK(metadata_.find(policy) != metadata_.end()); |
| 231 DCHECK_EQ(hash, metadata_[policy].hash); | 233 DCHECK_EQ(hash, metadata_[policy].hash); |
| 232 if (external_data_store_) | 234 if (external_data_store_) |
| 233 external_data_store_->Store(policy, hash, data); | 235 external_data_store_->Store(policy, hash, data); |
| 234 | 236 |
| 235 const FetchCallbackList& pending_callbacks = pending_downloads_[policy]; | 237 const FetchCallbackList& pending_callbacks = pending_downloads_[policy]; |
| 236 for (FetchCallbackList::const_iterator it = pending_callbacks.begin(); | 238 for (FetchCallbackList::const_iterator it = pending_callbacks.begin(); |
| 237 it != pending_callbacks.end(); ++it) { | 239 it != pending_callbacks.end(); ++it) { |
| 238 RunCallback(*it, make_scoped_ptr(new std::string(data))); | 240 RunCallback(*it, base::WrapUnique(new std::string(data))); |
| 239 } | 241 } |
| 240 pending_downloads_.erase(policy); | 242 pending_downloads_.erase(policy); |
| 241 return true; | 243 return true; |
| 242 } | 244 } |
| 243 | 245 |
| 244 void CloudExternalDataManagerBase::Backend::Fetch( | 246 void CloudExternalDataManagerBase::Backend::Fetch( |
| 245 const std::string& policy, | 247 const std::string& policy, |
| 246 const ExternalDataFetcher::FetchCallback& callback) { | 248 const ExternalDataFetcher::FetchCallback& callback) { |
| 247 Metadata::const_iterator metadata = metadata_.find(policy); | 249 Metadata::const_iterator metadata = metadata_.find(policy); |
| 248 if (metadata == metadata_.end()) { | 250 if (metadata == metadata_.end()) { |
| 249 // If |policy| does not reference any external data, indicate permanent | 251 // If |policy| does not reference any external data, indicate permanent |
| 250 // failure. | 252 // failure. |
| 251 RunCallback(callback, scoped_ptr<std::string>()); | 253 RunCallback(callback, std::unique_ptr<std::string>()); |
| 252 return; | 254 return; |
| 253 } | 255 } |
| 254 | 256 |
| 255 if (pending_downloads_.find(policy) != pending_downloads_.end()) { | 257 if (pending_downloads_.find(policy) != pending_downloads_.end()) { |
| 256 // If a download of the external data referenced by |policy| has already | 258 // If a download of the external data referenced by |policy| has already |
| 257 // been requested, add |callback| to the list of callbacks for |policy| and | 259 // been requested, add |callback| to the list of callbacks for |policy| and |
| 258 // return. | 260 // return. |
| 259 pending_downloads_[policy].push_back(callback); | 261 pending_downloads_[policy].push_back(callback); |
| 260 return; | 262 return; |
| 261 } | 263 } |
| 262 | 264 |
| 263 scoped_ptr<std::string> data(new std::string); | 265 std::unique_ptr<std::string> data(new std::string); |
| 264 if (external_data_store_ && external_data_store_->Load( | 266 if (external_data_store_ && external_data_store_->Load( |
| 265 policy, metadata->second.hash, GetMaxExternalDataSize(policy), | 267 policy, metadata->second.hash, GetMaxExternalDataSize(policy), |
| 266 data.get())) { | 268 data.get())) { |
| 267 // If the external data referenced by |policy| exists in the cache and | 269 // If the external data referenced by |policy| exists in the cache and |
| 268 // matches the expected hash, pass it to the callback. | 270 // matches the expected hash, pass it to the callback. |
| 269 RunCallback(callback, std::move(data)); | 271 RunCallback(callback, std::move(data)); |
| 270 return; | 272 return; |
| 271 } | 273 } |
| 272 | 274 |
| 273 // Request a download of the the external data referenced by |policy| and | 275 // Request a download of the the external data referenced by |policy| and |
| 274 // initialize the list of callbacks by adding |callback|. | 276 // initialize the list of callbacks by adding |callback|. |
| 275 pending_downloads_[policy].push_back(callback); | 277 pending_downloads_[policy].push_back(callback); |
| 276 StartDownload(policy); | 278 StartDownload(policy); |
| 277 } | 279 } |
| 278 | 280 |
| 279 void CloudExternalDataManagerBase::Backend::FetchAll() { | 281 void CloudExternalDataManagerBase::Backend::FetchAll() { |
| 280 // Loop through all external data references. | 282 // Loop through all external data references. |
| 281 for (Metadata::const_iterator it = metadata_.begin(); it != metadata_.end(); | 283 for (Metadata::const_iterator it = metadata_.begin(); it != metadata_.end(); |
| 282 ++it) { | 284 ++it) { |
| 283 const std::string& policy = it->first; | 285 const std::string& policy = it->first; |
| 284 scoped_ptr<std::string> data(new std::string); | 286 std::unique_ptr<std::string> data(new std::string); |
| 285 if (pending_downloads_.find(policy) != pending_downloads_.end() || | 287 if (pending_downloads_.find(policy) != pending_downloads_.end() || |
| 286 (external_data_store_ && external_data_store_->Load( | 288 (external_data_store_ && external_data_store_->Load( |
| 287 policy, it->second.hash, GetMaxExternalDataSize(policy), | 289 policy, it->second.hash, GetMaxExternalDataSize(policy), |
| 288 data.get()))) { | 290 data.get()))) { |
| 289 // If a download of the external data referenced by |policy| has already | 291 // If a download of the external data referenced by |policy| has already |
| 290 // been requested or the data exists in the cache and matches the expected | 292 // been requested or the data exists in the cache and matches the expected |
| 291 // hash, there is nothing to be done. | 293 // hash, there is nothing to be done. |
| 292 continue; | 294 continue; |
| 293 } | 295 } |
| 294 // Request a download of the the external data referenced by |policy| and | 296 // Request a download of the the external data referenced by |policy| and |
| (...skipping 14 matching lines...) Expand all Loading... |
| 309 // part of the policy definition. | 311 // part of the policy definition. |
| 310 const PolicyDetails* details = get_policy_details_.Run(policy); | 312 const PolicyDetails* details = get_policy_details_.Run(policy); |
| 311 if (details) | 313 if (details) |
| 312 return details->max_external_data_size; | 314 return details->max_external_data_size; |
| 313 NOTREACHED(); | 315 NOTREACHED(); |
| 314 return 0; | 316 return 0; |
| 315 } | 317 } |
| 316 | 318 |
| 317 void CloudExternalDataManagerBase::Backend::RunCallback( | 319 void CloudExternalDataManagerBase::Backend::RunCallback( |
| 318 const ExternalDataFetcher::FetchCallback& callback, | 320 const ExternalDataFetcher::FetchCallback& callback, |
| 319 scoped_ptr<std::string> data) const { | 321 std::unique_ptr<std::string> data) const { |
| 320 callback_task_runner_->PostTask(FROM_HERE, | 322 callback_task_runner_->PostTask(FROM_HERE, |
| 321 base::Bind(callback, base::Passed(&data))); | 323 base::Bind(callback, base::Passed(&data))); |
| 322 } | 324 } |
| 323 | 325 |
| 324 void CloudExternalDataManagerBase::Backend::StartDownload( | 326 void CloudExternalDataManagerBase::Backend::StartDownload( |
| 325 const std::string& policy) { | 327 const std::string& policy) { |
| 326 DCHECK(pending_downloads_.find(policy) != pending_downloads_.end()); | 328 DCHECK(pending_downloads_.find(policy) != pending_downloads_.end()); |
| 327 if (!updater_) | 329 if (!updater_) |
| 328 return; | 330 return; |
| 329 | 331 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 351 } | 353 } |
| 352 | 354 |
| 353 CloudExternalDataManagerBase::~CloudExternalDataManagerBase() { | 355 CloudExternalDataManagerBase::~CloudExternalDataManagerBase() { |
| 354 DCHECK(CalledOnValidThread()); | 356 DCHECK(CalledOnValidThread()); |
| 355 io_task_runner_->DeleteSoon(FROM_HERE, | 357 io_task_runner_->DeleteSoon(FROM_HERE, |
| 356 external_policy_data_fetcher_backend_.release()); | 358 external_policy_data_fetcher_backend_.release()); |
| 357 backend_task_runner_->DeleteSoon(FROM_HERE, backend_.release()); | 359 backend_task_runner_->DeleteSoon(FROM_HERE, backend_.release()); |
| 358 } | 360 } |
| 359 | 361 |
| 360 void CloudExternalDataManagerBase::SetExternalDataStore( | 362 void CloudExternalDataManagerBase::SetExternalDataStore( |
| 361 scoped_ptr<CloudExternalDataStore> external_data_store) { | 363 std::unique_ptr<CloudExternalDataStore> external_data_store) { |
| 362 DCHECK(CalledOnValidThread()); | 364 DCHECK(CalledOnValidThread()); |
| 363 backend_task_runner_->PostTask(FROM_HERE, base::Bind( | 365 backend_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 364 &Backend::SetExternalDataStore, | 366 &Backend::SetExternalDataStore, |
| 365 base::Unretained(backend_.get()), | 367 base::Unretained(backend_.get()), |
| 366 base::Passed(&external_data_store))); | 368 base::Passed(&external_data_store))); |
| 367 } | 369 } |
| 368 | 370 |
| 369 void CloudExternalDataManagerBase::SetPolicyStore( | 371 void CloudExternalDataManagerBase::SetPolicyStore( |
| 370 CloudPolicyStore* policy_store) { | 372 CloudPolicyStore* policy_store) { |
| 371 DCHECK(CalledOnValidThread()); | 373 DCHECK(CalledOnValidThread()); |
| 372 CloudExternalDataManager::SetPolicyStore(policy_store); | 374 CloudExternalDataManager::SetPolicyStore(policy_store); |
| 373 if (policy_store_ && policy_store_->is_initialized()) | 375 if (policy_store_ && policy_store_->is_initialized()) |
| 374 OnPolicyStoreLoaded(); | 376 OnPolicyStoreLoaded(); |
| 375 } | 377 } |
| 376 | 378 |
| 377 void CloudExternalDataManagerBase::OnPolicyStoreLoaded() { | 379 void CloudExternalDataManagerBase::OnPolicyStoreLoaded() { |
| 378 // Collect all external data references made by policies in |policy_store_| | 380 // Collect all external data references made by policies in |policy_store_| |
| 379 // and pass them to the |backend_|. | 381 // and pass them to the |backend_|. |
| 380 DCHECK(CalledOnValidThread()); | 382 DCHECK(CalledOnValidThread()); |
| 381 scoped_ptr<Metadata> metadata(new Metadata); | 383 std::unique_ptr<Metadata> metadata(new Metadata); |
| 382 const PolicyMap& policy_map = policy_store_->policy_map(); | 384 const PolicyMap& policy_map = policy_store_->policy_map(); |
| 383 for (PolicyMap::const_iterator it = policy_map.begin(); | 385 for (PolicyMap::const_iterator it = policy_map.begin(); |
| 384 it != policy_map.end(); ++it) { | 386 it != policy_map.end(); ++it) { |
| 385 if (!it->second.external_data_fetcher) { | 387 if (!it->second.external_data_fetcher) { |
| 386 // Skip policies that do not reference external data. | 388 // Skip policies that do not reference external data. |
| 387 continue; | 389 continue; |
| 388 } | 390 } |
| 389 const base::DictionaryValue* dict = NULL; | 391 const base::DictionaryValue* dict = NULL; |
| 390 std::string url; | 392 std::string url; |
| 391 std::string hex_hash; | 393 std::string hex_hash; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 max_external_data_size_for_testing = max_size; | 446 max_external_data_size_for_testing = max_size; |
| 445 } | 447 } |
| 446 | 448 |
| 447 void CloudExternalDataManagerBase::FetchAll() { | 449 void CloudExternalDataManagerBase::FetchAll() { |
| 448 DCHECK(CalledOnValidThread()); | 450 DCHECK(CalledOnValidThread()); |
| 449 backend_task_runner_->PostTask(FROM_HERE, base::Bind( | 451 backend_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 450 &Backend::FetchAll, base::Unretained(backend_.get()))); | 452 &Backend::FetchAll, base::Unretained(backend_.get()))); |
| 451 } | 453 } |
| 452 | 454 |
| 453 } // namespace policy | 455 } // namespace policy |
| OLD | NEW |