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/extensions/api/downloads/downloads_api.h" | 5 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 determined_filename_ = creator_suggested_filename_; | 652 determined_filename_ = creator_suggested_filename_; |
653 determined_conflict_action_ = creator_conflict_action_; | 653 determined_conflict_action_ = creator_conflict_action_; |
654 // determiner_.install_time should default to 0 so that creator suggestions | 654 // determiner_.install_time should default to 0 so that creator suggestions |
655 // should be lower priority than any actual onDeterminingFilename listeners. | 655 // should be lower priority than any actual onDeterminingFilename listeners. |
656 | 656 |
657 // Ensure that the callback is called within a time limit. | 657 // Ensure that the callback is called within a time limit. |
658 weak_ptr_factory_.reset( | 658 weak_ptr_factory_.reset( |
659 new base::WeakPtrFactory<ExtensionDownloadsEventRouterData>(this)); | 659 new base::WeakPtrFactory<ExtensionDownloadsEventRouterData>(this)); |
660 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 660 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
661 FROM_HERE, | 661 FROM_HERE, |
662 base::Bind(&ExtensionDownloadsEventRouterData::DetermineFilenameTimeout, | 662 base::BindOnce( |
663 weak_ptr_factory_->GetWeakPtr()), | 663 &ExtensionDownloadsEventRouterData::DetermineFilenameTimeout, |
| 664 weak_ptr_factory_->GetWeakPtr()), |
664 base::TimeDelta::FromSeconds(determine_filename_timeout_s_)); | 665 base::TimeDelta::FromSeconds(determine_filename_timeout_s_)); |
665 } | 666 } |
666 | 667 |
667 void DetermineFilenameTimeout() { | 668 void DetermineFilenameTimeout() { |
668 CallFilenameCallback(); | 669 CallFilenameCallback(); |
669 } | 670 } |
670 | 671 |
671 void ClearPendingDeterminers() { | 672 void ClearPendingDeterminers() { |
672 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 673 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
673 determined_filename_.clear(); | 674 determined_filename_.clear(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 | 819 |
819 // Don't clear determiners_ immediately in case there's a second listener | 820 // Don't clear determiners_ immediately in case there's a second listener |
820 // for one of the extensions, so that DetermineFilename can return | 821 // for one of the extensions, so that DetermineFilename can return |
821 // kTooManyListeners. After a few seconds, DetermineFilename will return | 822 // kTooManyListeners. After a few seconds, DetermineFilename will return |
822 // kUnexpectedDeterminer instead of kTooManyListeners so that determiners_ | 823 // kUnexpectedDeterminer instead of kTooManyListeners so that determiners_ |
823 // doesn't keep hogging memory. | 824 // doesn't keep hogging memory. |
824 weak_ptr_factory_.reset( | 825 weak_ptr_factory_.reset( |
825 new base::WeakPtrFactory<ExtensionDownloadsEventRouterData>(this)); | 826 new base::WeakPtrFactory<ExtensionDownloadsEventRouterData>(this)); |
826 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 827 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
827 FROM_HERE, | 828 FROM_HERE, |
828 base::Bind(&ExtensionDownloadsEventRouterData::ClearPendingDeterminers, | 829 base::BindOnce( |
829 weak_ptr_factory_->GetWeakPtr()), | 830 &ExtensionDownloadsEventRouterData::ClearPendingDeterminers, |
| 831 weak_ptr_factory_->GetWeakPtr()), |
830 base::TimeDelta::FromSeconds(15)); | 832 base::TimeDelta::FromSeconds(15)); |
831 } | 833 } |
832 | 834 |
833 void CallFilenameCallback() { | 835 void CallFilenameCallback() { |
834 if (determined_filename_.empty() && | 836 if (determined_filename_.empty() && |
835 (determined_conflict_action_ == | 837 (determined_conflict_action_ == |
836 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY)) { | 838 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY)) { |
837 if (!filename_no_change_.is_null()) | 839 if (!filename_no_change_.is_null()) |
838 filename_no_change_.Run(); | 840 filename_no_change_.Run(); |
839 } else { | 841 } else { |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 errors::kNotInProgress, &error_) || | 1271 errors::kNotInProgress, &error_) || |
1270 Fault(!download_item->IsDangerous(), errors::kNotDangerous, &error_) || | 1272 Fault(!download_item->IsDangerous(), errors::kNotDangerous, &error_) || |
1271 Fault(!web_contents, errors::kInvisibleContext, &error_)) { | 1273 Fault(!web_contents, errors::kInvisibleContext, &error_)) { |
1272 SendResponse(error_.empty()); | 1274 SendResponse(error_.empty()); |
1273 return; | 1275 return; |
1274 } | 1276 } |
1275 bool visible = platform_util::IsVisible(web_contents->GetNativeView()); | 1277 bool visible = platform_util::IsVisible(web_contents->GetNativeView()); |
1276 if (!visible) { | 1278 if (!visible) { |
1277 if (retries > 0) { | 1279 if (retries > 0) { |
1278 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1280 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1279 FROM_HERE, base::Bind(&DownloadsAcceptDangerFunction::PromptOrWait, | 1281 FROM_HERE, |
1280 this, download_id, retries - 1), | 1282 base::BindOnce(&DownloadsAcceptDangerFunction::PromptOrWait, this, |
| 1283 download_id, retries - 1), |
1281 base::TimeDelta::FromMilliseconds(100)); | 1284 base::TimeDelta::FromMilliseconds(100)); |
1282 return; | 1285 return; |
1283 } | 1286 } |
1284 error_ = errors::kInvisibleContext; | 1287 error_ = errors::kInvisibleContext; |
1285 SendResponse(false); | 1288 SendResponse(false); |
1286 return; | 1289 return; |
1287 } | 1290 } |
1288 RecordApiFunctions(DOWNLOADS_FUNCTION_ACCEPT_DANGER); | 1291 RecordApiFunctions(DOWNLOADS_FUNCTION_ACCEPT_DANGER); |
1289 // DownloadDangerPrompt displays a modal dialog using native widgets that the | 1292 // DownloadDangerPrompt displays a modal dialog using native widgets that the |
1290 // user must either accept or cancel. It cannot be scripted. | 1293 // user must either accept or cancel. It cannot be scripted. |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1920 return; | 1923 return; |
1921 base::Time now(base::Time::Now()); | 1924 base::Time now(base::Time::Now()); |
1922 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); | 1925 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); |
1923 if (delta <= kFileExistenceRateLimitSeconds) | 1926 if (delta <= kFileExistenceRateLimitSeconds) |
1924 return; | 1927 return; |
1925 last_checked_removal_ = now; | 1928 last_checked_removal_ = now; |
1926 manager->CheckForHistoryFilesRemoval(); | 1929 manager->CheckForHistoryFilesRemoval(); |
1927 } | 1930 } |
1928 | 1931 |
1929 } // namespace extensions | 1932 } // namespace extensions |
OLD | NEW |