OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/automation/automation_provider_observers.h" | 5 #include "chrome/browser/automation/automation_provider_observers.h" |
6 | 6 |
7 #include <deque> | 7 #include <deque> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1401 | 1401 |
1402 void AutomationProviderBookmarkModelObserver::ReplyAndDelete(bool success) { | 1402 void AutomationProviderBookmarkModelObserver::ReplyAndDelete(bool success) { |
1403 if (automation_provider_) { | 1403 if (automation_provider_) { |
1404 AutomationMsg_WaitForBookmarkModelToLoad::WriteReplyParams( | 1404 AutomationMsg_WaitForBookmarkModelToLoad::WriteReplyParams( |
1405 reply_message_.get(), success); | 1405 reply_message_.get(), success); |
1406 automation_provider_->Send(reply_message_.release()); | 1406 automation_provider_->Send(reply_message_.release()); |
1407 } | 1407 } |
1408 delete this; | 1408 delete this; |
1409 } | 1409 } |
1410 | 1410 |
1411 AutomationProviderDownloadItemObserver::AutomationProviderDownloadItemObserver( | |
1412 AutomationProvider* provider, | |
1413 IPC::Message* reply_message, | |
1414 int downloads) | |
1415 : provider_(provider->AsWeakPtr()), | |
1416 reply_message_(reply_message), | |
1417 downloads_(downloads), | |
1418 interrupted_(false) { | |
1419 } | |
1420 | |
1421 AutomationProviderDownloadItemObserver:: | |
1422 ~AutomationProviderDownloadItemObserver() {} | |
1423 | |
1424 void AutomationProviderDownloadItemObserver::OnDownloadUpdated( | |
1425 DownloadItem* download) { | |
1426 interrupted_ |= download->IsInterrupted(); | |
1427 // If any download was interrupted, on the next update each outstanding | |
1428 // download is cancelled. | |
1429 if (interrupted_) { | |
1430 // |Cancel()| does nothing if |download| is already interrupted. | |
1431 download->Cancel(true); | |
1432 RemoveAndCleanupOnLastEntry(download); | |
1433 } | |
1434 | |
1435 if (download->IsComplete()) | |
1436 RemoveAndCleanupOnLastEntry(download); | |
1437 } | |
1438 | |
1439 // We don't want to send multiple messages, as the behavior is undefined. | |
1440 // Set |interrupted_| on error, and on the last download completed/ | |
1441 // interrupted, send either an error or a success message. | |
1442 void AutomationProviderDownloadItemObserver::RemoveAndCleanupOnLastEntry( | |
1443 DownloadItem* download) { | |
1444 // Forget about the download. | |
1445 download->RemoveObserver(this); | |
1446 if (--downloads_ == 0) { | |
1447 if (provider_) { | |
1448 if (interrupted_) { | |
1449 AutomationJSONReply(provider_, reply_message_.release()).SendError( | |
1450 "Download Interrupted"); | |
1451 } else { | |
1452 AutomationJSONReply(provider_, reply_message_.release()).SendSuccess( | |
1453 NULL); | |
1454 } | |
1455 } | |
1456 delete this; | |
1457 } | |
1458 } | |
1459 | |
1460 void AutomationProviderDownloadItemObserver::OnDownloadOpened( | |
1461 DownloadItem* download) { | |
1462 } | |
1463 | |
1464 AutomationProviderDownloadUpdatedObserver:: | 1411 AutomationProviderDownloadUpdatedObserver:: |
1465 AutomationProviderDownloadUpdatedObserver( | 1412 AutomationProviderDownloadUpdatedObserver( |
1466 AutomationProvider* provider, | 1413 AutomationProvider* provider, |
1467 IPC::Message* reply_message, | 1414 IPC::Message* reply_message, |
1468 bool wait_for_open) | 1415 bool wait_for_open) |
1469 : provider_(provider->AsWeakPtr()), | 1416 : provider_(provider->AsWeakPtr()), |
1470 reply_message_(reply_message), | 1417 reply_message_(reply_message), |
1471 wait_for_open_(wait_for_open) { | 1418 wait_for_open_(wait_for_open) { |
1472 } | 1419 } |
1473 | 1420 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1519 ~AutomationProviderDownloadModelChangedObserver() {} | 1466 ~AutomationProviderDownloadModelChangedObserver() {} |
1520 | 1467 |
1521 void AutomationProviderDownloadModelChangedObserver::ModelChanged() { | 1468 void AutomationProviderDownloadModelChangedObserver::ModelChanged() { |
1522 download_manager_->RemoveObserver(this); | 1469 download_manager_->RemoveObserver(this); |
1523 | 1470 |
1524 if (provider_) | 1471 if (provider_) |
1525 AutomationJSONReply(provider_, reply_message_.release()).SendSuccess(NULL); | 1472 AutomationJSONReply(provider_, reply_message_.release()).SendSuccess(NULL); |
1526 delete this; | 1473 delete this; |
1527 } | 1474 } |
1528 | 1475 |
| 1476 AllDownloadsCompleteObserver::AllDownloadsCompleteObserver( |
| 1477 AutomationProvider* provider, |
| 1478 IPC::Message* reply_message, |
| 1479 DownloadManager* download_manager, |
| 1480 ListValue* pre_download_ids) |
| 1481 : provider_(provider->AsWeakPtr()), |
| 1482 reply_message_(reply_message), |
| 1483 download_manager_(download_manager) { |
| 1484 for (ListValue::iterator it = pre_download_ids->begin(); |
| 1485 it != pre_download_ids->end(); ++it) { |
| 1486 int val = 0; |
| 1487 if ((*it)->GetAsInteger(&val)) { |
| 1488 pre_download_ids_.insert(val); |
| 1489 } else { |
| 1490 AutomationJSONReply(provider_, reply_message_.release()) |
| 1491 .SendError("Cannot convert ID of prior download to integer."); |
| 1492 delete this; |
| 1493 return; |
| 1494 } |
| 1495 } |
| 1496 download_manager_->AddObserver(this); // Will call initial ModelChanged(). |
| 1497 } |
| 1498 |
| 1499 AllDownloadsCompleteObserver::~AllDownloadsCompleteObserver() {} |
| 1500 |
| 1501 void AllDownloadsCompleteObserver::ModelChanged() { |
| 1502 // The set of downloads in the download manager has changed. If there are |
| 1503 // any new downloads that are still in progress, add them to the pending list. |
| 1504 std::vector<DownloadItem*> downloads; |
| 1505 download_manager_->GetAllDownloads(FilePath(), &downloads); |
| 1506 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
| 1507 it != downloads.end(); ++it) { |
| 1508 if ((*it)->state() == DownloadItem::IN_PROGRESS && |
| 1509 pre_download_ids_.find((*it)->id()) == pre_download_ids_.end()) { |
| 1510 (*it)->AddObserver(this); |
| 1511 pending_downloads_.insert(*it); |
| 1512 } |
| 1513 } |
| 1514 ReplyIfNecessary(); |
| 1515 } |
| 1516 |
| 1517 void AllDownloadsCompleteObserver::OnDownloadUpdated(DownloadItem* download) { |
| 1518 // If the current download's status has changed to a final state (not state |
| 1519 // "in progress"), remove it from the pending list. |
| 1520 if (download->state() != DownloadItem::IN_PROGRESS) { |
| 1521 download->RemoveObserver(this); |
| 1522 pending_downloads_.erase(download); |
| 1523 ReplyIfNecessary(); |
| 1524 } |
| 1525 } |
| 1526 |
| 1527 void AllDownloadsCompleteObserver::ReplyIfNecessary() { |
| 1528 if (!pending_downloads_.empty()) |
| 1529 return; |
| 1530 |
| 1531 download_manager_->RemoveObserver(this); |
| 1532 if (provider_) |
| 1533 AutomationJSONReply(provider_, reply_message_.release()).SendSuccess(NULL); |
| 1534 delete this; |
| 1535 } |
| 1536 |
1529 AutomationProviderSearchEngineObserver::AutomationProviderSearchEngineObserver( | 1537 AutomationProviderSearchEngineObserver::AutomationProviderSearchEngineObserver( |
1530 AutomationProvider* provider, | 1538 AutomationProvider* provider, |
1531 IPC::Message* reply_message) | 1539 IPC::Message* reply_message) |
1532 : provider_(provider->AsWeakPtr()), | 1540 : provider_(provider->AsWeakPtr()), |
1533 reply_message_(reply_message) { | 1541 reply_message_(reply_message) { |
1534 } | 1542 } |
1535 | 1543 |
1536 AutomationProviderSearchEngineObserver:: | 1544 AutomationProviderSearchEngineObserver:: |
1537 ~AutomationProviderSearchEngineObserver() {} | 1545 ~AutomationProviderSearchEngineObserver() {} |
1538 | 1546 |
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2606 void DragTargetDropAckNotificationObserver::Observe( | 2614 void DragTargetDropAckNotificationObserver::Observe( |
2607 int type, | 2615 int type, |
2608 const NotificationSource& source, | 2616 const NotificationSource& source, |
2609 const NotificationDetails& details) { | 2617 const NotificationDetails& details) { |
2610 if (automation_) { | 2618 if (automation_) { |
2611 AutomationJSONReply(automation_, | 2619 AutomationJSONReply(automation_, |
2612 reply_message_.release()).SendSuccess(NULL); | 2620 reply_message_.release()).SendSuccess(NULL); |
2613 } | 2621 } |
2614 delete this; | 2622 delete this; |
2615 } | 2623 } |
OLD | NEW |