Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8988)

Unified Diff: chrome/browser/dom_ui/app_launcher_handler.cc

Issue 6162006: Changes to default apps promo per ui leads: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unit tests Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/dom_ui/app_launcher_handler.cc
diff --git a/chrome/browser/dom_ui/app_launcher_handler.cc b/chrome/browser/dom_ui/app_launcher_handler.cc
index 58ee56fc5489b492e9a70e588ef9049e71be6114..0a71c10f6c8b4641bca62be27841cf9e8bbf57d8 100644
--- a/chrome/browser/dom_ui/app_launcher_handler.cc
+++ b/chrome/browser/dom_ui/app_launcher_handler.cc
@@ -12,6 +12,7 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/app_launched_animation.h"
+#include "chrome/browser/dom_ui/shown_sections_handler.h"
#include "chrome/browser/extensions/default_apps.h"
#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/extensions/extension_service.h"
@@ -75,7 +76,8 @@ bool IsPromoActive(const std::string& path) {
AppLauncherHandler::AppLauncherHandler(ExtensionService* extension_service)
: extensions_service_(extension_service),
- promo_active_(false) {
+ promo_active_(false),
+ ignore_changes_(false) {
}
AppLauncherHandler::~AppLauncherHandler() {}
@@ -111,16 +113,26 @@ void AppLauncherHandler::CreateAppInfo(const Extension* extension,
}
// static
-bool AppLauncherHandler::HandlePing(const std::string& path) {
- if (path.find(kLaunchWebStorePingURL) != std::string::npos) {
- RecordWebStoreLaunch(IsPromoActive(path));
- return true;
- } else if (path.find(kLaunchAppPingURL) != std::string::npos) {
- RecordAppLaunch(IsPromoActive(path));
- return true;
- }
+bool AppLauncherHandler::HandlePing(Profile* profile, const std::string& path) {
+ bool is_web_store_ping =
+ path.find(kLaunchWebStorePingURL) != std::string::npos;
+ bool is_app_launch_ping =
+ path.find(kLaunchAppPingURL) != std::string::npos;
- return false;
+ if (!is_web_store_ping && !is_app_launch_ping)
+ return false;
Erik does not do reviews 2011/01/10 16:48:57 is there any legit way to hit this? should this b
Aaron Boodman 2011/01/10 19:36:19 Yes, it is legit. We send every request for chrome
+
+ bool is_promo_active = IsPromoActive(path);
+
+ if (is_web_store_ping)
+ RecordWebStoreLaunch(is_promo_active);
+ else
+ RecordAppLaunch(is_promo_active);
+
+ if (is_promo_active)
+ profile->GetExtensionService()->default_apps()->SetPromoHidden();
+
+ return true;
}
DOMMessageHandler* AppLauncherHandler::Attach(DOMUI* dom_ui) {
@@ -146,6 +158,9 @@ void AppLauncherHandler::RegisterMessages() {
void AppLauncherHandler::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
+ if (ignore_changes_)
+ return;
+
switch (type.value) {
case NotificationType::EXTENSION_LOADED:
case NotificationType::EXTENSION_UNLOADED:
@@ -201,7 +216,6 @@ void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) {
void AppLauncherHandler::HandleGetApps(const ListValue* args) {
DictionaryValue dictionary;
- FillAppDictionary(&dictionary);
// Tell the client whether to show the promo for this view. We don't do this
// in the case of PREF_CHANGED because:
@@ -212,15 +226,24 @@ void AppLauncherHandler::HandleGetApps(const ListValue* args) {
// b) Conceptually, it doesn't really make sense to count a
// prefchange-triggered refresh as a promo 'view'.
DefaultApps* default_apps = extensions_service_->default_apps();
- if (default_apps->ShouldShowPromo(extensions_service_->GetAppIds())) {
+ bool promo_just_expired = false;
+ if (default_apps->ShouldShowPromo(extensions_service_->GetAppIds(),
+ &promo_just_expired)) {
dictionary.SetBoolean("showPromo", true);
- default_apps->DidShowPromo();
promo_active_ = true;
} else {
+ if (promo_just_expired) {
+ ignore_changes_ = true;
+ UninstallDefaultApps();
+ ignore_changes_ = false;
+ ShownSectionsHandler::SetShownSection(dom_ui_->GetProfile()->GetPrefs(),
+ THUMB);
+ }
dictionary.SetBoolean("showPromo", false);
promo_active_ = false;
}
+ FillAppDictionary(&dictionary);
dom_ui_->CallJavascriptFunction(L"getAppsCallback", dictionary);
// First time we get here we set up the observer so that we can tell update
@@ -287,8 +310,10 @@ void AppLauncherHandler::HandleLaunchApp(const ListValue* args) {
if (new_contents != old_contents && browser->tab_count() > 1)
browser->CloseTabContents(old_contents);
- if (extension_id != extension_misc::kWebStoreAppId)
+ if (extension_id != extension_misc::kWebStoreAppId) {
RecordAppLaunch(promo_active_);
+ extensions_service_->default_apps()->SetPromoHidden();
+ }
}
void AppLauncherHandler::HandleSetLaunchType(const ListValue* args) {
@@ -331,15 +356,13 @@ void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) {
extension_misc::PROMO_CLOSE,
extension_misc::PROMO_BUCKET_BOUNDARY);
- DefaultApps* default_apps = extensions_service_->default_apps();
- const ExtensionIdSet& app_ids = default_apps->default_apps();
- for (ExtensionIdSet::const_iterator iter = app_ids.begin();
- iter != app_ids.end(); ++iter) {
- if (extensions_service_->GetExtensionById(*iter, true))
- extensions_service_->UninstallExtension(*iter, false);
- }
-
+ ShownSectionsHandler::SetShownSection(dom_ui_->GetProfile()->GetPrefs(),
+ THUMB);
+ ignore_changes_ = true;
+ UninstallDefaultApps();
extensions_service_->default_apps()->SetPromoHidden();
+ ignore_changes_ = false;
+ HandleGetApps(NULL);
}
void AppLauncherHandler::HandleCreateAppShortcut(const ListValue* args) {
@@ -418,3 +441,13 @@ void AppLauncherHandler::AnimateAppIcon(const Extension* extension,
#endif
}
}
+
+void AppLauncherHandler::UninstallDefaultApps() {
+ DefaultApps* default_apps = extensions_service_->default_apps();
+ const ExtensionIdSet& app_ids = default_apps->default_apps();
+ for (ExtensionIdSet::const_iterator iter = app_ids.begin();
+ iter != app_ids.end(); ++iter) {
+ if (extensions_service_->GetExtensionById(*iter, true))
+ extensions_service_->UninstallExtension(*iter, false);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698