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

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

Issue 10689093: Move Rename functionality from DownloadFileManager to DownloadFileImple. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Upload fater merging past revert to figure out if I still have a patch. 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/mock_download_manager.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"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 const content::TestFileErrorInjector::FileErrorInfo& error_info, 48 const content::TestFileErrorInjector::FileErrorInfo& error_info,
49 const ConstructionCallback& ctor_callback, 49 const ConstructionCallback& ctor_callback,
50 const DestructionCallback& dtor_callback); 50 const DestructionCallback& dtor_callback);
51 51
52 ~DownloadFileWithErrors(); 52 ~DownloadFileWithErrors();
53 53
54 // DownloadFile interface. 54 // DownloadFile interface.
55 virtual content::DownloadInterruptReason Initialize() OVERRIDE; 55 virtual content::DownloadInterruptReason Initialize() OVERRIDE;
56 virtual content::DownloadInterruptReason AppendDataToFile( 56 virtual content::DownloadInterruptReason AppendDataToFile(
57 const char* data, size_t data_len) OVERRIDE; 57 const char* data, size_t data_len) OVERRIDE;
58 virtual content::DownloadInterruptReason Rename( 58 virtual void Rename(const FilePath& full_path,
59 const FilePath& full_path) OVERRIDE; 59 bool overwrite_existing_file,
60 const RenameCompletionCallback& callback) OVERRIDE;
60 61
61 private: 62 private:
62 // Error generating helper. 63 // Error generating helper.
63 content::DownloadInterruptReason ShouldReturnError( 64 content::DownloadInterruptReason ShouldReturnError(
64 content::TestFileErrorInjector::FileOperationCode code, 65 content::TestFileErrorInjector::FileOperationCode code,
65 content::DownloadInterruptReason original_error); 66 content::DownloadInterruptReason original_error);
66 67
68 // Used in place of original rename callback to intercept with
69 // ShouldReturnError.
70 void RenameErrorCallback(
71 const RenameCompletionCallback& original_callback,
72 content::DownloadInterruptReason original_error,
73 const FilePath& path_result);
74
67 // Source URL for the file being downloaded. 75 // Source URL for the file being downloaded.
68 GURL source_url_; 76 GURL source_url_;
69 77
70 // Our injected error. Only one per file. 78 // Our injected error. Only one per file.
71 content::TestFileErrorInjector::FileErrorInfo error_info_; 79 content::TestFileErrorInjector::FileErrorInfo error_info_;
72 80
73 // Count per operation. 0-based. 81 // Count per operation. 0-based.
74 std::map<content::TestFileErrorInjector::FileOperationCode, int> 82 std::map<content::TestFileErrorInjector::FileOperationCode, int>
75 operation_counter_; 83 operation_counter_;
76 84
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 DownloadFileImpl::Initialize()); 119 DownloadFileImpl::Initialize());
112 } 120 }
113 121
114 content::DownloadInterruptReason DownloadFileWithErrors::AppendDataToFile( 122 content::DownloadInterruptReason DownloadFileWithErrors::AppendDataToFile(
115 const char* data, size_t data_len) { 123 const char* data, size_t data_len) {
116 return ShouldReturnError( 124 return ShouldReturnError(
117 content::TestFileErrorInjector::FILE_OPERATION_WRITE, 125 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
118 DownloadFileImpl::AppendDataToFile(data, data_len)); 126 DownloadFileImpl::AppendDataToFile(data, data_len));
119 } 127 }
120 128
121 content::DownloadInterruptReason DownloadFileWithErrors::Rename( 129 void DownloadFileWithErrors::Rename(
122 const FilePath& full_path) { 130 const FilePath& full_path,
123 return ShouldReturnError( 131 bool overwrite_existing_file,
124 content::TestFileErrorInjector::FILE_OPERATION_RENAME, 132 const RenameCompletionCallback& callback) {
125 DownloadFileImpl::Rename(full_path)); 133 DownloadFileImpl::Rename(
134 full_path, overwrite_existing_file,
135 base::Bind(&DownloadFileWithErrors::RenameErrorCallback,
136 // Unretained since this'll only be called from
137 // the DownloadFileImpl slice of the same object.
138 base::Unretained(this), callback));
126 } 139 }
127 140
128 content::DownloadInterruptReason DownloadFileWithErrors::ShouldReturnError( 141 content::DownloadInterruptReason DownloadFileWithErrors::ShouldReturnError(
129 content::TestFileErrorInjector::FileOperationCode code, 142 content::TestFileErrorInjector::FileOperationCode code,
130 content::DownloadInterruptReason original_error) { 143 content::DownloadInterruptReason original_error) {
131 int counter = operation_counter_[code]; 144 int counter = operation_counter_[code];
132 ++operation_counter_[code]; 145 ++operation_counter_[code];
133 146
134 if (code != error_info_.code) 147 if (code != error_info_.code)
135 return original_error; 148 return original_error;
136 149
137 if (counter != error_info_.operation_instance) 150 if (counter != error_info_.operation_instance)
138 return original_error; 151 return original_error;
139 152
140 VLOG(1) << " " << __FUNCTION__ << "()" 153 VLOG(1) << " " << __FUNCTION__ << "()"
141 << " url = '" << source_url_.spec() << "'" 154 << " url = '" << source_url_.spec() << "'"
142 << " code = " << content::TestFileErrorInjector::DebugString(code) 155 << " code = " << content::TestFileErrorInjector::DebugString(code)
143 << " (" << code << ")" 156 << " (" << code << ")"
144 << " counter = " << counter 157 << " counter = " << counter
145 << " original_error = " 158 << " original_error = "
146 << content::InterruptReasonDebugString(original_error) 159 << content::InterruptReasonDebugString(original_error)
147 << " (" << original_error << ")" 160 << " (" << original_error << ")"
148 << " new error = " 161 << " new error = "
149 << content::InterruptReasonDebugString(error_info_.error) 162 << content::InterruptReasonDebugString(error_info_.error)
150 << " (" << error_info_.error << ")"; 163 << " (" << error_info_.error << ")";
151 164
152 return error_info_.error; 165 return error_info_.error;
153 } 166 }
154 167
168 void DownloadFileWithErrors::RenameErrorCallback(
169 const RenameCompletionCallback& original_callback,
170 content::DownloadInterruptReason original_error,
171 const FilePath& path_result) {
172 original_callback.Run(ShouldReturnError(
173 content::TestFileErrorInjector::FILE_OPERATION_RENAME,
174 original_error), path_result);
175 }
176
155 } // namespace 177 } // namespace
156 178
157 namespace content { 179 namespace content {
158 180
159 // A factory for constructing DownloadFiles that inject errors. 181 // A factory for constructing DownloadFiles that inject errors.
160 class DownloadFileWithErrorsFactory 182 class DownloadFileWithErrorsFactory
161 : public DownloadFileManager::DownloadFileFactory { 183 : public DownloadFileManager::DownloadFileFactory {
162 public: 184 public:
163 185
164 DownloadFileWithErrorsFactory( 186 DownloadFileWithErrorsFactory(
165 const DownloadFileWithErrors::ConstructionCallback& ctor_callback, 187 const DownloadFileWithErrors::ConstructionCallback& ctor_callback,
166 const DownloadFileWithErrors::DestructionCallback& dtor_callback); 188 const DownloadFileWithErrors::DestructionCallback& dtor_callback);
167 virtual ~DownloadFileWithErrorsFactory(); 189 virtual ~DownloadFileWithErrorsFactory();
168 190
169 // DownloadFileFactory interface. 191 // DownloadFileFactory interface.
170 virtual content::DownloadFile* CreateFile( 192 virtual DownloadFile* CreateFile(
171 DownloadCreateInfo* info, 193 DownloadCreateInfo* info,
172 scoped_ptr<content::ByteStreamReader> stream, 194 scoped_ptr<content::ByteStreamReader> stream,
173 content::DownloadManager* download_manager, 195 content::DownloadManager* download_manager,
174 bool calculate_hash, 196 bool calculate_hash,
175 const net::BoundNetLog& bound_net_log); 197 const net::BoundNetLog& bound_net_log);
176 198
177 bool AddError( 199 bool AddError(
178 const TestFileErrorInjector::FileErrorInfo& error_info); 200 const TestFileErrorInjector::FileErrorInfo& error_info);
179 201
180 void ClearErrors(); 202 void ClearErrors();
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 case FILE_OPERATION_RENAME: 448 case FILE_OPERATION_RENAME:
427 return "RENAME"; 449 return "RENAME";
428 default: 450 default:
429 break; 451 break;
430 } 452 }
431 453
432 return "Unknown"; 454 return "Unknown";
433 } 455 }
434 456
435 } // namespace content 457 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/mock_download_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698