OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_ANDROID_SERVICE_TAB_LAUNCHER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_SERVICE_TAB_LAUNCHER_H_ |
6 #define CHROME_BROWSER_ANDROID_SERVICE_TAB_LAUNCHER_H_ | 6 #define CHROME_BROWSER_ANDROID_SERVICE_TAB_LAUNCHER_H_ |
7 | 7 |
8 #include <map> | |
9 | |
8 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
9 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
10 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
11 | 13 |
12 namespace content { | 14 namespace content { |
13 class BrowserContext; | 15 class BrowserContext; |
14 struct OpenURLParams; | 16 struct OpenURLParams; |
15 class WebContents; | 17 class WebContents; |
16 } | 18 } |
17 | 19 |
18 namespace chrome { | 20 namespace chrome { |
19 namespace android { | 21 namespace android { |
20 | 22 |
21 // Launcher for creating new tabs on Android from a background service, where | 23 // 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. | 24 // there may not necessarily be an Activity or a tab model at all. When the |
25 // tab has been launched, the user of this class will be informed with the | |
26 // content::WebContents instance associated with the tab. | |
23 class ServiceTabLauncher { | 27 class ServiceTabLauncher { |
28 using TabLaunchedCallback = base::Callback<void(content::WebContents*)>; | |
29 | |
24 public: | 30 public: |
25 // Returns the singleton instance of the service tab launcher. | 31 // Returns the singleton instance of the service tab launcher. |
26 static ServiceTabLauncher* GetInstance(); | 32 static ServiceTabLauncher* GetInstance(); |
27 | 33 |
28 // Launches a new tab when we're in a Service rather than in an Activity. | 34 // Launches a new tab when we're in a Service rather than in an Activity. |
29 // |callback| will be invoked with the resulting content::WebContents* when | 35 // |callback| will be invoked with the resulting content::WebContents* when |
30 // the tab is avialable. This method must only be called from the UI thread. | 36 // the tab is avialable. This method must only be called from the UI thread. |
31 void LaunchTab(content::BrowserContext* browser_context, | 37 void LaunchTab(content::BrowserContext* browser_context, |
32 const content::OpenURLParams& params, | 38 const content::OpenURLParams& params, |
33 const base::Callback<void(content::WebContents*)>& callback); | 39 const TabLaunchedCallback& callback); |
40 | |
41 // To be called when the tab for |request_id| has launched, with the | |
42 // associated |web_contents|. The WebContents must not yet have started | |
43 // the provisional load for the main frame of the navigation. | |
44 void OnTabLaunched(int request_id, content::WebContents* web_contents); | |
34 | 45 |
35 static bool RegisterServiceTabLauncher(JNIEnv* env); | 46 static bool RegisterServiceTabLauncher(JNIEnv* env); |
36 | 47 |
37 private: | 48 private: |
38 friend struct DefaultSingletonTraits<ServiceTabLauncher>; | 49 friend struct DefaultSingletonTraits<ServiceTabLauncher>; |
39 | 50 |
40 ServiceTabLauncher(); | 51 ServiceTabLauncher(); |
41 ~ServiceTabLauncher(); | 52 ~ServiceTabLauncher(); |
42 | 53 |
43 base::android::ScopedJavaGlobalRef<jobject> java_object_; | 54 base::android::ScopedJavaGlobalRef<jobject> java_object_; |
44 | 55 |
56 std::map<int, TabLaunchedCallback> tab_launched_callbacks_; | |
mlamouri (slow - plz ping)
2015/02/19 14:51:17
Could you use an IDMap? It will prevent having to
Bernhard Bauer
2015/02/19 15:03:05
FTR: Copies of callbacks are cheap, as they just c
Peter Beverloo
2015/02/19 16:03:07
Done.
| |
57 int last_request_id_; | |
58 | |
45 DISALLOW_COPY_AND_ASSIGN(ServiceTabLauncher); | 59 DISALLOW_COPY_AND_ASSIGN(ServiceTabLauncher); |
46 }; | 60 }; |
47 | 61 |
48 } // namespace android | 62 } // namespace android |
49 } // namespace chrome | 63 } // namespace chrome |
50 | 64 |
51 #endif // CHROME_BROWSER_ANDROID_SERVICE_TAB_LAUNCHER_H_ | 65 #endif // CHROME_BROWSER_ANDROID_SERVICE_TAB_LAUNCHER_H_ |
OLD | NEW |