| 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 "chrome/browser/extensions/api/image_writer_private/operation_manager.h
" |
| 6 |
| 7 #include <utility> |
| 8 |
| 5 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 6 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 7 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/extensions/api/image_writer_private/destroy_partitions_
operation.h" | 12 #include "chrome/browser/extensions/api/image_writer_private/destroy_partitions_
operation.h" |
| 9 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" | 13 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" |
| 10 #include "chrome/browser/extensions/api/image_writer_private/operation.h" | 14 #include "chrome/browser/extensions/api/image_writer_private/operation.h" |
| 11 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h
" | |
| 12 #include "chrome/browser/extensions/api/image_writer_private/write_from_file_ope
ration.h" | 15 #include "chrome/browser/extensions/api/image_writer_private/write_from_file_ope
ration.h" |
| 13 #include "chrome/browser/extensions/api/image_writer_private/write_from_url_oper
ation.h" | 16 #include "chrome/browser/extensions/api/image_writer_private/write_from_url_oper
ation.h" |
| 14 #include "chrome/browser/extensions/event_router_forwarder.h" | 17 #include "chrome/browser/extensions/event_router_forwarder.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 17 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
| 19 #include "extensions/browser/event_router.h" | 22 #include "extensions/browser/event_router.h" |
| 20 #include "extensions/browser/extension_host.h" | 23 #include "extensions/browser/extension_host.h" |
| 21 #include "extensions/browser/extension_registry.h" | 24 #include "extensions/browser/extension_registry.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 image_writer_api::Stage stage, | 157 image_writer_api::Stage stage, |
| 155 int progress) { | 158 int progress) { |
| 156 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 159 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 157 | 160 |
| 158 image_writer_api::ProgressInfo info; | 161 image_writer_api::ProgressInfo info; |
| 159 info.stage = stage; | 162 info.stage = stage; |
| 160 info.percent_complete = progress; | 163 info.percent_complete = progress; |
| 161 | 164 |
| 162 scoped_ptr<base::ListValue> args( | 165 scoped_ptr<base::ListValue> args( |
| 163 image_writer_api::OnWriteProgress::Create(info)); | 166 image_writer_api::OnWriteProgress::Create(info)); |
| 164 scoped_ptr<Event> event( | 167 scoped_ptr<Event> event(new Event( |
| 165 new Event(events::IMAGE_WRITER_PRIVATE_ON_WRITE_PROGRESS, | 168 events::IMAGE_WRITER_PRIVATE_ON_WRITE_PROGRESS, |
| 166 image_writer_api::OnWriteProgress::kEventName, args.Pass())); | 169 image_writer_api::OnWriteProgress::kEventName, std::move(args))); |
| 167 | 170 |
| 168 EventRouter::Get(browser_context_) | 171 EventRouter::Get(browser_context_) |
| 169 ->DispatchEventToExtension(extension_id, event.Pass()); | 172 ->DispatchEventToExtension(extension_id, std::move(event)); |
| 170 } | 173 } |
| 171 | 174 |
| 172 void OperationManager::OnComplete(const ExtensionId& extension_id) { | 175 void OperationManager::OnComplete(const ExtensionId& extension_id) { |
| 173 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 176 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 174 | 177 |
| 175 scoped_ptr<base::ListValue> args(image_writer_api::OnWriteComplete::Create()); | 178 scoped_ptr<base::ListValue> args(image_writer_api::OnWriteComplete::Create()); |
| 176 scoped_ptr<Event> event( | 179 scoped_ptr<Event> event(new Event( |
| 177 new Event(events::IMAGE_WRITER_PRIVATE_ON_WRITE_COMPLETE, | 180 events::IMAGE_WRITER_PRIVATE_ON_WRITE_COMPLETE, |
| 178 image_writer_api::OnWriteComplete::kEventName, args.Pass())); | 181 image_writer_api::OnWriteComplete::kEventName, std::move(args))); |
| 179 | 182 |
| 180 EventRouter::Get(browser_context_) | 183 EventRouter::Get(browser_context_) |
| 181 ->DispatchEventToExtension(extension_id, event.Pass()); | 184 ->DispatchEventToExtension(extension_id, std::move(event)); |
| 182 | 185 |
| 183 DeleteOperation(extension_id); | 186 DeleteOperation(extension_id); |
| 184 } | 187 } |
| 185 | 188 |
| 186 void OperationManager::OnError(const ExtensionId& extension_id, | 189 void OperationManager::OnError(const ExtensionId& extension_id, |
| 187 image_writer_api::Stage stage, | 190 image_writer_api::Stage stage, |
| 188 int progress, | 191 int progress, |
| 189 const std::string& error_message) { | 192 const std::string& error_message) { |
| 190 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 193 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 191 image_writer_api::ProgressInfo info; | 194 image_writer_api::ProgressInfo info; |
| 192 | 195 |
| 193 DLOG(ERROR) << "ImageWriter error: " << error_message; | 196 DLOG(ERROR) << "ImageWriter error: " << error_message; |
| 194 | 197 |
| 195 info.stage = stage; | 198 info.stage = stage; |
| 196 info.percent_complete = progress; | 199 info.percent_complete = progress; |
| 197 | 200 |
| 198 scoped_ptr<base::ListValue> args( | 201 scoped_ptr<base::ListValue> args( |
| 199 image_writer_api::OnWriteError::Create(info, error_message)); | 202 image_writer_api::OnWriteError::Create(info, error_message)); |
| 200 scoped_ptr<Event> event(new Event(events::IMAGE_WRITER_PRIVATE_ON_WRITE_ERROR, | 203 scoped_ptr<Event> event(new Event(events::IMAGE_WRITER_PRIVATE_ON_WRITE_ERROR, |
| 201 image_writer_api::OnWriteError::kEventName, | 204 image_writer_api::OnWriteError::kEventName, |
| 202 args.Pass())); | 205 std::move(args))); |
| 203 | 206 |
| 204 EventRouter::Get(browser_context_) | 207 EventRouter::Get(browser_context_) |
| 205 ->DispatchEventToExtension(extension_id, event.Pass()); | 208 ->DispatchEventToExtension(extension_id, std::move(event)); |
| 206 | 209 |
| 207 DeleteOperation(extension_id); | 210 DeleteOperation(extension_id); |
| 208 } | 211 } |
| 209 | 212 |
| 210 Operation* OperationManager::GetOperation(const ExtensionId& extension_id) { | 213 Operation* OperationManager::GetOperation(const ExtensionId& extension_id) { |
| 211 OperationMap::iterator existing_operation = operations_.find(extension_id); | 214 OperationMap::iterator existing_operation = operations_.find(extension_id); |
| 212 | 215 |
| 213 if (existing_operation == operations_.end()) | 216 if (existing_operation == operations_.end()) |
| 214 return NULL; | 217 return NULL; |
| 215 return existing_operation->second.get(); | 218 return existing_operation->second.get(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 g_factory = LAZY_INSTANCE_INITIALIZER; | 265 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 263 | 266 |
| 264 BrowserContextKeyedAPIFactory<OperationManager>* | 267 BrowserContextKeyedAPIFactory<OperationManager>* |
| 265 OperationManager::GetFactoryInstance() { | 268 OperationManager::GetFactoryInstance() { |
| 266 return g_factory.Pointer(); | 269 return g_factory.Pointer(); |
| 267 } | 270 } |
| 268 | 271 |
| 269 | 272 |
| 270 } // namespace image_writer | 273 } // namespace image_writer |
| 271 } // namespace extensions | 274 } // namespace extensions |
| OLD | NEW |