blob: e42cb2918e296f49676c0b6df24f10920d4f5c79 [file] [log] [blame]
peterbbcccc12015-02-11 22:23:331// 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
michaelpg33eea592017-01-19 01:34:565#ifndef CHROME_BROWSER_ANDROID_SERVICE_TAB_LAUNCHER_H_
6#define CHROME_BROWSER_ANDROID_SERVICE_TAB_LAUNCHER_H_
peterbbcccc12015-02-11 22:23:337
8#include "base/android/jni_android.h"
9#include "base/callback_forward.h"
Brett Wilsonf976d3f2017-08-18 17:23:3910#include "base/containers/id_map.h"
avif57136c12015-12-25 23:27:4511#include "base/macros.h"
peterbbcccc12015-02-11 22:23:3312#include "base/memory/singleton.h"
13
14namespace content {
15class BrowserContext;
16struct OpenURLParams;
17class WebContents;
18}
19
peterbbcccc12015-02-11 22:23:3320// Launcher for creating new tabs on Android from a background service, where
peter244c7612015-02-20 14:13:1921// 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.
peterbbcccc12015-02-11 22:23:3324class ServiceTabLauncher {
danakja9fe91c2019-05-01 19:02:2925 using TabLaunchedCallback = base::OnceCallback<void(content::WebContents*)>;
peter244c7612015-02-20 14:13:1926
peterbbcccc12015-02-11 22:23:3327 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,
danakja9fe91c2019-05-01 19:02:2936 TabLaunchedCallback callback);
peter244c7612015-02-20 14:13:1937
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);
peterbbcccc12015-02-11 22:23:3342
peterbbcccc12015-02-11 22:23:3343 private:
olli.raula36aa8be2015-09-10 11:14:2244 friend struct base::DefaultSingletonTraits<ServiceTabLauncher>;
peterbbcccc12015-02-11 22:23:3345
46 ServiceTabLauncher();
47 ~ServiceTabLauncher();
48
Brett Wilsonf976d3f2017-08-18 17:23:3949 base::IDMap<std::unique_ptr<TabLaunchedCallback>> tab_launched_callbacks_;
peter244c7612015-02-20 14:13:1950
peterbbcccc12015-02-11 22:23:3351 DISALLOW_COPY_AND_ASSIGN(ServiceTabLauncher);
52};
53
michaelpg33eea592017-01-19 01:34:5654#endif // CHROME_BROWSER_ANDROID_SERVICE_TAB_LAUNCHER_H_