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.
5 #ifndef COMPONENTS_SERVICE_TAB_LAUNCHER_BROWSER_ANDROID_SERVICE_TAB_LAUNCHER_H_
6 #define COMPONENTS_SERVICE_TAB_LAUNCHER_BROWSER_ANDROID_SERVICE_TAB_LAUNCHER_H_
8 #include "base/android/jni_android.h"
9 #include "base/callback_forward.h"
10 #include "base/id_map.h"
11 #include "base/memory/singleton.h"
19 namespace service_tab_launcher
{
21 // Launcher for creating new tabs on Android from a background service, where
22 // there may not necessarily be an Activity or a tab model at all. When the
23 // tab has been launched, the user of this class will be informed with the
24 // content::WebContents instance associated with the tab.
25 class ServiceTabLauncher
{
26 using TabLaunchedCallback
= base::Callback
<void(content::WebContents
*)>;
29 // Returns the singleton instance of the service tab launcher.
30 static ServiceTabLauncher
* GetInstance();
32 // Launches a new tab when we're in a Service rather than in an Activity.
33 // |callback| will be invoked with the resulting content::WebContents* when
34 // the tab is avialable. This method must only be called from the UI thread.
35 void LaunchTab(content::BrowserContext
* browser_context
,
36 const content::OpenURLParams
& params
,
37 const TabLaunchedCallback
& callback
);
39 // To be called when the tab for |request_id| has launched, with the
40 // associated |web_contents|. The WebContents must not yet have started
41 // the provisional load for the main frame of the navigation.
42 void OnTabLaunched(int request_id
, content::WebContents
* web_contents
);
44 static bool RegisterServiceTabLauncher(JNIEnv
* env
);
47 friend struct base::DefaultSingletonTraits
<ServiceTabLauncher
>;
50 ~ServiceTabLauncher();
52 IDMap
<TabLaunchedCallback
> tab_launched_callbacks_
;
54 base::android::ScopedJavaGlobalRef
<jobject
> java_object_
;
56 DISALLOW_COPY_AND_ASSIGN(ServiceTabLauncher
);
59 } // namespace service_tab_launcher
61 #endif // COMPONENTS_SERVICE_TAB_LAUNCHER_BROWSER_ANDROID_SERVICE_TAB_LAUNCHER_H_