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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_POLICY_CORE_COMMON_EXTERNAL_DATA_FETCHER_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_EXTERNAL_DATA_FETCHER_H_
10 #include "base/callback_forward.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "components/policy/policy_export.h"
17 class ExternalDataManager
;
19 // A helper that encapsulates the parameters required to retrieve the external
21 class POLICY_EXPORT ExternalDataFetcher
{
23 typedef base::Callback
<void(scoped_ptr
<std::string
>)> FetchCallback
;
25 // This instance's Fetch() method will instruct the |manager| to retrieve the
26 // external data referenced by the given |policy|.
27 ExternalDataFetcher(base::WeakPtr
<ExternalDataManager
> manager
,
28 const std::string
& policy
);
29 ExternalDataFetcher(const ExternalDataFetcher
& other
);
31 ~ExternalDataFetcher();
33 static bool Equals(const ExternalDataFetcher
* first
,
34 const ExternalDataFetcher
* second
);
36 // Retrieves the external data referenced by |policy_| and invokes |callback|
37 // with the result. If |policy_| does not reference any external data, the
38 // |callback| is invoked with a NULL pointer. Otherwise, the |callback| is
39 // invoked with the referenced data once it has been successfully retrieved.
40 // If retrieval is temporarily impossible (e.g. no network connectivity), the
41 // |callback| will be invoked when the temporary hindrance is resolved. If
42 // retrieval is permanently impossible (e.g. |policy_| references data that
43 // does not exist on the server), the |callback| will never be invoked.
44 void Fetch(const FetchCallback
& callback
) const;
47 base::WeakPtr
<ExternalDataManager
> manager_
;
48 const std::string policy_
;
53 #endif // COMPONENTS_POLICY_CORE_COMMON_EXTERNAL_DATA_FETCHER_H_