peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 1 | // Copyright 2015 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 | |
michaelpg | 33eea59 | 2017-01-19 01:34:56 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_ANDROID_SERVICE_TAB_LAUNCHER_H_ |
| 6 | #define CHROME_BROWSER_ANDROID_SERVICE_TAB_LAUNCHER_H_ |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 7 | |
| 8 | #include "base/android/jni_android.h" |
| 9 | #include "base/callback_forward.h" |
Brett Wilson | f976d3f | 2017-08-18 17:23:39 | [diff] [blame] | 10 | #include "base/containers/id_map.h" |
avi | f57136c1 | 2015-12-25 23:27:45 | [diff] [blame] | 11 | #include "base/macros.h" |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 12 | #include "base/memory/singleton.h" |
| 13 | |
| 14 | namespace content { |
| 15 | class BrowserContext; |
| 16 | struct OpenURLParams; |
| 17 | class WebContents; |
| 18 | } |
| 19 | |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 20 | // Launcher for creating new tabs on Android from a background service, where |
peter | 244c761 | 2015-02-20 14:13:19 | [diff] [blame] | 21 | // there may not necessarily be an Activity or a tab model at all. When the |
| 22 | // tab has been launched, the user of this class will be informed with the |
| 23 | // content::WebContents instance associated with the tab. |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 24 | class ServiceTabLauncher { |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 25 | using TabLaunchedCallback = base::OnceCallback<void(content::WebContents*)>; |
peter | 244c761 | 2015-02-20 14:13:19 | [diff] [blame] | 26 | |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 27 | public: |
| 28 | // Returns the singleton instance of the service tab launcher. |
| 29 | static ServiceTabLauncher* GetInstance(); |
| 30 | |
| 31 | // Launches a new tab when we're in a Service rather than in an Activity. |
| 32 | // |callback| will be invoked with the resulting content::WebContents* when |
| 33 | // the tab is avialable. This method must only be called from the UI thread. |
| 34 | void LaunchTab(content::BrowserContext* browser_context, |
| 35 | const content::OpenURLParams& params, |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 36 | TabLaunchedCallback callback); |
peter | 244c761 | 2015-02-20 14:13:19 | [diff] [blame] | 37 | |
| 38 | // To be called when the tab for |request_id| has launched, with the |
| 39 | // associated |web_contents|. The WebContents must not yet have started |
| 40 | // the provisional load for the main frame of the navigation. |
| 41 | void OnTabLaunched(int request_id, content::WebContents* web_contents); |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 42 | |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 43 | private: |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 44 | friend struct base::DefaultSingletonTraits<ServiceTabLauncher>; |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 45 | |
| 46 | ServiceTabLauncher(); |
| 47 | ~ServiceTabLauncher(); |
| 48 | |
Brett Wilson | f976d3f | 2017-08-18 17:23:39 | [diff] [blame] | 49 | base::IDMap<std::unique_ptr<TabLaunchedCallback>> tab_launched_callbacks_; |
peter | 244c761 | 2015-02-20 14:13:19 | [diff] [blame] | 50 | |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 51 | DISALLOW_COPY_AND_ASSIGN(ServiceTabLauncher); |
| 52 | }; |
| 53 | |
michaelpg | 33eea59 | 2017-01-19 01:34:56 | [diff] [blame] | 54 | #endif // CHROME_BROWSER_ANDROID_SERVICE_TAB_LAUNCHER_H_ |