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

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

Issue 336923002: Adds API test for imageWriterPrivate.writeFromFile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chrome OS fixes. Created 6 years, 5 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 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/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_enumerator.h" 8 #include "base/files/file_enumerator.h"
9 #include "base/lazy_instance.h"
9 #include "base/threading/worker_pool.h" 10 #include "base/threading/worker_pool.h"
10 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" 11 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h"
11 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h " 12 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h "
12 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
13 14
14 namespace extensions { 15 namespace extensions {
15 namespace image_writer { 16 namespace image_writer {
16 17
17 using content::BrowserThread; 18 using content::BrowserThread;
18 19
19 const int kMD5BufferSize = 1024; 20 const int kMD5BufferSize = 1024;
20 #if defined(OS_CHROMEOS) 21 #if defined(OS_CHROMEOS)
21 // Chrome OS only has a 1 GB temporary partition. This is too small to hold our 22 // Chrome OS only has a 1 GB temporary partition. This is too small to hold our
22 // unzipped image. Fortunately we mount part of the temporary partition under 23 // unzipped image. Fortunately we mount part of the temporary partition under
23 // /var/tmp. 24 // /var/tmp.
24 const char kChromeOSTempRoot[] = "/var/tmp"; 25 const char kChromeOSTempRoot[] = "/var/tmp";
25 #endif 26 #endif
26 27
28 #if !defined(OS_CHROMEOS)
29 static base::LazyInstance<scoped_refptr<ImageWriterUtilityClient> >
30 g_utility_client = LAZY_INSTANCE_INITIALIZER;
31 #endif
32
27 Operation::Operation(base::WeakPtr<OperationManager> manager, 33 Operation::Operation(base::WeakPtr<OperationManager> manager,
28 const ExtensionId& extension_id, 34 const ExtensionId& extension_id,
29 const std::string& device_path) 35 const std::string& device_path)
30 : manager_(manager), 36 : manager_(manager),
31 extension_id_(extension_id), 37 extension_id_(extension_id),
32 #if defined(OS_WIN) 38 #if defined(OS_WIN)
33 device_path_(base::FilePath::FromUTF8Unsafe(device_path)), 39 device_path_(base::FilePath::FromUTF8Unsafe(device_path)),
34 #else 40 #else
35 device_path_(device_path), 41 device_path_(device_path),
36 #endif 42 #endif
(...skipping 17 matching lines...) Expand all
54 60
55 int Operation::GetProgress() { 61 int Operation::GetProgress() {
56 return progress_; 62 return progress_;
57 } 63 }
58 64
59 image_writer_api::Stage Operation::GetStage() { 65 image_writer_api::Stage Operation::GetStage() {
60 return stage_; 66 return stage_;
61 } 67 }
62 68
63 #if !defined(OS_CHROMEOS) 69 #if !defined(OS_CHROMEOS)
70 // static
64 void Operation::SetUtilityClientForTesting( 71 void Operation::SetUtilityClientForTesting(
65 scoped_refptr<ImageWriterUtilityClient> client) { 72 scoped_refptr<ImageWriterUtilityClient> client) {
66 image_writer_client_ = client; 73 g_utility_client.Get() = client;
67 AddCleanUpFunction(
68 base::Bind(&ImageWriterUtilityClient::Shutdown, image_writer_client_));
69 } 74 }
70 #endif 75 #endif
71 76
72 void Operation::Start() { 77 void Operation::Start() {
73 #if defined(OS_CHROMEOS) 78 #if defined(OS_CHROMEOS)
74 if (!temp_dir_.CreateUniqueTempDirUnderPath( 79 if (!temp_dir_.CreateUniqueTempDirUnderPath(
75 base::FilePath(kChromeOSTempRoot))) { 80 base::FilePath(kChromeOSTempRoot))) {
76 #else 81 #else
77 if (!temp_dir_.CreateUniqueTempDir()) { 82 if (!temp_dir_.CreateUniqueTempDir()) {
78 #endif 83 #endif
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 242
238 void Operation::CompleteAndContinue(const base::Closure& continuation) { 243 void Operation::CompleteAndContinue(const base::Closure& continuation) {
239 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 244 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
240 SetProgress(kProgressComplete); 245 SetProgress(kProgressComplete);
241 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, continuation); 246 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, continuation);
242 } 247 }
243 248
244 #if !defined(OS_CHROMEOS) 249 #if !defined(OS_CHROMEOS)
245 void Operation::StartUtilityClient() { 250 void Operation::StartUtilityClient() {
246 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 251 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
252 if (g_utility_client.Get()) {
253 image_writer_client_ = g_utility_client.Get();
254 return;
255 }
247 if (!image_writer_client_) { 256 if (!image_writer_client_) {
248 image_writer_client_ = new ImageWriterUtilityClient(); 257 image_writer_client_ = new ImageWriterUtilityClient();
249 AddCleanUpFunction(base::Bind(&Operation::StopUtilityClient, this)); 258 AddCleanUpFunction(base::Bind(&Operation::StopUtilityClient, this));
250 } 259 }
251 } 260 }
252 261
253 void Operation::StopUtilityClient() { 262 void Operation::StopUtilityClient() {
254 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 263 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
255 BrowserThread::PostTask( 264 BrowserThread::PostTask(
256 BrowserThread::IO, 265 BrowserThread::IO,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 for (std::vector<base::Closure>::iterator it = cleanup_functions_.begin(); 387 for (std::vector<base::Closure>::iterator it = cleanup_functions_.begin();
379 it != cleanup_functions_.end(); 388 it != cleanup_functions_.end();
380 ++it) { 389 ++it) {
381 it->Run(); 390 it->Run();
382 } 391 }
383 cleanup_functions_.clear(); 392 cleanup_functions_.clear();
384 } 393 }
385 394
386 } // namespace image_writer 395 } // namespace image_writer
387 } // namespace extensions 396 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698