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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/dom_ui/app_launcher_handler.h" 5 #include "chrome/browser/dom_ui/app_launcher_handler.h"
6 6
7 #include "app/animation.h" 7 #include "app/animation.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_split.h" 10 #include "base/string_split.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/app_launched_animation.h" 14 #include "chrome/browser/app_launched_animation.h"
15 #include "chrome/browser/dom_ui/shown_sections_handler.h"
15 #include "chrome/browser/extensions/default_apps.h" 16 #include "chrome/browser/extensions/default_apps.h"
16 #include "chrome/browser/extensions/extension_prefs.h" 17 #include "chrome/browser/extensions/extension_prefs.h"
17 #include "chrome/browser/extensions/extension_service.h" 18 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/platform_util.h" 19 #include "chrome/browser/platform_util.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/tab_contents/tab_contents.h" 21 #include "chrome/browser/tab_contents/tab_contents.h"
21 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/browser_list.h" 23 #include "chrome/browser/ui/browser_list.h"
23 #include "chrome/browser/ui/browser_window.h" 24 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 69
69 CHECK(params.size() == 2); 70 CHECK(params.size() == 2);
70 71
71 return params.at(1) == "true"; 72 return params.at(1) == "true";
72 } 73 }
73 74
74 } // namespace 75 } // namespace
75 76
76 AppLauncherHandler::AppLauncherHandler(ExtensionService* extension_service) 77 AppLauncherHandler::AppLauncherHandler(ExtensionService* extension_service)
77 : extensions_service_(extension_service), 78 : extensions_service_(extension_service),
78 promo_active_(false) { 79 promo_active_(false),
80 ignore_changes_(false) {
79 } 81 }
80 82
81 AppLauncherHandler::~AppLauncherHandler() {} 83 AppLauncherHandler::~AppLauncherHandler() {}
82 84
83 // static 85 // static
84 void AppLauncherHandler::CreateAppInfo(const Extension* extension, 86 void AppLauncherHandler::CreateAppInfo(const Extension* extension,
85 ExtensionPrefs* extension_prefs, 87 ExtensionPrefs* extension_prefs,
86 DictionaryValue* value) { 88 DictionaryValue* value) {
87 value->Clear(); 89 value->Clear();
88 value->SetString("id", extension->id()); 90 value->SetString("id", extension->id());
(...skipping 15 matching lines...) Expand all
104 int app_launch_index = extension_prefs->GetAppLaunchIndex(extension->id()); 106 int app_launch_index = extension_prefs->GetAppLaunchIndex(extension->id());
105 if (app_launch_index == -1) { 107 if (app_launch_index == -1) {
106 // Make sure every app has a launch index (some predate the launch index). 108 // Make sure every app has a launch index (some predate the launch index).
107 app_launch_index = extension_prefs->GetNextAppLaunchIndex(); 109 app_launch_index = extension_prefs->GetNextAppLaunchIndex();
108 extension_prefs->SetAppLaunchIndex(extension->id(), app_launch_index); 110 extension_prefs->SetAppLaunchIndex(extension->id(), app_launch_index);
109 } 111 }
110 value->SetInteger("app_launch_index", app_launch_index); 112 value->SetInteger("app_launch_index", app_launch_index);
111 } 113 }
112 114
113 // static 115 // static
114 bool AppLauncherHandler::HandlePing(const std::string& path) { 116 bool AppLauncherHandler::HandlePing(Profile* profile, const std::string& path) {
115 if (path.find(kLaunchWebStorePingURL) != std::string::npos) { 117 bool is_web_store_ping =
116 RecordWebStoreLaunch(IsPromoActive(path)); 118 path.find(kLaunchWebStorePingURL) != std::string::npos;
117 return true; 119 bool is_app_launch_ping =
118 } else if (path.find(kLaunchAppPingURL) != std::string::npos) { 120 path.find(kLaunchAppPingURL) != std::string::npos;
119 RecordAppLaunch(IsPromoActive(path));
120 return true;
121 }
122 121
123 return false; 122 if (!is_web_store_ping && !is_app_launch_ping)
123 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
124
125 bool is_promo_active = IsPromoActive(path);
126
127 if (is_web_store_ping)
128 RecordWebStoreLaunch(is_promo_active);
129 else
130 RecordAppLaunch(is_promo_active);
131
132 if (is_promo_active)
133 profile->GetExtensionService()->default_apps()->SetPromoHidden();
134
135 return true;
124 } 136 }
125 137
126 DOMMessageHandler* AppLauncherHandler::Attach(DOMUI* dom_ui) { 138 DOMMessageHandler* AppLauncherHandler::Attach(DOMUI* dom_ui) {
127 // TODO(arv): Add initialization code to the Apps store etc. 139 // TODO(arv): Add initialization code to the Apps store etc.
128 return DOMMessageHandler::Attach(dom_ui); 140 return DOMMessageHandler::Attach(dom_ui);
129 } 141 }
130 142
131 void AppLauncherHandler::RegisterMessages() { 143 void AppLauncherHandler::RegisterMessages() {
132 dom_ui_->RegisterMessageCallback("getApps", 144 dom_ui_->RegisterMessageCallback("getApps",
133 NewCallback(this, &AppLauncherHandler::HandleGetApps)); 145 NewCallback(this, &AppLauncherHandler::HandleGetApps));
134 dom_ui_->RegisterMessageCallback("launchApp", 146 dom_ui_->RegisterMessageCallback("launchApp",
135 NewCallback(this, &AppLauncherHandler::HandleLaunchApp)); 147 NewCallback(this, &AppLauncherHandler::HandleLaunchApp));
136 dom_ui_->RegisterMessageCallback("setLaunchType", 148 dom_ui_->RegisterMessageCallback("setLaunchType",
137 NewCallback(this, &AppLauncherHandler::HandleSetLaunchType)); 149 NewCallback(this, &AppLauncherHandler::HandleSetLaunchType));
138 dom_ui_->RegisterMessageCallback("uninstallApp", 150 dom_ui_->RegisterMessageCallback("uninstallApp",
139 NewCallback(this, &AppLauncherHandler::HandleUninstallApp)); 151 NewCallback(this, &AppLauncherHandler::HandleUninstallApp));
140 dom_ui_->RegisterMessageCallback("hideAppsPromo", 152 dom_ui_->RegisterMessageCallback("hideAppsPromo",
141 NewCallback(this, &AppLauncherHandler::HandleHideAppsPromo)); 153 NewCallback(this, &AppLauncherHandler::HandleHideAppsPromo));
142 dom_ui_->RegisterMessageCallback("createAppShortcut", 154 dom_ui_->RegisterMessageCallback("createAppShortcut",
143 NewCallback(this, &AppLauncherHandler::HandleCreateAppShortcut)); 155 NewCallback(this, &AppLauncherHandler::HandleCreateAppShortcut));
144 } 156 }
145 157
146 void AppLauncherHandler::Observe(NotificationType type, 158 void AppLauncherHandler::Observe(NotificationType type,
147 const NotificationSource& source, 159 const NotificationSource& source,
148 const NotificationDetails& details) { 160 const NotificationDetails& details) {
161 if (ignore_changes_)
162 return;
163
149 switch (type.value) { 164 switch (type.value) {
150 case NotificationType::EXTENSION_LOADED: 165 case NotificationType::EXTENSION_LOADED:
151 case NotificationType::EXTENSION_UNLOADED: 166 case NotificationType::EXTENSION_UNLOADED:
152 if (dom_ui_->tab_contents()) 167 if (dom_ui_->tab_contents())
153 HandleGetApps(NULL); 168 HandleGetApps(NULL);
154 break; 169 break;
155 case NotificationType::PREF_CHANGED: { 170 case NotificationType::PREF_CHANGED: {
156 if (!dom_ui_->tab_contents()) 171 if (!dom_ui_->tab_contents())
157 break; 172 break;
158 173
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 #endif 209 #endif
195 210
196 dictionary->SetBoolean( 211 dictionary->SetBoolean(
197 "showLauncher", 212 "showLauncher",
198 extensions_service_->default_apps()->ShouldShowAppLauncher( 213 extensions_service_->default_apps()->ShouldShowAppLauncher(
199 extensions_service_->GetAppIds())); 214 extensions_service_->GetAppIds()));
200 } 215 }
201 216
202 void AppLauncherHandler::HandleGetApps(const ListValue* args) { 217 void AppLauncherHandler::HandleGetApps(const ListValue* args) {
203 DictionaryValue dictionary; 218 DictionaryValue dictionary;
204 FillAppDictionary(&dictionary);
205 219
206 // Tell the client whether to show the promo for this view. We don't do this 220 // Tell the client whether to show the promo for this view. We don't do this
207 // in the case of PREF_CHANGED because: 221 // in the case of PREF_CHANGED because:
208 // 222 //
209 // a) At that point in time, depending on the pref that changed, it can look 223 // a) At that point in time, depending on the pref that changed, it can look
210 // like the set of apps installed has changed, and we will mark the promo 224 // like the set of apps installed has changed, and we will mark the promo
211 // expired. 225 // expired.
212 // b) Conceptually, it doesn't really make sense to count a 226 // b) Conceptually, it doesn't really make sense to count a
213 // prefchange-triggered refresh as a promo 'view'. 227 // prefchange-triggered refresh as a promo 'view'.
214 DefaultApps* default_apps = extensions_service_->default_apps(); 228 DefaultApps* default_apps = extensions_service_->default_apps();
215 if (default_apps->ShouldShowPromo(extensions_service_->GetAppIds())) { 229 bool promo_just_expired = false;
230 if (default_apps->ShouldShowPromo(extensions_service_->GetAppIds(),
231 &promo_just_expired)) {
216 dictionary.SetBoolean("showPromo", true); 232 dictionary.SetBoolean("showPromo", true);
217 default_apps->DidShowPromo();
218 promo_active_ = true; 233 promo_active_ = true;
219 } else { 234 } else {
235 if (promo_just_expired) {
236 ignore_changes_ = true;
237 UninstallDefaultApps();
238 ignore_changes_ = false;
239 ShownSectionsHandler::SetShownSection(dom_ui_->GetProfile()->GetPrefs(),
240 THUMB);
241 }
220 dictionary.SetBoolean("showPromo", false); 242 dictionary.SetBoolean("showPromo", false);
221 promo_active_ = false; 243 promo_active_ = false;
222 } 244 }
223 245
246 FillAppDictionary(&dictionary);
224 dom_ui_->CallJavascriptFunction(L"getAppsCallback", dictionary); 247 dom_ui_->CallJavascriptFunction(L"getAppsCallback", dictionary);
225 248
226 // First time we get here we set up the observer so that we can tell update 249 // First time we get here we set up the observer so that we can tell update
227 // the apps as they change. 250 // the apps as they change.
228 if (registrar_.IsEmpty()) { 251 if (registrar_.IsEmpty()) {
229 registrar_.Add(this, NotificationType::EXTENSION_LOADED, 252 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
230 NotificationService::AllSources()); 253 NotificationService::AllSources());
231 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, 254 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
232 NotificationService::AllSources()); 255 NotificationService::AllSources());
233 } 256 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 extension_misc::LaunchContainer launch_container = 303 extension_misc::LaunchContainer launch_container =
281 extensions_service_->extension_prefs()->GetLaunchContainer( 304 extensions_service_->extension_prefs()->GetLaunchContainer(
282 extension, ExtensionPrefs::LAUNCH_REGULAR); 305 extension, ExtensionPrefs::LAUNCH_REGULAR);
283 306
284 TabContents* new_contents = Browser::OpenApplication( 307 TabContents* new_contents = Browser::OpenApplication(
285 profile, extension, launch_container, old_contents); 308 profile, extension, launch_container, old_contents);
286 309
287 if (new_contents != old_contents && browser->tab_count() > 1) 310 if (new_contents != old_contents && browser->tab_count() > 1)
288 browser->CloseTabContents(old_contents); 311 browser->CloseTabContents(old_contents);
289 312
290 if (extension_id != extension_misc::kWebStoreAppId) 313 if (extension_id != extension_misc::kWebStoreAppId) {
291 RecordAppLaunch(promo_active_); 314 RecordAppLaunch(promo_active_);
315 extensions_service_->default_apps()->SetPromoHidden();
316 }
292 } 317 }
293 318
294 void AppLauncherHandler::HandleSetLaunchType(const ListValue* args) { 319 void AppLauncherHandler::HandleSetLaunchType(const ListValue* args) {
295 std::string extension_id; 320 std::string extension_id;
296 int launch_type; 321 int launch_type;
297 if (!args->GetString(0, &extension_id) || 322 if (!args->GetString(0, &extension_id) ||
298 !ExtractInt(args, 1, &launch_type)) { 323 !ExtractInt(args, 1, &launch_type)) {
299 NOTREACHED(); 324 NOTREACHED();
300 return; 325 return;
301 } 326 }
(...skipping 22 matching lines...) Expand all
324 } 349 }
325 350
326 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { 351 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) {
327 // If the user has intentionally hidden the promotion, we'll uninstall all the 352 // If the user has intentionally hidden the promotion, we'll uninstall all the
328 // default apps (we know the user hasn't installed any apps on their own at 353 // default apps (we know the user hasn't installed any apps on their own at
329 // this point, or the promotion wouldn't have been shown). 354 // this point, or the promotion wouldn't have been shown).
330 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, 355 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram,
331 extension_misc::PROMO_CLOSE, 356 extension_misc::PROMO_CLOSE,
332 extension_misc::PROMO_BUCKET_BOUNDARY); 357 extension_misc::PROMO_BUCKET_BOUNDARY);
333 358
334 DefaultApps* default_apps = extensions_service_->default_apps(); 359 ShownSectionsHandler::SetShownSection(dom_ui_->GetProfile()->GetPrefs(),
335 const ExtensionIdSet& app_ids = default_apps->default_apps(); 360 THUMB);
336 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); 361 ignore_changes_ = true;
337 iter != app_ids.end(); ++iter) { 362 UninstallDefaultApps();
338 if (extensions_service_->GetExtensionById(*iter, true))
339 extensions_service_->UninstallExtension(*iter, false);
340 }
341
342 extensions_service_->default_apps()->SetPromoHidden(); 363 extensions_service_->default_apps()->SetPromoHidden();
364 ignore_changes_ = false;
365 HandleGetApps(NULL);
343 } 366 }
344 367
345 void AppLauncherHandler::HandleCreateAppShortcut(const ListValue* args) { 368 void AppLauncherHandler::HandleCreateAppShortcut(const ListValue* args) {
346 std::string extension_id; 369 std::string extension_id;
347 if (!args->GetString(0, &extension_id)) { 370 if (!args->GetString(0, &extension_id)) {
348 NOTREACHED(); 371 NOTREACHED();
349 return; 372 return;
350 } 373 }
351 374
352 const Extension* extension = 375 const Extension* extension =
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 // We make this check for the case of minimized windows, unit tests, etc. 434 // We make this check for the case of minimized windows, unit tests, etc.
412 if (platform_util::IsVisible(dom_ui_->tab_contents()->GetNativeView()) && 435 if (platform_util::IsVisible(dom_ui_->tab_contents()->GetNativeView()) &&
413 Animation::ShouldRenderRichAnimation()) { 436 Animation::ShouldRenderRichAnimation()) {
414 #if defined(OS_WIN) 437 #if defined(OS_WIN)
415 AppLaunchedAnimation::Show(extension, rect); 438 AppLaunchedAnimation::Show(extension, rect);
416 #else 439 #else
417 NOTIMPLEMENTED(); 440 NOTIMPLEMENTED();
418 #endif 441 #endif
419 } 442 }
420 } 443 }
444
445 void AppLauncherHandler::UninstallDefaultApps() {
446 DefaultApps* default_apps = extensions_service_->default_apps();
447 const ExtensionIdSet& app_ids = default_apps->default_apps();
448 for (ExtensionIdSet::const_iterator iter = app_ids.begin();
449 iter != app_ids.end(); ++iter) {
450 if (extensions_service_->GetExtensionById(*iter, true))
451 extensions_service_->UninstallExtension(*iter, false);
452 }
453 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698