Move StartsWith[ASCII] to base namespace.
[chromium-blink-merge.git] / chrome / browser / android / shortcut_helper.h
blob9f872f29c9a052ec7749c488ad6eb0a467113557
1 // Copyright 2013 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 CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_
6 #define CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_
8 #include "base/android/jni_android.h"
9 #include "base/android/jni_weak_ref.h"
10 #include "base/basictypes.h"
11 #include "chrome/browser/android/shortcut_data_fetcher.h"
12 #include "chrome/browser/android/shortcut_info.h"
13 #include "content/public/common/manifest.h"
15 namespace content {
16 class WebContents;
17 } // namespace content
19 namespace IPC {
20 class Message;
23 class GURL;
25 // ShortcutHelper is the C++ counterpart of org.chromium.chrome.browser's
26 // ShortcutHelper in Java. The object is owned by the Java object. It is created
27 // from there via a JNI (Initialize) call and MUST BE DESTROYED via Destroy().
28 class ShortcutHelper : public ShortcutDataFetcher::Observer {
29 public:
30 ShortcutHelper(JNIEnv* env,
31 jobject obj,
32 content::WebContents* web_contents);
34 // Called by the Java counterpart to destroy its native half.
35 void Destroy(JNIEnv* env, jobject obj);
37 // Registers JNI hooks.
38 static bool RegisterShortcutHelper(JNIEnv* env);
40 // Adds a shortcut to the current URL to the Android home screen.
41 void AddShortcut(JNIEnv* env, jobject obj, jstring title);
43 // Adds a shortcut to the launcher using a SkBitmap.
44 // Must be called on the IO thread.
45 static void AddShortcutInBackgroundWithSkBitmap(const ShortcutInfo& info,
46 const SkBitmap& icon_bitmap);
48 // ShortcutDataFetcher::Observer
49 void OnTitleAvailable(const base::string16& title) override;
50 void OnDataAvailable(const ShortcutInfo& info, const SkBitmap& icon) override;
51 SkBitmap FinalizeLauncherIcon(const SkBitmap& icon, const GURL& url) override;
53 private:
54 virtual ~ShortcutHelper();
56 // Called only when the ShortcutDataFetcher has retrieved all of the
57 // data needed to add the shortcut.
58 void AddShortcut(const ShortcutInfo& info, const SkBitmap& icon);
60 void RecordAddToHomescreen();
62 // Points to the Java object.
63 base::android::ScopedJavaGlobalRef<jobject> java_ref_;
65 // Whether the user has requested that a shortcut be added while a fetch was
66 // in progress.
67 bool add_shortcut_pending_;
69 // Fetches data required to add a shortcut.
70 scoped_refptr<ShortcutDataFetcher> data_fetcher_;
72 DISALLOW_COPY_AND_ASSIGN(ShortcutHelper);
75 #endif // CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_