OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_VALIDATOR_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_VALIDATOR_H_ |
6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_VALIDATOR_H_ | 6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_VALIDATOR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | |
10 #include <string> | 9 #include <string> |
| 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/sequenced_task_runner.h" | 18 #include "base/sequenced_task_runner.h" |
19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 | 316 |
317 virtual ~CloudPolicyValidator() {} | 317 virtual ~CloudPolicyValidator() {} |
318 | 318 |
319 // Creates a new validator. | 319 // Creates a new validator. |
320 // |background_task_runner| is optional; if RunValidation() is used directly | 320 // |background_task_runner| is optional; if RunValidation() is used directly |
321 // and StartValidation() is not used then it can be NULL. | 321 // and StartValidation() is not used then it can be NULL. |
322 static CloudPolicyValidator<PayloadProto>* Create( | 322 static CloudPolicyValidator<PayloadProto>* Create( |
323 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response, | 323 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response, |
324 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { | 324 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { |
325 return new CloudPolicyValidator( | 325 return new CloudPolicyValidator( |
326 policy_response.Pass(), | 326 std::move(policy_response), |
327 scoped_ptr<PayloadProto>(new PayloadProto()), | 327 scoped_ptr<PayloadProto>(new PayloadProto()), background_task_runner); |
328 background_task_runner); | |
329 } | 328 } |
330 | 329 |
331 scoped_ptr<PayloadProto>& payload() { | 330 scoped_ptr<PayloadProto>& payload() { |
332 return payload_; | 331 return payload_; |
333 } | 332 } |
334 | 333 |
335 // Kicks off asynchronous validation. |completion_callback| is invoked when | 334 // Kicks off asynchronous validation. |completion_callback| is invoked when |
336 // done. From this point on, the validator manages its own lifetime - this | 335 // done. From this point on, the validator manages its own lifetime - this |
337 // allows callers to provide a WeakPtr in the callback without leaking the | 336 // allows callers to provide a WeakPtr in the callback without leaking the |
338 // validator. | 337 // validator. |
339 void StartValidation(const CompletionCallback& completion_callback) { | 338 void StartValidation(const CompletionCallback& completion_callback) { |
340 PostValidationTask(base::Bind(completion_callback, this)); | 339 PostValidationTask(base::Bind(completion_callback, this)); |
341 } | 340 } |
342 | 341 |
343 private: | 342 private: |
344 CloudPolicyValidator( | 343 CloudPolicyValidator( |
345 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response, | 344 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response, |
346 scoped_ptr<PayloadProto> payload, | 345 scoped_ptr<PayloadProto> payload, |
347 scoped_refptr<base::SequencedTaskRunner> background_task_runner) | 346 scoped_refptr<base::SequencedTaskRunner> background_task_runner) |
348 : CloudPolicyValidatorBase(policy_response.Pass(), | 347 : CloudPolicyValidatorBase(std::move(policy_response), |
349 payload.get(), | 348 payload.get(), |
350 background_task_runner), | 349 background_task_runner), |
351 payload_(payload.Pass()) {} | 350 payload_(std::move(payload)) {} |
352 | 351 |
353 scoped_ptr<PayloadProto> payload_; | 352 scoped_ptr<PayloadProto> payload_; |
354 | 353 |
355 DISALLOW_COPY_AND_ASSIGN(CloudPolicyValidator); | 354 DISALLOW_COPY_AND_ASSIGN(CloudPolicyValidator); |
356 }; | 355 }; |
357 | 356 |
358 typedef CloudPolicyValidator<enterprise_management::CloudPolicySettings> | 357 typedef CloudPolicyValidator<enterprise_management::CloudPolicySettings> |
359 UserCloudPolicyValidator; | 358 UserCloudPolicyValidator; |
360 | 359 |
361 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 360 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
362 typedef CloudPolicyValidator<enterprise_management::ExternalPolicyData> | 361 typedef CloudPolicyValidator<enterprise_management::ExternalPolicyData> |
363 ComponentCloudPolicyValidator; | 362 ComponentCloudPolicyValidator; |
364 #endif | 363 #endif |
365 | 364 |
366 } // namespace policy | 365 } // namespace policy |
367 | 366 |
368 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_VALIDATOR_H_ | 367 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_VALIDATOR_H_ |
OLD | NEW |