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

Side by Side Diff: chrome/browser/extensions/api/image_writer_private/operation.cc

Issue 1432293003: Aura on Android: fix mangling of definitions in jni.h by Byte definition in zlib. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed feedback from patch set 3. Created 5 years, 1 month 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
« no previous file with comments | « chrome/browser/extensions/api/image_writer_private/operation.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/extensions/api/image_writer_private/operation.h" 5 #include "chrome/browser/extensions/api/image_writer_private/operation.h"
6 6
7 #include "base/files/file_enumerator.h" 7 #include "base/files/file_enumerator.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/threading/worker_pool.h" 10 #include "base/threading/worker_pool.h"
11 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" 11 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h"
12 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h " 12 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h "
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "third_party/zlib/google/zip_reader.h"
14 15
15 namespace extensions { 16 namespace extensions {
16 namespace image_writer { 17 namespace image_writer {
17 18
18 using content::BrowserThread; 19 using content::BrowserThread;
19 20
20 const int kMD5BufferSize = 1024; 21 const int kMD5BufferSize = 1024;
21 #if defined(OS_CHROMEOS) 22 #if defined(OS_CHROMEOS)
22 // Chrome OS only has a 1 GB temporary partition. This is too small to hold our 23 // Chrome OS only has a 1 GB temporary partition. This is too small to hold our
23 // unzipped image. Fortunately we mount part of the temporary partition under 24 // unzipped image. Fortunately we mount part of the temporary partition under
(...skipping 10 matching lines...) Expand all
34 const ExtensionId& extension_id, 35 const ExtensionId& extension_id,
35 const std::string& device_path) 36 const std::string& device_path)
36 : manager_(manager), 37 : manager_(manager),
37 extension_id_(extension_id), 38 extension_id_(extension_id),
38 #if defined(OS_WIN) 39 #if defined(OS_WIN)
39 device_path_(base::FilePath::FromUTF8Unsafe(device_path)), 40 device_path_(base::FilePath::FromUTF8Unsafe(device_path)),
40 #else 41 #else
41 device_path_(device_path), 42 device_path_(device_path),
42 #endif 43 #endif
43 stage_(image_writer_api::STAGE_UNKNOWN), 44 stage_(image_writer_api::STAGE_UNKNOWN),
44 progress_(0) { 45 progress_(0),
46 zip_reader_(new zip::ZipReader) {
45 } 47 }
46 48
47 Operation::~Operation() {} 49 Operation::~Operation() {}
48 50
49 void Operation::Cancel() { 51 void Operation::Cancel() {
50 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 52 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
51 53
52 stage_ = image_writer_api::STAGE_NONE; 54 stage_ = image_writer_api::STAGE_NONE;
53 55
54 CleanUp(); 56 CleanUp();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 return; 100 return;
99 } 101 }
100 102
101 if (image_path_.Extension() != FILE_PATH_LITERAL(".zip")) { 103 if (image_path_.Extension() != FILE_PATH_LITERAL(".zip")) {
102 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, continuation); 104 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, continuation);
103 return; 105 return;
104 } 106 }
105 107
106 SetStage(image_writer_api::STAGE_UNZIP); 108 SetStage(image_writer_api::STAGE_UNZIP);
107 109
108 if (!(zip_reader_.Open(image_path_) && zip_reader_.AdvanceToNextEntry() && 110 if (!(zip_reader_->Open(image_path_) && zip_reader_->AdvanceToNextEntry() &&
109 zip_reader_.OpenCurrentEntryInZip())) { 111 zip_reader_->OpenCurrentEntryInZip())) {
110 Error(error::kUnzipGenericError); 112 Error(error::kUnzipGenericError);
111 return; 113 return;
112 } 114 }
113 115
114 if (zip_reader_.HasMore()) { 116 if (zip_reader_->HasMore()) {
115 Error(error::kUnzipInvalidArchive); 117 Error(error::kUnzipInvalidArchive);
116 return; 118 return;
117 } 119 }
118 120
119 // Create a new target to unzip to. The original file is opened by the 121 // Create a new target to unzip to. The original file is opened by the
120 // zip_reader_. 122 // zip_reader_.
121 zip::ZipReader::EntryInfo* entry_info = zip_reader_.current_entry_info(); 123 zip::ZipReader::EntryInfo* entry_info = zip_reader_->current_entry_info();
122 if (entry_info) { 124 if (entry_info) {
123 image_path_ = temp_dir_.path().Append(entry_info->file_path().BaseName()); 125 image_path_ = temp_dir_.path().Append(entry_info->file_path().BaseName());
124 } else { 126 } else {
125 Error(error::kTempDirError); 127 Error(error::kTempDirError);
126 return; 128 return;
127 } 129 }
128 130
129 zip_reader_.ExtractCurrentEntryToFilePathAsync( 131 zip_reader_->ExtractCurrentEntryToFilePathAsync(
130 image_path_, 132 image_path_,
131 base::Bind(&Operation::CompleteAndContinue, this, continuation), 133 base::Bind(&Operation::CompleteAndContinue, this, continuation),
132 base::Bind(&Operation::OnUnzipFailure, this), 134 base::Bind(&Operation::OnUnzipFailure, this),
133 base::Bind(&Operation::OnUnzipProgress, 135 base::Bind(&Operation::OnUnzipProgress,
134 this, 136 this,
135 zip_reader_.current_entry_info()->original_size())); 137 zip_reader_->current_entry_info()->original_size()));
136 } 138 }
137 139
138 void Operation::Finish() { 140 void Operation::Finish() {
139 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { 141 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) {
140 BrowserThread::PostTask( 142 BrowserThread::PostTask(
141 BrowserThread::FILE, FROM_HERE, base::Bind(&Operation::Finish, this)); 143 BrowserThread::FILE, FROM_HERE, base::Bind(&Operation::Finish, this));
142 return; 144 return;
143 } 145 }
144 146
145 CleanUp(); 147 CleanUp();
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 for (std::vector<base::Closure>::iterator it = cleanup_functions_.begin(); 389 for (std::vector<base::Closure>::iterator it = cleanup_functions_.begin();
388 it != cleanup_functions_.end(); 390 it != cleanup_functions_.end();
389 ++it) { 391 ++it) {
390 it->Run(); 392 it->Run();
391 } 393 }
392 cleanup_functions_.clear(); 394 cleanup_functions_.clear();
393 } 395 }
394 396
395 } // namespace image_writer 397 } // namespace image_writer
396 } // namespace extensions 398 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/image_writer_private/operation.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698