Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/chromeos/arc/arc_navigation_throttle.h" | 5 #include "chrome/browser/chromeos/arc/arc_navigation_throttle.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/metrics/histogram_macros.h" | |
| 10 #include "components/arc/arc_bridge_service.h" | 11 #include "components/arc/arc_bridge_service.h" |
| 11 #include "components/arc/arc_service_manager.h" | 12 #include "components/arc/arc_service_manager.h" |
| 12 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" | 13 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" |
| 13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/navigation_handle.h" | 15 #include "content/public/browser/navigation_handle.h" |
| 15 | 16 |
| 16 namespace arc { | 17 namespace arc { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 } | 157 } |
| 157 | 158 |
| 158 void ArcNavigationThrottle::OnDisambigDialogClosed( | 159 void ArcNavigationThrottle::OnDisambigDialogClosed( |
| 159 mojo::Array<mojom::UrlHandlerInfoPtr> handlers, | 160 mojo::Array<mojom::UrlHandlerInfoPtr> handlers, |
| 160 size_t selected_app_index, | 161 size_t selected_app_index, |
| 161 CloseReason close_reason) { | 162 CloseReason close_reason) { |
| 162 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 163 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 163 const GURL& url = navigation_handle()->GetURL(); | 164 const GURL& url = navigation_handle()->GetURL(); |
| 164 content::NavigationHandle* handle = navigation_handle(); | 165 content::NavigationHandle* handle = navigation_handle(); |
| 165 | 166 |
| 166 // TODO(djacobo): Record UMA | 167 mojom::IntentHelperInstance* bridge = GetIntentHelper(); |
| 167 // If the user fails to select an option from the list, or the UI returned an | 168 if (!bridge || selected_app_index >= handlers.size()) { |
| 168 // error or if |selected_app_index| is not a valid index, then resume the | 169 close_reason = CloseReason::REASON_ERROR; |
| 169 // navigation in Chrome. Otherwise store the preferred app (if any) and start | |
| 170 // the selected app, either Chrome Browser or ARC app. | |
| 171 if (close_reason == CloseReason::REASON_DIALOG_DEACTIVATED || | |
| 172 close_reason == CloseReason::REASON_ERROR || | |
| 173 selected_app_index >= handlers.size()) { | |
| 174 DVLOG(1) << "User didn't select a valid option, resuming navigation."; | |
| 175 handle->Resume(); | |
| 176 return; | |
| 177 } | 170 } |
| 178 mojom::IntentHelperInstance* bridge = GetIntentHelper(); | 171 |
| 179 if (!bridge) { | 172 switch (close_reason) { |
| 180 handle->Resume(); | 173 case CloseReason::REASON_ALWAYS_PRESSED: |
| 181 return; | 174 bridge->AddPreferredPackage(handlers[selected_app_index]->package_name); |
| 175 // fall through | |
|
Luis Héctor Chávez
2016/06/27 16:01:11
nit: Can you run git cl format? I suspect that thi
Yusuke Sato
2016/06/27 16:19:32
git cl format did this actually.. and I don't like
| |
| 176 case CloseReason::REASON_JUST_ONCE_PRESSED: | |
| 177 case CloseReason::REASON_PREFERRED_ACTIVITY_FOUND: | |
| 178 if (ArcIntentHelperBridge::IsIntentHelperPackage( | |
| 179 handlers[selected_app_index]->package_name)) { | |
| 180 handle->Resume(); | |
| 181 } else { | |
| 182 bridge->HandleUrl(url.spec(), | |
| 183 handlers[selected_app_index]->package_name); | |
| 184 handle->CancelDeferredNavigation( | |
| 185 content::NavigationThrottle::CANCEL_AND_IGNORE); | |
| 186 } | |
| 187 break; | |
| 188 case CloseReason::REASON_DIALOG_DEACTIVATED: | |
| 189 case CloseReason::REASON_ERROR: | |
| 190 // If the user fails to select an option from the list, or the UI returned | |
| 191 // an error or if |selected_app_index| is not a valid index, then resume | |
| 192 // the navigation in Chrome. Otherwise store the preferred app (if any) | |
|
Luis Héctor Chávez
2016/06/27 16:01:11
The "Otherwise ..." part of this comment does not
Yusuke Sato
2016/06/27 16:19:33
Good catch, removed. The comment was added when |c
| |
| 193 // and start the selected app, either Chrome Browser or ARC app. | |
| 194 DVLOG(1) << "User didn't select a valid option, resuming navigation."; | |
| 195 handle->Resume(); | |
| 196 break; | |
| 197 case CloseReason::SIZE: | |
|
Luis Héctor Chávez
2016/06/27 16:01:11
nit: default instead of an explicit case.
Yusuke Sato
2016/06/27 16:19:32
I tend to avoid having default: when using switch-
| |
| 198 NOTREACHED(); | |
| 199 return; | |
| 182 } | 200 } |
| 183 if (close_reason == CloseReason::REASON_ALWAYS_PRESSED) { | 201 |
| 184 bridge->AddPreferredPackage(handlers[selected_app_index]->package_name); | 202 UMA_HISTOGRAM_ENUMERATION("Arc.IntentHandlerAction", |
| 185 } | 203 static_cast<int>(close_reason), |
| 186 if (ArcIntentHelperBridge::IsIntentHelperPackage( | 204 static_cast<int>(CloseReason::SIZE)); |
| 187 handlers[selected_app_index]->package_name)) { | |
| 188 handle->Resume(); | |
| 189 return; | |
| 190 } | |
| 191 bridge->HandleUrl(url.spec(), handlers[selected_app_index]->package_name); | |
| 192 handle->CancelDeferredNavigation( | |
| 193 content::NavigationThrottle::CANCEL_AND_IGNORE); | |
| 194 } | 205 } |
| 195 | 206 |
| 196 } // namespace arc | 207 } // namespace arc |
| OLD | NEW |