Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 COMPONENTS_DOODLE_DOODLE_FETCHER_H_ | 5 #ifndef COMPONENTS_DOODLE_DOODLE_FETCHER_H_ |
| 6 #define COMPONENTS_DOODLE_DOODLE_FETCHER_H_ | 6 #define COMPONENTS_DOODLE_DOODLE_FETCHER_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/optional.h" | 9 #include "base/optional.h" |
| 10 #include "components/doodle/doodle_types.h" | 10 #include "components/doodle/doodle_types.h" |
| 11 | 11 |
| 12 namespace base { | |
| 13 class TimeDelta; | |
| 14 } | |
| 15 | |
| 12 namespace doodle { | 16 namespace doodle { |
| 13 | 17 |
| 14 // Interface for fetching the current doodle from the network. | 18 // Interface for fetching the current doodle from the network. |
| 15 // It asynchronously calls a callback when fetching the doodle information from | 19 // It asynchronously calls a callback when fetching the doodle information from |
| 16 // the remote enpoint finishes. | 20 // the remote enpoint finishes. |
| 17 // DoodleFetcherImpl is the default implementation; this interface exists to | 21 // DoodleFetcherImpl is the default implementation; this interface exists to |
| 18 // make it easy to use fakes or mocks in tests. | 22 // make it easy to use fakes or mocks in tests. |
| 19 class DoodleFetcher { | 23 class DoodleFetcher { |
| 20 public: | 24 public: |
| 21 // Callback that is invoked when the fetching is done. | 25 // Callback that is invoked when the fetching is done. |
| 22 // |doodle_config| will only contain a value if |state| is AVAILABLE. | 26 // |time_to_live| will only be meaningful, and |doodle_config| will only |
| 27 // contain a value, if |state| is AVAILABLE. | |
| 23 using FinishedCallback = base::OnceCallback<void( | 28 using FinishedCallback = base::OnceCallback<void( |
| 24 DoodleState state, | 29 DoodleState state, |
| 30 base::TimeDelta time_to_live, | |
| 25 const base::Optional<DoodleConfig>& doodle_config)>; | 31 const base::Optional<DoodleConfig>& doodle_config)>; |
|
Marc Treib
2017/03/02 11:42:51
As an alternative, we could wrap ttl and config in
fhorschig
2017/03/02 13:18:08
Doesn't sound too bad but I think for three parame
| |
| 26 | 32 |
| 27 virtual ~DoodleFetcher() = default; | 33 virtual ~DoodleFetcher() = default; |
| 28 | 34 |
| 29 // Fetches a doodle asynchronously. The |callback| is called with a | 35 // Fetches a doodle asynchronously. The |callback| is called with a |
| 30 // DoodleState indicating whether the request succeded in fetching a doodle. | 36 // DoodleState indicating whether the request succeded in fetching a doodle. |
| 31 // If a fetch is already running, the callback will be queued and invoked with | 37 // If a fetch is already running, the callback will be queued and invoked with |
| 32 // the result from the next completed request. | 38 // the result from the next completed request. |
| 33 virtual void FetchDoodle(FinishedCallback callback) = 0; | 39 virtual void FetchDoodle(FinishedCallback callback) = 0; |
| 34 }; | 40 }; |
| 35 | 41 |
| 36 } // namespace doodle | 42 } // namespace doodle |
| 37 | 43 |
| 38 #endif // COMPONENTS_DOODLE_DOODLE_FETCHER_H_ | 44 #endif // COMPONENTS_DOODLE_DOODLE_FETCHER_H_ |
| OLD | NEW |