| 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_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 read_bytes->clear(); | 239 read_bytes->clear(); |
| 240 | 240 |
| 241 CacheAndSendScreenshot(screenshot_path, callback, read_bytes); | 241 CacheAndSendScreenshot(screenshot_path, callback, read_bytes); |
| 242 } | 242 } |
| 243 | 243 |
| 244 void ScreenshotSource::GetSavedScreenshotCallback( | 244 void ScreenshotSource::GetSavedScreenshotCallback( |
| 245 const std::string& screenshot_path, | 245 const std::string& screenshot_path, |
| 246 const content::URLDataSource::GotDataCallback& callback, | 246 const content::URLDataSource::GotDataCallback& callback, |
| 247 drive::FileError error, | 247 drive::FileError error, |
| 248 const base::FilePath& file, | 248 const base::FilePath& file, |
| 249 const std::string& unused_mime_type, | 249 scoped_ptr<drive::ResourceEntry> entry) { |
| 250 drive::DriveFileType file_type) { | 250 if (error != drive::FILE_ERROR_OK) { |
| 251 if (error != drive::FILE_ERROR_OK || file_type != drive::REGULAR_FILE) { | |
| 252 ScreenshotDataPtr read_bytes(new ScreenshotData); | 251 ScreenshotDataPtr read_bytes(new ScreenshotData); |
| 253 CacheAndSendScreenshot(screenshot_path, callback, read_bytes); | 252 CacheAndSendScreenshot(screenshot_path, callback, read_bytes); |
| 254 return; | 253 return; |
| 255 } | 254 } |
| 256 | 255 |
| 257 content::BrowserThread::PostTask( | 256 content::BrowserThread::PostTask( |
| 258 content::BrowserThread::FILE, FROM_HERE, | 257 content::BrowserThread::FILE, FROM_HERE, |
| 259 base::Bind(&ScreenshotSource::SendSavedScreenshot, | 258 base::Bind(&ScreenshotSource::SendSavedScreenshot, |
| 260 base::Unretained(this), screenshot_path, callback, file)); | 259 base::Unretained(this), screenshot_path, callback, file)); |
| 261 } | 260 } |
| 262 #endif | 261 #endif |
| 263 | 262 |
| 264 void ScreenshotSource::CacheAndSendScreenshot( | 263 void ScreenshotSource::CacheAndSendScreenshot( |
| 265 const std::string& screenshot_path, | 264 const std::string& screenshot_path, |
| 266 const content::URLDataSource::GotDataCallback& callback, | 265 const content::URLDataSource::GotDataCallback& callback, |
| 267 ScreenshotDataPtr bytes) { | 266 ScreenshotDataPtr bytes) { |
| 268 // Strip the query from the screenshot path. | 267 // Strip the query from the screenshot path. |
| 269 std::string path = screenshot_path.substr( | 268 std::string path = screenshot_path.substr( |
| 270 0, screenshot_path.find_first_of("?")); | 269 0, screenshot_path.find_first_of("?")); |
| 271 cached_screenshots_[path] = bytes; | 270 cached_screenshots_[path] = bytes; |
| 272 callback.Run(new base::RefCountedBytes(*bytes)); | 271 callback.Run(new base::RefCountedBytes(*bytes)); |
| 273 } | 272 } |
| OLD | NEW |