OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/download/download_test_file_activity_observer.h" | 5 #include "chrome/browser/download/download_test_file_activity_observer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 9 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
10 #include "chrome/browser/download/download_service.h" | 10 #include "chrome/browser/download/download_service.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 base::WeakPtr<MockDownloadManagerDelegate> GetWeakPtr() { | 46 base::WeakPtr<MockDownloadManagerDelegate> GetWeakPtr() { |
47 return weak_ptr_factory_.GetWeakPtr(); | 47 return weak_ptr_factory_.GetWeakPtr(); |
48 } | 48 } |
49 | 49 |
50 protected: | 50 protected: |
51 | 51 |
52 virtual void PromptUserForDownloadPath(content::DownloadItem* item, | 52 virtual void PromptUserForDownloadPath(content::DownloadItem* item, |
53 const base::FilePath& suggested_path, | 53 const base::FilePath& suggested_path, |
54 const FileSelectedCallback& | 54 const FileSelectedCallback& |
55 callback) OVERRIDE { | 55 callback) override { |
56 file_chooser_displayed_ = true; | 56 file_chooser_displayed_ = true; |
57 base::MessageLoop::current()->PostTask( | 57 base::MessageLoop::current()->PostTask( |
58 FROM_HERE, base::Bind(callback, (file_chooser_enabled_ ? suggested_path | 58 FROM_HERE, base::Bind(callback, (file_chooser_enabled_ ? suggested_path |
59 : base::FilePath()))); | 59 : base::FilePath()))); |
60 } | 60 } |
61 | 61 |
62 virtual void OpenDownload(content::DownloadItem* item) OVERRIDE {} | 62 virtual void OpenDownload(content::DownloadItem* item) override {} |
63 | 63 |
64 private: | 64 private: |
65 bool file_chooser_enabled_; | 65 bool file_chooser_enabled_; |
66 bool file_chooser_displayed_; | 66 bool file_chooser_displayed_; |
67 base::WeakPtrFactory<MockDownloadManagerDelegate> weak_ptr_factory_; | 67 base::WeakPtrFactory<MockDownloadManagerDelegate> weak_ptr_factory_; |
68 }; | 68 }; |
69 | 69 |
70 DownloadTestFileActivityObserver::DownloadTestFileActivityObserver( | 70 DownloadTestFileActivityObserver::DownloadTestFileActivityObserver( |
71 Profile* profile) { | 71 Profile* profile) { |
72 scoped_ptr<MockDownloadManagerDelegate> mock_delegate( | 72 scoped_ptr<MockDownloadManagerDelegate> mock_delegate( |
73 new MockDownloadManagerDelegate(profile)); | 73 new MockDownloadManagerDelegate(profile)); |
74 test_delegate_ = mock_delegate->GetWeakPtr(); | 74 test_delegate_ = mock_delegate->GetWeakPtr(); |
75 DownloadServiceFactory::GetForBrowserContext(profile)-> | 75 DownloadServiceFactory::GetForBrowserContext(profile)-> |
76 SetDownloadManagerDelegateForTesting( | 76 SetDownloadManagerDelegateForTesting( |
77 mock_delegate.PassAs<ChromeDownloadManagerDelegate>()); | 77 mock_delegate.PassAs<ChromeDownloadManagerDelegate>()); |
78 } | 78 } |
79 | 79 |
80 DownloadTestFileActivityObserver::~DownloadTestFileActivityObserver() { | 80 DownloadTestFileActivityObserver::~DownloadTestFileActivityObserver() { |
81 } | 81 } |
82 | 82 |
83 void DownloadTestFileActivityObserver::EnableFileChooser(bool enable) { | 83 void DownloadTestFileActivityObserver::EnableFileChooser(bool enable) { |
84 if (test_delegate_.get()) | 84 if (test_delegate_.get()) |
85 test_delegate_->EnableFileChooser(enable); | 85 test_delegate_->EnableFileChooser(enable); |
86 } | 86 } |
87 | 87 |
88 bool DownloadTestFileActivityObserver::TestAndResetDidShowFileChooser() { | 88 bool DownloadTestFileActivityObserver::TestAndResetDidShowFileChooser() { |
89 return test_delegate_.get() && | 89 return test_delegate_.get() && |
90 test_delegate_->TestAndResetDidShowFileChooser(); | 90 test_delegate_->TestAndResetDidShowFileChooser(); |
91 } | 91 } |
OLD | NEW |