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

Side by Side Diff: content/test/test_file_error_injector.cc

Issue 10696043: Shifted DownloadFile to exporting DownloadInterruptReasons. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd to TOT. Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « content/public/test/test_file_error_injector.h ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/public/test/test_file_error_injector.h" 5 #include "content/public/test/test_file_error_injector.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "content/browser/download/download_create_info.h" 11 #include "content/browser/download/download_create_info.h"
12 #include "content/browser/download/download_file_impl.h" 12 #include "content/browser/download/download_file_impl.h"
13 #include "content/browser/download/download_file_manager.h" 13 #include "content/browser/download/download_file_manager.h"
14 #include "content/browser/download/download_interrupt_reasons_impl.h"
14 #include "content/browser/power_save_blocker.h" 15 #include "content/browser/power_save_blocker.h"
15 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" 16 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/download_id.h" 18 #include "content/public/browser/download_id.h"
18 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
19 20
20 namespace content { 21 namespace content {
21 class ByteStreamReader; 22 class ByteStreamReader;
22 } 23 }
23 24
(...skipping 20 matching lines...) Expand all
44 content::DownloadManager* download_manager, 45 content::DownloadManager* download_manager,
45 bool calculate_hash, 46 bool calculate_hash,
46 const net::BoundNetLog& bound_net_log, 47 const net::BoundNetLog& bound_net_log,
47 const content::TestFileErrorInjector::FileErrorInfo& error_info, 48 const content::TestFileErrorInjector::FileErrorInfo& error_info,
48 const ConstructionCallback& ctor_callback, 49 const ConstructionCallback& ctor_callback,
49 const DestructionCallback& dtor_callback); 50 const DestructionCallback& dtor_callback);
50 51
51 ~DownloadFileWithErrors(); 52 ~DownloadFileWithErrors();
52 53
53 // DownloadFile interface. 54 // DownloadFile interface.
54 virtual net::Error Initialize() OVERRIDE; 55 virtual content::DownloadInterruptReason Initialize() OVERRIDE;
55 virtual net::Error AppendDataToFile(const char* data, 56 virtual content::DownloadInterruptReason AppendDataToFile(
56 size_t data_len) OVERRIDE; 57 const char* data, size_t data_len) OVERRIDE;
57 virtual net::Error Rename(const FilePath& full_path) OVERRIDE; 58 virtual content::DownloadInterruptReason Rename(
59 const FilePath& full_path) OVERRIDE;
58 60
59 private: 61 private:
60 // Error generating helper. 62 // Error generating helper.
61 net::Error ShouldReturnError( 63 content::DownloadInterruptReason ShouldReturnError(
62 content::TestFileErrorInjector::FileOperationCode code, 64 content::TestFileErrorInjector::FileOperationCode code,
63 net::Error original_net_error); 65 content::DownloadInterruptReason original_error);
64 66
65 // Source URL for the file being downloaded. 67 // Source URL for the file being downloaded.
66 GURL source_url_; 68 GURL source_url_;
67 69
68 // Our injected error. Only one per file. 70 // Our injected error. Only one per file.
69 content::TestFileErrorInjector::FileErrorInfo error_info_; 71 content::TestFileErrorInjector::FileErrorInfo error_info_;
70 72
71 // Count per operation. 0-based. 73 // Count per operation. 0-based.
72 std::map<content::TestFileErrorInjector::FileOperationCode, int> 74 std::map<content::TestFileErrorInjector::FileOperationCode, int>
73 operation_counter_; 75 operation_counter_;
(...skipping 22 matching lines...) Expand all
96 source_url_(info->url()), 98 source_url_(info->url()),
97 error_info_(error_info), 99 error_info_(error_info),
98 destruction_callback_(dtor_callback) { 100 destruction_callback_(dtor_callback) {
99 ctor_callback.Run(source_url_, info->download_id); 101 ctor_callback.Run(source_url_, info->download_id);
100 } 102 }
101 103
102 DownloadFileWithErrors::~DownloadFileWithErrors() { 104 DownloadFileWithErrors::~DownloadFileWithErrors() {
103 destruction_callback_.Run(source_url_); 105 destruction_callback_.Run(source_url_);
104 } 106 }
105 107
106 net::Error DownloadFileWithErrors::Initialize() { 108 content::DownloadInterruptReason DownloadFileWithErrors::Initialize() {
107 return ShouldReturnError( 109 return ShouldReturnError(
108 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 110 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
109 DownloadFileImpl::Initialize()); 111 DownloadFileImpl::Initialize());
110 } 112 }
111 113
112 net::Error DownloadFileWithErrors::AppendDataToFile(const char* data, 114 content::DownloadInterruptReason DownloadFileWithErrors::AppendDataToFile(
113 size_t data_len) { 115 const char* data, size_t data_len) {
114 return ShouldReturnError( 116 return ShouldReturnError(
115 content::TestFileErrorInjector::FILE_OPERATION_WRITE, 117 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
116 DownloadFileImpl::AppendDataToFile(data, data_len)); 118 DownloadFileImpl::AppendDataToFile(data, data_len));
117 } 119 }
118 120
119 net::Error DownloadFileWithErrors::Rename(const FilePath& full_path) { 121 content::DownloadInterruptReason DownloadFileWithErrors::Rename(
122 const FilePath& full_path) {
120 return ShouldReturnError( 123 return ShouldReturnError(
121 content::TestFileErrorInjector::FILE_OPERATION_RENAME, 124 content::TestFileErrorInjector::FILE_OPERATION_RENAME,
122 DownloadFileImpl::Rename(full_path)); 125 DownloadFileImpl::Rename(full_path));
123 } 126 }
124 127
125 net::Error DownloadFileWithErrors::ShouldReturnError( 128 content::DownloadInterruptReason DownloadFileWithErrors::ShouldReturnError(
126 content::TestFileErrorInjector::FileOperationCode code, 129 content::TestFileErrorInjector::FileOperationCode code,
127 net::Error original_net_error) { 130 content::DownloadInterruptReason original_error) {
128 int counter = operation_counter_[code]; 131 int counter = operation_counter_[code];
129 ++operation_counter_[code]; 132 ++operation_counter_[code];
130 133
131 if (code != error_info_.code) 134 if (code != error_info_.code)
132 return original_net_error; 135 return original_error;
133 136
134 if (counter != error_info_.operation_instance) 137 if (counter != error_info_.operation_instance)
135 return original_net_error; 138 return original_error;
136 139
137 VLOG(1) << " " << __FUNCTION__ << "()" 140 VLOG(1) << " " << __FUNCTION__ << "()"
138 << " url = '" << source_url_.spec() << "'" 141 << " url = '" << source_url_.spec() << "'"
139 << " code = " << content::TestFileErrorInjector::DebugString(code) 142 << " code = " << content::TestFileErrorInjector::DebugString(code)
140 << " (" << code << ")" 143 << " (" << code << ")"
141 << " counter = " << counter 144 << " counter = " << counter
142 << " original_error = " << net::ErrorToString(original_net_error) 145 << " original_error = "
143 << " (" << original_net_error << ")" 146 << content::InterruptReasonDebugString(original_error)
144 << " new error = " << net::ErrorToString(error_info_.net_error) 147 << " (" << original_error << ")"
145 << " (" << error_info_.net_error << ")"; 148 << " new error = "
149 << content::InterruptReasonDebugString(error_info_.error)
150 << " (" << error_info_.error << ")";
146 151
147 return error_info_.net_error; 152 return error_info_.error;
148 } 153 }
149 154
150 } // namespace 155 } // namespace
151 156
152 namespace content { 157 namespace content {
153 158
154 // A factory for constructing DownloadFiles that inject errors. 159 // A factory for constructing DownloadFiles that inject errors.
155 class DownloadFileWithErrorsFactory 160 class DownloadFileWithErrorsFactory
156 : public DownloadFileManager::DownloadFileFactory { 161 : public DownloadFileManager::DownloadFileFactory {
157 public: 162 public:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 bool calculate_hash, 205 bool calculate_hash,
201 const net::BoundNetLog& bound_net_log) { 206 const net::BoundNetLog& bound_net_log) {
202 std::string url = info->url().spec(); 207 std::string url = info->url().spec();
203 208
204 if (injected_errors_.find(url) == injected_errors_.end()) { 209 if (injected_errors_.find(url) == injected_errors_.end()) {
205 // Have to create entry, because FileErrorInfo is not a POD type. 210 // Have to create entry, because FileErrorInfo is not a POD type.
206 TestFileErrorInjector::FileErrorInfo err_info = { 211 TestFileErrorInjector::FileErrorInfo err_info = {
207 url, 212 url,
208 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 213 TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
209 -1, 214 -1,
210 net::OK 215 content::DOWNLOAD_INTERRUPT_REASON_NONE
211 }; 216 };
212 injected_errors_[url] = err_info; 217 injected_errors_[url] = err_info;
213 } 218 }
214 219
215 return new DownloadFileWithErrors( 220 return new DownloadFileWithErrors(
216 info, 221 info,
217 stream.Pass(), 222 stream.Pass(),
218 new DownloadRequestHandle(info->request_handle), 223 new DownloadRequestHandle(info->request_handle),
219 download_manager, 224 download_manager,
220 calculate_hash, 225 calculate_hash,
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 case FILE_OPERATION_RENAME: 426 case FILE_OPERATION_RENAME:
422 return "RENAME"; 427 return "RENAME";
423 default: 428 default:
424 break; 429 break;
425 } 430 }
426 431
427 return "Unknown"; 432 return "Unknown";
428 } 433 }
429 434
430 } // namespace content 435 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/test_file_error_injector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698