| OLD | NEW |
| 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 2314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2325 browser_handler_map["GetPrefsInfo"] = | 2325 browser_handler_map["GetPrefsInfo"] = |
| 2326 &TestingAutomationProvider::GetPrefsInfo; | 2326 &TestingAutomationProvider::GetPrefsInfo; |
| 2327 browser_handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; | 2327 browser_handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; |
| 2328 | 2328 |
| 2329 browser_handler_map["SetWindowDimensions"] = | 2329 browser_handler_map["SetWindowDimensions"] = |
| 2330 &TestingAutomationProvider::SetWindowDimensions; | 2330 &TestingAutomationProvider::SetWindowDimensions; |
| 2331 | 2331 |
| 2332 browser_handler_map["GetDownloadsInfo"] = | 2332 browser_handler_map["GetDownloadsInfo"] = |
| 2333 &TestingAutomationProvider::GetDownloadsInfo; | 2333 &TestingAutomationProvider::GetDownloadsInfo; |
| 2334 browser_handler_map["WaitForAllDownloadsToComplete"] = | 2334 browser_handler_map["WaitForAllDownloadsToComplete"] = |
| 2335 &TestingAutomationProvider::WaitForDownloadsToComplete; | 2335 &TestingAutomationProvider::WaitForAllDownloadsToComplete; |
| 2336 browser_handler_map["PerformActionOnDownload"] = | 2336 browser_handler_map["PerformActionOnDownload"] = |
| 2337 &TestingAutomationProvider::PerformActionOnDownload; | 2337 &TestingAutomationProvider::PerformActionOnDownload; |
| 2338 | 2338 |
| 2339 browser_handler_map["GetInitialLoadTimes"] = | 2339 browser_handler_map["GetInitialLoadTimes"] = |
| 2340 &TestingAutomationProvider::GetInitialLoadTimes; | 2340 &TestingAutomationProvider::GetInitialLoadTimes; |
| 2341 | 2341 |
| 2342 browser_handler_map["SaveTabContents"] = | 2342 browser_handler_map["SaveTabContents"] = |
| 2343 &TestingAutomationProvider::SaveTabContents; | 2343 &TestingAutomationProvider::SaveTabContents; |
| 2344 | 2344 |
| 2345 browser_handler_map["ImportSettings"] = | 2345 browser_handler_map["ImportSettings"] = |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2931 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); | 2931 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
| 2932 it != downloads.end(); | 2932 it != downloads.end(); |
| 2933 it++) { // Fill info about each download item. | 2933 it++) { // Fill info about each download item. |
| 2934 list_of_downloads->Append(GetDictionaryFromDownloadItem(*it)); | 2934 list_of_downloads->Append(GetDictionaryFromDownloadItem(*it)); |
| 2935 } | 2935 } |
| 2936 } | 2936 } |
| 2937 return_value->Set("downloads", list_of_downloads); | 2937 return_value->Set("downloads", list_of_downloads); |
| 2938 reply.SendSuccess(return_value.get()); | 2938 reply.SendSuccess(return_value.get()); |
| 2939 } | 2939 } |
| 2940 | 2940 |
| 2941 void TestingAutomationProvider::WaitForDownloadsToComplete( | 2941 void TestingAutomationProvider::WaitForAllDownloadsToComplete( |
| 2942 Browser* browser, | 2942 Browser* browser, |
| 2943 DictionaryValue* args, | 2943 DictionaryValue* args, |
| 2944 IPC::Message* reply_message) { | 2944 IPC::Message* reply_message) { |
| 2945 ListValue* pre_download_ids = NULL; |
| 2945 | 2946 |
| 2946 // Look for a quick return. | 2947 if (!args->GetList("pre_download_ids", &pre_download_ids)) { |
| 2948 AutomationJSONReply(this, reply_message) |
| 2949 .SendError(StringPrintf("List of IDs of previous downloads required.")); |
| 2950 return; |
| 2951 } |
| 2947 if (!browser->profile()->HasCreatedDownloadManager()) { | 2952 if (!browser->profile()->HasCreatedDownloadManager()) { |
| 2948 // No download manager. | 2953 // No download manager, so no downloads to wait for. |
| 2949 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 2954 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 2950 return; | 2955 return; |
| 2951 } | 2956 } |
| 2952 std::vector<DownloadItem*> downloads; | 2957 |
| 2953 browser->profile()->GetDownloadManager()-> | 2958 // This observer will delete itself. |
| 2954 GetCurrentDownloads(FilePath(), &downloads); | 2959 new AllDownloadsCompleteObserver( |
| 2955 if (downloads.empty()) { | 2960 this, reply_message, browser->profile()->GetDownloadManager(), |
| 2956 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 2961 pre_download_ids); |
| 2957 return; | |
| 2958 } | |
| 2959 // The observer owns itself. When the last observed item pings, it | |
| 2960 // deletes itself. | |
| 2961 AutomationProviderDownloadItemObserver* item_observer = | |
| 2962 new AutomationProviderDownloadItemObserver( | |
| 2963 this, reply_message, downloads.size()); | |
| 2964 for (std::vector<DownloadItem*>::iterator i = downloads.begin(); | |
| 2965 i != downloads.end(); | |
| 2966 i++) { | |
| 2967 (*i)->AddObserver(item_observer); | |
| 2968 } | |
| 2969 } | 2962 } |
| 2970 | 2963 |
| 2971 namespace { | 2964 namespace { |
| 2972 | 2965 |
| 2973 DownloadItem* GetDownloadItemFromId(int id, DownloadManager* download_manager) { | 2966 DownloadItem* GetDownloadItemFromId(int id, DownloadManager* download_manager) { |
| 2974 std::vector<DownloadItem*> downloads; | 2967 std::vector<DownloadItem*> downloads; |
| 2975 download_manager->GetAllDownloads(FilePath(), &downloads); | 2968 download_manager->GetAllDownloads(FilePath(), &downloads); |
| 2976 DownloadItem* selected_item = NULL; | 2969 DownloadItem* selected_item = NULL; |
| 2977 | 2970 |
| 2978 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); | 2971 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
| (...skipping 3181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6160 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); | 6153 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); |
| 6161 | 6154 |
| 6162 Send(reply_message_); | 6155 Send(reply_message_); |
| 6163 redirect_query_ = 0; | 6156 redirect_query_ = 0; |
| 6164 reply_message_ = NULL; | 6157 reply_message_ = NULL; |
| 6165 } | 6158 } |
| 6166 | 6159 |
| 6167 void TestingAutomationProvider::OnRemoveProvider() { | 6160 void TestingAutomationProvider::OnRemoveProvider() { |
| 6168 AutomationProviderList::GetInstance()->RemoveProvider(this); | 6161 AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 6169 } | 6162 } |
| OLD | NEW |