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.internal.dagger; 17 18 import com.google.android.libraries.mobiledatadownload.delta.DeltaDecoder; 19 import com.google.android.libraries.mobiledatadownload.downloader.FileDownloader; 20 import com.google.common.base.Optional; 21 import com.google.common.base.Supplier; 22 import com.google.common.base.Suppliers; 23 import dagger.Module; 24 import dagger.Provides; 25 import javax.inject.Singleton; 26 27 /** Module for MDD Lib downloader dependencies * */ 28 @Module 29 public class DownloaderModule { 30 31 private final Optional<DeltaDecoder> deltaDecoderOptional; 32 private final Supplier<FileDownloader> fileDownloaderSupplier; 33 DownloaderModule( Optional<DeltaDecoder> deltaDecoderOptional, Supplier<FileDownloader> fileDownloaderSupplier)34 public DownloaderModule( 35 Optional<DeltaDecoder> deltaDecoderOptional, 36 Supplier<FileDownloader> fileDownloaderSupplier) { 37 this.deltaDecoderOptional = deltaDecoderOptional; 38 this.fileDownloaderSupplier = Suppliers.memoize(fileDownloaderSupplier); 39 } 40 41 @Provides 42 @Singleton provideFileDownloaderSupplier()43 Supplier<FileDownloader> provideFileDownloaderSupplier() { 44 return fileDownloaderSupplier; 45 } 46 47 @Provides 48 @Singleton provideDeltaDecoder()49 Optional<DeltaDecoder> provideDeltaDecoder() { 50 return deltaDecoderOptional; 51 } 52 } 53