OLD | NEW |
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 "chrome/browser/ui/webui/screenshot_source.h" | 5 #include "chrome/browser/ui/webui/screenshot_source.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 181 |
182 url_canon::RawCanonOutputT<char16> decoded; | 182 url_canon::RawCanonOutputT<char16> decoded; |
183 url_util::DecodeURLEscapeSequences( | 183 url_util::DecodeURLEscapeSequences( |
184 filename.data(), filename.size(), &decoded); | 184 filename.data(), filename.size(), &decoded); |
185 // Screenshot filenames don't use non-ascii characters. | 185 // Screenshot filenames don't use non-ascii characters. |
186 std::string decoded_filename = UTF16ToASCII(string16( | 186 std::string decoded_filename = UTF16ToASCII(string16( |
187 decoded.data(), decoded.length())); | 187 decoded.data(), decoded.length())); |
188 | 188 |
189 FilePath download_path; | 189 FilePath download_path; |
190 GetScreenshotDirectory(&download_path); | 190 GetScreenshotDirectory(&download_path); |
191 if (gdata::util::IsUnderDriveMountPoint(download_path)) { | 191 if (drive::util::IsUnderDriveMountPoint(download_path)) { |
192 gdata::DriveFileSystemInterface* file_system = | 192 drive::DriveFileSystemInterface* file_system = |
193 gdata::DriveSystemServiceFactory::GetForProfile( | 193 drive::DriveSystemServiceFactory::GetForProfile( |
194 profile_)->file_system(); | 194 profile_)->file_system(); |
195 file_system->GetFileByResourceId( | 195 file_system->GetFileByResourceId( |
196 decoded_filename, | 196 decoded_filename, |
197 base::Bind(&ScreenshotSource::GetSavedScreenshotCallback, | 197 base::Bind(&ScreenshotSource::GetSavedScreenshotCallback, |
198 base::Unretained(this), screenshot_path, request_id), | 198 base::Unretained(this), screenshot_path, request_id), |
199 gdata::GetContentCallback()); | 199 gdata::GetContentCallback()); |
200 } else { | 200 } else { |
201 BrowserThread::PostTask( | 201 BrowserThread::PostTask( |
202 BrowserThread::FILE, FROM_HERE, | 202 BrowserThread::FILE, FROM_HERE, |
203 base::Bind(&ScreenshotSource::SendSavedScreenshot, | 203 base::Bind(&ScreenshotSource::SendSavedScreenshot, |
(...skipping 25 matching lines...) Expand all Loading... |
229 if (!file_util::ReadFile(file, reinterpret_cast<char*>(&read_bytes->front()), | 229 if (!file_util::ReadFile(file, reinterpret_cast<char*>(&read_bytes->front()), |
230 static_cast<int>(file_size))) | 230 static_cast<int>(file_size))) |
231 read_bytes->clear(); | 231 read_bytes->clear(); |
232 | 232 |
233 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); | 233 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); |
234 } | 234 } |
235 | 235 |
236 void ScreenshotSource::GetSavedScreenshotCallback( | 236 void ScreenshotSource::GetSavedScreenshotCallback( |
237 const std::string& screenshot_path, | 237 const std::string& screenshot_path, |
238 int request_id, | 238 int request_id, |
239 gdata::DriveFileError error, | 239 drive::DriveFileError error, |
240 const FilePath& file, | 240 const FilePath& file, |
241 const std::string& unused_mime_type, | 241 const std::string& unused_mime_type, |
242 gdata::DriveFileType file_type) { | 242 drive::DriveFileType file_type) { |
243 if (error != gdata::DRIVE_FILE_OK || file_type != gdata::REGULAR_FILE) { | 243 if (error != drive::DRIVE_FILE_OK || file_type != drive::REGULAR_FILE) { |
244 ScreenshotDataPtr read_bytes(new ScreenshotData); | 244 ScreenshotDataPtr read_bytes(new ScreenshotData); |
245 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); | 245 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); |
246 return; | 246 return; |
247 } | 247 } |
248 | 248 |
249 content::BrowserThread::PostTask( | 249 content::BrowserThread::PostTask( |
250 content::BrowserThread::FILE, FROM_HERE, | 250 content::BrowserThread::FILE, FROM_HERE, |
251 base::Bind(&ScreenshotSource::SendSavedScreenshot, | 251 base::Bind(&ScreenshotSource::SendSavedScreenshot, |
252 base::Unretained(this), screenshot_path, request_id, file)); | 252 base::Unretained(this), screenshot_path, request_id, file)); |
253 } | 253 } |
254 #endif | 254 #endif |
255 | 255 |
256 void ScreenshotSource::CacheAndSendScreenshot( | 256 void ScreenshotSource::CacheAndSendScreenshot( |
257 const std::string& screenshot_path, | 257 const std::string& screenshot_path, |
258 int request_id, | 258 int request_id, |
259 ScreenshotDataPtr bytes) { | 259 ScreenshotDataPtr bytes) { |
260 // Strip the query from the screenshot path. | 260 // Strip the query from the screenshot path. |
261 std::string path = screenshot_path.substr( | 261 std::string path = screenshot_path.substr( |
262 0, screenshot_path.find_first_of("?")); | 262 0, screenshot_path.find_first_of("?")); |
263 cached_screenshots_[path] = bytes; | 263 cached_screenshots_[path] = bytes; |
264 SendResponse(request_id, new base::RefCountedBytes(*bytes)); | 264 SendResponse(request_id, new base::RefCountedBytes(*bytes)); |
265 } | 265 } |
OLD | NEW |