David Black | 71ab74d | 2018-04-12 06:52:31 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
David Black | e8f81504 | 2018-03-28 18:59:37 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
David Black | 00fdce3 | 2018-05-10 20:59:14 | [diff] [blame] | 5 | #include "ash/assistant/assistant_controller.h" |
David Black | e8f81504 | 2018-03-28 18:59:37 | [diff] [blame] | 6 | |
Meilin Wang | 4980022 | 2018-08-22 17:27:48 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | #include <utility> |
| 9 | |
David Black | 6b4b1ad2 | 2018-08-21 02:45:08 | [diff] [blame] | 10 | #include "ash/assistant/assistant_cache_controller.h" |
David Black | e802d406 | 2018-06-29 01:59:05 | [diff] [blame] | 11 | #include "ash/assistant/assistant_controller_observer.h" |
David Black | 9766ecd | 2018-06-20 18:29:11 | [diff] [blame] | 12 | #include "ash/assistant/assistant_interaction_controller.h" |
wutao | 16db603c | 2018-07-10 06:43:59 | [diff] [blame] | 13 | #include "ash/assistant/assistant_notification_controller.h" |
David Black | c22e435 | 2018-07-11 21:29:48 | [diff] [blame] | 14 | #include "ash/assistant/assistant_screen_context_controller.h" |
David Black | ee6f32b5 | 2018-08-09 21:28:46 | [diff] [blame] | 15 | #include "ash/assistant/assistant_setup_controller.h" |
David Black | 1d1b1b67 | 2018-06-20 21:41:57 | [diff] [blame] | 16 | #include "ash/assistant/assistant_ui_controller.h" |
David Black | edaf0c3 | 2018-06-28 22:06:39 | [diff] [blame] | 17 | #include "ash/assistant/util/deep_link_util.h" |
David Black | 2f7a70c3 | 2018-06-26 02:14:22 | [diff] [blame] | 18 | #include "ash/new_window_controller.h" |
David Black | e1a4b9ed | 2018-04-19 19:55:08 | [diff] [blame] | 19 | #include "ash/session/session_controller.h" |
David Black | e8f81504 | 2018-03-28 18:59:37 | [diff] [blame] | 20 | #include "ash/shell.h" |
David Black | d08c051 | 2018-08-21 17:18:26 | [diff] [blame] | 21 | #include "ash/utility/screenshot_controller.h" |
Yue Li | bf33defd | 2018-08-01 21:04:06 | [diff] [blame] | 22 | #include "ash/voice_interaction/voice_interaction_controller.h" |
Muyuan Li | 0070f44d | 2018-05-16 02:57:23 | [diff] [blame] | 23 | #include "base/bind.h" |
| 24 | #include "base/memory/scoped_refptr.h" |
David Black | e1a4b9ed | 2018-04-19 19:55:08 | [diff] [blame] | 25 | #include "base/unguessable_token.h" |
David Black | e8f81504 | 2018-03-28 18:59:37 | [diff] [blame] | 26 | |
| 27 | namespace ash { |
| 28 | |
David Black | 00fdce3 | 2018-05-10 20:59:14 | [diff] [blame] | 29 | AssistantController::AssistantController() |
Muyuan Li | ed7c7640 | 2018-08-07 23:59:00 | [diff] [blame] | 30 | : assistant_volume_control_binding_(this), |
David Black | 02974f8 | 2018-08-21 22:56:05 | [diff] [blame] | 31 | assistant_cache_controller_( |
| 32 | std::make_unique<AssistantCacheController>(this)), |
Muyuan Li | ed7c7640 | 2018-08-07 23:59:00 | [diff] [blame] | 33 | assistant_interaction_controller_( |
David Black | 2f7a70c3 | 2018-06-26 02:14:22 | [diff] [blame] | 34 | std::make_unique<AssistantInteractionController>(this)), |
wutao | 16db603c | 2018-07-10 06:43:59 | [diff] [blame] | 35 | assistant_notification_controller_( |
| 36 | std::make_unique<AssistantNotificationController>(this)), |
David Black | c22e435 | 2018-07-11 21:29:48 | [diff] [blame] | 37 | assistant_screen_context_controller_( |
David Black | 1f58bcc | 2018-07-12 17:59:40 | [diff] [blame] | 38 | std::make_unique<AssistantScreenContextController>(this)), |
David Black | ee6f32b5 | 2018-08-09 21:28:46 | [diff] [blame] | 39 | assistant_setup_controller_( |
| 40 | std::make_unique<AssistantSetupController>(this)), |
David Black | c22e435 | 2018-07-11 21:29:48 | [diff] [blame] | 41 | assistant_ui_controller_(std::make_unique<AssistantUiController>(this)), |
Yue Li | bf33defd | 2018-08-01 21:04:06 | [diff] [blame] | 42 | voice_interaction_binding_(this), |
wutao | 16db603c | 2018-07-10 06:43:59 | [diff] [blame] | 43 | weak_factory_(this) { |
Yue Li | bf33defd | 2018-08-01 21:04:06 | [diff] [blame] | 44 | mojom::VoiceInteractionObserverPtr ptr; |
| 45 | voice_interaction_binding_.Bind(mojo::MakeRequest(&ptr)); |
| 46 | Shell::Get()->voice_interaction_controller()->AddObserver(std::move(ptr)); |
| 47 | |
David Black | f946f83 | 2018-07-13 17:29:09 | [diff] [blame] | 48 | AddObserver(this); |
David Black | 1f58bcc | 2018-07-12 17:59:40 | [diff] [blame] | 49 | NotifyConstructed(); |
Muyuan Li | ed7c7640 | 2018-08-07 23:59:00 | [diff] [blame] | 50 | chromeos::CrasAudioHandler::Get()->AddAudioObserver(this); |
David Black | 4703d7b | 2018-06-22 00:16:39 | [diff] [blame] | 51 | } |
David Black | e8f81504 | 2018-03-28 18:59:37 | [diff] [blame] | 52 | |
David Black | 4703d7b | 2018-06-22 00:16:39 | [diff] [blame] | 53 | AssistantController::~AssistantController() { |
Muyuan Li | ed7c7640 | 2018-08-07 23:59:00 | [diff] [blame] | 54 | chromeos::CrasAudioHandler::Get()->RemoveAudioObserver(this); |
David Black | 1f58bcc | 2018-07-12 17:59:40 | [diff] [blame] | 55 | NotifyDestroying(); |
David Black | f946f83 | 2018-07-13 17:29:09 | [diff] [blame] | 56 | RemoveObserver(this); |
David Black | 4703d7b | 2018-06-22 00:16:39 | [diff] [blame] | 57 | } |
David Black | e8f81504 | 2018-03-28 18:59:37 | [diff] [blame] | 58 | |
David Black | 00fdce3 | 2018-05-10 20:59:14 | [diff] [blame] | 59 | void AssistantController::BindRequest( |
| 60 | mojom::AssistantControllerRequest request) { |
David Black | 75f9fec | 2018-05-17 22:10:39 | [diff] [blame] | 61 | assistant_controller_bindings_.AddBinding(this, std::move(request)); |
David Black | e8f81504 | 2018-03-28 18:59:37 | [diff] [blame] | 62 | } |
| 63 | |
Muyuan Li | ed7c7640 | 2018-08-07 23:59:00 | [diff] [blame] | 64 | void AssistantController::BindRequest( |
| 65 | mojom::AssistantVolumeControlRequest request) { |
| 66 | assistant_volume_control_binding_.Bind(std::move(request)); |
| 67 | } |
| 68 | |
David Black | e802d406 | 2018-06-29 01:59:05 | [diff] [blame] | 69 | void AssistantController::AddObserver(AssistantControllerObserver* observer) { |
| 70 | observers_.AddObserver(observer); |
| 71 | } |
| 72 | |
| 73 | void AssistantController::RemoveObserver( |
| 74 | AssistantControllerObserver* observer) { |
| 75 | observers_.RemoveObserver(observer); |
| 76 | } |
| 77 | |
David Black | 00fdce3 | 2018-05-10 20:59:14 | [diff] [blame] | 78 | void AssistantController::SetAssistant( |
David Black | e8f81504 | 2018-03-28 18:59:37 | [diff] [blame] | 79 | chromeos::assistant::mojom::AssistantPtr assistant) { |
David Black | 4c3656c | 2018-04-19 17:31:47 | [diff] [blame] | 80 | assistant_ = std::move(assistant); |
| 81 | |
David Black | 4703d7b | 2018-06-22 00:16:39 | [diff] [blame] | 82 | // Provide reference to sub-controllers. |
David Black | 9766ecd | 2018-06-20 18:29:11 | [diff] [blame] | 83 | assistant_interaction_controller_->SetAssistant(assistant_.get()); |
wutao | 16db603c | 2018-07-10 06:43:59 | [diff] [blame] | 84 | assistant_notification_controller_->SetAssistant(assistant_.get()); |
David Black | c22e435 | 2018-07-11 21:29:48 | [diff] [blame] | 85 | assistant_screen_context_controller_->SetAssistant(assistant_.get()); |
| 86 | assistant_ui_controller_->SetAssistant(assistant_.get()); |
David Black | 4c3656c | 2018-04-19 17:31:47 | [diff] [blame] | 87 | } |
| 88 | |
David Black | 7ffd284 | 2018-05-25 01:25:53 | [diff] [blame] | 89 | void AssistantController::SetAssistantImageDownloader( |
| 90 | mojom::AssistantImageDownloaderPtr assistant_image_downloader) { |
| 91 | assistant_image_downloader_ = std::move(assistant_image_downloader); |
| 92 | } |
| 93 | |
David Black | ee6f32b5 | 2018-08-09 21:28:46 | [diff] [blame] | 94 | // TODO(dmblack): Call SetAssistantSetup directly on AssistantSetupController |
| 95 | // instead of going through AssistantController. |
Yue Li | bf89f72a | 2018-06-18 16:51:16 | [diff] [blame] | 96 | void AssistantController::SetAssistantSetup( |
| 97 | mojom::AssistantSetupPtr assistant_setup) { |
| 98 | assistant_setup_ = std::move(assistant_setup); |
David Black | ee6f32b5 | 2018-08-09 21:28:46 | [diff] [blame] | 99 | assistant_setup_controller_->SetAssistantSetup(assistant_setup_.get()); |
David Black | 9766ecd | 2018-06-20 18:29:11 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | void AssistantController::SetWebContentsManager( |
| 103 | mojom::WebContentsManagerPtr web_contents_manager) { |
| 104 | web_contents_manager_ = std::move(web_contents_manager); |
Yue Li | bf89f72a | 2018-06-18 16:51:16 | [diff] [blame] | 105 | } |
| 106 | |
David Black | c22e435 | 2018-07-11 21:29:48 | [diff] [blame] | 107 | // TODO(dmblack): Expose AssistantScreenContextController over mojo rather |
| 108 | // than implementing RequestScreenshot here in AssistantController. |
Muyuan Li | 0070f44d | 2018-05-16 02:57:23 | [diff] [blame] | 109 | void AssistantController::RequestScreenshot( |
| 110 | const gfx::Rect& rect, |
| 111 | RequestScreenshotCallback callback) { |
David Black | c22e435 | 2018-07-11 21:29:48 | [diff] [blame] | 112 | assistant_screen_context_controller_->RequestScreenshot(rect, |
| 113 | std::move(callback)); |
Muyuan Li | 0070f44d | 2018-05-16 02:57:23 | [diff] [blame] | 114 | } |
| 115 | |
Meilin Wang | 4980022 | 2018-08-22 17:27:48 | [diff] [blame] | 116 | void AssistantController::OpenAssistantSettings() { |
| 117 | // Launch Assistant settings via deeplink. |
| 118 | OpenUrl(assistant::util::CreateAssistantSettingsDeepLink()); |
| 119 | } |
| 120 | |
David Black | 5326a8eb | 2018-06-12 22:05:34 | [diff] [blame] | 121 | void AssistantController::ManageWebContents( |
David Black | e1a4b9ed | 2018-04-19 19:55:08 | [diff] [blame] | 122 | const base::UnguessableToken& id_token, |
David Black | 5326a8eb | 2018-06-12 22:05:34 | [diff] [blame] | 123 | mojom::ManagedWebContentsParamsPtr params, |
| 124 | mojom::WebContentsManager::ManageWebContentsCallback callback) { |
| 125 | DCHECK(web_contents_manager_); |
David Black | e1a4b9ed | 2018-04-19 19:55:08 | [diff] [blame] | 126 | |
| 127 | const mojom::UserSession* user_session = |
| 128 | Shell::Get()->session_controller()->GetUserSession(0); |
| 129 | |
| 130 | if (!user_session) { |
| 131 | LOG(WARNING) << "Unable to retrieve active user session."; |
David Black | 5326a8eb | 2018-06-12 22:05:34 | [diff] [blame] | 132 | std::move(callback).Run(base::nullopt); |
David Black | e1a4b9ed | 2018-04-19 19:55:08 | [diff] [blame] | 133 | return; |
| 134 | } |
| 135 | |
David Black | 5326a8eb | 2018-06-12 22:05:34 | [diff] [blame] | 136 | // Supply account ID. |
| 137 | params->account_id = user_session->user_info->account_id; |
| 138 | |
| 139 | // Specify that we will handle top level browser requests. |
David Black | 5326a8eb | 2018-06-12 22:05:34 | [diff] [blame] | 140 | ash::mojom::ManagedWebContentsOpenUrlDelegatePtr ptr; |
David Black | 2f7a70c3 | 2018-06-26 02:14:22 | [diff] [blame] | 141 | web_contents_open_url_delegate_bindings_.AddBinding(this, |
| 142 | mojo::MakeRequest(&ptr)); |
David Black | 5326a8eb | 2018-06-12 22:05:34 | [diff] [blame] | 143 | params->open_url_delegate_ptr_info = ptr.PassInterface(); |
| 144 | |
| 145 | web_contents_manager_->ManageWebContents(id_token, std::move(params), |
| 146 | std::move(callback)); |
David Black | e1a4b9ed | 2018-04-19 19:55:08 | [diff] [blame] | 147 | } |
| 148 | |
David Black | 5326a8eb | 2018-06-12 22:05:34 | [diff] [blame] | 149 | void AssistantController::ReleaseWebContents( |
| 150 | const base::UnguessableToken& id_token) { |
| 151 | web_contents_manager_->ReleaseWebContents(id_token); |
David Black | e1a4b9ed | 2018-04-19 19:55:08 | [diff] [blame] | 152 | } |
| 153 | |
David Black | 5326a8eb | 2018-06-12 22:05:34 | [diff] [blame] | 154 | void AssistantController::ReleaseWebContents( |
David Black | 3bfd96860 | 2018-04-24 22:07:46 | [diff] [blame] | 155 | const std::vector<base::UnguessableToken>& id_tokens) { |
David Black | 5326a8eb | 2018-06-12 22:05:34 | [diff] [blame] | 156 | web_contents_manager_->ReleaseAllWebContents(id_tokens); |
David Black | 3bfd96860 | 2018-04-24 22:07:46 | [diff] [blame] | 157 | } |
| 158 | |
David Black | 1a42f16 | 2018-08-13 23:07:01 | [diff] [blame] | 159 | void AssistantController::NavigateWebContentsBack( |
| 160 | const base::UnguessableToken& id_token, |
| 161 | mojom::WebContentsManager::NavigateWebContentsBackCallback callback) { |
| 162 | web_contents_manager_->NavigateWebContentsBack(id_token, std::move(callback)); |
| 163 | } |
| 164 | |
David Black | 7ffd284 | 2018-05-25 01:25:53 | [diff] [blame] | 165 | void AssistantController::DownloadImage( |
| 166 | const GURL& url, |
| 167 | mojom::AssistantImageDownloader::DownloadCallback callback) { |
| 168 | DCHECK(assistant_image_downloader_); |
| 169 | |
| 170 | const mojom::UserSession* user_session = |
| 171 | Shell::Get()->session_controller()->GetUserSession(0); |
| 172 | |
| 173 | if (!user_session) { |
| 174 | LOG(WARNING) << "Unable to retrieve active user session."; |
David Black | 5326a8eb | 2018-06-12 22:05:34 | [diff] [blame] | 175 | std::move(callback).Run(gfx::ImageSkia()); |
David Black | 7ffd284 | 2018-05-25 01:25:53 | [diff] [blame] | 176 | return; |
| 177 | } |
| 178 | |
| 179 | AccountId account_id = user_session->user_info->account_id; |
| 180 | assistant_image_downloader_->Download(account_id, url, std::move(callback)); |
| 181 | } |
| 182 | |
David Black | b0749ca5 | 2018-07-13 21:30:02 | [diff] [blame] | 183 | void AssistantController::OnDeepLinkReceived( |
| 184 | assistant::util::DeepLinkType type, |
| 185 | const std::map<std::string, std::string>& params) { |
Meilin Wang | 4980022 | 2018-08-22 17:27:48 | [diff] [blame] | 186 | using assistant::util::DeepLinkType; |
David Black | 7c07e30e | 2018-07-25 02:27:19 | [diff] [blame] | 187 | |
David Black | b0749ca5 | 2018-07-13 21:30:02 | [diff] [blame] | 188 | switch (type) { |
David Black | 7c07e30e | 2018-07-25 02:27:19 | [diff] [blame] | 189 | case DeepLinkType::kFeedback: |
David Black | b0749ca5 | 2018-07-13 21:30:02 | [diff] [blame] | 190 | // TODO(dmblack): Possibly use a new FeedbackSource (this method defaults |
| 191 | // to kFeedbackSourceAsh). This may be useful for differentiating feedback |
| 192 | // UI and behavior for Assistant. |
| 193 | Shell::Get()->new_window_controller()->OpenFeedbackPage(); |
| 194 | break; |
David Black | d08c051 | 2018-08-21 17:18:26 | [diff] [blame] | 195 | case DeepLinkType::kScreenshot: |
| 196 | // TODO(dmblack): The user probably doesn't want their screenshot to |
| 197 | // include Assistant so we may want to hide it before calling this API. |
| 198 | // Unfortunately, hiding our UI immediately beforehand doesn't resolve the |
| 199 | // issue, so we may need to introduce a delay or visibility change |
| 200 | // callback to remedy this. For now, keeping Assistant UI open since it |
| 201 | // will be included in the screenshot anyway. |
| 202 | Shell::Get()->screenshot_controller()->TakeScreenshotForAllRootWindows(); |
| 203 | break; |
David Black | 7c07e30e | 2018-07-25 02:27:19 | [diff] [blame] | 204 | case DeepLinkType::kUnsupported: |
David Black | ee6f32b5 | 2018-08-09 21:28:46 | [diff] [blame] | 205 | case DeepLinkType::kOnboarding: |
David Black | 7c07e30e | 2018-07-25 02:27:19 | [diff] [blame] | 206 | case DeepLinkType::kQuery: |
| 207 | case DeepLinkType::kReminders: |
| 208 | case DeepLinkType::kSettings: |
David Black | d08c051 | 2018-08-21 17:18:26 | [diff] [blame] | 209 | case DeepLinkType::kWhatsOnMyScreen: |
David Black | b0749ca5 | 2018-07-13 21:30:02 | [diff] [blame] | 210 | // No action needed. |
| 211 | break; |
David Black | 1859f9f | 2018-07-13 18:03:34 | [diff] [blame] | 212 | } |
David Black | f946f83 | 2018-07-13 17:29:09 | [diff] [blame] | 213 | } |
| 214 | |
David Black | 304cbdf | 2018-08-26 21:39:32 | [diff] [blame] | 215 | void AssistantController::ShouldOpenUrlFromTab( |
| 216 | const GURL& url, |
David Black | f360d0b | 2018-09-18 19:23:15 | [diff] [blame] | 217 | WindowOpenDisposition disposition, |
David Black | 304cbdf | 2018-08-26 21:39:32 | [diff] [blame] | 218 | ash::mojom::ManagedWebContentsOpenUrlDelegate::ShouldOpenUrlFromTabCallback |
| 219 | callback) { |
| 220 | // We always handle deep links ourselves. |
| 221 | if (assistant::util::IsDeepLinkUrl(url)) { |
| 222 | std::move(callback).Run(/*should_open=*/false); |
| 223 | NotifyDeepLinkReceived(url); |
| 224 | return; |
| 225 | } |
| 226 | |
David Black | f360d0b | 2018-09-18 19:23:15 | [diff] [blame] | 227 | AssistantUiMode ui_mode = assistant_ui_controller_->model()->ui_mode(); |
| 228 | |
David Black | 304cbdf | 2018-08-26 21:39:32 | [diff] [blame] | 229 | // When in main UI mode, WebContents should not navigate as they are hosting |
David Black | f360d0b | 2018-09-18 19:23:15 | [diff] [blame] | 230 | // Assistant cards. Instead, we route navigation attempts to the browser. We |
| 231 | // also respect open |disposition| to launch in the browser if appropriate. |
| 232 | if (ui_mode == AssistantUiMode::kMainUi || |
| 233 | disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) { |
David Black | 304cbdf | 2018-08-26 21:39:32 | [diff] [blame] | 234 | std::move(callback).Run(/*should_open=*/false); |
| 235 | OpenUrl(url); |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | // In all other cases WebContents should be able to navigate freely. |
| 240 | std::move(callback).Run(/*should_open=*/true); |
David Black | 2f7a70c3 | 2018-06-26 02:14:22 | [diff] [blame] | 241 | } |
| 242 | |
Muyuan Li | ed7c7640 | 2018-08-07 23:59:00 | [diff] [blame] | 243 | void AssistantController::SetVolume(int volume, bool user_initiated) { |
| 244 | volume = std::min(100, volume); |
| 245 | volume = std::max(volume, 0); |
| 246 | chromeos::CrasAudioHandler::Get()->SetOutputVolumePercent(volume); |
| 247 | } |
| 248 | |
| 249 | void AssistantController::SetMuted(bool muted) { |
| 250 | chromeos::CrasAudioHandler::Get()->SetOutputMute(muted); |
| 251 | } |
| 252 | |
| 253 | void AssistantController::AddVolumeObserver(mojom::VolumeObserverPtr observer) { |
| 254 | volume_observer_.AddPtr(std::move(observer)); |
| 255 | |
| 256 | int output_volume = |
| 257 | chromeos::CrasAudioHandler::Get()->GetOutputVolumePercent(); |
| 258 | bool mute = chromeos::CrasAudioHandler::Get()->IsOutputMuted(); |
| 259 | OnOutputMuteChanged(mute, false /* system_adjust */); |
| 260 | OnOutputNodeVolumeChanged(0 /* node */, output_volume); |
| 261 | } |
| 262 | |
| 263 | void AssistantController::OnOutputMuteChanged(bool mute_on, |
| 264 | bool system_adjust) { |
| 265 | volume_observer_.ForAllPtrs([mute_on](mojom::VolumeObserver* observer) { |
| 266 | observer->OnMuteStateChanged(mute_on); |
| 267 | }); |
| 268 | } |
| 269 | |
| 270 | void AssistantController::OnOutputNodeVolumeChanged(uint64_t node, int volume) { |
| 271 | // |node| refers to the active volume device, which we don't care here. |
| 272 | volume_observer_.ForAllPtrs([volume](mojom::VolumeObserver* observer) { |
| 273 | observer->OnVolumeChanged(volume); |
| 274 | }); |
| 275 | } |
| 276 | |
David Black | 2f7a70c3 | 2018-06-26 02:14:22 | [diff] [blame] | 277 | void AssistantController::OpenUrl(const GURL& url) { |
David Black | edaf0c3 | 2018-06-28 22:06:39 | [diff] [blame] | 278 | if (assistant::util::IsDeepLinkUrl(url)) { |
David Black | 1f58bcc | 2018-07-12 17:59:40 | [diff] [blame] | 279 | NotifyDeepLinkReceived(url); |
David Black | edaf0c3 | 2018-06-28 22:06:39 | [diff] [blame] | 280 | return; |
| 281 | } |
David Black | 2f7a70c3 | 2018-06-26 02:14:22 | [diff] [blame] | 282 | |
David Black | edaf0c3 | 2018-06-28 22:06:39 | [diff] [blame] | 283 | Shell::Get()->new_window_controller()->NewTabWithUrl(url); |
David Black | 1f58bcc | 2018-07-12 17:59:40 | [diff] [blame] | 284 | NotifyUrlOpened(url); |
| 285 | } |
David Black | e802d406 | 2018-06-29 01:59:05 | [diff] [blame] | 286 | |
David Black | 1f58bcc | 2018-07-12 17:59:40 | [diff] [blame] | 287 | void AssistantController::NotifyConstructed() { |
| 288 | for (AssistantControllerObserver& observer : observers_) |
| 289 | observer.OnAssistantControllerConstructed(); |
| 290 | } |
| 291 | |
| 292 | void AssistantController::NotifyDestroying() { |
| 293 | for (AssistantControllerObserver& observer : observers_) |
| 294 | observer.OnAssistantControllerDestroying(); |
| 295 | } |
| 296 | |
| 297 | void AssistantController::NotifyDeepLinkReceived(const GURL& deep_link) { |
Meilin Wang | 4980022 | 2018-08-22 17:27:48 | [diff] [blame] | 298 | using assistant::util::DeepLinkType; |
David Black | b0749ca5 | 2018-07-13 21:30:02 | [diff] [blame] | 299 | |
| 300 | // Retrieve deep link type and parsed parameters. |
Meilin Wang | 4980022 | 2018-08-22 17:27:48 | [diff] [blame] | 301 | DeepLinkType type = assistant::util::GetDeepLinkType(deep_link); |
David Black | b0749ca5 | 2018-07-13 21:30:02 | [diff] [blame] | 302 | const std::map<std::string, std::string> params = |
Meilin Wang | 4980022 | 2018-08-22 17:27:48 | [diff] [blame] | 303 | assistant::util::GetDeepLinkParams(deep_link); |
David Black | b0749ca5 | 2018-07-13 21:30:02 | [diff] [blame] | 304 | |
David Black | 1f58bcc | 2018-07-12 17:59:40 | [diff] [blame] | 305 | for (AssistantControllerObserver& observer : observers_) |
David Black | b0749ca5 | 2018-07-13 21:30:02 | [diff] [blame] | 306 | observer.OnDeepLinkReceived(type, params); |
David Black | 1f58bcc | 2018-07-12 17:59:40 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | void AssistantController::NotifyUrlOpened(const GURL& url) { |
David Black | e802d406 | 2018-06-29 01:59:05 | [diff] [blame] | 310 | for (AssistantControllerObserver& observer : observers_) |
| 311 | observer.OnUrlOpened(url); |
David Black | 2f7a70c3 | 2018-06-26 02:14:22 | [diff] [blame] | 312 | } |
| 313 | |
Yue Li | bf33defd | 2018-08-01 21:04:06 | [diff] [blame] | 314 | void AssistantController::OnVoiceInteractionStatusChanged( |
| 315 | mojom::VoiceInteractionState state) { |
Xiaohui Chen | 0571521 | 2018-08-08 15:52:28 | [diff] [blame] | 316 | if (state == mojom::VoiceInteractionState::NOT_READY) |
Yue Li | bf33defd | 2018-08-01 21:04:06 | [diff] [blame] | 317 | assistant_ui_controller_->HideUi(AssistantSource::kUnspecified); |
| 318 | } |
| 319 | |
wutao | 16db603c | 2018-07-10 06:43:59 | [diff] [blame] | 320 | base::WeakPtr<AssistantController> AssistantController::GetWeakPtr() { |
| 321 | return weak_factory_.GetWeakPtr(); |
| 322 | } |
| 323 | |
David Black | e8f81504 | 2018-03-28 18:59:37 | [diff] [blame] | 324 | } // namespace ash |