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 17 matching lines...) Expand all Loading... |
28 #include "base/stl_util.h" | 28 #include "base/stl_util.h" |
29 #include "base/strings/string16.h" | 29 #include "base/strings/string16.h" |
30 #include "base/strings/string_split.h" | 30 #include "base/strings/string_split.h" |
31 #include "base/strings/string_util.h" | 31 #include "base/strings/string_util.h" |
32 #include "base/strings/stringprintf.h" | 32 #include "base/strings/stringprintf.h" |
33 #include "base/task/cancelable_task_tracker.h" | 33 #include "base/task/cancelable_task_tracker.h" |
34 #include "base/threading/thread_task_runner_handle.h" | 34 #include "base/threading/thread_task_runner_handle.h" |
35 #include "base/values.h" | 35 #include "base/values.h" |
36 #include "build/build_config.h" | 36 #include "build/build_config.h" |
37 #include "chrome/browser/browser_process.h" | 37 #include "chrome/browser/browser_process.h" |
| 38 #include "chrome/browser/download/download_core_service.h" |
| 39 #include "chrome/browser/download/download_core_service_factory.h" |
38 #include "chrome/browser/download/download_danger_prompt.h" | 40 #include "chrome/browser/download/download_danger_prompt.h" |
39 #include "chrome/browser/download/download_file_icon_extractor.h" | 41 #include "chrome/browser/download/download_file_icon_extractor.h" |
40 #include "chrome/browser/download/download_prefs.h" | 42 #include "chrome/browser/download/download_prefs.h" |
41 #include "chrome/browser/download/download_query.h" | 43 #include "chrome/browser/download/download_query.h" |
42 #include "chrome/browser/download/download_service.h" | |
43 #include "chrome/browser/download/download_service_factory.h" | |
44 #include "chrome/browser/download/download_shelf.h" | 44 #include "chrome/browser/download/download_shelf.h" |
45 #include "chrome/browser/download/download_stats.h" | 45 #include "chrome/browser/download/download_stats.h" |
46 #include "chrome/browser/download/drag_download_item.h" | 46 #include "chrome/browser/download/drag_download_item.h" |
47 #include "chrome/browser/extensions/chrome_extension_function_details.h" | 47 #include "chrome/browser/extensions/chrome_extension_function_details.h" |
48 #include "chrome/browser/icon_loader.h" | 48 #include "chrome/browser/icon_loader.h" |
49 #include "chrome/browser/icon_manager.h" | 49 #include "chrome/browser/icon_manager.h" |
50 #include "chrome/browser/platform_util.h" | 50 #include "chrome/browser/platform_util.h" |
51 #include "chrome/browser/profiles/profile.h" | 51 #include "chrome/browser/profiles/profile.h" |
52 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 52 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
53 #include "chrome/browser/ui/browser.h" | 53 #include "chrome/browser/ui/browser.h" |
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 | 1084 |
1085 ExtensionFunction::ResponseAction DownloadsSearchFunction::Run() { | 1085 ExtensionFunction::ResponseAction DownloadsSearchFunction::Run() { |
1086 std::unique_ptr<downloads::Search::Params> params( | 1086 std::unique_ptr<downloads::Search::Params> params( |
1087 downloads::Search::Params::Create(*args_)); | 1087 downloads::Search::Params::Create(*args_)); |
1088 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1088 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1089 DownloadManager* manager = NULL; | 1089 DownloadManager* manager = NULL; |
1090 DownloadManager* incognito_manager = NULL; | 1090 DownloadManager* incognito_manager = NULL; |
1091 GetManagers(browser_context(), include_incognito(), &manager, | 1091 GetManagers(browser_context(), include_incognito(), &manager, |
1092 &incognito_manager); | 1092 &incognito_manager); |
1093 ExtensionDownloadsEventRouter* router = | 1093 ExtensionDownloadsEventRouter* router = |
1094 DownloadServiceFactory::GetForBrowserContext( | 1094 DownloadCoreServiceFactory::GetForBrowserContext( |
1095 manager->GetBrowserContext())->GetExtensionEventRouter(); | 1095 manager->GetBrowserContext()) |
| 1096 ->GetExtensionEventRouter(); |
1096 router->CheckForHistoryFilesRemoval(); | 1097 router->CheckForHistoryFilesRemoval(); |
1097 if (incognito_manager) { | 1098 if (incognito_manager) { |
1098 ExtensionDownloadsEventRouter* incognito_router = | 1099 ExtensionDownloadsEventRouter* incognito_router = |
1099 DownloadServiceFactory::GetForBrowserContext( | 1100 DownloadCoreServiceFactory::GetForBrowserContext( |
1100 incognito_manager->GetBrowserContext())->GetExtensionEventRouter(); | 1101 incognito_manager->GetBrowserContext()) |
| 1102 ->GetExtensionEventRouter(); |
1101 incognito_router->CheckForHistoryFilesRemoval(); | 1103 incognito_router->CheckForHistoryFilesRemoval(); |
1102 } | 1104 } |
1103 DownloadQuery::DownloadVector results; | 1105 DownloadQuery::DownloadVector results; |
1104 std::string error; | 1106 std::string error; |
1105 RunDownloadQuery(params->query, manager, incognito_manager, &error, &results); | 1107 RunDownloadQuery(params->query, manager, incognito_manager, &error, &results); |
1106 if (!error.empty()) | 1108 if (!error.empty()) |
1107 return RespondNow(Error(error)); | 1109 return RespondNow(Error(error)); |
1108 | 1110 |
1109 std::unique_ptr<base::ListValue> json_results(new base::ListValue()); | 1111 std::unique_ptr<base::ListValue> json_results(new base::ListValue()); |
1110 for (DownloadManager::DownloadVector::const_iterator it = results.begin(); | 1112 for (DownloadManager::DownloadVector::const_iterator it = results.begin(); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 if (!extension()->permissions_data()->HasAPIPermission( | 1429 if (!extension()->permissions_data()->HasAPIPermission( |
1428 APIPermission::kDownloadsShelf)) { | 1430 APIPermission::kDownloadsShelf)) { |
1429 return RespondNow(Error(download_extension_errors::kShelfPermission)); | 1431 return RespondNow(Error(download_extension_errors::kShelfPermission)); |
1430 } | 1432 } |
1431 | 1433 |
1432 RecordApiFunctions(DOWNLOADS_FUNCTION_SET_SHELF_ENABLED); | 1434 RecordApiFunctions(DOWNLOADS_FUNCTION_SET_SHELF_ENABLED); |
1433 DownloadManager* manager = NULL; | 1435 DownloadManager* manager = NULL; |
1434 DownloadManager* incognito_manager = NULL; | 1436 DownloadManager* incognito_manager = NULL; |
1435 GetManagers(browser_context(), include_incognito(), &manager, | 1437 GetManagers(browser_context(), include_incognito(), &manager, |
1436 &incognito_manager); | 1438 &incognito_manager); |
1437 DownloadService* service = NULL; | 1439 DownloadCoreService* service = NULL; |
1438 DownloadService* incognito_service = NULL; | 1440 DownloadCoreService* incognito_service = NULL; |
1439 if (manager) { | 1441 if (manager) { |
1440 service = DownloadServiceFactory::GetForBrowserContext( | 1442 service = DownloadCoreServiceFactory::GetForBrowserContext( |
1441 manager->GetBrowserContext()); | 1443 manager->GetBrowserContext()); |
1442 service->GetExtensionEventRouter()->SetShelfEnabled(extension(), | 1444 service->GetExtensionEventRouter()->SetShelfEnabled(extension(), |
1443 params->enabled); | 1445 params->enabled); |
1444 } | 1446 } |
1445 if (incognito_manager) { | 1447 if (incognito_manager) { |
1446 incognito_service = DownloadServiceFactory::GetForBrowserContext( | 1448 incognito_service = DownloadCoreServiceFactory::GetForBrowserContext( |
1447 incognito_manager->GetBrowserContext()); | 1449 incognito_manager->GetBrowserContext()); |
1448 incognito_service->GetExtensionEventRouter()->SetShelfEnabled( | 1450 incognito_service->GetExtensionEventRouter()->SetShelfEnabled( |
1449 extension(), params->enabled); | 1451 extension(), params->enabled); |
1450 } | 1452 } |
1451 | 1453 |
1452 BrowserList* browsers = BrowserList::GetInstance(); | 1454 BrowserList* browsers = BrowserList::GetInstance(); |
1453 if (browsers) { | 1455 if (browsers) { |
1454 for (BrowserList::const_iterator iter = browsers->begin(); | 1456 for (BrowserList::const_iterator iter = browsers->begin(); |
1455 iter != browsers->end(); ++iter) { | 1457 iter != browsers->end(); ++iter) { |
1456 const Browser* browser = *iter; | 1458 const Browser* browser = *iter; |
1457 DownloadService* current_service = | 1459 DownloadCoreService* current_service = |
1458 DownloadServiceFactory::GetForBrowserContext(browser->profile()); | 1460 DownloadCoreServiceFactory::GetForBrowserContext(browser->profile()); |
1459 if (((current_service == service) || | 1461 if (((current_service == service) || |
1460 (current_service == incognito_service)) && | 1462 (current_service == incognito_service)) && |
1461 browser->window()->IsDownloadShelfVisible() && | 1463 browser->window()->IsDownloadShelfVisible() && |
1462 !current_service->IsShelfEnabled()) | 1464 !current_service->IsShelfEnabled()) |
1463 browser->window()->GetDownloadShelf()->Close(DownloadShelf::AUTOMATIC); | 1465 browser->window()->GetDownloadShelf()->Close(DownloadShelf::AUTOMATIC); |
1464 } | 1466 } |
1465 } | 1467 } |
1466 | 1468 |
1467 if (params->enabled && | 1469 if (params->enabled && |
1468 ((manager && !service->IsShelfEnabled()) || | 1470 ((manager && !service->IsShelfEnabled()) || |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1923 return; | 1925 return; |
1924 base::Time now(base::Time::Now()); | 1926 base::Time now(base::Time::Now()); |
1925 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); | 1927 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); |
1926 if (delta <= kFileExistenceRateLimitSeconds) | 1928 if (delta <= kFileExistenceRateLimitSeconds) |
1927 return; | 1929 return; |
1928 last_checked_removal_ = now; | 1930 last_checked_removal_ = now; |
1929 manager->CheckForHistoryFilesRemoval(); | 1931 manager->CheckForHistoryFilesRemoval(); |
1930 } | 1932 } |
1931 | 1933 |
1932 } // namespace extensions | 1934 } // namespace extensions |
OLD | NEW |