Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / cloud_external_data_manager_base.h
blob181f13ef0e1060e9d3d058fd1d59e4879795dd75
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 CHROME_BROWSER_CHROMEOS_POLICY_CLOUD_EXTERNAL_DATA_MANAGER_BASE_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_CLOUD_EXTERNAL_DATA_MANAGER_BASE_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/non_thread_safe.h"
13 #include "components/policy/core/common/cloud/cloud_external_data_manager.h"
14 #include "components/policy/core/common/policy_details.h"
16 namespace base {
17 class SequencedTaskRunner;
20 namespace policy {
22 class CloudExternalDataStore;
23 class ExternalPolicyDataFetcherBackend;
25 // Downloads, verifies, caches and retrieves external data referenced by
26 // policies.
27 // This is a common base class used by specializations for regular users and
28 // device-local accounts.
29 class CloudExternalDataManagerBase : public CloudExternalDataManager,
30 public base::NonThreadSafe {
31 public:
32 // |get_policy_details| is used to determine the maximum size that the
33 // data referenced by each policy can have. Download scheduling, verification,
34 // caching and retrieval tasks are done via the |backend_task_runner|, which
35 // must support file I/O. Network I/O is done via the |io_task_runner|.
36 CloudExternalDataManagerBase(
37 const GetChromePolicyDetailsCallback& get_policy_details,
38 scoped_refptr<base::SequencedTaskRunner> backend_task_runner,
39 scoped_refptr<base::SequencedTaskRunner> io_task_runner);
40 ~CloudExternalDataManagerBase() override;
42 // Allows downloaded external data to be cached in |external_data_store|.
43 // Ownership of the store is taken. The store can be destroyed by calling
44 // SetExternalDataStore(scoped_ptr<CloudExternalDataStore>()). Accesses to the
45 // store are made via |backend_task_runner_| only.
46 void SetExternalDataStore(
47 scoped_ptr<CloudExternalDataStore> external_data_store);
49 // CloudExternalDataManager:
50 void SetPolicyStore(CloudPolicyStore* policy_store) override;
51 void OnPolicyStoreLoaded() override;
52 void Connect(
53 scoped_refptr<net::URLRequestContextGetter> request_context) override;
54 void Disconnect() override;
55 void Fetch(const std::string& policy,
56 const ExternalDataFetcher::FetchCallback& callback) override;
58 // Allows policies to reference |max_size| bytes of external data even if no
59 // |max_size| was specified in policy_templates.json.
60 // TODO(bartfab): This override is only needed because there are no policies
61 // that reference external data and have a |max_size| yet. Once the first such
62 // policy is added, use that policy in tests and remove the override.
63 static void SetMaxExternalDataSizeForTesting(int max_size);
65 protected:
66 friend class CloudExternalDataManagerBaseTest;
68 // Try to download and cache all external data referenced by policies in
69 // |policy_store_|.
70 void FetchAll();
72 scoped_refptr<base::SequencedTaskRunner> backend_task_runner_;
73 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
75 private:
76 // The |external_policy_data_fetcher_backend_| handles network I/O for the
77 // |backend_| because URLRequestContextGetter and URLFetchers cannot be
78 // referenced from background threads. It is instantiated on the thread |this|
79 // runs on but after that, must only be accessed and eventually destroyed via
80 // the |io_task_runner_|.
81 scoped_ptr<ExternalPolicyDataFetcherBackend>
82 external_policy_data_fetcher_backend_;
84 // The |backend_| handles all data download scheduling, verification, caching
85 // and retrieval. It is instantiated on the thread |this| runs on but after
86 // that, must only be accessed and eventually destroyed via the
87 // |backend_task_runner_|.
88 class Backend;
89 scoped_ptr<Backend> backend_;
91 DISALLOW_COPY_AND_ASSIGN(CloudExternalDataManagerBase);
94 } // namespace policy
96 #endif // CHROME_BROWSER_CHROMEOS_POLICY_CLOUD_EXTERNAL_DATA_MANAGER_BASE_H_