OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_POLICY_EXTERNAL_DATA_FETCHER_H_ | |
6 #define CHROME_BROWSER_POLICY_EXTERNAL_DATA_FETCHER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback_forward.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 | |
14 namespace policy { | |
15 | |
16 class ExternalDataManager; | |
17 | |
18 // A helper that encapsulates the parameters required to retrieve the external | |
19 // data for a policy. | |
20 class ExternalDataFetcher { | |
21 public: | |
22 typedef base::Callback<void(scoped_ptr<std::string>)> FetchCallback; | |
23 | |
24 // This instance's Fetch() method will instruct the |manager| to retrieve the | |
25 // external data referenced by the given |policy|. | |
26 ExternalDataFetcher(base::WeakPtr<ExternalDataManager> manager, | |
27 const std::string& policy); | |
28 ExternalDataFetcher(const ExternalDataFetcher& other); | |
29 | |
30 ~ExternalDataFetcher(); | |
31 | |
32 static bool Equals(const ExternalDataFetcher* first, | |
33 const ExternalDataFetcher* second); | |
34 | |
35 // Retrieves the external data referenced by |policy_| and invokes |callback| | |
36 // with the result. If |policy_| does not reference any external data, the | |
37 // |callback| is invoked with a NULL pointer. Otherwise, the |callback| is | |
38 // invoked with the referenced data once it has been successfully retrieved. | |
39 // If retrieval is temporarily impossible (e.g. no network connectivity), the | |
40 // |callback| will be invoked when the temporary hindrance is resolved. If | |
41 // retrieval is permanently impossible (e.g. |policy_| references data that | |
42 // does not exist on the server), the |callback| will never be invoked. | |
43 void Fetch(const FetchCallback& callback) const; | |
44 | |
45 private: | |
46 base::WeakPtr<ExternalDataManager> manager_; | |
47 const std::string policy_; | |
48 }; | |
49 | |
50 } // namespace policy | |
51 | |
52 #endif // CHROME_BROWSER_POLICY_EXTERNAL_DATA_FETCHER_H_ | |
OLD | NEW |