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

Side by Side Diff: chrome/browser/dom_ui/downloads_dom_handler.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 | « chrome/browser/dom_ui/downloads_dom_handler.h ('k') | chrome/browser/dom_ui/filebrowse_ui.cc » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/dom_ui/downloads_dom_handler.h" 5 #include "chrome/browser/dom_ui/downloads_dom_handler.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/singleton.h" 9 #include "base/singleton.h"
10 #include "base/string_piece.h" 10 #include "base/string_piece.h"
11 #include "base/thread.h" 11 #include "base/thread.h"
12 #include "base/utf_string_conversions.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_thread.h" 15 #include "chrome/browser/chrome_thread.h"
15 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" 16 #include "chrome/browser/dom_ui/chrome_url_data_manager.h"
16 #include "chrome/browser/dom_ui/fileicon_source.h" 17 #include "chrome/browser/dom_ui/fileicon_source.h"
18 #include "chrome/browser/download/download_history.h"
17 #include "chrome/browser/download/download_item.h" 19 #include "chrome/browser/download/download_item.h"
18 #include "chrome/browser/download/download_util.h" 20 #include "chrome/browser/download/download_util.h"
19 #include "chrome/browser/metrics/user_metrics.h" 21 #include "chrome/browser/metrics/user_metrics.h"
20 #include "chrome/browser/profile.h" 22 #include "chrome/browser/profile.h"
21 #include "chrome/browser/tab_contents/tab_contents.h" 23 #include "chrome/browser/tab_contents/tab_contents.h"
22 #include "chrome/common/jstemplate_builder.h" 24 #include "chrome/common/jstemplate_builder.h"
23 #include "chrome/common/url_constants.h" 25 #include "chrome/common/url_constants.h"
24 #include "grit/browser_resources.h" 26 #include "grit/browser_resources.h"
25 #include "grit/generated_resources.h" 27 #include "grit/generated_resources.h"
26 28
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 if (it == download_items_.end()) 105 if (it == download_items_.end())
104 return; 106 return;
105 const int id = static_cast<int>(it - download_items_.begin()); 107 const int id = static_cast<int>(it - download_items_.begin());
106 108
107 ListValue results_value; 109 ListValue results_value;
108 results_value.Append(download_util::CreateDownloadItemValue(download, id)); 110 results_value.Append(download_util::CreateDownloadItemValue(download, id));
109 dom_ui_->CallJavascriptFunction(L"downloadUpdated", results_value); 111 dom_ui_->CallJavascriptFunction(L"downloadUpdated", results_value);
110 } 112 }
111 113
112 // A download has started or been deleted. Query our DownloadManager for the 114 // A download has started or been deleted. Query our DownloadManager for the
113 // current set of downloads, which will call us back in SetDownloads once it 115 // current set of downloads.
114 // has retrieved them.
115 void DownloadsDOMHandler::ModelChanged() { 116 void DownloadsDOMHandler::ModelChanged() {
116 ClearDownloadItems(); 117 ClearDownloadItems();
117 download_manager_->GetDownloads(this, search_text_); 118 download_manager_->download_history()->Search(
119 WideToUTF16(search_text_),
120 NewCallback(this, &DownloadsDOMHandler::OnSearchDownloadsComplete));
118 } 121 }
119 122
120 void DownloadsDOMHandler::SetDownloads( 123 void DownloadsDOMHandler::OnSearchDownloadsComplete(
121 std::vector<DownloadItem*>& downloads) { 124 std::vector<DownloadItem*> downloads) {
122 ClearDownloadItems(); 125 ClearDownloadItems();
123 126
124 // Swap new downloads in. 127 // Swap new downloads in.
125 download_items_.swap(downloads); 128 download_items_.swap(downloads);
126 sort(download_items_.begin(), download_items_.end(), DownloadItemSorter()); 129 sort(download_items_.begin(), download_items_.end(), DownloadItemSorter());
127 130
128 // Scan for any in progress downloads and add ourself to them as an observer. 131 // Scan for any in progress downloads and add ourself to them as an observer.
129 for (OrderedDownloads::iterator it = download_items_.begin(); 132 for (OrderedDownloads::iterator it = download_items_.begin();
130 it != download_items_.end(); ++it) { 133 it != download_items_.end(); ++it) {
131 if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads) 134 if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads)
(...skipping 10 matching lines...) Expand all
142 } 145 }
143 146
144 SendCurrentDownloads(); 147 SendCurrentDownloads();
145 } 148 }
146 149
147 void DownloadsDOMHandler::HandleGetDownloads(const Value* value) { 150 void DownloadsDOMHandler::HandleGetDownloads(const Value* value) {
148 std::wstring new_search = ExtractStringValue(value); 151 std::wstring new_search = ExtractStringValue(value);
149 if (search_text_.compare(new_search) != 0) { 152 if (search_text_.compare(new_search) != 0) {
150 search_text_ = new_search; 153 search_text_ = new_search;
151 ClearDownloadItems(); 154 ClearDownloadItems();
152 download_manager_->GetDownloads(this, search_text_); 155 download_manager_->download_history()->Search(
156 WideToUTF16(search_text_),
157 NewCallback(this, &DownloadsDOMHandler::OnSearchDownloadsComplete));
153 } else { 158 } else {
154 SendCurrentDownloads(); 159 SendCurrentDownloads();
155 } 160 }
156 } 161 }
157 162
158 void DownloadsDOMHandler::HandleOpenFile(const Value* value) { 163 void DownloadsDOMHandler::HandleOpenFile(const Value* value) {
159 DownloadItem* file = GetDownloadByValue(value); 164 DownloadItem* file = GetDownloadByValue(value);
160 if (file) 165 if (file)
161 download_manager_->OpenDownload(file, NULL); 166 download_manager_->OpenDownload(file, NULL);
162 } 167 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 return NULL; 251 return NULL;
247 } 252 }
248 253
249 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const Value* value) { 254 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const Value* value) {
250 int id; 255 int id;
251 if (ExtractIntegerValue(value, &id)) { 256 if (ExtractIntegerValue(value, &id)) {
252 return GetDownloadById(id); 257 return GetDownloadById(id);
253 } 258 }
254 return NULL; 259 return NULL;
255 } 260 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/downloads_dom_handler.h ('k') | chrome/browser/dom_ui/filebrowse_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698