| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/app_list/start_page_handler.h" | 5 #include "chrome/browser/ui/webui/app_list/start_page_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "base/version.h" | 13 #include "base/version.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/search/hotword_service.h" | 15 #include "chrome/browser/search/hotword_service.h" |
| 15 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 16 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| 16 #include "chrome/browser/ui/app_list/app_list_service.h" | 17 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 17 #include "chrome/browser/ui/app_list/start_page_service.h" | 18 #include "chrome/browser/ui/app_list/start_page_service.h" |
| 18 #include "chrome/browser/ui/host_desktop.h" | 19 #include "chrome/browser/ui/host_desktop.h" |
| 19 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 20 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 21 #include "components/update_client/update_query_params.h" | 22 #include "components/update_client/update_query_params.h" |
| 22 #include "content/public/browser/web_ui.h" | 23 #include "content/public/browser/web_ui.h" |
| 23 #include "extensions/browser/extension_registry.h" | 24 #include "extensions/browser/extension_registry.h" |
| 24 #include "extensions/browser/extension_system.h" | 25 #include "extensions/browser/extension_system.h" |
| 25 #include "extensions/common/constants.h" | 26 #include "extensions/common/constants.h" |
| 26 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
| 27 #include "extensions/common/extension_icon_set.h" | 28 #include "extensions/common/extension_icon_set.h" |
| 28 #include "ui/app_list/app_list_switches.h" | 29 #include "ui/app_list/app_list_switches.h" |
| 29 #include "ui/app_list/speech_ui_model_observer.h" | 30 #include "ui/app_list/speech_ui_model_observer.h" |
| 30 #include "ui/events/event_constants.h" | 31 #include "ui/events/event_constants.h" |
| 31 | 32 |
| 32 namespace app_list { | 33 namespace app_list { |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| 37 const char kAppListDoodleActionHistogram[] = "Apps.AppListDoodleAction"; |
| 38 |
| 39 // Interactions a user has with the app list doodle. This enum must not have its |
| 40 // order altered as it is used in histograms. |
| 41 enum DoodleAction { |
| 42 DOODLE_SHOWN = 0, |
| 43 DOODLE_CLICKED, |
| 44 // Add values here. |
| 45 |
| 46 DOODLE_ACTION_LAST, |
| 47 }; |
| 48 |
| 36 #if defined(OS_CHROMEOS) | 49 #if defined(OS_CHROMEOS) |
| 37 const char kOldHotwordExtensionVersionString[] = "0.1.1.5023"; | 50 const char kOldHotwordExtensionVersionString[] = "0.1.1.5023"; |
| 38 #endif | 51 #endif |
| 39 | 52 |
| 40 } // namespace | 53 } // namespace |
| 41 | 54 |
| 42 StartPageHandler::StartPageHandler() : extension_registry_observer_(this) { | 55 StartPageHandler::StartPageHandler() : extension_registry_observer_(this) { |
| 43 } | 56 } |
| 44 | 57 |
| 45 StartPageHandler::~StartPageHandler() { | 58 StartPageHandler::~StartPageHandler() { |
| 46 } | 59 } |
| 47 | 60 |
| 48 void StartPageHandler::RegisterMessages() { | 61 void StartPageHandler::RegisterMessages() { |
| 49 web_ui()->RegisterMessageCallback( | 62 web_ui()->RegisterMessageCallback( |
| 63 "appListShown", base::Bind(&StartPageHandler::HandleAppListShown, |
| 64 base::Unretained(this))); |
| 65 web_ui()->RegisterMessageCallback( |
| 66 "doodleClicked", base::Bind(&StartPageHandler::HandleDoodleClicked, |
| 67 base::Unretained(this))); |
| 68 web_ui()->RegisterMessageCallback( |
| 50 "initialize", | 69 "initialize", |
| 51 base::Bind(&StartPageHandler::HandleInitialize, base::Unretained(this))); | 70 base::Bind(&StartPageHandler::HandleInitialize, base::Unretained(this))); |
| 52 web_ui()->RegisterMessageCallback( | 71 web_ui()->RegisterMessageCallback( |
| 53 "launchApp", | 72 "launchApp", |
| 54 base::Bind(&StartPageHandler::HandleLaunchApp, base::Unretained(this))); | 73 base::Bind(&StartPageHandler::HandleLaunchApp, base::Unretained(this))); |
| 55 web_ui()->RegisterMessageCallback( | 74 web_ui()->RegisterMessageCallback( |
| 56 "speechResult", | 75 "speechResult", |
| 57 base::Bind(&StartPageHandler::HandleSpeechResult, | 76 base::Bind(&StartPageHandler::HandleSpeechResult, |
| 58 base::Unretained(this))); | 77 base::Unretained(this))); |
| 59 web_ui()->RegisterMessageCallback( | 78 web_ui()->RegisterMessageCallback( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 base::Version(kOldHotwordExtensionVersionString)) <= 0 && | 125 base::Version(kOldHotwordExtensionVersionString)) <= 0 && |
| 107 !HotwordService::IsExperimentalHotwordingEnabled()) { | 126 !HotwordService::IsExperimentalHotwordingEnabled()) { |
| 108 StartPageService* service = StartPageService::Get(profile); | 127 StartPageService* service = StartPageService::Get(profile); |
| 109 web_ui()->CallJavascriptFunction( | 128 web_ui()->CallJavascriptFunction( |
| 110 "appList.startPage.setHotwordEnabled", | 129 "appList.startPage.setHotwordEnabled", |
| 111 base::FundamentalValue(service->HotwordEnabled())); | 130 base::FundamentalValue(service->HotwordEnabled())); |
| 112 } | 131 } |
| 113 } | 132 } |
| 114 #endif | 133 #endif |
| 115 | 134 |
| 135 void StartPageHandler::HandleAppListShown(const base::ListValue* args) { |
| 136 bool doodle_shown = false; |
| 137 if (args->GetBoolean(0, &doodle_shown) && doodle_shown) { |
| 138 UMA_HISTOGRAM_ENUMERATION(kAppListDoodleActionHistogram, DOODLE_SHOWN, |
| 139 DOODLE_ACTION_LAST); |
| 140 } |
| 141 } |
| 142 |
| 143 void StartPageHandler::HandleDoodleClicked(const base::ListValue* args) { |
| 144 UMA_HISTOGRAM_ENUMERATION(kAppListDoodleActionHistogram, DOODLE_CLICKED, |
| 145 DOODLE_ACTION_LAST); |
| 146 } |
| 147 |
| 116 void StartPageHandler::HandleInitialize(const base::ListValue* args) { | 148 void StartPageHandler::HandleInitialize(const base::ListValue* args) { |
| 117 Profile* profile = Profile::FromWebUI(web_ui()); | 149 Profile* profile = Profile::FromWebUI(web_ui()); |
| 118 StartPageService* service = StartPageService::Get(profile); | 150 StartPageService* service = StartPageService::Get(profile); |
| 119 if (!service) | 151 if (!service) |
| 120 return; | 152 return; |
| 121 | 153 |
| 122 service->WebUILoaded(); | 154 service->WebUILoaded(); |
| 123 | 155 |
| 124 #if defined(OS_CHROMEOS) | 156 #if defined(OS_CHROMEOS) |
| 125 if (app_list::switches::IsVoiceSearchEnabled() && | 157 if (app_list::switches::IsVoiceSearchEnabled() && |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 else if (state_string == "NETWORK_ERROR") | 254 else if (state_string == "NETWORK_ERROR") |
| 223 new_state = SPEECH_RECOGNITION_NETWORK_ERROR; | 255 new_state = SPEECH_RECOGNITION_NETWORK_ERROR; |
| 224 | 256 |
| 225 StartPageService* service = | 257 StartPageService* service = |
| 226 StartPageService::Get(Profile::FromWebUI(web_ui())); | 258 StartPageService::Get(Profile::FromWebUI(web_ui())); |
| 227 if (service) | 259 if (service) |
| 228 service->OnSpeechRecognitionStateChanged(new_state); | 260 service->OnSpeechRecognitionStateChanged(new_state); |
| 229 } | 261 } |
| 230 | 262 |
| 231 } // namespace app_list | 263 } // namespace app_list |
| OLD | NEW |