1 // Copyright 2019 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 #include "chrome/browser/download/android/download_startup_utils.h"
6 
7 #include <jni.h>
8 #include <utility>
9 
10 #include "chrome/browser/android/profile_key_startup_accessor.h"
11 #include "chrome/browser/download/android/jni_headers/DownloadStartupUtils_jni.h"
12 #include "chrome/browser/download/download_manager_utils.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "components/download/public/common/in_progress_download_manager.h"
15 
JNI_DownloadStartupUtils_EnsureDownloadSystemInitialized(JNIEnv * env,jboolean is_full_browser_started,jboolean is_off_the_record)16 static void JNI_DownloadStartupUtils_EnsureDownloadSystemInitialized(
17     JNIEnv* env,
18     jboolean is_full_browser_started,
19     jboolean is_off_the_record) {
20   DCHECK(is_full_browser_started || !is_off_the_record)
21       << "OffTheRecord mode must load full browser.";
22   std::vector<Profile*> profiles;
23   if (is_full_browser_started) {
24     Profile* active_profile = ProfileManager::GetActiveUserProfile();
25     if (is_off_the_record)
26       profiles = active_profile->GetAllOffTheRecordProfiles();
27     else
28       profiles.push_back(active_profile);
29   }
30   for (Profile* profile : profiles)
31     DownloadStartupUtils::EnsureDownloadSystemInitialized(
32         profile->GetProfileKey());
33 }
34 
35 // static
EnsureDownloadSystemInitialized(ProfileKey * profile_key)36 ProfileKey* DownloadStartupUtils::EnsureDownloadSystemInitialized(
37     ProfileKey* profile_key) {
38   if (!profile_key)
39     profile_key = ProfileKeyStartupAccessor::GetInstance()->profile_key();
40   DownloadManagerUtils::GetInProgressDownloadManager(profile_key);
41   return profile_key;
42 }
43