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
3 // found in the LICENSE file.
4 
5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_NETWORK_REQUEST_FACTORY_H_
6 #define COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_NETWORK_REQUEST_FACTORY_H_
7 
8 #include <memory>
9 #include <set>
10 #include <string>
11 #include <vector>
12 
13 #include "components/offline_pages/core/prefetch/prefetch_types.h"
14 
15 namespace offline_pages {
16 class GetOperationRequest;
17 
18 class PrefetchNetworkRequestFactory {
19  public:
20   virtual ~PrefetchNetworkRequestFactory() = default;
21 
22   // Returns 'true' if there is at least one outstanding active network
23   // request. Used to determine if the background processing window can be
24   // closed.
25   virtual bool HasOutstandingRequests() const = 0;
26 
27   // Creates and starts a new GeneratePageBundle request, retaining ownership.
28   // If a GeneratePageBundle request for one or more specified URLs already
29   // exists, this will create another one regardless.
30   virtual void MakeGeneratePageBundleRequest(
31       const std::vector<std::string>& prefetch_urls,
32       const std::string& gcm_registration_id,
33       PrefetchRequestFinishedCallback callback) = 0;
34 
35   // Returns a list of URLs included into all currently ongoing
36   // GeneratePageBundle requests.
37   virtual std::unique_ptr<std::set<std::string>> GetAllUrlsRequested()
38       const = 0;
39 
40   // Creates and starts a new GetOperationRequest, retaining ownership.
41   // If a GetOperation request already exists with the same operation name, this
42   // will cancel the existing request and start a new one.
43   virtual void MakeGetOperationRequest(
44       const std::string& operation_name,
45       PrefetchRequestFinishedCallback callback) = 0;
46 
47   // Returns the current GetOperationRequest with the given name, if any.
48   virtual GetOperationRequest* FindGetOperationRequestByName(
49       const std::string& operation_name) const = 0;
50 
51   // Returns a list of operation names included into all currently ongoing
52   // GetOperation requests.
53   virtual std::unique_ptr<std::set<std::string>> GetAllOperationNamesRequested()
54       const = 0;
55 };
56 
57 }  // namespace offline_pages
58 
59 #endif  // COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_NETWORK_REQUEST_FACTORY_H_
60