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

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

Issue 3071005: Download code cleanup patch of death: (Closed)
Patch Set: inline the dtor Created 10 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/automation/automation_provider_observers.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/automation_provider.h" 5 #include "chrome/browser/automation/automation_provider.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "app/message_box_flags.h" 9 #include "app/message_box_flags.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 2081 matching lines...) Expand 10 before | Expand all | Expand 10 after
2092 if (title.length()) 2092 if (title.length())
2093 hs->SetPageTitle(gurl, title); 2093 hs->SetPageTitle(gurl, title);
2094 reply.SendSuccess(NULL); 2094 reply.SendSuccess(NULL);
2095 } 2095 }
2096 2096
2097 // Sample json input: { "command": "GetDownloadsInfo" } 2097 // Sample json input: { "command": "GetDownloadsInfo" }
2098 // Refer chrome/test/pyautolib/download_info.py for sample json output. 2098 // Refer chrome/test/pyautolib/download_info.py for sample json output.
2099 void AutomationProvider::GetDownloadsInfo(Browser* browser, 2099 void AutomationProvider::GetDownloadsInfo(Browser* browser,
2100 DictionaryValue* args, 2100 DictionaryValue* args,
2101 IPC::Message* reply_message) { 2101 IPC::Message* reply_message) {
2102 AutomationProviderDownloadManagerObserver observer;
2103 std::vector<DownloadItem*> downloads;
2104 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); 2102 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
2105 AutomationJSONReply reply(this, reply_message); 2103 AutomationJSONReply reply(this, reply_message);
2106 2104
2107 if (!profile_->HasCreatedDownloadManager()) { 2105 if (!profile_->HasCreatedDownloadManager()) {
2108 reply.SendError("no download manager"); 2106 reply.SendError("no download manager");
2109 return; 2107 return;
2110 } 2108 }
2111 // Use DownloadManager's GetDownloads() method and not GetCurrentDownloads() 2109
2112 // since that would be transient; a download might enter and empty out 2110 std::vector<DownloadItem*> downloads;
2113 // the current download queue too soon to be noticed. 2111 profile_->GetDownloadManager()->GetAllDownloads(FilePath(), &downloads);
2114 profile_->GetDownloadManager()->GetDownloads(&observer, L"");
2115 downloads = observer.Downloads();
2116 2112
2117 std::map<DownloadItem::DownloadState, std::string> state_to_string; 2113 std::map<DownloadItem::DownloadState, std::string> state_to_string;
2118 state_to_string[DownloadItem::IN_PROGRESS] = std::string("IN_PROGRESS"); 2114 state_to_string[DownloadItem::IN_PROGRESS] = std::string("IN_PROGRESS");
2119 state_to_string[DownloadItem::CANCELLED] = std::string("CANCELLED"); 2115 state_to_string[DownloadItem::CANCELLED] = std::string("CANCELLED");
2120 state_to_string[DownloadItem::REMOVING] = std::string("REMOVING"); 2116 state_to_string[DownloadItem::REMOVING] = std::string("REMOVING");
2121 state_to_string[DownloadItem::COMPLETE] = std::string("COMPLETE"); 2117 state_to_string[DownloadItem::COMPLETE] = std::string("COMPLETE");
2122 2118
2123 std::map<DownloadItem::SafetyState, std::string> safety_state_to_string; 2119 std::map<DownloadItem::SafetyState, std::string> safety_state_to_string;
2124 safety_state_to_string[DownloadItem::SAFE] = std::string("SAFE"); 2120 safety_state_to_string[DownloadItem::SAFE] = std::string("SAFE");
2125 safety_state_to_string[DownloadItem::DANGEROUS] = std::string("DANGEROUS"); 2121 safety_state_to_string[DownloadItem::DANGEROUS] = std::string("DANGEROUS");
(...skipping 27 matching lines...) Expand all
2153 2149
2154 reply.SendSuccess(return_value.get()); 2150 reply.SendSuccess(return_value.get());
2155 // All value objects allocated above are owned by |return_value| 2151 // All value objects allocated above are owned by |return_value|
2156 // and get freed by it. 2152 // and get freed by it.
2157 } 2153 }
2158 2154
2159 void AutomationProvider::WaitForDownloadsToComplete( 2155 void AutomationProvider::WaitForDownloadsToComplete(
2160 Browser* browser, 2156 Browser* browser,
2161 DictionaryValue* args, 2157 DictionaryValue* args,
2162 IPC::Message* reply_message) { 2158 IPC::Message* reply_message) {
2163 AutomationProviderDownloadManagerObserver observer;
2164 std::vector<DownloadItem*> downloads;
2165 AutomationJSONReply reply(this, reply_message); 2159 AutomationJSONReply reply(this, reply_message);
2166 2160
2167 // Look for a quick return. 2161 // Look for a quick return.
2168 if (!profile_->HasCreatedDownloadManager()) { 2162 if (!profile_->HasCreatedDownloadManager()) {
2169 reply.SendSuccess(NULL); // No download manager. 2163 reply.SendSuccess(NULL); // No download manager.
2170 return; 2164 return;
2171 } 2165 }
2172 profile_->GetDownloadManager()->GetCurrentDownloads(&observer, FilePath()); 2166 std::vector<DownloadItem*> downloads;
2173 downloads = observer.Downloads(); 2167 profile_->GetDownloadManager()->GetCurrentDownloads(FilePath(), &downloads);
2174 if (downloads.size() == 0) { 2168 if (downloads.empty()) {
2175 reply.SendSuccess(NULL); 2169 reply.SendSuccess(NULL);
2176 return; 2170 return;
2177 } 2171 }
2178 2172
2179 // The observer owns itself. When the last observed item pings, it 2173 // The observer owns itself. When the last observed item pings, it
2180 // deletes itself. 2174 // deletes itself.
2181 AutomationProviderDownloadItemObserver* item_observer = 2175 AutomationProviderDownloadItemObserver* item_observer =
2182 new AutomationProviderDownloadItemObserver( 2176 new AutomationProviderDownloadItemObserver(
2183 this, reply_message, downloads.size()); 2177 this, reply_message, downloads.size());
2184 for (std::vector<DownloadItem*>::iterator i = downloads.begin(); 2178 for (std::vector<DownloadItem*>::iterator i = downloads.begin();
(...skipping 2210 matching lines...) Expand 10 before | Expand all | Expand 10 after
4395 } 4389 }
4396 4390
4397 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { 4391 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) {
4398 NOTIMPLEMENTED(); 4392 NOTIMPLEMENTED();
4399 } 4393 }
4400 #endif // !defined(TOOLKIT_VIEWS) 4394 #endif // !defined(TOOLKIT_VIEWS)
4401 4395
4402 void AutomationProvider::ResetToDefaultTheme() { 4396 void AutomationProvider::ResetToDefaultTheme() {
4403 profile_->ClearTheme(); 4397 profile_->ClearTheme();
4404 } 4398 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/automation/automation_provider_observers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698