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 | |
45 std::string hash; | 34 std::string hash; |
46 if (params->options.get() && params->options->image_hash.get()) { | 35 if (params->options.get() && params->options->image_hash.get()) { |
47 hash = *params->options->image_hash; | 36 hash = *params->options->image_hash; |
48 } | 37 } |
49 | 38 |
50 image_writer::OperationManager::Get(GetProfile())->StartWriteFromUrl( | 39 image_writer::OperationManager::Get(GetProfile())->StartWriteFromUrl( |
51 extension_id(), | 40 extension_id(), |
52 url, | 41 url, |
53 render_view_host(), | |
54 hash, | 42 hash, |
55 save_image_as_download, | |
56 params->storage_unit_id, | 43 params->storage_unit_id, |
57 base::Bind(&ImageWriterPrivateWriteFromUrlFunction::OnWriteStarted, | 44 base::Bind(&ImageWriterPrivateWriteFromUrlFunction::OnWriteStarted, |
58 this)); | 45 this)); |
59 return true; | 46 return true; |
60 } | 47 } |
61 | 48 |
62 void ImageWriterPrivateWriteFromUrlFunction::OnWriteStarted( | 49 void ImageWriterPrivateWriteFromUrlFunction::OnWriteStarted( |
63 bool success, | 50 bool success, |
64 const std::string& error) { | 51 const std::string& error) { |
65 if (!success) { | 52 if (!success) { |
(...skipping 16 matching lines...) Expand all Loading... |
82 std::string filesystem_path; | 69 std::string filesystem_path; |
83 std::string storage_unit_id; | 70 std::string storage_unit_id; |
84 | 71 |
85 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &storage_unit_id)); | 72 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &storage_unit_id)); |
86 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_name)); | 73 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_name)); |
87 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &filesystem_path)); | 74 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &filesystem_path)); |
88 | 75 |
89 base::FilePath path; | 76 base::FilePath path; |
90 | 77 |
91 if (!extensions::app_file_handler_util::ValidateFileEntryAndGetPath( | 78 if (!extensions::app_file_handler_util::ValidateFileEntryAndGetPath( |
92 filesystem_name, | 79 filesystem_name, |
93 filesystem_path, | 80 filesystem_path, |
94 render_view_host_, | 81 render_view_host(), |
95 &path, | 82 &path, |
96 &error_)) | 83 &error_)) |
97 return false; | 84 return false; |
98 | 85 |
99 image_writer::OperationManager::Get(GetProfile())->StartWriteFromFile( | 86 image_writer::OperationManager::Get(GetProfile())->StartWriteFromFile( |
100 extension_id(), | 87 extension_id(), |
101 path, | 88 path, |
102 storage_unit_id, | 89 storage_unit_id, |
103 base::Bind(&ImageWriterPrivateWriteFromFileFunction::OnWriteStarted, | 90 base::Bind(&ImageWriterPrivateWriteFromFileFunction::OnWriteStarted, |
104 this)); | 91 this)); |
105 return true; | 92 return true; |
106 } | 93 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 image_writer_api::ListRemovableStorageDevices::Results::Create( | 181 image_writer_api::ListRemovableStorageDevices::Results::Create( |
195 device_list.get()->data); | 182 device_list.get()->data); |
196 SendResponse(true); | 183 SendResponse(true); |
197 } else { | 184 } else { |
198 error_ = image_writer::error::kDeviceListError; | 185 error_ = image_writer::error::kDeviceListError; |
199 SendResponse(false); | 186 SendResponse(false); |
200 } | 187 } |
201 } | 188 } |
202 | 189 |
203 } // namespace extensions | 190 } // namespace extensions |
OLD | NEW |