Chromium Code Reviews| 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/intents/web_intent_picker_controller.h" | 5 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 virtual void WebContentsDestroyed(content::WebContents* web_contents) { | 128 virtual void WebContentsDestroyed(content::WebContents* web_contents) { |
| 129 if (controller_) | 129 if (controller_) |
| 130 controller_->SourceWebContentsDestroyed(web_contents); | 130 controller_->SourceWebContentsDestroyed(web_contents); |
| 131 delete this; | 131 delete this; |
| 132 } | 132 } |
| 133 | 133 |
| 134 private: | 134 private: |
| 135 base::WeakPtr<WebIntentPickerController> controller_; | 135 base::WeakPtr<WebIntentPickerController> controller_; |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 // A WebIntentsDispatcher wrapper that deletes a itself, | |
| 139 // and a service once a response is received. | |
|
Greg Billock
2012/10/10 17:12:51
I think we can just do this with a closure using R
Steve McKay
2012/10/10 23:12:57
Done.
| |
| 140 class DeletingDispatcherWrapper : public content::WebIntentsDispatcher { | |
| 141 public: | |
| 142 explicit DeletingDispatcherWrapper( | |
| 143 web_intents::IntentServiceHost* service, | |
| 144 content::WebIntentsDispatcher* delegate) | |
| 145 : service_(service), | |
| 146 delegate_(delegate) {} | |
| 147 | |
| 148 virtual const webkit_glue::WebIntentData& GetIntent() OVERRIDE { | |
| 149 return delegate_->GetIntent(); | |
| 150 } | |
| 151 | |
| 152 virtual void DispatchIntent(content::WebContents* web_contents) OVERRIDE { | |
| 153 NOTREACHED(); | |
| 154 } | |
| 155 virtual void ResetDispatch() OVERRIDE { | |
| 156 NOTREACHED(); | |
| 157 } | |
| 158 | |
| 159 virtual void SendReplyMessage( | |
| 160 webkit_glue::WebIntentReplyType reply_type, | |
| 161 const string16& data) OVERRIDE { | |
| 162 delegate_->SendReplyMessage(reply_type, data); | |
| 163 } | |
| 164 | |
| 165 virtual void RegisterReplyNotification( | |
| 166 const base::Callback<void(webkit_glue::WebIntentReplyType)>&) OVERRIDE { | |
| 167 NOTREACHED(); | |
| 168 } | |
| 169 | |
| 170 private: | |
| 171 ~DeletingDispatcherWrapper() { | |
| 172 delete service_; | |
| 173 delete this; | |
| 174 } | |
| 175 | |
| 176 web_intents::IntentServiceHost* service_; | |
| 177 content::WebIntentsDispatcher* delegate_; | |
| 178 }; | |
| 179 | |
| 138 } // namespace | 180 } // namespace |
| 139 | 181 |
| 140 // UMAReporter handles reporting Web Intents events to UMA. | 182 // UMAReporter handles reporting Web Intents events to UMA. |
| 141 class WebIntentPickerController::UMAReporter { | 183 class WebIntentPickerController::UMAReporter { |
| 142 public: | 184 public: |
| 143 | 185 |
| 144 // Resets the service active duration timer to "now". | 186 // Resets the service active duration timer to "now". |
| 145 void ResetServiceActiveTimer(); | 187 void ResetServiceActiveTimer(); |
| 146 | 188 |
| 147 // Records the duration of time spent using the service. Uses |reply_type| | 189 // Records the duration of time spent using the service. Uses |reply_type| |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 | 397 |
| 356 // TODO(smckay): This entire method shold basically be pulled out | 398 // TODO(smckay): This entire method shold basically be pulled out |
| 357 // into a separate class dedicated to the execution of intents. | 399 // into a separate class dedicated to the execution of intents. |
| 358 // The tricky part is with the "INLINE" disposition where we | 400 // The tricky part is with the "INLINE" disposition where we |
| 359 // want to (re)use the picker to handle the intent. A bit of | 401 // want to (re)use the picker to handle the intent. A bit of |
| 360 // artful composition + lazy instantiation should make that possible. | 402 // artful composition + lazy instantiation should make that possible. |
| 361 switch (disposition) { | 403 switch (disposition) { |
| 362 case webkit_glue::WebIntentServiceData::DISPOSITION_NATIVE: { | 404 case webkit_glue::WebIntentServiceData::DISPOSITION_NATIVE: { |
| 363 web_intents::IntentServiceHost* service = | 405 web_intents::IntentServiceHost* service = |
| 364 native_services_->CreateServiceInstance( | 406 native_services_->CreateServiceInstance( |
| 365 url, intents_dispatcher_->GetIntent()); | 407 url, intents_dispatcher_->GetIntent(), web_contents_); |
| 366 DCHECK(service); | 408 DCHECK(service); |
| 367 service->HandleIntent(intents_dispatcher_); | 409 service->HandleIntent( |
| 410 new DeletingDispatcherWrapper(service, intents_dispatcher_)); | |
| 368 break; | 411 break; |
| 369 } | 412 } |
| 370 | 413 |
| 371 case webkit_glue::WebIntentServiceData::DISPOSITION_INLINE: { | 414 case webkit_glue::WebIntentServiceData::DISPOSITION_INLINE: { |
| 372 // Set the model to inline disposition. It will notify the picker which | 415 // Set the model to inline disposition. It will notify the picker which |
| 373 // will respond (via OnInlineDispositionWebContentsCreated) with the | 416 // will respond (via OnInlineDispositionWebContentsCreated) with the |
| 374 // WebContents to dispatch the intent to. | 417 // WebContents to dispatch the intent to. |
| 375 picker_model_->SetInlineDisposition(url); | 418 picker_model_->SetInlineDisposition(url); |
| 376 break; | 419 break; |
| 377 } | 420 } |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1120 content::DownloadManager* download_manager = | 1163 content::DownloadManager* download_manager = |
| 1121 content::BrowserContext::GetDownloadManager(profile); | 1164 content::BrowserContext::GetDownloadManager(profile); |
| 1122 if (!download_manager) | 1165 if (!download_manager) |
| 1123 return; | 1166 return; |
| 1124 content::DownloadItem* item = | 1167 content::DownloadItem* item = |
| 1125 download_manager->GetDownload(download_id_.local()); | 1168 download_manager->GetDownload(download_id_.local()); |
| 1126 if (item) | 1169 if (item) |
| 1127 item->Cancel(true); | 1170 item->Cancel(true); |
| 1128 download_id_ = content::DownloadId(); | 1171 download_id_ = content::DownloadId(); |
| 1129 } | 1172 } |
| OLD | NEW |