OLD | NEW |
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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" | 6 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" |
7 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" | 7 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" |
8 #include "chrome/browser/extensions/api/image_writer_private/image_writer_privat
e_api.h" | 8 #include "chrome/browser/extensions/api/image_writer_private/image_writer_privat
e_api.h" |
9 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h
" | 9 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h
" |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 scoped_ptr<image_writer_api::WriteFromUrl::Params> params( | 24 scoped_ptr<image_writer_api::WriteFromUrl::Params> params( |
25 image_writer_api::WriteFromUrl::Params::Create(*args_)); | 25 image_writer_api::WriteFromUrl::Params::Create(*args_)); |
26 EXTENSION_FUNCTION_VALIDATE(params.get()); | 26 EXTENSION_FUNCTION_VALIDATE(params.get()); |
27 | 27 |
28 GURL url(params->image_url); | 28 GURL url(params->image_url); |
29 if (!url.is_valid()) { | 29 if (!url.is_valid()) { |
30 error_ = image_writer::error::kUrlInvalid; | 30 error_ = image_writer::error::kUrlInvalid; |
31 return false; | 31 return false; |
32 } | 32 } |
33 | 33 |
| 34 #if defined(OS_CHROMEOS) |
| 35 // The Chrome OS temporary partition is too small for Chrome OS images, thus |
| 36 // we must always use the downloads folder. |
| 37 bool save_image_as_download = true; |
| 38 #else |
| 39 bool save_image_as_download = false; |
| 40 if (params->options.get() && params->options->save_as_download.get()) { |
| 41 save_image_as_download = true; |
| 42 } |
| 43 #endif |
| 44 |
34 std::string hash; | 45 std::string hash; |
35 if (params->options.get() && params->options->image_hash.get()) { | 46 if (params->options.get() && params->options->image_hash.get()) { |
36 hash = *params->options->image_hash; | 47 hash = *params->options->image_hash; |
37 } | 48 } |
38 | 49 |
39 image_writer::OperationManager::Get(GetProfile())->StartWriteFromUrl( | 50 image_writer::OperationManager::Get(GetProfile())->StartWriteFromUrl( |
40 extension_id(), | 51 extension_id(), |
41 url, | 52 url, |
| 53 render_view_host(), |
42 hash, | 54 hash, |
| 55 save_image_as_download, |
43 params->storage_unit_id, | 56 params->storage_unit_id, |
44 base::Bind(&ImageWriterPrivateWriteFromUrlFunction::OnWriteStarted, | 57 base::Bind(&ImageWriterPrivateWriteFromUrlFunction::OnWriteStarted, |
45 this)); | 58 this)); |
46 return true; | 59 return true; |
47 } | 60 } |
48 | 61 |
49 void ImageWriterPrivateWriteFromUrlFunction::OnWriteStarted( | 62 void ImageWriterPrivateWriteFromUrlFunction::OnWriteStarted( |
50 bool success, | 63 bool success, |
51 const std::string& error) { | 64 const std::string& error) { |
52 if (!success) { | 65 if (!success) { |
(...skipping 16 matching lines...) Expand all Loading... |
69 std::string filesystem_path; | 82 std::string filesystem_path; |
70 std::string storage_unit_id; | 83 std::string storage_unit_id; |
71 | 84 |
72 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &storage_unit_id)); | 85 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &storage_unit_id)); |
73 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_name)); | 86 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_name)); |
74 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &filesystem_path)); | 87 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &filesystem_path)); |
75 | 88 |
76 base::FilePath path; | 89 base::FilePath path; |
77 | 90 |
78 if (!extensions::app_file_handler_util::ValidateFileEntryAndGetPath( | 91 if (!extensions::app_file_handler_util::ValidateFileEntryAndGetPath( |
79 filesystem_name, | 92 filesystem_name, |
80 filesystem_path, | 93 filesystem_path, |
81 render_view_host(), | 94 render_view_host_, |
82 &path, | 95 &path, |
83 &error_)) | 96 &error_)) |
84 return false; | 97 return false; |
85 | 98 |
86 image_writer::OperationManager::Get(GetProfile())->StartWriteFromFile( | 99 image_writer::OperationManager::Get(GetProfile())->StartWriteFromFile( |
87 extension_id(), | 100 extension_id(), |
88 path, | 101 path, |
89 storage_unit_id, | 102 storage_unit_id, |
90 base::Bind(&ImageWriterPrivateWriteFromFileFunction::OnWriteStarted, | 103 base::Bind(&ImageWriterPrivateWriteFromFileFunction::OnWriteStarted, |
91 this)); | 104 this)); |
92 return true; | 105 return true; |
93 } | 106 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 image_writer_api::ListRemovableStorageDevices::Results::Create( | 194 image_writer_api::ListRemovableStorageDevices::Results::Create( |
182 device_list.get()->data); | 195 device_list.get()->data); |
183 SendResponse(true); | 196 SendResponse(true); |
184 } else { | 197 } else { |
185 error_ = image_writer::error::kDeviceListError; | 198 error_ = image_writer::error::kDeviceListError; |
186 SendResponse(false); | 199 SendResponse(false); |
187 } | 200 } |
188 } | 201 } |
189 | 202 |
190 } // namespace extensions | 203 } // namespace extensions |
OLD | NEW |