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 <string> | 5 #include <string> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/i18n/number_formatting.h" | 9 #include "base/i18n/number_formatting.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/string16.h" |
13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
14 #include "base/string16.h" | |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 17 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
18 #include "chrome/browser/download/download_item_model.h" | 18 #include "chrome/browser/download/download_item_model.h" |
19 #include "chrome/browser/download/download_prefs.h" | 19 #include "chrome/browser/download/download_prefs.h" |
20 #include "chrome/browser/download/download_util.h" | 20 #include "chrome/browser/download/download_util.h" |
21 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
24 #include "content/browser/browser_thread.h" | 24 #include "content/browser/browser_thread.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 download_manager_->Shutdown(); | 59 download_manager_->Shutdown(); |
60 // profile_ must outlive download_manager_, so we explicitly delete | 60 // profile_ must outlive download_manager_, so we explicitly delete |
61 // download_manager_ first. | 61 // download_manager_ first. |
62 download_manager_ = NULL; | 62 download_manager_ = NULL; |
63 download_manager_delegate_ = NULL; | 63 download_manager_delegate_ = NULL; |
64 profile_.reset(NULL); | 64 profile_.reset(NULL); |
65 message_loop_.RunAllPending(); | 65 message_loop_.RunAllPending(); |
66 } | 66 } |
67 | 67 |
68 void AddDownloadToFileManager(int id, DownloadFile* download_file) { | 68 void AddDownloadToFileManager(int id, DownloadFile* download_file) { |
69 file_manager()->downloads_[id] = download_file; | 69 file_manager()->downloads_[DownloadId(download_manager_.get(), id)] = |
| 70 download_file; |
70 } | 71 } |
71 | 72 |
72 void OnResponseCompleted(int32 download_id, int64 size, | 73 void OnResponseCompleted(int32 download_id, int64 size, |
73 const std::string& hash) { | 74 const std::string& hash) { |
74 download_manager_->OnResponseCompleted(download_id, size, hash); | 75 download_manager_->OnResponseCompleted(download_id, size, hash); |
75 } | 76 } |
76 | 77 |
77 void FileSelected(const FilePath& path, void* params) { | 78 void FileSelected(const FilePath& path, void* params) { |
78 download_manager_->FileSelected(path, params); | 79 download_manager_->FileSelected(path, params); |
79 } | 80 } |
(...skipping 13 matching lines...) Expand all Loading... |
93 base::AutoLock auto_lock(download_buffer_.lock); | 94 base::AutoLock auto_lock(download_buffer_.lock); |
94 | 95 |
95 download_buffer_.contents.push_back( | 96 download_buffer_.contents.push_back( |
96 std::make_pair(io_buffer, length)); | 97 std::make_pair(io_buffer, length)); |
97 } | 98 } |
98 | 99 |
99 BrowserThread::PostTask( | 100 BrowserThread::PostTask( |
100 BrowserThread::FILE, FROM_HERE, | 101 BrowserThread::FILE, FROM_HERE, |
101 NewRunnableMethod(file_manager_.get(), | 102 NewRunnableMethod(file_manager_.get(), |
102 &DownloadFileManager::UpdateDownload, | 103 &DownloadFileManager::UpdateDownload, |
103 id, | 104 DownloadId(download_manager_.get(), id), |
104 &download_buffer_)); | 105 &download_buffer_)); |
105 | 106 |
106 message_loop_.RunAllPending(); | 107 message_loop_.RunAllPending(); |
107 } | 108 } |
108 | 109 |
109 void OnDownloadError(int32 download_id, int64 size, net::Error os_error) { | 110 void OnDownloadError(int32 download_id, int64 size, net::Error os_error) { |
110 download_manager_->OnDownloadError(download_id, size, os_error); | 111 download_manager_->OnDownloadError(download_id, size, os_error); |
111 } | 112 } |
112 | 113 |
113 // Get the download item with ID |id|. | 114 // Get the download item with ID |id|. |
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 870 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
870 EXPECT_TRUE(observer->was_updated()); | 871 EXPECT_TRUE(observer->was_updated()); |
871 EXPECT_FALSE(observer->was_opened()); | 872 EXPECT_FALSE(observer->was_opened()); |
872 EXPECT_TRUE(download->file_externally_removed()); | 873 EXPECT_TRUE(download->file_externally_removed()); |
873 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); | 874 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); |
874 EXPECT_EQ(download_item_model->GetStatusText(), | 875 EXPECT_EQ(download_item_model->GetStatusText(), |
875 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); | 876 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); |
876 | 877 |
877 EXPECT_FALSE(file_util::PathExists(new_path)); | 878 EXPECT_FALSE(file_util::PathExists(new_path)); |
878 } | 879 } |
OLD | NEW |