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

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 8135017: Refactor downloads into a ProfileKeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged to LKGR to run try bots. Created 9 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/automation/testing_automation_provider.h" 5 #include "chrome/browser/automation/testing_automation_provider.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 27 matching lines...) Expand all
38 #include "chrome/browser/automation/automation_util.h" 38 #include "chrome/browser/automation/automation_util.h"
39 #include "chrome/browser/automation/automation_window_tracker.h" 39 #include "chrome/browser/automation/automation_window_tracker.h"
40 #include "chrome/browser/automation/ui_controls.h" 40 #include "chrome/browser/automation/ui_controls.h"
41 #include "chrome/browser/bookmarks/bookmark_model.h" 41 #include "chrome/browser/bookmarks/bookmark_model.h"
42 #include "chrome/browser/bookmarks/bookmark_storage.h" 42 #include "chrome/browser/bookmarks/bookmark_storage.h"
43 #include "chrome/browser/browser_process.h" 43 #include "chrome/browser/browser_process.h"
44 #include "chrome/browser/browser_shutdown.h" 44 #include "chrome/browser/browser_shutdown.h"
45 #include "chrome/browser/content_settings/host_content_settings_map.h" 45 #include "chrome/browser/content_settings/host_content_settings_map.h"
46 #include "chrome/browser/debugger/devtools_window.h" 46 #include "chrome/browser/debugger/devtools_window.h"
47 #include "chrome/browser/download/download_prefs.h" 47 #include "chrome/browser/download/download_prefs.h"
48 #include "chrome/browser/download/download_service.h"
49 #include "chrome/browser/download/download_service_factory.h"
48 #include "chrome/browser/download/save_package_file_picker.h" 50 #include "chrome/browser/download/save_package_file_picker.h"
49 #include "chrome/browser/extensions/extension_browser_event_router.h" 51 #include "chrome/browser/extensions/extension_browser_event_router.h"
50 #include "chrome/browser/extensions/extension_host.h" 52 #include "chrome/browser/extensions/extension_host.h"
51 #include "chrome/browser/extensions/extension_process_manager.h" 53 #include "chrome/browser/extensions/extension_process_manager.h"
52 #include "chrome/browser/extensions/extension_service.h" 54 #include "chrome/browser/extensions/extension_service.h"
53 #include "chrome/browser/extensions/extension_updater.h" 55 #include "chrome/browser/extensions/extension_updater.h"
54 #include "chrome/browser/history/top_sites.h" 56 #include "chrome/browser/history/top_sites.h"
55 #include "chrome/browser/importer/importer_host.h" 57 #include "chrome/browser/importer/importer_host.h"
56 #include "chrome/browser/importer/importer_list.h" 58 #include "chrome/browser/importer/importer_list.h"
57 #include "chrome/browser/infobars/infobar_tab_helper.h" 59 #include "chrome/browser/infobars/infobar_tab_helper.h"
(...skipping 3013 matching lines...) Expand 10 before | Expand all | Expand 10 after
3071 3073
3072 // Sample json input: { "command": "GetDownloadsInfo" } 3074 // Sample json input: { "command": "GetDownloadsInfo" }
3073 // Refer chrome/test/pyautolib/download_info.py for sample json output. 3075 // Refer chrome/test/pyautolib/download_info.py for sample json output.
3074 void TestingAutomationProvider::GetDownloadsInfo(Browser* browser, 3076 void TestingAutomationProvider::GetDownloadsInfo(Browser* browser,
3075 DictionaryValue* args, 3077 DictionaryValue* args,
3076 IPC::Message* reply_message) { 3078 IPC::Message* reply_message) {
3077 AutomationJSONReply reply(this, reply_message); 3079 AutomationJSONReply reply(this, reply_message);
3078 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); 3080 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
3079 ListValue* list_of_downloads = new ListValue; 3081 ListValue* list_of_downloads = new ListValue;
3080 3082
3081 if (browser->profile()->HasCreatedDownloadManager()) { 3083 DownloadService* download_service(
3084 DownloadServiceFactory::GetForProfile(profile()));
3085
3086 if (download_service->HasCreatedDownloadManager()) {
3082 std::vector<DownloadItem*> downloads; 3087 std::vector<DownloadItem*> downloads;
3083 browser->profile()->GetDownloadManager()-> 3088 download_service->GetDownloadManager()->
3084 GetAllDownloads(FilePath(), &downloads); 3089 GetAllDownloads(FilePath(), &downloads);
3085 3090
3086 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); 3091 for (std::vector<DownloadItem*>::iterator it = downloads.begin();
3087 it != downloads.end(); 3092 it != downloads.end();
3088 it++) { // Fill info about each download item. 3093 it++) { // Fill info about each download item.
3089 list_of_downloads->Append(GetDictionaryFromDownloadItem(*it)); 3094 list_of_downloads->Append(GetDictionaryFromDownloadItem(*it));
3090 } 3095 }
3091 } 3096 }
3092 return_value->Set("downloads", list_of_downloads); 3097 return_value->Set("downloads", list_of_downloads);
3093 reply.SendSuccess(return_value.get()); 3098 reply.SendSuccess(return_value.get());
3094 } 3099 }
3095 3100
3096 void TestingAutomationProvider::WaitForAllDownloadsToComplete( 3101 void TestingAutomationProvider::WaitForAllDownloadsToComplete(
3097 Browser* browser, 3102 Browser* browser,
3098 DictionaryValue* args, 3103 DictionaryValue* args,
3099 IPC::Message* reply_message) { 3104 IPC::Message* reply_message) {
3100 ListValue* pre_download_ids = NULL; 3105 ListValue* pre_download_ids = NULL;
3101 3106
3102 if (!args->GetList("pre_download_ids", &pre_download_ids)) { 3107 if (!args->GetList("pre_download_ids", &pre_download_ids)) {
3103 AutomationJSONReply(this, reply_message) 3108 AutomationJSONReply(this, reply_message)
3104 .SendError(StringPrintf("List of IDs of previous downloads required.")); 3109 .SendError(StringPrintf("List of IDs of previous downloads required."));
3105 return; 3110 return;
3106 } 3111 }
3107 if (!browser->profile()->HasCreatedDownloadManager()) { 3112
3113 DownloadService* download_service =
3114 DownloadServiceFactory::GetForProfile(profile());
3115 if (!download_service->HasCreatedDownloadManager()) {
3108 // No download manager, so no downloads to wait for. 3116 // No download manager, so no downloads to wait for.
3109 AutomationJSONReply(this, reply_message).SendSuccess(NULL); 3117 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
3110 return; 3118 return;
3111 } 3119 }
3112 3120
3113 // This observer will delete itself. 3121 // This observer will delete itself.
3114 new AllDownloadsCompleteObserver( 3122 new AllDownloadsCompleteObserver(
3115 this, reply_message, browser->profile()->GetDownloadManager(), 3123 this, reply_message, download_service->GetDownloadManager(),
3116 pre_download_ids); 3124 pre_download_ids);
3117 } 3125 }
3118 3126
3119 namespace { 3127 namespace {
3120 3128
3121 DownloadItem* GetDownloadItemFromId(int id, DownloadManager* download_manager) { 3129 DownloadItem* GetDownloadItemFromId(int id, DownloadManager* download_manager) {
3122 std::vector<DownloadItem*> downloads; 3130 std::vector<DownloadItem*> downloads;
3123 download_manager->GetAllDownloads(FilePath(), &downloads); 3131 download_manager->GetAllDownloads(FilePath(), &downloads);
3124 DownloadItem* selected_item = NULL; 3132 DownloadItem* selected_item = NULL;
3125 3133
(...skipping 13 matching lines...) Expand all
3139 3147
3140 // See PerformActionOnDownload() in chrome/test/pyautolib/pyauto.py for sample 3148 // See PerformActionOnDownload() in chrome/test/pyautolib/pyauto.py for sample
3141 // json input and output. 3149 // json input and output.
3142 void TestingAutomationProvider::PerformActionOnDownload( 3150 void TestingAutomationProvider::PerformActionOnDownload(
3143 Browser* browser, 3151 Browser* browser,
3144 DictionaryValue* args, 3152 DictionaryValue* args,
3145 IPC::Message* reply_message) { 3153 IPC::Message* reply_message) {
3146 int id; 3154 int id;
3147 std::string action; 3155 std::string action;
3148 3156
3149 if (!browser->profile()->HasCreatedDownloadManager()) { 3157 DownloadService* download_service =
3158 DownloadServiceFactory::GetForProfile(profile());
3159 if (!download_service->HasCreatedDownloadManager()) {
3150 AutomationJSONReply(this, reply_message).SendError("No download manager."); 3160 AutomationJSONReply(this, reply_message).SendError("No download manager.");
3151 return; 3161 return;
3152 } 3162 }
3153 if (!args->GetInteger("id", &id) || !args->GetString("action", &action)) { 3163 if (!args->GetInteger("id", &id) || !args->GetString("action", &action)) {
3154 AutomationJSONReply(this, reply_message) 3164 AutomationJSONReply(this, reply_message)
3155 .SendError("Must include int id and string action."); 3165 .SendError("Must include int id and string action.");
3156 return; 3166 return;
3157 } 3167 }
3158 3168
3159 DownloadManager* download_manager = browser->profile()->GetDownloadManager(); 3169 DownloadManager* download_manager = download_service->GetDownloadManager();
3160 DownloadItem* selected_item = GetDownloadItemFromId(id, download_manager); 3170 DownloadItem* selected_item = GetDownloadItemFromId(id, download_manager);
3161 if (!selected_item) { 3171 if (!selected_item) {
3162 AutomationJSONReply(this, reply_message) 3172 AutomationJSONReply(this, reply_message)
3163 .SendError(StringPrintf("No download with an id of %d\n", id)); 3173 .SendError(StringPrintf("No download with an id of %d\n", id));
3164 return; 3174 return;
3165 } 3175 }
3166 3176
3167 if (action == "open") { 3177 if (action == "open") {
3168 selected_item->AddObserver( 3178 selected_item->AddObserver(
3169 new AutomationProviderDownloadUpdatedObserver( 3179 new AutomationProviderDownloadUpdatedObserver(
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
3678 if (!tab_contents->SavePage( 3688 if (!tab_contents->SavePage(
3679 FilePath(filename), 3689 FilePath(filename),
3680 FilePath(parent_directory), 3690 FilePath(parent_directory),
3681 SavePackage::SAVE_AS_ONLY_HTML)) { 3691 SavePackage::SAVE_AS_ONLY_HTML)) {
3682 AutomationJSONReply(this, reply_message).SendError( 3692 AutomationJSONReply(this, reply_message).SendError(
3683 "Could not initiate SavePage"); 3693 "Could not initiate SavePage");
3684 return; 3694 return;
3685 } 3695 }
3686 // The observer will delete itself when done. 3696 // The observer will delete itself when done.
3687 new SavePackageNotificationObserver( 3697 new SavePackageNotificationObserver(
3688 browser->profile()->GetDownloadManager(), this, reply_message); 3698 DownloadServiceFactory::GetForProfile(profile())->GetDownloadManager(),
3699 this, reply_message);
3689 } 3700 }
3690 3701
3691 // Refer to ImportSettings() in chrome/test/pyautolib/pyauto.py for sample 3702 // Refer to ImportSettings() in chrome/test/pyautolib/pyauto.py for sample
3692 // json input. 3703 // json input.
3693 // Sample json output: "{}" 3704 // Sample json output: "{}"
3694 void TestingAutomationProvider::ImportSettings(Browser* browser, 3705 void TestingAutomationProvider::ImportSettings(Browser* browser,
3695 DictionaryValue* args, 3706 DictionaryValue* args,
3696 IPC::Message* reply_message) { 3707 IPC::Message* reply_message) {
3697 // Map from the json string passed over to the import item masks. 3708 // Map from the json string passed over to the import item masks.
3698 std::map<std::string, importer::ImportItem> string_to_import_item; 3709 std::map<std::string, importer::ImportItem> string_to_import_item;
(...skipping 2792 matching lines...) Expand 10 before | Expand all | Expand 10 after
6491 6502
6492 Send(reply_message_); 6503 Send(reply_message_);
6493 redirect_query_ = 0; 6504 redirect_query_ = 0;
6494 reply_message_ = NULL; 6505 reply_message_ = NULL;
6495 } 6506 }
6496 6507
6497 void TestingAutomationProvider::OnRemoveProvider() { 6508 void TestingAutomationProvider::OnRemoveProvider() {
6498 if (g_browser_process) 6509 if (g_browser_process)
6499 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 6510 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6500 } 6511 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698