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

Side by Side Diff: chrome/browser/chromeos/policy/cloud_external_data_manager_base.cc

Issue 58313002: Removed the PolicyDefinitionList. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome-policy-schema-10-use-registry
Patch Set: Created 7 years, 1 month 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 unified diff | Download patch
OLDNEW
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 <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
bartfab (slow) 2013/11/05 18:18:33 Nit: policy/policy_constants.h now implicitly pull
Joao da Silva 2013/11/07 20:27:27 Done.
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/message_loop/message_loop_proxy.h" 15 #include "base/message_loop/message_loop_proxy.h"
16 #include "base/sequenced_task_runner.h" 16 #include "base/sequenced_task_runner.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/chromeos/policy/cloud_external_data_store.h" 19 #include "chrome/browser/chromeos/policy/cloud_external_data_store.h"
20 #include "chrome/browser/policy/cloud/cloud_policy_store.h" 20 #include "chrome/browser/policy/cloud/cloud_policy_store.h"
21 #include "chrome/browser/policy/cloud/external_policy_data_fetcher.h" 21 #include "chrome/browser/policy/cloud/external_policy_data_fetcher.h"
22 #include "chrome/browser/policy/cloud/external_policy_data_updater.h" 22 #include "chrome/browser/policy/cloud/external_policy_data_updater.h"
23 #include "chrome/browser/policy/external_data_fetcher.h" 23 #include "chrome/browser/policy/external_data_fetcher.h"
24 #include "chrome/browser/policy/policy_map.h" 24 #include "chrome/browser/policy/policy_map.h"
25 #include "net/url_request/url_request_context_getter.h" 25 #include "net/url_request/url_request_context_getter.h"
26 #include "policy/policy_constants.h"
27 26
28 namespace policy { 27 namespace policy {
29 28
30 namespace { 29 namespace {
31 30
32 // Fetch data for at most two external data references at the same time. 31 // Fetch data for at most two external data references at the same time.
33 const int kMaxParallelFetches = 2; 32 const int kMaxParallelFetches = 2;
34 33
35 // Allows policies to reference |max_external_data_size_for_testing| bytes of 34 // Allows policies to reference |max_external_data_size_for_testing| bytes of
36 // external data even if no |max_size| was specified in policy_templates.json. 35 // external data even if no |max_size| was specified in policy_templates.json.
37 int max_external_data_size_for_testing = 0; 36 int max_external_data_size_for_testing = 0;
38 37
39 } // namespace 38 } // namespace
40 39
41 // Backend for the CloudExternalDataManagerBase that handles all data download, 40 // Backend for the CloudExternalDataManagerBase that handles all data download,
42 // verification, caching and retrieval. 41 // verification, caching and retrieval.
43 class CloudExternalDataManagerBase::Backend { 42 class CloudExternalDataManagerBase::Backend {
44 public: 43 public:
45 // The |policy_definitions| are used to determine the maximum size that the 44 // |get_policy_details| is used to determine the maximum size that the
46 // data referenced by each policy can have. This class can be instantiated on 45 // data referenced by each policy can have. This class can be instantiated on
47 // any thread but from then on, may be accessed via the |task_runner_| only. 46 // any thread but from then on, may be accessed via the |task_runner_| only.
48 // All FetchCallbacks will be invoked via |callback_task_runner|. 47 // All FetchCallbacks will be invoked via |callback_task_runner|.
49 Backend(const PolicyDefinitionList* policy_definitions, 48 Backend(const GetChromePolicyDetailsCallback& get_policy_details,
50 scoped_refptr<base::SequencedTaskRunner> task_runner, 49 scoped_refptr<base::SequencedTaskRunner> task_runner,
51 scoped_refptr<base::SequencedTaskRunner> callback_task_runner); 50 scoped_refptr<base::SequencedTaskRunner> callback_task_runner);
52 51
53 // Allows downloaded external data to be cached in |external_data_store|. 52 // Allows downloaded external data to be cached in |external_data_store|.
54 // Ownership of the store is taken. The store can be destroyed by calling 53 // Ownership of the store is taken. The store can be destroyed by calling
55 // SetExternalDataStore(scoped_ptr<CloudExternalDataStore>()). 54 // SetExternalDataStore(scoped_ptr<CloudExternalDataStore>()).
56 void SetExternalDataStore( 55 void SetExternalDataStore(
57 scoped_ptr<CloudExternalDataStore> external_data_store); 56 scoped_ptr<CloudExternalDataStore> external_data_store);
58 57
59 // Allows downloading of external data via the |external_policy_data_fetcher|. 58 // Allows downloading of external data via the |external_policy_data_fetcher|.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 void FetchAll(); 93 void FetchAll();
95 94
96 private: 95 private:
97 // List of callbacks to invoke when the attempt to retrieve external data 96 // List of callbacks to invoke when the attempt to retrieve external data
98 // referenced by a policy completes successfully or fails permanently. 97 // referenced by a policy completes successfully or fails permanently.
99 typedef std::vector<ExternalDataFetcher::FetchCallback> FetchCallbackList; 98 typedef std::vector<ExternalDataFetcher::FetchCallback> FetchCallbackList;
100 99
101 // Map from policy names to the lists of callbacks defined above. 100 // Map from policy names to the lists of callbacks defined above.
102 typedef std::map<std::string, FetchCallbackList> FetchCallbackMap; 101 typedef std::map<std::string, FetchCallbackList> FetchCallbackMap;
103 102
104 // Looks up the maximum size that the data referenced by |policy| can have in 103 // Looks up the maximum size that the data referenced by |policy| can have.
105 // |policy_definitions_|.
106 size_t GetMaxExternalDataSize(const std::string& policy) const; 104 size_t GetMaxExternalDataSize(const std::string& policy) const;
107 105
108 // Invokes |callback| via the |callback_task_runner_|, passing |data| as a 106 // Invokes |callback| via the |callback_task_runner_|, passing |data| as a
109 // parameter. 107 // parameter.
110 void RunCallback(const ExternalDataFetcher::FetchCallback& callback, 108 void RunCallback(const ExternalDataFetcher::FetchCallback& callback,
111 scoped_ptr<std::string> data) const; 109 scoped_ptr<std::string> data) const;
112 110
113 // Tells the |updater_| to download the external data referenced by |policy|. 111 // Tells the |updater_| to download the external data referenced by |policy|.
114 // If Connect() was not called yet and no |updater_| exists, does nothing. 112 // If Connect() was not called yet and no |updater_| exists, does nothing.
115 void StartDownload(const std::string& policy); 113 void StartDownload(const std::string& policy);
116 114
117 // Used to determine the maximum size that the data referenced by each policy 115 // Used to determine the maximum size that the data referenced by each policy
118 // can have. 116 // can have.
119 const PolicyDefinitionList* policy_definitions_; 117 GetChromePolicyDetailsCallback get_policy_details_;
120 118
121 scoped_refptr<base::SequencedTaskRunner> task_runner_; 119 scoped_refptr<base::SequencedTaskRunner> task_runner_;
122 scoped_refptr<base::SequencedTaskRunner> callback_task_runner_; 120 scoped_refptr<base::SequencedTaskRunner> callback_task_runner_;
123 121
124 // Contains the policies for which a download of the referenced external data 122 // Contains the policies for which a download of the referenced external data
125 // has been requested. Each policy is mapped to a list of callbacks to invoke 123 // has been requested. Each policy is mapped to a list of callbacks to invoke
126 // when the download completes successfully or fails permanently. If no 124 // when the download completes successfully or fails permanently. If no
127 // callback needs to be invoked (because the download was requested via 125 // callback needs to be invoked (because the download was requested via
128 // FetchAll()), a map entry will still exist but the list of callbacks it maps 126 // FetchAll()), a map entry will still exist but the list of callbacks it maps
129 // to will be empty. 127 // to will be empty.
(...skipping 10 matching lines...) Expand all
140 // Used to cache external data referenced by policies. 138 // Used to cache external data referenced by policies.
141 scoped_ptr<CloudExternalDataStore> external_data_store_; 139 scoped_ptr<CloudExternalDataStore> external_data_store_;
142 140
143 // Used to download external data referenced by policies. 141 // Used to download external data referenced by policies.
144 scoped_ptr<ExternalPolicyDataUpdater> updater_; 142 scoped_ptr<ExternalPolicyDataUpdater> updater_;
145 143
146 DISALLOW_COPY_AND_ASSIGN(Backend); 144 DISALLOW_COPY_AND_ASSIGN(Backend);
147 }; 145 };
148 146
149 CloudExternalDataManagerBase::Backend::Backend( 147 CloudExternalDataManagerBase::Backend::Backend(
150 const PolicyDefinitionList* policy_definitions, 148 const GetChromePolicyDetailsCallback& get_policy_details,
151 scoped_refptr<base::SequencedTaskRunner> task_runner, 149 scoped_refptr<base::SequencedTaskRunner> task_runner,
152 scoped_refptr<base::SequencedTaskRunner> callback_task_runner) 150 scoped_refptr<base::SequencedTaskRunner> callback_task_runner)
153 : policy_definitions_(policy_definitions), 151 : get_policy_details_(get_policy_details),
154 task_runner_(task_runner), 152 task_runner_(task_runner),
155 callback_task_runner_(callback_task_runner), 153 callback_task_runner_(callback_task_runner),
156 metadata_set_(false) { 154 metadata_set_(false) {
157 } 155 }
158 156
159 void CloudExternalDataManagerBase::Backend::SetExternalDataStore( 157 void CloudExternalDataManagerBase::Backend::SetExternalDataStore(
160 scoped_ptr<CloudExternalDataStore> external_data_store) { 158 scoped_ptr<CloudExternalDataStore> external_data_store) {
161 external_data_store_.reset(external_data_store.release()); 159 external_data_store_.reset(external_data_store.release());
162 if (metadata_set_ && external_data_store_) 160 if (metadata_set_ && external_data_store_)
163 external_data_store_->Prune(metadata_); 161 external_data_store_->Prune(metadata_);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 StartDownload(policy); 292 StartDownload(policy);
295 } 293 }
296 } 294 }
297 295
298 size_t CloudExternalDataManagerBase::Backend::GetMaxExternalDataSize( 296 size_t CloudExternalDataManagerBase::Backend::GetMaxExternalDataSize(
299 const std::string& policy) const { 297 const std::string& policy) const {
300 if (max_external_data_size_for_testing) 298 if (max_external_data_size_for_testing)
301 return max_external_data_size_for_testing; 299 return max_external_data_size_for_testing;
302 300
303 // Look up the maximum size that the data referenced by |policy| can have in 301 // Look up the maximum size that the data referenced by |policy| can have in
304 // policy_definitions_, which is constructed from the information in 302 // get_policy_details, which is constructed from the information in
305 // policy_templates.json, allowing the maximum data size to be specified as 303 // policy_templates.json, allowing the maximum data size to be specified as
306 // part of the policy definition. 304 // part of the policy definition.
307 for (const PolicyDefinitionList::Entry* entry = policy_definitions_->begin; 305 const PolicyDetails* details = get_policy_details_.Run(policy);
308 entry != policy_definitions_->end; ++entry) { 306 if (details)
309 if (entry->name == policy) 307 return details->max_external_data_size;
310 return entry->max_external_data_size;
311 }
312 NOTREACHED(); 308 NOTREACHED();
313 return 0; 309 return 0;
314 } 310 }
315 311
316 void CloudExternalDataManagerBase::Backend::RunCallback( 312 void CloudExternalDataManagerBase::Backend::RunCallback(
317 const ExternalDataFetcher::FetchCallback& callback, 313 const ExternalDataFetcher::FetchCallback& callback,
318 scoped_ptr<std::string> data) const { 314 scoped_ptr<std::string> data) const {
319 callback_task_runner_->PostTask(FROM_HERE, 315 callback_task_runner_->PostTask(FROM_HERE,
320 base::Bind(callback, base::Passed(&data))); 316 base::Bind(callback, base::Passed(&data)));
321 } 317 }
(...skipping 10 matching lines...) Expand all
332 ExternalPolicyDataUpdater::Request(metadata.url, 328 ExternalPolicyDataUpdater::Request(metadata.url,
333 metadata.hash, 329 metadata.hash,
334 GetMaxExternalDataSize(policy)), 330 GetMaxExternalDataSize(policy)),
335 base::Bind(&CloudExternalDataManagerBase::Backend::OnDownloadSuccess, 331 base::Bind(&CloudExternalDataManagerBase::Backend::OnDownloadSuccess,
336 base::Unretained(this), 332 base::Unretained(this),
337 policy, 333 policy,
338 metadata.hash)); 334 metadata.hash));
339 } 335 }
340 336
341 CloudExternalDataManagerBase::CloudExternalDataManagerBase( 337 CloudExternalDataManagerBase::CloudExternalDataManagerBase(
342 const PolicyDefinitionList* policy_definitions, 338 const GetChromePolicyDetailsCallback& get_policy_details,
343 scoped_refptr<base::SequencedTaskRunner> backend_task_runner, 339 scoped_refptr<base::SequencedTaskRunner> backend_task_runner,
344 scoped_refptr<base::SequencedTaskRunner> io_task_runner) 340 scoped_refptr<base::SequencedTaskRunner> io_task_runner)
345 : backend_task_runner_(backend_task_runner), 341 : backend_task_runner_(backend_task_runner),
346 io_task_runner_(io_task_runner), 342 io_task_runner_(io_task_runner),
347 backend_(new Backend(policy_definitions, 343 backend_(new Backend(get_policy_details,
348 backend_task_runner_, 344 backend_task_runner_,
349 base::MessageLoopProxy::current())) { 345 base::MessageLoopProxy::current())) {
350 } 346 }
351 347
352 CloudExternalDataManagerBase::~CloudExternalDataManagerBase() { 348 CloudExternalDataManagerBase::~CloudExternalDataManagerBase() {
353 DCHECK(CalledOnValidThread()); 349 DCHECK(CalledOnValidThread());
354 io_task_runner_->DeleteSoon(FROM_HERE, 350 io_task_runner_->DeleteSoon(FROM_HERE,
355 external_policy_data_fetcher_backend_.release()); 351 external_policy_data_fetcher_backend_.release());
356 backend_task_runner_->DeleteSoon(FROM_HERE, backend_.release()); 352 backend_task_runner_->DeleteSoon(FROM_HERE, backend_.release());
357 } 353 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 max_external_data_size_for_testing = max_size; 439 max_external_data_size_for_testing = max_size;
444 } 440 }
445 441
446 void CloudExternalDataManagerBase::FetchAll() { 442 void CloudExternalDataManagerBase::FetchAll() {
447 DCHECK(CalledOnValidThread()); 443 DCHECK(CalledOnValidThread());
448 backend_task_runner_->PostTask(FROM_HERE, base::Bind( 444 backend_task_runner_->PostTask(FROM_HERE, base::Bind(
449 &Backend::FetchAll, base::Unretained(backend_.get()))); 445 &Backend::FetchAll, base::Unretained(backend_.get())));
450 } 446 }
451 447
452 } // namespace policy 448 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698