diff options
author | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-23 22:53:34 +0000 |
---|---|---|
committer | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-23 22:53:34 +0000 |
commit | eb42324face9d818f6a413da023e6285066bc75c (patch) | |
tree | 5fc3a1afb4dedaf0b1a43fd00e53d77c01999296 /chrome/browser | |
parent | e2dc7a9ed47809db64bb516ffcca831fe4548964 (diff) | |
download | chromium_src-eb42324face9d818f6a413da023e6285066bc75c.zip chromium_src-eb42324face9d818f6a413da023e6285066bc75c.tar.gz chromium_src-eb42324face9d818f6a413da023e6285066bc75c.tar.bz2 |
Revert 178351
Seems to have broken aura on windows
> content: remove NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED
>
> BUG=170921
>
> Review URL: https://codereview.chromium.org/11867023
TBR=phajdan.jr@chromium.org
Review URL: https://codereview.chromium.org/11953064
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178404 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
4 files changed, 48 insertions, 156 deletions
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index 004398b..051bf68 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -1707,31 +1707,31 @@ void OmniboxAcceptNotificationObserver::Observe( } SavePackageNotificationObserver::SavePackageNotificationObserver( - content::DownloadManager* download_manager, + DownloadManager* download_manager, AutomationProvider* automation, IPC::Message* reply_message) - : download_manager_(download_manager), - automation_(automation->AsWeakPtr()), + : automation_(automation->AsWeakPtr()), reply_message_(reply_message) { - download_manager_->AddObserver(this); + content::Source<DownloadManager> source(download_manager); + registrar_.Add(this, content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, + source); } -SavePackageNotificationObserver::~SavePackageNotificationObserver() { - download_manager_->RemoveObserver(this); -} +SavePackageNotificationObserver::~SavePackageNotificationObserver() {} -void SavePackageNotificationObserver::OnSavePackageSuccessfullyFinished( - content::DownloadManager* manager, content::DownloadItem* item) { - if (automation_) { - AutomationJSONReply(automation_, - reply_message_.release()).SendSuccess(NULL); +void SavePackageNotificationObserver::Observe( + int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + if (type == content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED) { + if (automation_) { + AutomationJSONReply(automation_, + reply_message_.release()).SendSuccess(NULL); + } + delete this; + } else { + NOTREACHED(); } - delete this; -} - -void SavePackageNotificationObserver::ManagerGoingDown( - content::DownloadManager* manager) { - delete this; } PageSnapshotTaker::PageSnapshotTaker(AutomationProvider* automation, diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h index fec988a..6ba85ae 100644 --- a/chrome/browser/automation/automation_provider_observers.h +++ b/chrome/browser/automation/automation_provider_observers.h @@ -1246,21 +1246,20 @@ class OmniboxAcceptNotificationObserver : public content::NotificationObserver { }; // Allows the automation provider to wait for a save package notification. -class SavePackageNotificationObserver -: public content::DownloadManager::Observer { +class SavePackageNotificationObserver : public content::NotificationObserver { public: SavePackageNotificationObserver(content::DownloadManager* download_manager, AutomationProvider* automation, IPC::Message* reply_message); virtual ~SavePackageNotificationObserver(); - // Overridden from content::DownloadManager::Observer: - virtual void OnSavePackageSuccessfullyFinished( - content::DownloadManager* manager, content::DownloadItem* item) OVERRIDE; - virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE; + // Overridden from content::NotificationObserver: + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) OVERRIDE; private: - content::DownloadManager* download_manager_; + content::NotificationRegistrar registrar_; base::WeakPtr<AutomationProvider> automation_; scoped_ptr<IPC::Message> reply_message_; diff --git a/chrome/browser/browser_encoding_browsertest.cc b/chrome/browser/browser_encoding_browsertest.cc index 8c5fe94..6b292bc 100644 --- a/chrome/browser/browser_encoding_browsertest.cc +++ b/chrome/browser/browser_encoding_browsertest.cc @@ -16,7 +16,6 @@ #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/download_manager.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" @@ -66,37 +65,6 @@ const EncodingTestData kEncodingTestDatas[] = { { "windows-1258.html", "windows-1258" } }; -class SavePackageFinishedObserver : public content::DownloadManager::Observer { - public: - SavePackageFinishedObserver(content::DownloadManager* manager, - const base::Closure& callback) - : download_manager_(manager), - callback_(callback) { - download_manager_->AddObserver(this); - } - - virtual ~SavePackageFinishedObserver() { - if (download_manager_) - download_manager_->RemoveObserver(this); - } - - // DownloadManager::Observer: - virtual void OnSavePackageSuccessfullyFinished( - content::DownloadManager* manager, content::DownloadItem* item) OVERRIDE { - callback_.Run(); - } - virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE { - download_manager_->RemoveObserver(this); - download_manager_ = NULL; - } - - private: - content::DownloadManager* download_manager_; - base::Closure callback_; - - DISALLOW_COPY_AND_ASSIGN(SavePackageFinishedObserver); -}; - } // namespace using content::BrowserThread; @@ -118,15 +86,13 @@ class BrowserEncodingTest // We save the page as way of complete HTML file, which requires a directory // name to save sub resources in it. Although this test file does not have // sub resources, but the directory name is still required. - scoped_refptr<content::MessageLoopRunner> loop_runner( - new content::MessageLoopRunner); - SavePackageFinishedObserver observer( - content::BrowserContext::GetDownloadManager(browser()->profile()), - loop_runner->QuitClosure()); + content::WindowedNotificationObserver observer( + content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, + content::NotificationService::AllSources()); chrome::GetActiveWebContents(browser())->SavePage( full_file_name, temp_sub_resource_dir_, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML); - loop_runner->Run(); + observer.Wait(); FilePath expected_file_name = ui_test_utils::GetTestFilePath( FilePath(kTestDir), expected); diff --git a/chrome/browser/download/save_page_browsertest.cc b/chrome/browser/download/save_page_browsertest.cc index 43c8781..166a039 100644 --- a/chrome/browser/download/save_page_browsertest.cc +++ b/chrome/browser/download/save_page_browsertest.cc @@ -53,8 +53,6 @@ using content::DownloadManager; using content::URLRequestMockHTTPJob; using content::WebContents; -namespace { - // Waits for an item record in the downloads database to match |filter|. See // DownloadStoredProperly() below for an example filter. class DownloadPersistedObserver : public DownloadHistory::Observer { @@ -242,37 +240,6 @@ class DownloadItemCreatedObserver : public DownloadManager::Observer { DISALLOW_COPY_AND_ASSIGN(DownloadItemCreatedObserver); }; -class SavePackageFinishedObserver : public content::DownloadManager::Observer { - public: - SavePackageFinishedObserver(content::DownloadManager* manager, - const base::Closure& callback) - : download_manager_(manager), - callback_(callback) { - download_manager_->AddObserver(this); - } - - virtual ~SavePackageFinishedObserver() { - if (download_manager_) - download_manager_->RemoveObserver(this); - } - - // DownloadManager::Observer: - virtual void OnSavePackageSuccessfullyFinished( - content::DownloadManager* manager, content::DownloadItem* item) OVERRIDE { - callback_.Run(); - } - virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE { - download_manager_->RemoveObserver(this); - download_manager_ = NULL; - } - - private: - content::DownloadManager* download_manager_; - base::Closure callback_; - - DISALLOW_COPY_AND_ASSIGN(SavePackageFinishedObserver); -}; - class SavePageBrowserTest : public InProcessBrowserTest { public: SavePageBrowserTest() {} @@ -316,9 +283,14 @@ class SavePageBrowserTest : public InProcessBrowserTest { // Returns true if and when there was a single download created, and its url // is |expected_url|. - bool VerifySavePackageExpectations( + bool WaitForSavePackageToFinish( Browser* browser, const GURL& expected_url) const { + content::WindowedNotificationObserver observer( + content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, + content::NotificationService::AllSources()); + observer.Wait(); + // Generally, there should only be one download item created // in all of these tests. If it's already here, grab it; if not, // wait for it to show up. @@ -335,7 +307,9 @@ class SavePageBrowserTest : public InProcessBrowserTest { return false; DownloadItem* download_item(items[0]); - return (expected_url == download_item->GetOriginalUrl()); + return ((expected_url == download_item->GetOriginalUrl()) && + (expected_url == content::Details<DownloadItem>( + observer.details()).ptr()->GetOriginalUrl())); } // Note on synchronization: @@ -384,15 +358,9 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveHTMLOnly) { DownloadPersistedObserver persisted(browser()->profile(), base::Bind( &DownloadStoredProperly, url, full_file_name, 1, DownloadItem::COMPLETE)); - scoped_refptr<content::MessageLoopRunner> loop_runner( - new content::MessageLoopRunner); - SavePackageFinishedObserver observer( - content::BrowserContext::GetDownloadManager(browser()->profile()), - loop_runner->QuitClosure()); ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); - loop_runner->Run(); - ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); + ASSERT_TRUE(WaitForSavePackageToFinish(browser(), url)); persisted.WaitForPersisted(); EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); EXPECT_TRUE(file_util::PathExists(full_file_name)); @@ -486,15 +454,9 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveViewSourceHTMLOnly) { DownloadPersistedObserver persisted(browser()->profile(), base::Bind( &DownloadStoredProperly, actual_page_url, full_file_name, 1, DownloadItem::COMPLETE)); - scoped_refptr<content::MessageLoopRunner> loop_runner( - new content::MessageLoopRunner); - SavePackageFinishedObserver observer( - content::BrowserContext::GetDownloadManager(browser()->profile()), - loop_runner->QuitClosure()); ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); - loop_runner->Run(); - ASSERT_TRUE(VerifySavePackageExpectations(browser(), actual_page_url)); + ASSERT_TRUE(WaitForSavePackageToFinish(browser(), actual_page_url)); persisted.WaitForPersisted(); EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); @@ -520,15 +482,9 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveCompleteHTML) { DownloadPersistedObserver persisted(browser()->profile(), base::Bind( &DownloadStoredProperly, url, full_file_name, 3, DownloadItem::COMPLETE)); - scoped_refptr<content::MessageLoopRunner> loop_runner( - new content::MessageLoopRunner); - SavePackageFinishedObserver observer( - content::BrowserContext::GetDownloadManager(browser()->profile()), - loop_runner->QuitClosure()); ASSERT_TRUE(GetCurrentTab(browser())->SavePage( full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); - loop_runner->Run(); - ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); + ASSERT_TRUE(WaitForSavePackageToFinish(browser(), url)); persisted.WaitForPersisted(); EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); @@ -574,16 +530,10 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, // Save the page before completion. FilePath full_file_name, dir; GetDestinationPaths("b", &full_file_name, &dir); - scoped_refptr<content::MessageLoopRunner> loop_runner( - new content::MessageLoopRunner); - SavePackageFinishedObserver observer( - content::BrowserContext::GetDownloadManager(incognito->profile()), - loop_runner->QuitClosure()); ASSERT_TRUE(GetCurrentTab(incognito)->SavePage( full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); - loop_runner->Run(); - ASSERT_TRUE(VerifySavePackageExpectations(incognito, url)); + ASSERT_TRUE(WaitForSavePackageToFinish(incognito, url)); // Confirm download shelf is visible. EXPECT_TRUE(incognito->window()->IsDownloadShelfVisible()); @@ -616,16 +566,10 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_FileNameFromPageTitle) { DownloadPersistedObserver persisted(browser()->profile(), base::Bind( &DownloadStoredProperly, url, full_file_name, 3, DownloadItem::COMPLETE)); - scoped_refptr<content::MessageLoopRunner> loop_runner( - new content::MessageLoopRunner); - SavePackageFinishedObserver observer( - content::BrowserContext::GetDownloadManager(browser()->profile()), - loop_runner->QuitClosure()); ASSERT_TRUE(GetCurrentTab(browser())->SavePage( full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); - loop_runner->Run(); - ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); + ASSERT_TRUE(WaitForSavePackageToFinish(browser(), url)); persisted.WaitForPersisted(); EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); @@ -657,16 +601,10 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_RemoveFromList) { DownloadPersistedObserver persisted(browser()->profile(), base::Bind( &DownloadStoredProperly, url, full_file_name, 1, DownloadItem::COMPLETE)); - scoped_refptr<content::MessageLoopRunner> loop_runner( - new content::MessageLoopRunner); - SavePackageFinishedObserver observer( - content::BrowserContext::GetDownloadManager(browser()->profile()), - loop_runner->QuitClosure()); ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); - loop_runner->Run(); - ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); + ASSERT_TRUE(WaitForSavePackageToFinish(browser(), url)); persisted.WaitForPersisted(); EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); @@ -707,13 +645,11 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, CleanFilenameFromPageTitle) { ui_test_utils::NavigateToURL(browser(), url); SavePackageFilePicker::SetShouldPromptUser(false); - scoped_refptr<content::MessageLoopRunner> loop_runner( - new content::MessageLoopRunner); - SavePackageFinishedObserver observer( - content::BrowserContext::GetDownloadManager(browser()->profile()), - loop_runner->QuitClosure()); + content::WindowedNotificationObserver observer( + content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, + content::NotificationService::AllSources()); chrome::SavePage(browser()); - loop_runner->Run(); + observer.Wait(); EXPECT_TRUE(file_util::PathExists(full_file_name)); @@ -752,14 +688,8 @@ IN_PROC_BROWSER_TEST_F(SavePageAsMHTMLBrowserTest, SavePageAsMHTML) { DownloadPersistedObserver persisted(browser()->profile(), base::Bind( &DownloadStoredProperly, url, full_file_name, -1, DownloadItem::COMPLETE)); - scoped_refptr<content::MessageLoopRunner> loop_runner( - new content::MessageLoopRunner); - SavePackageFinishedObserver observer( - content::BrowserContext::GetDownloadManager(browser()->profile()), - loop_runner->QuitClosure()); chrome::SavePage(browser()); - loop_runner->Run(); - ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); + ASSERT_TRUE(WaitForSavePackageToFinish(browser(), url)); persisted.WaitForPersisted(); EXPECT_TRUE(file_util::PathExists(full_file_name)); @@ -767,6 +697,3 @@ IN_PROC_BROWSER_TEST_F(SavePageAsMHTMLBrowserTest, SavePageAsMHTML) { EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); EXPECT_LE(kFileSizeMin, actual_file_size); } - -} // namespace - |