• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.google.android.libraries.mobiledatadownload.downloader;
17 
18 import com.google.android.libraries.mobiledatadownload.DownloadException;
19 import com.google.common.util.concurrent.Futures;
20 import com.google.common.util.concurrent.ListenableFuture;
21 import com.google.errorprone.annotations.CheckReturnValue;
22 
23 /**
24  * Responsible for downloading files in MDD.
25  *
26  * <p>Implement this interface to replace the MDD networking stack.
27  */
28 public interface FileDownloader {
29   /**
30    * Start downloading the file. The download result is provided asynchronously as a {@link
31    * ListenableFuture} that resolves when the download is complete.
32    *
33    * <p>The download can be cancelled by calling {@link ListenableFuture#cancel} on the future
34    * instance returned by this method. Cancellation is best-effort and does not guarantee that the
35    * download will stop immediately, as it is impossible to stop a thread that is in the middle of
36    * reading bytes off the network.
37    *
38    * @param downloadRequest the download request.
39    * @return - A ListenableFuture representing the download state of the file. The ListenableFuture
40    *     fails with {@link DownloadException} if downloading fails.
41    */
42   @CheckReturnValue
startDownloading(DownloadRequest downloadRequest)43   ListenableFuture<Void> startDownloading(DownloadRequest downloadRequest);
44 
45   /**
46    * Checks if the content of url is changed. The ListenableFuture throws {@link DownloadException}
47    * when it fails.
48    */
49   @CheckReturnValue
isContentChanged( CheckContentChangeRequest checkContentChangeRequest)50   default ListenableFuture<CheckContentChangeResponse> isContentChanged(
51       CheckContentChangeRequest checkContentChangeRequest) {
52     return Futures.immediateFailedFuture(new UnsupportedOperationException("Not implemented"));
53   }
54 }
55