automation_provider_observers.h revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_ 6#define CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_ 7#pragma once 8 9#include <deque> 10#include <map> 11#include <set> 12 13#include "chrome/browser/automation/testing_automation_provider.h" 14#include "chrome/browser/bookmarks/bookmark_model_observer.h" 15#include "chrome/browser/browsing_data_remover.h" 16#include "chrome/browser/download/download_item.h" 17#include "chrome/browser/download/download_manager.h" 18#include "chrome/browser/history/history.h" 19#include "chrome/browser/importer/importer.h" 20#include "chrome/browser/importer/importer_data_types.h" 21#include "chrome/browser/password_manager/password_store.h" 22#include "chrome/browser/search_engines/template_url_model_observer.h" 23#include "chrome/browser/tabs/tab_strip_model.h" 24#include "chrome/common/notification_observer.h" 25#include "chrome/common/notification_registrar.h" 26#include "chrome/common/notification_type.h" 27#include "chrome/test/automation/automation_messages.h" 28 29class AutocompleteEditModel; 30class AutomationProvider; 31class Browser; 32class Extension; 33class ExtensionProcessManager; 34class NavigationController; 35class SavePackage; 36class TabContents; 37class TranslateInfoBarDelegate; 38 39namespace IPC { 40class Message; 41} 42 43class InitialLoadObserver : public NotificationObserver { 44 public: 45 InitialLoadObserver(size_t tab_count, AutomationProvider* automation); 46 ~InitialLoadObserver(); 47 48 virtual void Observe(NotificationType type, 49 const NotificationSource& source, 50 const NotificationDetails& details); 51 52 // Caller owns the return value and is responsible for deleting it. 53 // Example return value: 54 // {'tabs': [{'start_time_ms': 1, 'stop_time_ms': 2.5}, 55 // {'start_time_ms': 0.5, 'stop_time_ms': 3}]} 56 // stop_time_ms values may be null if WaitForInitialLoads has not finished. 57 // Only includes entries for the |tab_count| tabs we are monitoring. 58 // There is no defined ordering of the return value. 59 DictionaryValue* GetTimingInformation() const; 60 61 private: 62 class TabTime; 63 typedef std::map<uintptr_t, TabTime> TabTimeMap; 64 typedef std::set<uintptr_t> TabSet; 65 66 void ConditionMet(); 67 68 NotificationRegistrar registrar_; 69 70 AutomationProvider* automation_; 71 size_t outstanding_tab_count_; 72 base::TimeTicks init_time_; 73 TabTimeMap loading_tabs_; 74 TabSet finished_tabs_; 75 76 DISALLOW_COPY_AND_ASSIGN(InitialLoadObserver); 77}; 78 79// Watches for NewTabUI page loads for performance timing purposes. 80class NewTabUILoadObserver : public NotificationObserver { 81 public: 82 explicit NewTabUILoadObserver(AutomationProvider* automation); 83 ~NewTabUILoadObserver(); 84 85 virtual void Observe(NotificationType type, 86 const NotificationSource& source, 87 const NotificationDetails& details); 88 89 private: 90 NotificationRegistrar registrar_; 91 AutomationProvider* automation_; 92 93 DISALLOW_COPY_AND_ASSIGN(NewTabUILoadObserver); 94}; 95 96class NavigationControllerRestoredObserver : public NotificationObserver { 97 public: 98 NavigationControllerRestoredObserver(AutomationProvider* automation, 99 NavigationController* controller, 100 IPC::Message* reply_message); 101 ~NavigationControllerRestoredObserver(); 102 103 virtual void Observe(NotificationType type, 104 const NotificationSource& source, 105 const NotificationDetails& details); 106 107 private: 108 bool FinishedRestoring(); 109 void SendDone(); 110 111 NotificationRegistrar registrar_; 112 AutomationProvider* automation_; 113 NavigationController* controller_; 114 IPC::Message* reply_message_; 115 116 DISALLOW_COPY_AND_ASSIGN(NavigationControllerRestoredObserver); 117}; 118 119class NavigationNotificationObserver : public NotificationObserver { 120 public: 121 NavigationNotificationObserver(NavigationController* controller, 122 AutomationProvider* automation, 123 IPC::Message* reply_message, 124 int number_of_navigations, 125 bool include_current_navigation); 126 ~NavigationNotificationObserver(); 127 128 virtual void Observe(NotificationType type, 129 const NotificationSource& source, 130 const NotificationDetails& details); 131 132 private: 133 void ConditionMet(AutomationMsg_NavigationResponseValues navigation_result); 134 135 NotificationRegistrar registrar_; 136 AutomationProvider* automation_; 137 IPC::Message* reply_message_; 138 NavigationController* controller_; 139 int navigations_remaining_; 140 bool navigation_started_; 141 142 DISALLOW_COPY_AND_ASSIGN(NavigationNotificationObserver); 143}; 144 145class TabStripNotificationObserver : public NotificationObserver { 146 public: 147 TabStripNotificationObserver(NotificationType notification, 148 AutomationProvider* automation); 149 virtual ~TabStripNotificationObserver(); 150 151 virtual void Observe(NotificationType type, 152 const NotificationSource& source, 153 const NotificationDetails& details); 154 155 virtual void ObserveTab(NavigationController* controller) = 0; 156 157 protected: 158 NotificationRegistrar registrar_; 159 AutomationProvider* automation_; 160 NotificationType notification_; 161}; 162 163class TabAppendedNotificationObserver : public TabStripNotificationObserver { 164 public: 165 TabAppendedNotificationObserver(Browser* parent, 166 AutomationProvider* automation, 167 IPC::Message* reply_message); 168 169 virtual void ObserveTab(NavigationController* controller); 170 171 protected: 172 Browser* parent_; 173 IPC::Message* reply_message_; 174 175 private: 176 DISALLOW_COPY_AND_ASSIGN(TabAppendedNotificationObserver); 177}; 178 179class TabClosedNotificationObserver : public TabStripNotificationObserver { 180 public: 181 TabClosedNotificationObserver(AutomationProvider* automation, 182 bool wait_until_closed, 183 IPC::Message* reply_message); 184 185 virtual void ObserveTab(NavigationController* controller); 186 187 void set_for_browser_command(bool for_browser_command); 188 189 protected: 190 IPC::Message* reply_message_; 191 bool for_browser_command_; 192 193 private: 194 DISALLOW_COPY_AND_ASSIGN(TabClosedNotificationObserver); 195}; 196 197// Notifies when the tab count reaches the target number. 198class TabCountChangeObserver : public TabStripModelObserver { 199 public: 200 TabCountChangeObserver(AutomationProvider* automation, 201 Browser* browser, 202 IPC::Message* reply_message, 203 int target_tab_count); 204 // Implementation of TabStripModelObserver. 205 virtual void TabInsertedAt(TabContents* contents, 206 int index, 207 bool foreground); 208 virtual void TabClosingAt(TabContents* contents, int index); 209 virtual void TabStripModelDeleted(); 210 211 private: 212 ~TabCountChangeObserver(); 213 214 // Checks if the current tab count matches our target, and if so, 215 // sends the reply message and deletes self. 216 void CheckTabCount(); 217 218 AutomationProvider* automation_; 219 IPC::Message* reply_message_; 220 221 TabStripModel* tab_strip_model_; 222 223 const int target_tab_count_; 224 225 DISALLOW_COPY_AND_ASSIGN(TabCountChangeObserver); 226}; 227 228// Observes when an extension has finished installing or possible install 229// errors. This does not guarantee that the extension is ready for use. 230class ExtensionInstallNotificationObserver : public NotificationObserver { 231 public: 232 ExtensionInstallNotificationObserver(AutomationProvider* automation, 233 int id, 234 IPC::Message* reply_message); 235 ~ExtensionInstallNotificationObserver(); 236 237 // Implementation of NotificationObserver. 238 virtual void Observe(NotificationType type, 239 const NotificationSource& source, 240 const NotificationDetails& details); 241 242 private: 243 // Send |response| back to the provider's client. 244 void SendResponse(AutomationMsg_ExtensionResponseValues response); 245 246 NotificationRegistrar registrar_; 247 scoped_refptr<AutomationProvider> automation_; 248 int id_; 249 IPC::Message* reply_message_; 250 251 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallNotificationObserver); 252}; 253 254// Observes when an extension has finished loading and is ready for use. Also 255// checks for possible install errors. 256class ExtensionReadyNotificationObserver : public NotificationObserver { 257 public: 258 ExtensionReadyNotificationObserver(ExtensionProcessManager* manager, 259 AutomationProvider* automation, 260 int id, 261 IPC::Message* reply_message); 262 ~ExtensionReadyNotificationObserver(); 263 264 // Implementation of NotificationObserver. 265 virtual void Observe(NotificationType type, 266 const NotificationSource& source, 267 const NotificationDetails& details); 268 269 private: 270 NotificationRegistrar registrar_; 271 ExtensionProcessManager* manager_; 272 scoped_refptr<AutomationProvider> automation_; 273 int id_; 274 IPC::Message* reply_message_; 275 Extension* extension_; 276 277 DISALLOW_COPY_AND_ASSIGN(ExtensionReadyNotificationObserver); 278}; 279 280class ExtensionUnloadNotificationObserver : public NotificationObserver { 281 public: 282 ExtensionUnloadNotificationObserver(); 283 ~ExtensionUnloadNotificationObserver(); 284 285 // Implementation of NotificationObserver. 286 virtual void Observe(NotificationType type, 287 const NotificationSource& source, 288 const NotificationDetails& details); 289 290 bool did_receive_unload_notification() { 291 return did_receive_unload_notification_; 292 } 293 294 private: 295 NotificationRegistrar registrar_; 296 bool did_receive_unload_notification_; 297 298 DISALLOW_COPY_AND_ASSIGN(ExtensionUnloadNotificationObserver); 299}; 300 301class ExtensionTestResultNotificationObserver : public NotificationObserver { 302 public: 303 explicit ExtensionTestResultNotificationObserver( 304 AutomationProvider* automation); 305 ~ExtensionTestResultNotificationObserver(); 306 307 // Implementation of NotificationObserver. 308 virtual void Observe(NotificationType type, 309 const NotificationSource& source, 310 const NotificationDetails& details); 311 312 // Sends a test result back to the provider's client, if there is a pending 313 // provider message and there is a result in the queue. 314 void MaybeSendResult(); 315 316 private: 317 NotificationRegistrar registrar_; 318 AutomationProvider* automation_; 319 // Two queues containing the test results. Although typically only 320 // one result will be in each queue, there are cases where a queue is 321 // needed. 322 // For example, perhaps two events occur asynchronously and their 323 // order of completion is not guaranteed. If the test wants to make sure 324 // both finish before continuing, a queue is needed. The test would then 325 // need to wait twice. 326 std::deque<bool> results_; 327 std::deque<std::string> messages_; 328 329 DISALLOW_COPY_AND_ASSIGN(ExtensionTestResultNotificationObserver); 330}; 331 332class BrowserOpenedNotificationObserver : public NotificationObserver { 333 public: 334 BrowserOpenedNotificationObserver(AutomationProvider* automation, 335 IPC::Message* reply_message); 336 ~BrowserOpenedNotificationObserver(); 337 338 virtual void Observe(NotificationType type, 339 const NotificationSource& source, 340 const NotificationDetails& details); 341 342 void set_for_browser_command(bool for_browser_command); 343 344 private: 345 NotificationRegistrar registrar_; 346 AutomationProvider* automation_; 347 IPC::Message* reply_message_; 348 bool for_browser_command_; 349 350 DISALLOW_COPY_AND_ASSIGN(BrowserOpenedNotificationObserver); 351}; 352 353class BrowserClosedNotificationObserver : public NotificationObserver { 354 public: 355 BrowserClosedNotificationObserver(Browser* browser, 356 AutomationProvider* automation, 357 IPC::Message* reply_message); 358 359 virtual void Observe(NotificationType type, 360 const NotificationSource& source, 361 const NotificationDetails& details); 362 363 void set_for_browser_command(bool for_browser_command); 364 365 private: 366 NotificationRegistrar registrar_; 367 AutomationProvider* automation_; 368 IPC::Message* reply_message_; 369 bool for_browser_command_; 370 371 DISALLOW_COPY_AND_ASSIGN(BrowserClosedNotificationObserver); 372}; 373 374class BrowserCountChangeNotificationObserver : public NotificationObserver { 375 public: 376 BrowserCountChangeNotificationObserver(int target_count, 377 AutomationProvider* automation, 378 IPC::Message* reply_message); 379 380 virtual void Observe(NotificationType type, 381 const NotificationSource& source, 382 const NotificationDetails& details); 383 384 private: 385 int target_count_; 386 NotificationRegistrar registrar_; 387 AutomationProvider* automation_; 388 IPC::Message* reply_message_; 389 390 DISALLOW_COPY_AND_ASSIGN(BrowserCountChangeNotificationObserver); 391}; 392 393class AppModalDialogShownObserver : public NotificationObserver { 394 public: 395 AppModalDialogShownObserver(AutomationProvider* automation, 396 IPC::Message* reply_message); 397 ~AppModalDialogShownObserver(); 398 399 virtual void Observe(NotificationType type, 400 const NotificationSource& source, 401 const NotificationDetails& details); 402 403 private: 404 NotificationRegistrar registrar_; 405 AutomationProvider* automation_; 406 IPC::Message* reply_message_; 407 408 DISALLOW_COPY_AND_ASSIGN(AppModalDialogShownObserver); 409}; 410 411class ExecuteBrowserCommandObserver : public NotificationObserver { 412 public: 413 ~ExecuteBrowserCommandObserver(); 414 415 static bool CreateAndRegisterObserver(AutomationProvider* automation, 416 Browser* browser, 417 int command, 418 IPC::Message* reply_message); 419 420 virtual void Observe(NotificationType type, 421 const NotificationSource& source, 422 const NotificationDetails& details); 423 424 private: 425 ExecuteBrowserCommandObserver(AutomationProvider* automation, 426 IPC::Message* reply_message); 427 428 bool Register(int command); 429 430 bool GetNotificationType(int command, NotificationType::Type* type); 431 432 NotificationRegistrar registrar_; 433 AutomationProvider* automation_; 434 NotificationType::Type notification_type_; 435 IPC::Message* reply_message_; 436 437 DISALLOW_COPY_AND_ASSIGN(ExecuteBrowserCommandObserver); 438}; 439 440class FindInPageNotificationObserver : public NotificationObserver { 441 public: 442 FindInPageNotificationObserver(AutomationProvider* automation, 443 TabContents* parent_tab, 444 IPC::Message* reply_message); 445 ~FindInPageNotificationObserver(); 446 447 virtual void Observe(NotificationType type, 448 const NotificationSource& source, 449 const NotificationDetails& details); 450 451 // The Find mechanism is over asynchronous IPC, so a search is kicked off and 452 // we wait for notification to find out what the results are. As the user is 453 // typing, new search requests can be issued and the Request ID helps us make 454 // sense of whether this is the current request or an old one. The unit tests, 455 // however, which uses this constant issues only one search at a time, so we 456 // don't need a rolling id to identify each search. But, we still need to 457 // specify one, so we just use a fixed one - its value does not matter. 458 static const int kFindInPageRequestId; 459 460 private: 461 NotificationRegistrar registrar_; 462 AutomationProvider* automation_; 463 // We will at some point (before final update) be notified of the ordinal and 464 // we need to preserve it so we can send it later. 465 int active_match_ordinal_; 466 IPC::Message* reply_message_; 467 468 DISALLOW_COPY_AND_ASSIGN(FindInPageNotificationObserver); 469}; 470 471class DomOperationNotificationObserver : public NotificationObserver { 472 public: 473 explicit DomOperationNotificationObserver(AutomationProvider* automation); 474 ~DomOperationNotificationObserver(); 475 476 virtual void Observe(NotificationType type, 477 const NotificationSource& source, 478 const NotificationDetails& details); 479 480 private: 481 NotificationRegistrar registrar_; 482 AutomationProvider* automation_; 483 484 DISALLOW_COPY_AND_ASSIGN(DomOperationNotificationObserver); 485}; 486 487class DocumentPrintedNotificationObserver : public NotificationObserver { 488 public: 489 DocumentPrintedNotificationObserver(AutomationProvider* automation, 490 IPC::Message* reply_message); 491 ~DocumentPrintedNotificationObserver(); 492 493 virtual void Observe(NotificationType type, const NotificationSource& source, 494 const NotificationDetails& details); 495 496 private: 497 NotificationRegistrar registrar_; 498 scoped_refptr<AutomationProvider> automation_; 499 bool success_; 500 IPC::Message* reply_message_; 501 502 DISALLOW_COPY_AND_ASSIGN(DocumentPrintedNotificationObserver); 503}; 504 505// Collects METRIC_EVENT_DURATION notifications and keep track of the times. 506class MetricEventDurationObserver : public NotificationObserver { 507 public: 508 MetricEventDurationObserver(); 509 510 // Get the duration of an event. Returns -1 if we haven't seen the event. 511 int GetEventDurationMs(const std::string& event_name); 512 513 // NotificationObserver interface. 514 virtual void Observe(NotificationType type, const NotificationSource& source, 515 const NotificationDetails& details); 516 517 private: 518 NotificationRegistrar registrar_; 519 520 typedef std::map<std::string, int> EventDurationMap; 521 EventDurationMap durations_; 522 523 DISALLOW_COPY_AND_ASSIGN(MetricEventDurationObserver); 524}; 525 526class PageTranslatedObserver : public NotificationObserver { 527 public: 528 PageTranslatedObserver(AutomationProvider* automation, 529 IPC::Message* reply_message, 530 TabContents* tab_contents); 531 532 // NotificationObserver interface. 533 virtual void Observe(NotificationType type, 534 const NotificationSource& source, 535 const NotificationDetails& details); 536 537 private: 538 NotificationRegistrar registrar_; 539 scoped_refptr<AutomationProvider> automation_; 540 IPC::Message* reply_message_; 541 542 DISALLOW_COPY_AND_ASSIGN(PageTranslatedObserver); 543}; 544 545class TabLanguageDeterminedObserver : public NotificationObserver { 546 public: 547 TabLanguageDeterminedObserver(AutomationProvider* automation, 548 IPC::Message* reply_message, 549 TabContents* tab_contents, 550 TranslateInfoBarDelegate* translate_bar); 551 552 // NotificationObserver interface. 553 virtual void Observe(NotificationType type, 554 const NotificationSource& source, 555 const NotificationDetails& details); 556 557 private: 558 NotificationRegistrar registrar_; 559 AutomationProvider* automation_; 560 IPC::Message* reply_message_; 561 TabContents* tab_contents_; 562 TranslateInfoBarDelegate* translate_bar_; 563 564 DISALLOW_COPY_AND_ASSIGN(TabLanguageDeterminedObserver); 565}; 566 567class InfoBarCountObserver : public NotificationObserver { 568 public: 569 InfoBarCountObserver(AutomationProvider* automation, 570 IPC::Message* reply_message, 571 TabContents* tab_contents, 572 int target_count); 573 574 // NotificationObserver interface. 575 virtual void Observe(NotificationType type, 576 const NotificationSource& source, 577 const NotificationDetails& details); 578 579 private: 580 // Checks whether the infobar count matches our target, and if so 581 // sends the reply message and deletes itself. 582 void CheckCount(); 583 584 NotificationRegistrar registrar_; 585 AutomationProvider* automation_; 586 IPC::Message* reply_message_; 587 TabContents* tab_contents_; 588 589 const int target_count_; 590 591 DISALLOW_COPY_AND_ASSIGN(InfoBarCountObserver); 592}; 593 594#if defined(OS_CHROMEOS) 595// Collects LOGIN_AUTHENTICATION notifications and returns 596// whether authentication succeeded to the automation provider. 597class LoginManagerObserver : public NotificationObserver { 598 public: 599 LoginManagerObserver(AutomationProvider* automation, 600 IPC::Message* reply_message); 601 602 // NotificationObserver interface. 603 virtual void Observe(NotificationType type, const NotificationSource& source, 604 const NotificationDetails& details); 605 606 private: 607 NotificationRegistrar registrar_; 608 AutomationProvider* automation_; 609 IPC::Message* reply_message_; 610 611 DISALLOW_COPY_AND_ASSIGN(LoginManagerObserver); 612}; 613#endif 614 615// Waits for the bookmark model to load. 616class AutomationProviderBookmarkModelObserver : BookmarkModelObserver { 617 public: 618 AutomationProviderBookmarkModelObserver(AutomationProvider* provider, 619 IPC::Message* reply_message, 620 BookmarkModel* model); 621 virtual ~AutomationProviderBookmarkModelObserver(); 622 623 virtual void Loaded(BookmarkModel* model) { 624 ReplyAndDelete(true); 625 } 626 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) { 627 ReplyAndDelete(false); 628 } 629 virtual void BookmarkNodeMoved(BookmarkModel* model, 630 const BookmarkNode* old_parent, 631 int old_index, 632 const BookmarkNode* new_parent, 633 int new_index) {} 634 virtual void BookmarkNodeAdded(BookmarkModel* model, 635 const BookmarkNode* parent, 636 int index) {} 637 virtual void BookmarkNodeRemoved(BookmarkModel* model, 638 const BookmarkNode* parent, 639 int old_index, 640 const BookmarkNode* node) {} 641 virtual void BookmarkNodeChanged(BookmarkModel* model, 642 const BookmarkNode* node) {} 643 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, 644 const BookmarkNode* node) {} 645 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, 646 const BookmarkNode* node) {} 647 648 private: 649 // Reply to the automation message with the given success value, 650 // then delete myself (which removes myself from the bookmark model 651 // observer list). 652 void ReplyAndDelete(bool success); 653 654 scoped_refptr<AutomationProvider> automation_provider_; 655 IPC::Message* reply_message_; 656 BookmarkModel* model_; 657 658 DISALLOW_COPY_AND_ASSIGN(AutomationProviderBookmarkModelObserver); 659}; 660 661// Allows the automation provider to wait for all downloads to finish. 662class AutomationProviderDownloadItemObserver : public DownloadItem::Observer { 663 public: 664 AutomationProviderDownloadItemObserver( 665 AutomationProvider* provider, 666 IPC::Message* reply_message, 667 int downloads) { 668 provider_ = provider; 669 reply_message_ = reply_message; 670 downloads_ = downloads; 671 } 672 virtual ~AutomationProviderDownloadItemObserver() {} 673 674 virtual void OnDownloadUpdated(DownloadItem* download) { } 675 virtual void OnDownloadFileCompleted(DownloadItem* download); 676 virtual void OnDownloadOpened(DownloadItem* download) { } 677 678 private: 679 AutomationProvider* provider_; 680 IPC::Message* reply_message_; 681 int downloads_; 682 683 DISALLOW_COPY_AND_ASSIGN(AutomationProviderDownloadItemObserver); 684}; 685 686// Allows the automation provider to wait until the download has been updated 687// or opened. 688class AutomationProviderDownloadUpdatedObserver 689 : public DownloadItem::Observer { 690 public: 691 AutomationProviderDownloadUpdatedObserver( 692 AutomationProvider* provider, 693 IPC::Message* reply_message, 694 bool wait_for_open) 695 : provider_(provider), 696 reply_message_(reply_message), 697 wait_for_open_(wait_for_open) {} 698 699 virtual void OnDownloadUpdated(DownloadItem* download); 700 virtual void OnDownloadOpened(DownloadItem* download); 701 virtual void OnDownloadFileCompleted(DownloadItem* download) { } 702 703 private: 704 AutomationProvider* provider_; 705 IPC::Message* reply_message_; 706 bool wait_for_open_; 707 708 DISALLOW_COPY_AND_ASSIGN(AutomationProviderDownloadUpdatedObserver); 709}; 710 711// Allows the automation provider to wait until the download model has changed 712// (because a new download has been added or removed). 713class AutomationProviderDownloadModelChangedObserver 714 : public DownloadManager::Observer { 715 public: 716 AutomationProviderDownloadModelChangedObserver( 717 AutomationProvider* provider, 718 IPC::Message* reply_message, 719 DownloadManager* download_manager) 720 : provider_(provider), 721 reply_message_(reply_message), 722 download_manager_(download_manager) {} 723 724 virtual void ModelChanged(); 725 726 private: 727 AutomationProvider* provider_; 728 IPC::Message* reply_message_; 729 DownloadManager* download_manager_; 730 731 DISALLOW_COPY_AND_ASSIGN(AutomationProviderDownloadModelChangedObserver); 732}; 733 734// Allows automation provider to wait until TemplateURLModel has loaded 735// before looking up/returning search engine info. 736class AutomationProviderSearchEngineObserver 737 : public TemplateURLModelObserver { 738 public: 739 AutomationProviderSearchEngineObserver( 740 TestingAutomationProvider* provider, 741 IPC::Message* reply_message) 742 : provider_(provider), 743 reply_message_(reply_message) {} 744 745 void OnTemplateURLModelChanged(); 746 747 private: 748 TestingAutomationProvider* provider_; 749 IPC::Message* reply_message_; 750 751 DISALLOW_COPY_AND_ASSIGN(AutomationProviderSearchEngineObserver); 752}; 753 754// Allows the automation provider to wait for history queries to finish. 755class AutomationProviderHistoryObserver { 756 public: 757 AutomationProviderHistoryObserver( 758 AutomationProvider* provider, 759 IPC::Message* reply_message) { 760 provider_ = provider; 761 reply_message_ = reply_message; 762 } 763 ~AutomationProviderHistoryObserver() {} 764 void HistoryQueryComplete(HistoryService::Handle request_handle, 765 history::QueryResults* results); 766 767 private: 768 AutomationProvider* provider_; 769 IPC::Message* reply_message_; 770}; 771 772// Allows the automation provider to wait for import queries to finish. 773class AutomationProviderImportSettingsObserver 774 : public ImporterHost::Observer { 775 public: 776 AutomationProviderImportSettingsObserver( 777 AutomationProvider* provider, 778 IPC::Message* reply_message) 779 : provider_(provider), 780 reply_message_(reply_message) {} 781 void ImportStarted() {} 782 void ImportItemStarted(importer::ImportItem item) {} 783 void ImportItemEnded(importer::ImportItem item) {} 784 void ImportEnded(); 785 private: 786 AutomationProvider* provider_; 787 IPC::Message* reply_message_; 788}; 789 790// Allows automation provider to wait for getting passwords to finish. 791class AutomationProviderGetPasswordsObserver 792 : public PasswordStoreConsumer { 793 public: 794 AutomationProviderGetPasswordsObserver( 795 AutomationProvider* provider, 796 IPC::Message* reply_message) 797 : provider_(provider), 798 reply_message_(reply_message) {} 799 800 void OnPasswordStoreRequestDone( 801 int handle, const std::vector<webkit_glue::PasswordForm*>& result); 802 803 private: 804 AutomationProvider* provider_; 805 IPC::Message* reply_message_; 806}; 807 808// Allows the automation provider to wait for clearing browser data to finish. 809class AutomationProviderBrowsingDataObserver 810 : public BrowsingDataRemover::Observer { 811 public: 812 AutomationProviderBrowsingDataObserver( 813 AutomationProvider* provider, 814 IPC::Message* reply_message) 815 : provider_(provider), 816 reply_message_(reply_message) {} 817 void OnBrowsingDataRemoverDone(); 818 819 private: 820 AutomationProvider* provider_; 821 IPC::Message* reply_message_; 822}; 823 824// Allows automation provider to wait until page load after selecting an item 825// in the omnibox popup. 826class OmniboxAcceptNotificationObserver : public NotificationObserver { 827 public: 828 OmniboxAcceptNotificationObserver(NavigationController* controller, 829 AutomationProvider* automation, 830 IPC::Message* reply_message); 831 ~OmniboxAcceptNotificationObserver(); 832 833 virtual void Observe(NotificationType type, 834 const NotificationSource& source, 835 const NotificationDetails& details); 836 837 private: 838 NotificationRegistrar registrar_; 839 AutomationProvider* automation_; 840 IPC::Message* reply_message_; 841 NavigationController* controller_; 842 843 DISALLOW_COPY_AND_ASSIGN(OmniboxAcceptNotificationObserver); 844}; 845 846// Allows the automation provider to wait for a save package notification. 847class SavePackageNotificationObserver : public NotificationObserver { 848 public: 849 SavePackageNotificationObserver(SavePackage* save_package, 850 AutomationProvider* automation, 851 IPC::Message* reply_message); 852 virtual ~SavePackageNotificationObserver() {} 853 854 virtual void Observe(NotificationType type, 855 const NotificationSource& source, 856 const NotificationDetails& details); 857 858 private: 859 NotificationRegistrar registrar_; 860 AutomationProvider* automation_; 861 IPC::Message* reply_message_; 862 863 DISALLOW_COPY_AND_ASSIGN(SavePackageNotificationObserver); 864}; 865 866// Allows automation provider to wait until the autocomplete edit 867// has received focus 868class AutocompleteEditFocusedObserver : public NotificationObserver { 869 public: 870 AutocompleteEditFocusedObserver(AutomationProvider* automation, 871 AutocompleteEditModel* autocomplete_edit, 872 IPC::Message* reply_message); 873 874 virtual void Observe(NotificationType type, 875 const NotificationSource& source, 876 const NotificationDetails& details); 877 878 private: 879 NotificationRegistrar registrar_; 880 AutomationProvider* automation_; 881 IPC::Message* reply_message_; 882 AutocompleteEditModel* autocomplete_edit_model_; 883 884 DISALLOW_COPY_AND_ASSIGN(AutocompleteEditFocusedObserver); 885}; 886 887#endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_ 888