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

Side by Side Diff: net/url_request/url_request_file_dir_job.cc

Issue 10942004: Cleanup: avoid foo ? true : false, part 2. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 3 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
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 "net/url_request/url_request_file_dir_job.h" 5 #include "net/url_request/url_request_file_dir_job.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/file_util.h"
10 #include "base/message_loop.h" 9 #include "base/message_loop.h"
11 #include "base/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
12 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
13 #include "base/time.h" 12 #include "base/time.h"
14 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
15 #include "net/base/io_buffer.h" 14 #include "net/base/io_buffer.h"
16 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
17 #include "net/base/net_util.h" 16 #include "net/base/net_util.h"
18 #include "net/url_request/url_request_status.h" 17 #include "net/url_request/url_request_status.h"
19 18
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 59
61 if (!list_complete_) 60 if (!list_complete_)
62 lister_.Cancel(); 61 lister_.Cancel();
63 62
64 URLRequestJob::Kill(); 63 URLRequestJob::Kill();
65 64
66 weak_factory_.InvalidateWeakPtrs(); 65 weak_factory_.InvalidateWeakPtrs();
67 } 66 }
68 67
69 bool URLRequestFileDirJob::ReadRawData(IOBuffer* buf, int buf_size, 68 bool URLRequestFileDirJob::ReadRawData(IOBuffer* buf, int buf_size,
70 int *bytes_read) { 69 int* bytes_read) {
71 DCHECK(bytes_read); 70 DCHECK(bytes_read);
72 *bytes_read = 0; 71 *bytes_read = 0;
73 72
74 if (is_done()) 73 if (is_done())
75 return true; 74 return true;
76 75
77 if (FillReadBuffer(buf->data(), buf_size, bytes_read)) 76 if (FillReadBuffer(buf->data(), buf_size, bytes_read))
78 return true; 77 return true;
79 78
80 // We are waiting for more data 79 // We are waiting for more data
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 116 }
118 117
119 #if defined(OS_WIN) 118 #if defined(OS_WIN)
120 int64 size = (static_cast<unsigned __int64>(data.info.nFileSizeHigh) << 32) | 119 int64 size = (static_cast<unsigned __int64>(data.info.nFileSizeHigh) << 32) |
121 data.info.nFileSizeLow; 120 data.info.nFileSizeLow;
122 121
123 // Note that we should not convert ftLastWriteTime to the local time because 122 // Note that we should not convert ftLastWriteTime to the local time because
124 // ICU's datetime formatting APIs expect time in UTC and take into account 123 // ICU's datetime formatting APIs expect time in UTC and take into account
125 // the timezone before formatting. 124 // the timezone before formatting.
126 data_.append(GetDirectoryListingEntry( 125 data_.append(GetDirectoryListingEntry(
127 data.info.cFileName, std::string(), 126 data.info.cFileName,
128 (data.info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? true : false, 127 std::string(),
128 ((data.info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0),
129 size, 129 size,
130 base::Time::FromFileTime(data.info.ftLastWriteTime))); 130 base::Time::FromFileTime(data.info.ftLastWriteTime)));
131
132 #elif defined(OS_POSIX) 131 #elif defined(OS_POSIX)
133 // TOOD(jungshik): The same issue as for the directory name. 132 // TOOD(jungshik): The same issue as for the directory name.
134 data_.append(GetDirectoryListingEntry( 133 data_.append(GetDirectoryListingEntry(
135 WideToUTF16(base::SysNativeMBToWide(data.info.filename)), 134 WideToUTF16(base::SysNativeMBToWide(data.info.filename)),
136 data.info.filename, 135 data.info.filename,
137 S_ISDIR(data.info.stat.st_mode), 136 S_ISDIR(data.info.stat.st_mode),
138 data.info.stat.st_size, 137 data.info.stat.st_size,
139 base::Time::FromTimeT(data.info.stat.st_mtime))); 138 base::Time::FromTimeT(data.info.stat.st_mtime)));
140 #endif 139 #endif
141 140
(...skipping 27 matching lines...) Expand all
169 SetStatus(URLRequestStatus()); 168 SetStatus(URLRequestStatus());
170 NotifyReadComplete(bytes_read); 169 NotifyReadComplete(bytes_read);
171 } else { 170 } else {
172 NOTREACHED(); 171 NOTREACHED();
173 // TODO: Better error code. 172 // TODO: Better error code.
174 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, 0)); 173 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, 0));
175 } 174 }
176 } 175 }
177 } 176 }
178 177
179 bool URLRequestFileDirJob::FillReadBuffer(char *buf, int buf_size, 178 bool URLRequestFileDirJob::FillReadBuffer(char* buf, int buf_size,
180 int *bytes_read) { 179 int* bytes_read) {
181 DCHECK(bytes_read); 180 DCHECK(bytes_read);
182 181
183 *bytes_read = 0; 182 *bytes_read = 0;
184 183
185 int count = std::min(buf_size, static_cast<int>(data_.size())); 184 int count = std::min(buf_size, static_cast<int>(data_.size()));
186 if (count) { 185 if (count) {
187 memcpy(buf, &data_[0], count); 186 memcpy(buf, &data_[0], count);
188 data_.erase(0, count); 187 data_.erase(0, count);
189 *bytes_read = count; 188 *bytes_read = count;
190 return true; 189 return true;
191 } else if (list_complete_) { 190 } else if (list_complete_) {
192 // EOF 191 // EOF
193 return true; 192 return true;
194 } 193 }
195 return false; 194 return false;
196 } 195 }
197 196
198 } // namespace net 197 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_response_info.cc ('k') | ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_font_rpc_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698