1 // Copyright 2020 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_NEARBY_SHARING_SCHEDULING_NEARBY_SHARE_SCHEDULER_FACTORY_H_
6 #define CHROME_BROWSER_NEARBY_SHARING_SCHEDULING_NEARBY_SHARE_SCHEDULER_FACTORY_H_
7 
8 #include <memory>
9 #include <string>
10 
11 #include "base/time/default_clock.h"
12 #include "chrome/browser/nearby_sharing/scheduling/nearby_share_expiration_scheduler.h"
13 #include "chrome/browser/nearby_sharing/scheduling/nearby_share_scheduler.h"
14 
15 class NearbyShareScheduler;
16 class PrefService;
17 
18 // Used to create instances of NearbyShareExpirationScheduler,
19 // NearbyShareOnDemandScheduler, and NearbySharePeriodicScheduler. A fake
20 // factory can also be set for testing purposes.
21 class NearbyShareSchedulerFactory {
22  public:
23   static std::unique_ptr<NearbyShareScheduler> CreateExpirationScheduler(
24       NearbyShareExpirationScheduler::ExpirationTimeFunctor
25           expiration_time_functor,
26       bool retry_failures,
27       bool require_connectivity,
28       const std::string& pref_name,
29       PrefService* pref_service,
30       NearbyShareScheduler::OnRequestCallback on_request_callback,
31       const base::Clock* clock = base::DefaultClock::GetInstance());
32 
33   static std::unique_ptr<NearbyShareScheduler> CreateOnDemandScheduler(
34       bool retry_failures,
35       bool require_connectivity,
36       const std::string& pref_name,
37       PrefService* pref_service,
38       NearbyShareScheduler::OnRequestCallback callback,
39       const base::Clock* clock = base::DefaultClock::GetInstance());
40 
41   static std::unique_ptr<NearbyShareScheduler> CreatePeriodicScheduler(
42       base::TimeDelta request_period,
43       bool retry_failures,
44       bool require_connectivity,
45       const std::string& pref_name,
46       PrefService* pref_service,
47       NearbyShareScheduler::OnRequestCallback callback,
48       const base::Clock* clock = base::DefaultClock::GetInstance());
49 
50   static void SetFactoryForTesting(NearbyShareSchedulerFactory* test_factory);
51 
52  protected:
53   virtual ~NearbyShareSchedulerFactory();
54 
55   virtual std::unique_ptr<NearbyShareScheduler>
56   CreateExpirationSchedulerInstance(
57       NearbyShareExpirationScheduler::ExpirationTimeFunctor
58           expiration_time_functor,
59       bool retry_failures,
60       bool require_connectivity,
61       const std::string& pref_name,
62       PrefService* pref_service,
63       NearbyShareScheduler::OnRequestCallback on_request_callback,
64       const base::Clock* clock) = 0;
65 
66   virtual std::unique_ptr<NearbyShareScheduler> CreateOnDemandSchedulerInstance(
67       bool retry_failures,
68       bool require_connectivity,
69       const std::string& pref_name,
70       PrefService* pref_service,
71       NearbyShareScheduler::OnRequestCallback callback,
72       const base::Clock* clock) = 0;
73 
74   virtual std::unique_ptr<NearbyShareScheduler> CreatePeriodicSchedulerInstance(
75       base::TimeDelta request_period,
76       bool retry_failures,
77       bool require_connectivity,
78       const std::string& pref_name,
79       PrefService* pref_service,
80       NearbyShareScheduler::OnRequestCallback callback,
81       const base::Clock* clock) = 0;
82 
83  private:
84   static NearbyShareSchedulerFactory* test_factory_;
85 };
86 
87 #endif  // CHROME_BROWSER_NEARBY_SHARING_SCHEDULING_NEARBY_SHARE_SCHEDULER_FACTORY_H_
88