| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/webui/ntp/app_launcher_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 extension_misc::AppLaunchBucket ParseLaunchSource( | 61 extension_misc::AppLaunchBucket ParseLaunchSource( |
| 62 const std::string& launch_source) { | 62 const std::string& launch_source) { |
| 63 int bucket_num = extension_misc::APP_LAUNCH_BUCKET_INVALID; | 63 int bucket_num = extension_misc::APP_LAUNCH_BUCKET_INVALID; |
| 64 base::StringToInt(launch_source, &bucket_num); | 64 base::StringToInt(launch_source, &bucket_num); |
| 65 extension_misc::AppLaunchBucket bucket = | 65 extension_misc::AppLaunchBucket bucket = |
| 66 static_cast<extension_misc::AppLaunchBucket>(bucket_num); | 66 static_cast<extension_misc::AppLaunchBucket>(bucket_num); |
| 67 CHECK(bucket < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 67 CHECK(bucket < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 68 return bucket; | 68 return bucket; |
| 69 } | 69 } |
| 70 | 70 |
| 71 enum { |
| 72 APP_LAUNCHED_FROM_INDEX_WIDE_OFFSET = 100, |
| 73 APP_LAUNCHED_FROM_INDEX_BOUNDARY = 200, |
| 74 }; |
| 75 |
| 71 } // namespace | 76 } // namespace |
| 72 | 77 |
| 73 AppLauncherHandler::AppInstallInfo::AppInstallInfo() {} | 78 AppLauncherHandler::AppInstallInfo::AppInstallInfo() {} |
| 74 | 79 |
| 75 AppLauncherHandler::AppInstallInfo::~AppInstallInfo() {} | 80 AppLauncherHandler::AppInstallInfo::~AppInstallInfo() {} |
| 76 | 81 |
| 77 AppLauncherHandler::AppLauncherHandler(ExtensionService* extension_service) | 82 AppLauncherHandler::AppLauncherHandler(ExtensionService* extension_service) |
| 78 : extension_service_(extension_service), | 83 : extension_service_(extension_service), |
| 79 ignore_changes_(false), | 84 ignore_changes_(false), |
| 80 attempted_bookmark_app_install_(false), | 85 attempted_bookmark_app_install_(false), |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 base::Unretained(this))); | 233 base::Unretained(this))); |
| 229 web_ui()->RegisterMessageCallback("saveAppPageName", | 234 web_ui()->RegisterMessageCallback("saveAppPageName", |
| 230 base::Bind(&AppLauncherHandler::HandleSaveAppPageName, | 235 base::Bind(&AppLauncherHandler::HandleSaveAppPageName, |
| 231 base::Unretained(this))); | 236 base::Unretained(this))); |
| 232 web_ui()->RegisterMessageCallback("generateAppForLink", | 237 web_ui()->RegisterMessageCallback("generateAppForLink", |
| 233 base::Bind(&AppLauncherHandler::HandleGenerateAppForLink, | 238 base::Bind(&AppLauncherHandler::HandleGenerateAppForLink, |
| 234 base::Unretained(this))); | 239 base::Unretained(this))); |
| 235 web_ui()->RegisterMessageCallback("recordAppLaunchByURL", | 240 web_ui()->RegisterMessageCallback("recordAppLaunchByURL", |
| 236 base::Bind(&AppLauncherHandler::HandleRecordAppLaunchByURL, | 241 base::Bind(&AppLauncherHandler::HandleRecordAppLaunchByURL, |
| 237 base::Unretained(this))); | 242 base::Unretained(this))); |
| 243 web_ui()->RegisterMessageCallback("recordAppLaunchedFromIndex", |
| 244 base::Bind(&AppLauncherHandler::HandleRecordAppLaunchedFromIndex, |
| 245 base::Unretained(this))); |
| 238 web_ui()->RegisterMessageCallback("closeNotification", | 246 web_ui()->RegisterMessageCallback("closeNotification", |
| 239 base::Bind(&AppLauncherHandler::HandleNotificationClose, | 247 base::Bind(&AppLauncherHandler::HandleNotificationClose, |
| 240 base::Unretained(this))); | 248 base::Unretained(this))); |
| 241 web_ui()->RegisterMessageCallback("setNotificationsDisabled", | 249 web_ui()->RegisterMessageCallback("setNotificationsDisabled", |
| 242 base::Bind(&AppLauncherHandler::HandleSetNotificationsDisabled, | 250 base::Bind(&AppLauncherHandler::HandleSetNotificationsDisabled, |
| 243 base::Unretained(this))); | 251 base::Unretained(this))); |
| 244 } | 252 } |
| 245 | 253 |
| 246 void AppLauncherHandler::Observe(int type, | 254 void AppLauncherHandler::Observe(int type, |
| 247 const content::NotificationSource& source, | 255 const content::NotificationSource& source, |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 double source; | 770 double source; |
| 763 CHECK(args->GetDouble(1, &source)); | 771 CHECK(args->GetDouble(1, &source)); |
| 764 | 772 |
| 765 extension_misc::AppLaunchBucket bucket = | 773 extension_misc::AppLaunchBucket bucket = |
| 766 static_cast<extension_misc::AppLaunchBucket>(static_cast<int>(source)); | 774 static_cast<extension_misc::AppLaunchBucket>(static_cast<int>(source)); |
| 767 CHECK(source < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 775 CHECK(source < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 768 | 776 |
| 769 RecordAppLaunchByURL(Profile::FromWebUI(web_ui()), url, bucket); | 777 RecordAppLaunchByURL(Profile::FromWebUI(web_ui()), url, bucket); |
| 770 } | 778 } |
| 771 | 779 |
| 780 void AppLauncherHandler::HandleRecordAppLaunchedFromIndex( |
| 781 const base::ListValue* args) { |
| 782 double index_double; |
| 783 CHECK(args->GetDouble(0, &index_double)); |
| 784 bool wide; |
| 785 CHECK(args->GetBoolean(1, &wide)); |
| 786 |
| 787 // +1 to make it a natural (i.e. 1,2,3 instead of 0,1,2). |
| 788 size_t index = static_cast<size_t>(index_double) + 1; |
| 789 if (wide) |
| 790 index += APP_LAUNCHED_FROM_INDEX_WIDE_OFFSET; |
| 791 else if (index >= APP_LAUNCHED_FROM_INDEX_WIDE_OFFSET + 1) |
| 792 index = APP_LAUNCHED_FROM_INDEX_BOUNDARY + 1; |
| 793 |
| 794 UMA_HISTOGRAM_ENUMERATION("NewTabPage.AppLaunchedFromIndex", index, |
| 795 APP_LAUNCHED_FROM_INDEX_BOUNDARY); |
| 796 } |
| 797 |
| 772 void AppLauncherHandler::HandleNotificationClose(const ListValue* args) { | 798 void AppLauncherHandler::HandleNotificationClose(const ListValue* args) { |
| 773 std::string extension_id; | 799 std::string extension_id; |
| 774 CHECK(args->GetString(0, &extension_id)); | 800 CHECK(args->GetString(0, &extension_id)); |
| 775 | 801 |
| 776 const Extension* extension = extension_service_->GetExtensionById( | 802 const Extension* extension = extension_service_->GetExtensionById( |
| 777 extension_id, true); | 803 extension_id, true); |
| 778 if (!extension) | 804 if (!extension) |
| 779 return; | 805 return; |
| 780 | 806 |
| 781 UMA_HISTOGRAM_COUNTS("AppNotification.NTPNotificationClosed", 1); | 807 UMA_HISTOGRAM_COUNTS("AppNotification.NTPNotificationClosed", 1); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 | 1021 |
| 996 void AppLauncherHandler::UninstallDefaultApps() { | 1022 void AppLauncherHandler::UninstallDefaultApps() { |
| 997 AppsPromo* apps_promo = extension_service_->apps_promo(); | 1023 AppsPromo* apps_promo = extension_service_->apps_promo(); |
| 998 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 1024 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
| 999 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 1025 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
| 1000 iter != app_ids.end(); ++iter) { | 1026 iter != app_ids.end(); ++iter) { |
| 1001 if (extension_service_->GetExtensionById(*iter, true)) | 1027 if (extension_service_->GetExtensionById(*iter, true)) |
| 1002 extension_service_->UninstallExtension(*iter, false, NULL); | 1028 extension_service_->UninstallExtension(*iter, false, NULL); |
| 1003 } | 1029 } |
| 1004 } | 1030 } |
| OLD | NEW |