Chromium Code Reviews| 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 #include "chrome/browser/banners/app_banner_manager_desktop.h" | 5 #include "chrome/browser/banners/app_banner_manager_desktop.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/string_number_conversions.h" | |
| 9 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 10 #include "chrome/browser/banners/app_banner_infobar_delegate_desktop.h" | 9 #include "chrome/browser/banners/app_banner_infobar_delegate_desktop.h" |
| 11 #include "chrome/browser/banners/app_banner_metrics.h" | 10 #include "chrome/browser/banners/app_banner_metrics.h" |
| 12 #include "chrome/browser/banners/app_banner_settings_helper.h" | 11 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 13 #include "chrome/browser/extensions/bookmark_app_helper.h" | 12 #include "chrome/browser/extensions/bookmark_app_helper.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/render_messages.h" | |
| 17 #include "chrome/common/web_application_info.h" | 15 #include "chrome/common/web_application_info.h" |
| 18 #include "content/public/browser/render_frame_host.h" | |
| 19 #include "extensions/common/constants.h" | 16 #include "extensions/common/constants.h" |
| 20 | 17 |
| 21 DEFINE_WEB_CONTENTS_USER_DATA_KEY(banners::AppBannerManagerDesktop); | 18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(banners::AppBannerManagerDesktop); |
| 22 | 19 |
| 23 namespace banners { | 20 namespace banners { |
| 24 | 21 |
| 25 bool AppBannerManagerDesktop::IsEnabled() { | 22 bool AppBannerManagerDesktop::IsEnabled() { |
| 26 #if defined(OS_CHROMEOS) | 23 #if defined(OS_CHROMEOS) |
| 27 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | 24 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 28 switches::kDisableAddToShelf); | 25 switches::kDisableAddToShelf); |
| 29 #else | 26 #else |
| 30 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 27 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 31 switches::kEnableAddToShelf); | 28 switches::kEnableAddToShelf); |
| 32 #endif | 29 #endif |
| 33 } | 30 } |
| 34 | 31 |
| 35 AppBannerManagerDesktop::AppBannerManagerDesktop( | 32 AppBannerManagerDesktop::AppBannerManagerDesktop( |
| 36 content::WebContents* web_contents) | 33 content::WebContents* web_contents) |
| 37 : AppBannerManager(web_contents) { } | 34 : AppBannerManager(web_contents) { } |
| 38 | 35 |
| 39 AppBannerManagerDesktop::~AppBannerManagerDesktop() { } | 36 AppBannerManagerDesktop::~AppBannerManagerDesktop() { } |
| 40 | 37 |
| 41 void AppBannerManagerDesktop::DidFinishCreatingBookmarkApp( | 38 void AppBannerManagerDesktop::DidFinishCreatingBookmarkApp( |
| 42 const extensions::Extension* extension, | 39 const extensions::Extension* extension, |
| 43 const WebApplicationInfo& web_app_info) { | 40 const WebApplicationInfo& web_app_info) { |
| 44 content::WebContents* contents = web_contents(); | 41 content::WebContents* contents = web_contents(); |
| 45 if (contents) { | 42 if (contents) { |
| 46 // A null extension pointer indicates that the bookmark app install was | 43 // A null extension pointer indicates that the bookmark app install was |
| 47 // not successful. | 44 // not successful. Call Stop() to terminate the flow. Don't record a dismiss |
| 45 // metric here because the banner isn't necessarily dismissed. | |
|
benwells
2016/10/12 03:00:17
Is this an orthogonal fix?
dominickn
2016/10/13 00:18:15
The Stop() or the no dismiss? The Stop() fix is so
| |
| 48 if (extension == nullptr) { | 46 if (extension == nullptr) { |
| 49 contents->GetMainFrame()->Send(new ChromeViewMsg_AppBannerDismissed( | 47 Stop(); |
| 50 contents->GetMainFrame()->GetRoutingID(), event_request_id())); | |
| 51 | |
| 52 AppBannerSettingsHelper::RecordBannerDismissEvent( | |
| 53 contents, GetAppIdentifier(), AppBannerSettingsHelper::WEB); | |
| 54 } else { | 48 } else { |
| 55 contents->GetMainFrame()->Send(new ChromeViewMsg_AppBannerAccepted( | 49 SendBannerAccepted(event_request_id()); |
| 56 contents->GetMainFrame()->GetRoutingID(), event_request_id(), | |
| 57 GetBannerType())); | |
| 58 | 50 |
| 59 AppBannerSettingsHelper::RecordBannerInstallEvent( | 51 AppBannerSettingsHelper::RecordBannerInstallEvent( |
| 60 contents, GetAppIdentifier(), AppBannerSettingsHelper::WEB); | 52 contents, GetAppIdentifier(), AppBannerSettingsHelper::WEB); |
| 61 } | 53 } |
| 62 } | 54 } |
| 63 } | 55 } |
| 64 | 56 |
| 65 bool AppBannerManagerDesktop::IsWebAppInstalled( | 57 bool AppBannerManagerDesktop::IsWebAppInstalled( |
| 66 content::BrowserContext* browser_context, | 58 content::BrowserContext* browser_context, |
| 67 const GURL& start_url) { | 59 const GURL& start_url) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 double score) { | 104 double score) { |
| 113 // Explicitly forbid banners from triggering on navigation unless this is | 105 // Explicitly forbid banners from triggering on navigation unless this is |
| 114 // enabled. | 106 // enabled. |
| 115 if (!IsEnabled()) | 107 if (!IsEnabled()) |
| 116 return; | 108 return; |
| 117 | 109 |
| 118 AppBannerManager::OnEngagementIncreased(web_contents, url, score); | 110 AppBannerManager::OnEngagementIncreased(web_contents, url, score); |
| 119 } | 111 } |
| 120 | 112 |
| 121 } // namespace banners | 113 } // namespace banners |
| OLD | NEW |