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

Side by Side Diff: chrome/utility/image_writer/image_writer.cc

Issue 294163008: Adds USB writing for OS X. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@list-devices
Patch Set: Fixes windows compilation. Created 6 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/utility/image_writer/image_writer.h"
6
5 #include "base/memory/aligned_memory.h" 7 #include "base/memory/aligned_memory.h"
6 #include "chrome/utility/image_writer/error_messages.h" 8 #include "chrome/utility/image_writer/error_messages.h"
7 #include "chrome/utility/image_writer/image_writer.h"
8 #include "chrome/utility/image_writer/image_writer_handler.h" 9 #include "chrome/utility/image_writer/image_writer_handler.h"
9 #include "content/public/utility/utility_thread.h" 10 #include "content/public/utility/utility_thread.h"
10 11
12 #if defined(OS_MACOSX)
13 #include "chrome/utility/image_writer/disk_unmounter_mac.h"
14 #endif
15
11 namespace image_writer { 16 namespace image_writer {
12 17
13 // Since block devices like large sequential access and IPC is expensive we're 18 // Since block devices like large sequential access and IPC is expensive we're
14 // doing work in 1MB chunks. 19 // doing work in 1MB chunks.
15 const int kBurningBlockSize = 1 << 20; // 1 MB 20 const int kBurningBlockSize = 1 << 20; // 1 MB
16 const int kMemoryAlignment = 4096; 21 const int kMemoryAlignment = 4096;
17 22
18 ImageWriter::ImageWriter(ImageWriterHandler* handler, 23 ImageWriter::ImageWriter(ImageWriterHandler* handler,
19 const base::FilePath& image_path, 24 const base::FilePath& image_path,
20 const base::FilePath& device_path) 25 const base::FilePath& device_path)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 base::File::FLAG_EXCLUSIVE_READ); 88 base::File::FLAG_EXCLUSIVE_READ);
84 89
85 if (!image_file_.IsValid()) { 90 if (!image_file_.IsValid()) {
86 DLOG(ERROR) << "Unable to open file for read: " << image_path_.value(); 91 DLOG(ERROR) << "Unable to open file for read: " << image_path_.value();
87 Error(error::kOpenImage); 92 Error(error::kOpenImage);
88 return false; 93 return false;
89 } 94 }
90 } 95 }
91 96
92 if (!device_file_.IsValid()) { 97 if (!device_file_.IsValid()) {
93 #if defined(OS_WIN) 98 if (!OpenDevice()) {
94 // Windows requires that device files be opened with FILE_FLAG_NO_BUFFERING
95 // and FILE_FLAG_WRITE_THROUGH. These two flags are not part of base::File.
96 device_file_ =
97 base::File(CreateFile(device_path_.value().c_str(),
98 GENERIC_READ | GENERIC_WRITE,
99 FILE_SHARE_READ | FILE_SHARE_WRITE,
100 NULL,
101 OPEN_EXISTING,
102 FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH,
103 NULL));
104 #else
105 device_file_.Initialize(
106 device_path_,
107 base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_WRITE |
108 base::File::FLAG_EXCLUSIVE_READ | base::File::FLAG_EXCLUSIVE_WRITE);
109 #endif
110 if (!device_file_.IsValid()) {
111 Error(error::kOpenDevice); 99 Error(error::kOpenDevice);
112 return false; 100 return false;
113 } 101 }
114 } 102 }
115 103
116 bytes_processed_ = 0; 104 bytes_processed_ = 0;
117 running_ = true; 105 running_ = true;
118 106
119 return true; 107 return true;
120 } 108 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 running_ = false; 188 running_ = false;
201 } else { 189 } else {
202 // Unable to read entire file. 190 // Unable to read entire file.
203 LOG(ERROR) << "Failed to read " << kBurningBlockSize << " bytes of image " 191 LOG(ERROR) << "Failed to read " << kBurningBlockSize << " bytes of image "
204 << "at offset " << bytes_processed_; 192 << "at offset " << bytes_processed_;
205 Error(error::kReadImage); 193 Error(error::kReadImage);
206 } 194 }
207 } 195 }
208 196
209 } // namespace image_writer 197 } // namespace image_writer
OLDNEW
« no previous file with comments | « chrome/utility/image_writer/image_writer.h ('k') | chrome/utility/image_writer/image_writer_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698