OLD | NEW |
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 <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/singleton.h" | 12 #include "base/singleton.h" |
13 #include "base/string_piece.h" | 13 #include "base/string_piece.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/browser_thread.h" | 18 #include "chrome/browser/browser_thread.h" |
19 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 19 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
20 #include "chrome/browser/dom_ui/fileicon_source.h" | 20 #include "chrome/browser/dom_ui/fileicon_source.h" |
21 #include "chrome/browser/download/download_history.h" | 21 #include "chrome/browser/download/download_history.h" |
22 #include "chrome/browser/download/download_item.h" | 22 #include "chrome/browser/download/download_item.h" |
23 #include "chrome/browser/download/download_util.h" | 23 #include "chrome/browser/download/download_util.h" |
24 #include "chrome/browser/metrics/user_metrics.h" | 24 #include "chrome/browser/metrics/user_metrics.h" |
| 25 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/tab_contents/tab_contents.h" | 26 #include "chrome/browser/tab_contents/tab_contents.h" |
26 #include "chrome/common/jstemplate_builder.h" | 27 #include "chrome/common/jstemplate_builder.h" |
27 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
28 #include "grit/browser_resources.h" | 29 #include "grit/browser_resources.h" |
29 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 // Maximum number of downloads to show. TODO(glen): Remove this and instead | 34 // Maximum number of downloads to show. TODO(glen): Remove this and instead |
34 // stuff the downloads down the pipe slowly. | 35 // stuff the downloads down the pipe slowly. |
35 static const int kMaxDownloads = 150; | 36 static const int kMaxDownloads = 150; |
36 | 37 |
37 // Sort DownloadItems into descending order by their start time. | 38 // Sort DownloadItems into descending order by their start time. |
38 class DownloadItemSorter : public std::binary_function<DownloadItem*, | 39 class DownloadItemSorter : public std::binary_function<DownloadItem*, |
39 DownloadItem*, | 40 DownloadItem*, |
40 bool> { | 41 bool> { |
41 public: | 42 public: |
42 bool operator()(const DownloadItem* lhs, const DownloadItem* rhs) { | 43 bool operator()(const DownloadItem* lhs, const DownloadItem* rhs) { |
43 return lhs->start_time() > rhs->start_time(); | 44 return lhs->start_time() > rhs->start_time(); |
44 } | 45 } |
45 }; | 46 }; |
46 | 47 |
47 } // namespace | 48 } // namespace |
48 | 49 |
49 DownloadsDOMHandler::DownloadsDOMHandler(DownloadManager* dlm) | 50 DownloadsDOMHandler::DownloadsDOMHandler(DownloadManager* dlm) |
50 : search_text_(), | 51 : search_text_(), |
51 download_manager_(dlm), | 52 download_manager_(dlm), |
52 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 53 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
53 // Create our fileicon data source. | 54 // Create our fileicon data source. |
54 BrowserThread::PostTask( | 55 dlm->profile()->GetChromeURLDataManager()->AddDataSource( |
55 BrowserThread::IO, FROM_HERE, | 56 new FileIconSource()); |
56 NewRunnableMethod( | |
57 ChromeURLDataManager::GetInstance(), | |
58 &ChromeURLDataManager::AddDataSource, | |
59 make_scoped_refptr(new FileIconSource()))); | |
60 } | 57 } |
61 | 58 |
62 DownloadsDOMHandler::~DownloadsDOMHandler() { | 59 DownloadsDOMHandler::~DownloadsDOMHandler() { |
63 ClearDownloadItems(); | 60 ClearDownloadItems(); |
64 download_manager_->RemoveObserver(this); | 61 download_manager_->RemoveObserver(this); |
65 } | 62 } |
66 | 63 |
67 // DownloadsDOMHandler, public: ----------------------------------------------- | 64 // DownloadsDOMHandler, public: ----------------------------------------------- |
68 | 65 |
69 void DownloadsDOMHandler::Init() { | 66 void DownloadsDOMHandler::Init() { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 return NULL; | 240 return NULL; |
244 } | 241 } |
245 | 242 |
246 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { | 243 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { |
247 int id; | 244 int id; |
248 if (ExtractIntegerValue(args, &id)) { | 245 if (ExtractIntegerValue(args, &id)) { |
249 return GetDownloadById(id); | 246 return GetDownloadById(id); |
250 } | 247 } |
251 return NULL; | 248 return NULL; |
252 } | 249 } |
OLD | NEW |