OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_POLICY_CLOUD_EXTERNAL_POLICY_DATA_FETCHER_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_EXTERNAL_POLICY_DATA_FETCHER_H_ |
6 #define CHROME_BROWSER_POLICY_CLOUD_EXTERNAL_POLICY_DATA_FETCHER_H_ | 6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_EXTERNAL_POLICY_DATA_FETCHER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "components/policy/policy_export.h" |
18 #include "net/url_request/url_fetcher_delegate.h" | 19 #include "net/url_request/url_fetcher_delegate.h" |
19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
20 | 21 |
21 namespace base { | 22 namespace base { |
22 class SequencedTaskRunner; | 23 class SequencedTaskRunner; |
23 } | 24 } |
24 | 25 |
25 namespace net { | 26 namespace net { |
26 class URLFetcher; | 27 class URLFetcher; |
27 class URLRequestContextGetter; | 28 class URLRequestContextGetter; |
28 } | 29 } |
29 | 30 |
30 namespace policy { | 31 namespace policy { |
31 | 32 |
32 class ExternalPolicyDataFetcherBackend; | 33 class ExternalPolicyDataFetcherBackend; |
33 | 34 |
34 // This class handles network fetch jobs for the ExternalPolicyDataUpdater by | 35 // This class handles network fetch jobs for the ExternalPolicyDataUpdater by |
35 // forwarding them to an ExternalPolicyDataFetcherBackend running on a different | 36 // forwarding them to an ExternalPolicyDataFetcherBackend running on a different |
36 // thread. This is necessary because the ExternalPolicyDataUpdater runs on a | 37 // thread. This is necessary because the ExternalPolicyDataUpdater runs on a |
37 // background thread where network I/O is not allowed. | 38 // background thread where network I/O is not allowed. |
38 // The class can be instantiated on any thread but from then on, it must be | 39 // The class can be instantiated on any thread but from then on, it must be |
39 // accessed and destroyed on the background thread that the | 40 // accessed and destroyed on the background thread that the |
40 // ExternalPolicyDataUpdater runs on only. | 41 // ExternalPolicyDataUpdater runs on only. |
41 class ExternalPolicyDataFetcher { | 42 class POLICY_EXPORT ExternalPolicyDataFetcher { |
42 public: | 43 public: |
43 // The result of a fetch job. | 44 // The result of a fetch job. |
44 enum Result { | 45 enum Result { |
45 // Successful fetch. | 46 // Successful fetch. |
46 SUCCESS, | 47 SUCCESS, |
47 // The connection was interrupted. | 48 // The connection was interrupted. |
48 CONNECTION_INTERRUPTED, | 49 CONNECTION_INTERRUPTED, |
49 // Another network error occurred. | 50 // Another network error occurred. |
50 NETWORK_ERROR, | 51 NETWORK_ERROR, |
51 // Problem at the server. | 52 // Problem at the server. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 116 |
116 DISALLOW_COPY_AND_ASSIGN(ExternalPolicyDataFetcher); | 117 DISALLOW_COPY_AND_ASSIGN(ExternalPolicyDataFetcher); |
117 }; | 118 }; |
118 | 119 |
119 // This class handles network I/O for one or more ExternalPolicyDataFetchers. It | 120 // This class handles network I/O for one or more ExternalPolicyDataFetchers. It |
120 // can be instantiated on any thread that is allowed to reference | 121 // can be instantiated on any thread that is allowed to reference |
121 // URLRequestContextGetters (in Chrome, these are the UI and IO threads) and | 122 // URLRequestContextGetters (in Chrome, these are the UI and IO threads) and |
122 // CreateFrontend() may be called from the same thread after instantiation. From | 123 // CreateFrontend() may be called from the same thread after instantiation. From |
123 // then on, it must be accessed and destroyed on the thread that handles network | 124 // then on, it must be accessed and destroyed on the thread that handles network |
124 // I/O only (in Chrome, this is the IO thread). | 125 // I/O only (in Chrome, this is the IO thread). |
125 class ExternalPolicyDataFetcherBackend : public net::URLFetcherDelegate { | 126 class POLICY_EXPORT ExternalPolicyDataFetcherBackend |
| 127 : public net::URLFetcherDelegate { |
126 public: | 128 public: |
127 // Callback invoked when a fetch job finishes. If the fetch was successful, | 129 // Callback invoked when a fetch job finishes. If the fetch was successful, |
128 // the Result is SUCCESS and the scoped_ptr contains the retrieved data. | 130 // the Result is SUCCESS and the scoped_ptr contains the retrieved data. |
129 // Otherwise, Result indicates the type of error that occurred and the | 131 // Otherwise, Result indicates the type of error that occurred and the |
130 // scoped_ptr is NULL. | 132 // scoped_ptr is NULL. |
131 typedef base::Callback<void(ExternalPolicyDataFetcher::Job*, | 133 typedef base::Callback<void(ExternalPolicyDataFetcher::Job*, |
132 ExternalPolicyDataFetcher::Result, | 134 ExternalPolicyDataFetcher::Result, |
133 scoped_ptr<std::string>)> FetchCallback; | 135 scoped_ptr<std::string>)> FetchCallback; |
134 | 136 |
135 // |io_task_runner_| represents the thread that handles network I/O and that | 137 // |io_task_runner_| represents the thread that handles network I/O and that |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 JobMap job_map_; | 174 JobMap job_map_; |
173 | 175 |
174 base::WeakPtrFactory<ExternalPolicyDataFetcherBackend> weak_factory_; | 176 base::WeakPtrFactory<ExternalPolicyDataFetcherBackend> weak_factory_; |
175 | 177 |
176 DISALLOW_COPY_AND_ASSIGN(ExternalPolicyDataFetcherBackend); | 178 DISALLOW_COPY_AND_ASSIGN(ExternalPolicyDataFetcherBackend); |
177 }; | 179 }; |
178 | 180 |
179 | 181 |
180 } // namespace policy | 182 } // namespace policy |
181 | 183 |
182 #endif // CHROME_BROWSER_POLICY_CLOUD_EXTERNAL_POLICY_DATA_FETCHER_H_ | 184 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_EXTERNAL_POLICY_DATA_FETCHER_H_ |
OLD | NEW |