Chromium Code Reviews| 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 (*it)->GetAsInteger(&val); | |
|
Nirnimesh
2011/08/08 17:26:17
wrap this inside if()
dennis_jeffrey
2011/08/08 22:29:51
Done.
| |
| 1488 pre_download_ids_.insert(val); | |
| 1489 } | |
| 1490 download_manager_->AddObserver(this); // Will call initial ModelChanged(). | |
| 1491 } | |
| 1492 | |
| 1493 AllDownloadsCompleteObserver::~AllDownloadsCompleteObserver() {} | |
| 1494 | |
| 1495 void AllDownloadsCompleteObserver::ModelChanged() { | |
| 1496 // The set of downloads in the download manager has changed. If there are | |
| 1497 // any new downloads that are still in progress, add them to the pending list. | |
| 1498 std::vector<DownloadItem*> downloads; | |
| 1499 download_manager_->GetAllDownloads(FilePath(), &downloads); | |
| 1500 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); | |
| 1501 it != downloads.end(); ++it) { | |
| 1502 if ((*it)->state() == DownloadItem::IN_PROGRESS && | |
| 1503 pre_download_ids_.find((*it)->id()) == pre_download_ids_.end()) { | |
| 1504 (*it)->AddObserver(this); | |
| 1505 pending_downloads_.insert(*it); | |
| 1506 } | |
| 1507 } | |
| 1508 ReplyIfNecessary(); | |
| 1509 } | |
| 1510 | |
| 1511 void AllDownloadsCompleteObserver::OnDownloadUpdated(DownloadItem* download) { | |
| 1512 // If the current download's status has changed to a final state (not state | |
| 1513 // "in progress"), remove it from the pending list. | |
| 1514 if (download->state() != DownloadItem::IN_PROGRESS) { | |
|
Nirnimesh
2011/08/08 17:26:17
shouldn't you check for status COMPLETED?
dennis_jeffrey
2011/08/08 22:29:51
No, I want the hook to return as soon as we don't
| |
| 1515 download->RemoveObserver(this); | |
| 1516 pending_downloads_.erase(download); | |
| 1517 ReplyIfNecessary(); | |
| 1518 } | |
| 1519 } | |
| 1520 | |
| 1521 void AllDownloadsCompleteObserver::ReplyIfNecessary() { | |
| 1522 if (pending_downloads_.empty()) { | |
|
Paweł Hajdan Jr.
2011/08/08 16:36:13
nit: Preferred would be:
if (!pending_downloads_.
dennis_jeffrey
2011/08/08 22:29:51
Done.
| |
| 1523 download_manager_->RemoveObserver(this); | |
| 1524 if (provider_) | |
|
Paweł Hajdan Jr.
2011/08/08 16:36:13
nit: Add braces {} here.
dennis_jeffrey
2011/08/08 22:29:51
I assume this is to improve readability because li
| |
| 1525 AutomationJSONReply(provider_, | |
| 1526 reply_message_.release()).SendSuccess(NULL); | |
| 1527 delete this; | |
| 1528 } | |
| 1529 } | |
| 1530 | |
| 1529 AutomationProviderSearchEngineObserver::AutomationProviderSearchEngineObserver( | 1531 AutomationProviderSearchEngineObserver::AutomationProviderSearchEngineObserver( |
| 1530 AutomationProvider* provider, | 1532 AutomationProvider* provider, |
| 1531 IPC::Message* reply_message) | 1533 IPC::Message* reply_message) |
| 1532 : provider_(provider->AsWeakPtr()), | 1534 : provider_(provider->AsWeakPtr()), |
| 1533 reply_message_(reply_message) { | 1535 reply_message_(reply_message) { |
| 1534 } | 1536 } |
| 1535 | 1537 |
| 1536 AutomationProviderSearchEngineObserver:: | 1538 AutomationProviderSearchEngineObserver:: |
| 1537 ~AutomationProviderSearchEngineObserver() {} | 1539 ~AutomationProviderSearchEngineObserver() {} |
| 1538 | 1540 |
| (...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2606 void DragTargetDropAckNotificationObserver::Observe( | 2608 void DragTargetDropAckNotificationObserver::Observe( |
| 2607 int type, | 2609 int type, |
| 2608 const NotificationSource& source, | 2610 const NotificationSource& source, |
| 2609 const NotificationDetails& details) { | 2611 const NotificationDetails& details) { |
| 2610 if (automation_) { | 2612 if (automation_) { |
| 2611 AutomationJSONReply(automation_, | 2613 AutomationJSONReply(automation_, |
| 2612 reply_message_.release()).SendSuccess(NULL); | 2614 reply_message_.release()).SendSuccess(NULL); |
| 2613 } | 2615 } |
| 2614 delete this; | 2616 delete this; |
| 2615 } | 2617 } |
| OLD | NEW |