| 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/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 if (!file_util::ReadFile(file, reinterpret_cast<char*>(&read_bytes->front()), | 135 if (!file_util::ReadFile(file, reinterpret_cast<char*>(&read_bytes->front()), |
| 136 static_cast<int>(file_size))) | 136 static_cast<int>(file_size))) |
| 137 read_bytes->clear(); | 137 read_bytes->clear(); |
| 138 | 138 |
| 139 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); | 139 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void ScreenshotSource::GetSavedScreenshotCallback( | 142 void ScreenshotSource::GetSavedScreenshotCallback( |
| 143 const std::string& screenshot_path, | 143 const std::string& screenshot_path, |
| 144 int request_id, | 144 int request_id, |
| 145 gdata::GDataFileError error, | 145 gdata::DriveFileError error, |
| 146 const FilePath& file, | 146 const FilePath& file, |
| 147 const std::string& unused_mime_type, | 147 const std::string& unused_mime_type, |
| 148 gdata::DriveFileType file_type) { | 148 gdata::DriveFileType file_type) { |
| 149 if (error != gdata::GDATA_FILE_OK || file_type != gdata::REGULAR_FILE) { | 149 if (error != gdata::DRIVE_FILE_OK || file_type != gdata::REGULAR_FILE) { |
| 150 ScreenshotDataPtr read_bytes(new ScreenshotData); | 150 ScreenshotDataPtr read_bytes(new ScreenshotData); |
| 151 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); | 151 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); |
| 152 return; | 152 return; |
| 153 } | 153 } |
| 154 | 154 |
| 155 content::BrowserThread::PostTask( | 155 content::BrowserThread::PostTask( |
| 156 content::BrowserThread::FILE, FROM_HERE, | 156 content::BrowserThread::FILE, FROM_HERE, |
| 157 base::Bind(&ScreenshotSource::SendSavedScreenshot, | 157 base::Bind(&ScreenshotSource::SendSavedScreenshot, |
| 158 base::Unretained(this), screenshot_path, request_id, file)); | 158 base::Unretained(this), screenshot_path, request_id, file)); |
| 159 } | 159 } |
| 160 #endif | 160 #endif |
| 161 | 161 |
| 162 void ScreenshotSource::CacheAndSendScreenshot( | 162 void ScreenshotSource::CacheAndSendScreenshot( |
| 163 const std::string& screenshot_path, | 163 const std::string& screenshot_path, |
| 164 int request_id, | 164 int request_id, |
| 165 ScreenshotDataPtr bytes) { | 165 ScreenshotDataPtr bytes) { |
| 166 cached_screenshots_[screenshot_path] = bytes; | 166 cached_screenshots_[screenshot_path] = bytes; |
| 167 SendResponse(request_id, new base::RefCountedBytes(*bytes)); | 167 SendResponse(request_id, new base::RefCountedBytes(*bytes)); |
| 168 } | 168 } |
| OLD | NEW |