Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / android / banners / app_banner_data_fetcher_android.cc
blob6fa6931c7c2681a1e5f4ae6ecade3c22ddc8d141
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 #include "chrome/browser/android/banners/app_banner_data_fetcher_android.h"
7 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h"
8 #include "chrome/browser/ui/android/infobars/app_banner_infobar.h"
9 #include "third_party/skia/include/core/SkBitmap.h"
11 namespace banners {
13 AppBannerDataFetcherAndroid::AppBannerDataFetcherAndroid(
14 content::WebContents* web_contents,
15 base::WeakPtr<Delegate> weak_delegate,
16 int ideal_icon_size)
17 : AppBannerDataFetcher(web_contents, weak_delegate, ideal_icon_size) {
20 AppBannerDataFetcherAndroid::~AppBannerDataFetcherAndroid() {
23 std::string AppBannerDataFetcherAndroid::GetBannerType() {
24 return native_app_data_.is_null()
25 ? AppBannerDataFetcher::GetBannerType() : "android";
28 bool AppBannerDataFetcherAndroid::ContinueFetching(
29 const base::string16& app_title,
30 const std::string& app_package,
31 base::android::ScopedJavaLocalRef<jobject> app_data,
32 const GURL& image_url) {
33 set_app_title(app_title);
34 native_app_package_ = app_package;
35 native_app_data_.Reset(app_data);
36 return FetchIcon(image_url);
39 std::string AppBannerDataFetcherAndroid::GetAppIdentifier() {
40 return native_app_data_.is_null()
41 ? AppBannerDataFetcher::GetAppIdentifier() : native_app_package_;
44 infobars::InfoBar* AppBannerDataFetcherAndroid::CreateBanner(
45 const SkBitmap* icon,
46 const base::string16& title) {
47 content::WebContents* web_contents = GetWebContents();
48 DCHECK(web_contents);
50 infobars::InfoBar* infobar = nullptr;
51 if (native_app_data_.is_null()) {
52 scoped_ptr<AppBannerInfoBarDelegate> delegate(
53 new AppBannerInfoBarDelegate(title,
54 new SkBitmap(*icon),
55 web_app_data()));
57 infobar = new AppBannerInfoBar(delegate.Pass(), web_app_data().start_url);
58 if (infobar)
59 RecordDidShowBanner("AppBanner.WebApp.Shown");
60 } else {
61 scoped_ptr<AppBannerInfoBarDelegate> delegate(
62 new AppBannerInfoBarDelegate(title,
63 new SkBitmap(*icon),
64 native_app_data_,
65 native_app_package_));
66 infobar = new AppBannerInfoBar(delegate.Pass(), native_app_data_);
67 if (infobar)
68 RecordDidShowBanner("AppBanner.NativeApp.Shown");
71 return infobar;
74 } // namespace banners