summaryrefslogtreecommitdiffstats
path: root/chrome/browser/policy/external_data_fetcher.h
blob: 4e2f55d78a8cc5c3689ec1156d676b87f54ab2e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_POLICY_EXTERNAL_DATA_FETCHER_H_
#define CHROME_BROWSER_POLICY_EXTERNAL_DATA_FETCHER_H_

#include <string>

#include "base/callback_forward.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"

namespace policy {

class ExternalDataManager;

// A helper that encapsulates the parameters required to retrieve the external
// data for a policy.
class ExternalDataFetcher {
 public:
  enum Status {
    // This policy does not reference any external data.
    STATUS_NO_DATA,
    // This policy references external data. The data has been requested but is
    // not available yet. Once the data is successfully downloaded and verified,
    // the PolicyService that this ExternalDataFetcher belongs to will invoke
    // OnPolicyUpdated() to inform its observers that the data is available.
    STATUS_DATA_PENDING,
    // This external data referenced by the policy has been downloaded, verified
    // and is included in the callback.
    STATUS_DATA_AVAILABLE
  };

  typedef base::Callback<void(Status, scoped_ptr<std::string>)> FetchCallback;

  ExternalDataFetcher(const ExternalDataFetcher& other);
  ~ExternalDataFetcher();

  static bool Equals(const ExternalDataFetcher* first,
                     const ExternalDataFetcher* second);

  void Fetch(const FetchCallback& callback) const;

 protected:
  friend class PolicyDomainDescriptorTest;
  friend class PolicyMapTest;

  ExternalDataFetcher(base::WeakPtr<ExternalDataManager> manager,
                      const std::string& policy);

 private:
  base::WeakPtr<ExternalDataManager> manager_;
  std::string policy_;
};

}  // namespace policy

#endif  // CHROME_BROWSER_POLICY_EXTERNAL_DATA_FETCHER_H_