| 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/lazy_instance.h" | 5 #include "base/lazy_instance.h" |
| 6 #include "chrome/browser/browser_process.h" | 6 #include "chrome/browser/browser_process.h" |
| 7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/extensions/api/image_writer_private/destroy_partitions_
operation.h" | 8 #include "chrome/browser/extensions/api/image_writer_private/destroy_partitions_
operation.h" |
| 9 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" | 9 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" |
| 10 #include "chrome/browser/extensions/api/image_writer_private/operation.h" | 10 #include "chrome/browser/extensions/api/image_writer_private/operation.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 BrowserThread::PostTask(BrowserThread::FILE, | 51 BrowserThread::PostTask(BrowserThread::FILE, |
| 52 FROM_HERE, | 52 FROM_HERE, |
| 53 base::Bind(&Operation::Abort, | 53 base::Bind(&Operation::Abort, |
| 54 iter->second)); | 54 iter->second)); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 void OperationManager::StartWriteFromUrl( | 58 void OperationManager::StartWriteFromUrl( |
| 59 const ExtensionId& extension_id, | 59 const ExtensionId& extension_id, |
| 60 GURL url, | 60 GURL url, |
| 61 content::RenderViewHost* rvh, | |
| 62 const std::string& hash, | 61 const std::string& hash, |
| 63 bool saveImageAsDownload, | 62 const std::string& device_path, |
| 64 const std::string& storage_unit_id, | |
| 65 const Operation::StartWriteCallback& callback) { | 63 const Operation::StartWriteCallback& callback) { |
| 66 OperationMap::iterator existing_operation = operations_.find(extension_id); | 64 OperationMap::iterator existing_operation = operations_.find(extension_id); |
| 67 | 65 |
| 68 if (existing_operation != operations_.end()) { | 66 if (existing_operation != operations_.end()) { |
| 69 return callback.Run(false, error::kOperationAlreadyInProgress); | 67 return callback.Run(false, error::kOperationAlreadyInProgress); |
| 70 } | 68 } |
| 71 | 69 |
| 72 scoped_refptr<Operation> operation( | 70 scoped_refptr<Operation> operation( |
| 73 new WriteFromUrlOperation(weak_factory_.GetWeakPtr(), | 71 new WriteFromUrlOperation(weak_factory_.GetWeakPtr(), |
| 74 extension_id, | 72 extension_id, |
| 75 rvh, | 73 profile_->GetRequestContext(), |
| 76 url, | 74 url, |
| 77 hash, | 75 hash, |
| 78 saveImageAsDownload, | 76 device_path)); |
| 79 storage_unit_id)); | |
| 80 operations_[extension_id] = operation; | 77 operations_[extension_id] = operation; |
| 81 BrowserThread::PostTask(BrowserThread::FILE, | 78 BrowserThread::PostTask(BrowserThread::FILE, |
| 82 FROM_HERE, | 79 FROM_HERE, |
| 83 base::Bind(&Operation::Start, operation)); | 80 base::Bind(&Operation::Start, operation)); |
| 84 callback.Run(true, ""); | 81 callback.Run(true, ""); |
| 85 } | 82 } |
| 86 | 83 |
| 87 void OperationManager::StartWriteFromFile( | 84 void OperationManager::StartWriteFromFile( |
| 88 const ExtensionId& extension_id, | 85 const ExtensionId& extension_id, |
| 89 const base::FilePath& path, | 86 const base::FilePath& path, |
| 90 const std::string& storage_unit_id, | 87 const std::string& device_path, |
| 91 const Operation::StartWriteCallback& callback) { | 88 const Operation::StartWriteCallback& callback) { |
| 92 OperationMap::iterator existing_operation = operations_.find(extension_id); | 89 OperationMap::iterator existing_operation = operations_.find(extension_id); |
| 93 | 90 |
| 94 if (existing_operation != operations_.end()) { | 91 if (existing_operation != operations_.end()) { |
| 95 return callback.Run(false, error::kOperationAlreadyInProgress); | 92 return callback.Run(false, error::kOperationAlreadyInProgress); |
| 96 } | 93 } |
| 97 | 94 |
| 98 scoped_refptr<Operation> operation( | 95 scoped_refptr<Operation> operation(new WriteFromFileOperation( |
| 99 new WriteFromFileOperation(weak_factory_.GetWeakPtr(), | 96 weak_factory_.GetWeakPtr(), extension_id, path, device_path)); |
| 100 extension_id, | |
| 101 path, | |
| 102 storage_unit_id)); | |
| 103 operations_[extension_id] = operation; | 97 operations_[extension_id] = operation; |
| 104 BrowserThread::PostTask(BrowserThread::FILE, | 98 BrowserThread::PostTask(BrowserThread::FILE, |
| 105 FROM_HERE, | 99 FROM_HERE, |
| 106 base::Bind(&Operation::Start, operation)); | 100 base::Bind(&Operation::Start, operation)); |
| 107 callback.Run(true, ""); | 101 callback.Run(true, ""); |
| 108 } | 102 } |
| 109 | 103 |
| 110 void OperationManager::CancelWrite( | 104 void OperationManager::CancelWrite( |
| 111 const ExtensionId& extension_id, | 105 const ExtensionId& extension_id, |
| 112 const Operation::CancelWriteCallback& callback) { | 106 const Operation::CancelWriteCallback& callback) { |
| 113 Operation* existing_operation = GetOperation(extension_id); | 107 Operation* existing_operation = GetOperation(extension_id); |
| 114 | 108 |
| 115 if (existing_operation == NULL) { | 109 if (existing_operation == NULL) { |
| 116 callback.Run(false, error::kNoOperationInProgress); | 110 callback.Run(false, error::kNoOperationInProgress); |
| 117 } else { | 111 } else { |
| 118 BrowserThread::PostTask(BrowserThread::FILE, | 112 BrowserThread::PostTask(BrowserThread::FILE, |
| 119 FROM_HERE, | 113 FROM_HERE, |
| 120 base::Bind(&Operation::Cancel, existing_operation)); | 114 base::Bind(&Operation::Cancel, existing_operation)); |
| 121 DeleteOperation(extension_id); | 115 DeleteOperation(extension_id); |
| 122 callback.Run(true, ""); | 116 callback.Run(true, ""); |
| 123 } | 117 } |
| 124 } | 118 } |
| 125 | 119 |
| 126 void OperationManager::DestroyPartitions( | 120 void OperationManager::DestroyPartitions( |
| 127 const ExtensionId& extension_id, | 121 const ExtensionId& extension_id, |
| 128 const std::string& storage_unit_id, | 122 const std::string& device_path, |
| 129 const Operation::StartWriteCallback& callback) { | 123 const Operation::StartWriteCallback& callback) { |
| 130 OperationMap::iterator existing_operation = operations_.find(extension_id); | 124 OperationMap::iterator existing_operation = operations_.find(extension_id); |
| 131 | 125 |
| 132 if (existing_operation != operations_.end()) { | 126 if (existing_operation != operations_.end()) { |
| 133 return callback.Run(false, error::kOperationAlreadyInProgress); | 127 return callback.Run(false, error::kOperationAlreadyInProgress); |
| 134 } | 128 } |
| 135 | 129 |
| 136 scoped_refptr<Operation> operation( | 130 scoped_refptr<Operation> operation(new DestroyPartitionsOperation( |
| 137 new DestroyPartitionsOperation(weak_factory_.GetWeakPtr(), | 131 weak_factory_.GetWeakPtr(), extension_id, device_path)); |
| 138 extension_id, | |
| 139 storage_unit_id)); | |
| 140 operations_[extension_id] = operation; | 132 operations_[extension_id] = operation; |
| 141 BrowserThread::PostTask(BrowserThread::FILE, | 133 BrowserThread::PostTask(BrowserThread::FILE, |
| 142 FROM_HERE, | 134 FROM_HERE, |
| 143 base::Bind(&Operation::Start, operation)); | 135 base::Bind(&Operation::Start, operation)); |
| 144 callback.Run(true, ""); | 136 callback.Run(true, ""); |
| 145 } | 137 } |
| 146 | 138 |
| 147 void OperationManager::OnProgress(const ExtensionId& extension_id, | 139 void OperationManager::OnProgress(const ExtensionId& extension_id, |
| 148 image_writer_api::Stage stage, | 140 image_writer_api::Stage stage, |
| 149 int progress) { | 141 int progress) { |
| 150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 151 DVLOG(2) << "progress - " << stage << " at " << progress << "%"; | |
| 152 | 143 |
| 153 image_writer_api::ProgressInfo info; | 144 image_writer_api::ProgressInfo info; |
| 154 info.stage = stage; | 145 info.stage = stage; |
| 155 info.percent_complete = progress; | 146 info.percent_complete = progress; |
| 156 | 147 |
| 157 scoped_ptr<base::ListValue> args( | 148 scoped_ptr<base::ListValue> args( |
| 158 image_writer_api::OnWriteProgress::Create(info)); | 149 image_writer_api::OnWriteProgress::Create(info)); |
| 159 scoped_ptr<Event> event(new Event( | 150 scoped_ptr<Event> event(new Event( |
| 160 image_writer_api::OnWriteProgress::kEventName, args.Pass())); | 151 image_writer_api::OnWriteProgress::kEventName, args.Pass())); |
| 161 | 152 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 g_factory = LAZY_INSTANCE_INITIALIZER; | 247 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 257 | 248 |
| 258 ProfileKeyedAPIFactory<OperationManager>* | 249 ProfileKeyedAPIFactory<OperationManager>* |
| 259 OperationManager::GetFactoryInstance() { | 250 OperationManager::GetFactoryInstance() { |
| 260 return g_factory.Pointer(); | 251 return g_factory.Pointer(); |
| 261 } | 252 } |
| 262 | 253 |
| 263 | 254 |
| 264 } // namespace image_writer | 255 } // namespace image_writer |
| 265 } // namespace extensions | 256 } // namespace extensions |
| OLD | NEW |