Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6068)

Unified Diff: chrome/browser/download/download_test_file_activity_observer.cc

Issue 12850002: Move download filename determintion into a separate class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/download_test_file_activity_observer.cc
diff --git a/chrome/browser/download/download_test_file_activity_observer.cc b/chrome/browser/download/download_test_file_activity_observer.cc
index 2137409dea736177b4e7bfb4ec306df8d5eeeabc..759aa345b55af8ecee523c1d7c941b8f8cfb0df2 100644
--- a/chrome/browser/download/download_test_file_activity_observer.cc
+++ b/chrome/browser/download/download_test_file_activity_observer.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/message_loop.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h"
+#include "chrome/browser/download/download_file_picker.h"
#include "chrome/browser/download/download_service.h"
#include "chrome/browser/download/download_service_factory.h"
#include "chrome/browser/profiles/profile.h"
@@ -15,16 +16,26 @@ namespace content {
class DownloadItem;
}
-// Test ChromeDownloadManagerDelegate that controls whether how file chooser
-// dialogs are handled, and how files are opend.
-// By default, file chooser dialogs are disabled.
-class DownloadTestFileActivityObserver::MockDownloadManagerDelegate
- : public ChromeDownloadManagerDelegate {
+class DownloadTestFileActivityObserver::TestDownloadFilePickerFactory
+ : public DownloadFilePickerFactory {
public:
- explicit MockDownloadManagerDelegate(Profile* profile)
- : ChromeDownloadManagerDelegate(profile),
- file_chooser_enabled_(false),
- file_chooser_displayed_(false) {}
+ TestDownloadFilePickerFactory()
+ : file_chooser_enabled_(false),
+ file_chooser_displayed_(false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
+ }
+
+ // DownloadFilePicker
+ virtual void Create(
+ content::DownloadItem* download,
+ const base::FilePath& suggested_path,
+ const DownloadFilePicker::FileSelectedCallback& callback) OVERRIDE {
+ base::FilePath target_path =
+ file_chooser_enabled_ ? suggested_path : base::FilePath();
+ file_chooser_displayed_ = true;
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, target_path, target_path));
+ }
void EnableFileChooser(bool enable) {
file_chooser_enabled_ = enable;
@@ -36,41 +47,36 @@ class DownloadTestFileActivityObserver::MockDownloadManagerDelegate
return did_show;
}
- protected:
-
- virtual void ChooseDownloadPath(content::DownloadItem* item,
- const base::FilePath& suggested_path,
- const FileSelectedCallback&
- callback) OVERRIDE {
- file_chooser_displayed_ = true;
- MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, (file_chooser_enabled_ ? suggested_path
- : base::FilePath())));
+ base::WeakPtr<TestDownloadFilePickerFactory> GetWeakPtr() {
+ return weak_ptr_factory_.GetWeakPtr();
}
- virtual void OpenDownload(content::DownloadItem* item) OVERRIDE {}
-
private:
- virtual ~MockDownloadManagerDelegate() {}
-
bool file_chooser_enabled_;
bool file_chooser_displayed_;
+ base::WeakPtrFactory<TestDownloadFilePickerFactory> weak_ptr_factory_;
};
DownloadTestFileActivityObserver::DownloadTestFileActivityObserver(
Profile* profile) {
- test_delegate_ = new MockDownloadManagerDelegate(profile);
- DownloadServiceFactory::GetForProfile(profile)->
- SetDownloadManagerDelegateForTesting(test_delegate_.get());
+ scoped_ptr<TestDownloadFilePickerFactory> file_picker_factory(
+ new TestDownloadFilePickerFactory);
+ test_file_picker_factory_ = file_picker_factory->GetWeakPtr();
+
+ DownloadService* service = DownloadServiceFactory::GetForProfile(profile);
+ service->GetDownloadManagerDelegate()->SetFilePickerFactoryForTesting(
+ file_picker_factory.PassAs<DownloadFilePickerFactory>());
}
DownloadTestFileActivityObserver::~DownloadTestFileActivityObserver() {
}
void DownloadTestFileActivityObserver::EnableFileChooser(bool enable) {
- test_delegate_->EnableFileChooser(enable);
+ if (test_file_picker_factory_.get())
+ test_file_picker_factory_->EnableFileChooser(enable);
}
bool DownloadTestFileActivityObserver::TestAndResetDidShowFileChooser() {
- return test_delegate_->TestAndResetDidShowFileChooser();
+ return test_file_picker_factory_.get() &&
+ test_file_picker_factory_->TestAndResetDidShowFileChooser();
}

Powered by Google App Engine
This is Rietveld 408576698