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

Side by Side Diff: content/browser/download/mhtml_generation_manager.cc

Issue 1545243002: Convert Pass()→std::move() in //content/browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
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/browser/download/mhtml_generation_manager.h" 5 #include "content/browser/download/mhtml_generation_manager.h"
6 6
7 #include <map> 7 #include <map>
8 #include <queue> 8 #include <queue>
9 #include <utility>
9 10
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/files/file.h" 12 #include "base/files/file.h"
12 #include "base/guid.h" 13 #include "base/guid.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/rand_util.h" 15 #include "base/rand_util.h"
15 #include "base/scoped_observer.h" 16 #include "base/scoped_observer.h"
16 #include "base/stl_util.h" 17 #include "base/stl_util.h"
17 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
19 #include "content/browser/frame_host/frame_tree_node.h" 20 #include "content/browser/frame_host/frame_tree_node.h"
20 #include "content/common/frame_messages.h" 21 #include "content/common/frame_messages.h"
21 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/render_frame_host.h" 23 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/browser/render_process_host.h" 24 #include "content/public/browser/render_process_host.h"
24 #include "content/public/browser/render_process_host_observer.h" 25 #include "content/public/browser/render_process_host_observer.h"
25 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
26 27
27 namespace content { 28 namespace content {
28 29
29 // The class and all of its members live on the UI thread. Only static methods 30 // The class and all of its members live on the UI thread. Only static methods
30 // are executed on other threads. 31 // are executed on other threads.
31 class MHTMLGenerationManager::Job : public RenderProcessHostObserver { 32 class MHTMLGenerationManager::Job : public RenderProcessHostObserver {
32 public: 33 public:
33 Job(int job_id, WebContents* web_contents, GenerateMHTMLCallback callback); 34 Job(int job_id, WebContents* web_contents, GenerateMHTMLCallback callback);
34 ~Job() override; 35 ~Job() override;
35 36
36 void set_browser_file(base::File file) { browser_file_ = file.Pass(); } 37 void set_browser_file(base::File file) { browser_file_ = std::move(file); }
37 38
38 GenerateMHTMLCallback callback() const { return callback_; } 39 GenerateMHTMLCallback callback() const { return callback_; }
39 40
40 // Sends IPC to the renderer, asking for MHTML generation of the next frame. 41 // Sends IPC to the renderer, asking for MHTML generation of the next frame.
41 // 42 //
42 // Returns true if the message was sent successfully; false otherwise. 43 // Returns true if the message was sent successfully; false otherwise.
43 bool SendToNextRenderFrame(); 44 bool SendToNextRenderFrame();
44 45
45 // Indicates if more calls to SendToNextRenderFrame are needed. 46 // Indicates if more calls to SendToNextRenderFrame are needed.
46 bool HasMoreFramesToProcess() const { 47 bool HasMoreFramesToProcess() const {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 DCHECK_CURRENTLY_ON(BrowserThread::UI); 196 DCHECK_CURRENTLY_ON(BrowserThread::UI);
196 197
197 if (!browser_file_.IsValid()) { 198 if (!browser_file_.IsValid()) {
198 callback.Run(-1); 199 callback.Run(-1);
199 return; 200 return;
200 } 201 }
201 202
202 BrowserThread::PostTaskAndReplyWithResult( 203 BrowserThread::PostTaskAndReplyWithResult(
203 BrowserThread::FILE, FROM_HERE, 204 BrowserThread::FILE, FROM_HERE,
204 base::Bind(&MHTMLGenerationManager::Job::CloseFileOnFileThread, 205 base::Bind(&MHTMLGenerationManager::Job::CloseFileOnFileThread,
205 base::Passed(browser_file_.Pass())), 206 base::Passed(std::move(browser_file_))),
206 callback); 207 callback);
207 } 208 }
208 209
209 // static 210 // static
210 int64_t MHTMLGenerationManager::Job::CloseFileOnFileThread(base::File file) { 211 int64_t MHTMLGenerationManager::Job::CloseFileOnFileThread(base::File file) {
211 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 212 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
212 DCHECK(file.IsValid()); 213 DCHECK(file.IsValid());
213 int64_t file_size = file.GetLength(); 214 int64_t file_size = file.GetLength();
214 file.Close(); 215 file.Close();
215 return file_size; 216 return file_size;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 // only allow writing to the file and forbid reading from the file (as this 294 // only allow writing to the file and forbid reading from the file (as this
294 // would allow reading content generated by other renderers / other web 295 // would allow reading content generated by other renderers / other web
295 // principals). 296 // principals).
296 uint32_t file_flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE; 297 uint32_t file_flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE;
297 298
298 base::File browser_file(file_path, file_flags); 299 base::File browser_file(file_path, file_flags);
299 if (!browser_file.IsValid()) { 300 if (!browser_file.IsValid()) {
300 LOG(ERROR) << "Failed to create file to save MHTML at: " << 301 LOG(ERROR) << "Failed to create file to save MHTML at: " <<
301 file_path.value(); 302 file_path.value();
302 } 303 }
303 return browser_file.Pass(); 304 return browser_file;
304 } 305 }
305 306
306 void MHTMLGenerationManager::OnFileAvailable(int job_id, 307 void MHTMLGenerationManager::OnFileAvailable(int job_id,
307 base::File browser_file) { 308 base::File browser_file) {
308 DCHECK_CURRENTLY_ON(BrowserThread::UI); 309 DCHECK_CURRENTLY_ON(BrowserThread::UI);
309 310
310 if (!browser_file.IsValid()) { 311 if (!browser_file.IsValid()) {
311 LOG(ERROR) << "Failed to create file"; 312 LOG(ERROR) << "Failed to create file";
312 JobFinished(job_id, JobStatus::FAILURE); 313 JobFinished(job_id, JobStatus::FAILURE);
313 return; 314 return;
314 } 315 }
315 316
316 Job* job = FindJob(job_id); 317 Job* job = FindJob(job_id);
317 if (!job) 318 if (!job)
318 return; 319 return;
319 320
320 job->set_browser_file(browser_file.Pass()); 321 job->set_browser_file(std::move(browser_file));
321 322
322 if (!job->SendToNextRenderFrame()) { 323 if (!job->SendToNextRenderFrame()) {
323 JobFinished(job_id, JobStatus::FAILURE); 324 JobFinished(job_id, JobStatus::FAILURE);
324 } 325 }
325 } 326 }
326 327
327 void MHTMLGenerationManager::JobFinished(int job_id, JobStatus job_status) { 328 void MHTMLGenerationManager::JobFinished(int job_id, JobStatus job_status) {
328 DCHECK_CURRENTLY_ON(BrowserThread::UI); 329 DCHECK_CURRENTLY_ON(BrowserThread::UI);
329 330
330 Job* job = FindJob(job_id); 331 Job* job = FindJob(job_id);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 ++it) { 380 ++it) {
380 if (it->second == job) { 381 if (it->second == job) {
381 JobFinished(it->first, JobStatus::FAILURE); 382 JobFinished(it->first, JobStatus::FAILURE);
382 return; 383 return;
383 } 384 }
384 } 385 }
385 NOTREACHED(); 386 NOTREACHED();
386 } 387 }
387 388
388 } // namespace content 389 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/drag_download_util.cc ('k') | content/browser/download/save_package.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698