| 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" |
| 11 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.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" | 12 #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" | 13 #include "chrome/browser/extensions/api/image_writer_private/write_from_url_oper
ation.h" |
| 14 #include "chrome/browser/extensions/event_router_forwarder.h" | 14 #include "chrome/browser/extensions/event_router_forwarder.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 19 #include "extensions/browser/event_router.h" | 19 #include "extensions/browser/event_router.h" |
| 20 #include "extensions/browser/extension_host.h" | 20 #include "extensions/browser/extension_host.h" |
| 21 #include "extensions/browser/extension_system.h" | |
| 22 | 21 |
| 23 namespace image_writer_api = extensions::api::image_writer_private; | 22 namespace image_writer_api = extensions::api::image_writer_private; |
| 24 | 23 |
| 25 namespace extensions { | 24 namespace extensions { |
| 26 namespace image_writer { | 25 namespace image_writer { |
| 27 | 26 |
| 28 using content::BrowserThread; | 27 using content::BrowserThread; |
| 29 | 28 |
| 30 OperationManager::OperationManager(content::BrowserContext* context) | 29 OperationManager::OperationManager(content::BrowserContext* context) |
| 31 : profile_(Profile::FromBrowserContext(context)), weak_factory_(this) { | 30 : profile_(Profile::FromBrowserContext(context)), weak_factory_(this) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 142 |
| 144 image_writer_api::ProgressInfo info; | 143 image_writer_api::ProgressInfo info; |
| 145 info.stage = stage; | 144 info.stage = stage; |
| 146 info.percent_complete = progress; | 145 info.percent_complete = progress; |
| 147 | 146 |
| 148 scoped_ptr<base::ListValue> args( | 147 scoped_ptr<base::ListValue> args( |
| 149 image_writer_api::OnWriteProgress::Create(info)); | 148 image_writer_api::OnWriteProgress::Create(info)); |
| 150 scoped_ptr<Event> event(new Event( | 149 scoped_ptr<Event> event(new Event( |
| 151 image_writer_api::OnWriteProgress::kEventName, args.Pass())); | 150 image_writer_api::OnWriteProgress::kEventName, args.Pass())); |
| 152 | 151 |
| 153 ExtensionSystem::Get(profile_)->event_router()-> | 152 EventRouter::Get(profile_) |
| 154 DispatchEventToExtension(extension_id, event.Pass()); | 153 ->DispatchEventToExtension(extension_id, event.Pass()); |
| 155 } | 154 } |
| 156 | 155 |
| 157 void OperationManager::OnComplete(const ExtensionId& extension_id) { | 156 void OperationManager::OnComplete(const ExtensionId& extension_id) { |
| 158 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 157 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 159 | 158 |
| 160 scoped_ptr<base::ListValue> args(image_writer_api::OnWriteComplete::Create()); | 159 scoped_ptr<base::ListValue> args(image_writer_api::OnWriteComplete::Create()); |
| 161 scoped_ptr<Event> event(new Event( | 160 scoped_ptr<Event> event(new Event( |
| 162 image_writer_api::OnWriteComplete::kEventName, args.Pass())); | 161 image_writer_api::OnWriteComplete::kEventName, args.Pass())); |
| 163 | 162 |
| 164 ExtensionSystem::Get(profile_)->event_router()-> | 163 EventRouter::Get(profile_) |
| 165 DispatchEventToExtension(extension_id, event.Pass()); | 164 ->DispatchEventToExtension(extension_id, event.Pass()); |
| 166 | 165 |
| 167 DeleteOperation(extension_id); | 166 DeleteOperation(extension_id); |
| 168 } | 167 } |
| 169 | 168 |
| 170 void OperationManager::OnError(const ExtensionId& extension_id, | 169 void OperationManager::OnError(const ExtensionId& extension_id, |
| 171 image_writer_api::Stage stage, | 170 image_writer_api::Stage stage, |
| 172 int progress, | 171 int progress, |
| 173 const std::string& error_message) { | 172 const std::string& error_message) { |
| 174 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 173 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 175 image_writer_api::ProgressInfo info; | 174 image_writer_api::ProgressInfo info; |
| 176 | 175 |
| 177 DLOG(ERROR) << "ImageWriter error: " << error_message; | 176 DLOG(ERROR) << "ImageWriter error: " << error_message; |
| 178 | 177 |
| 179 info.stage = stage; | 178 info.stage = stage; |
| 180 info.percent_complete = progress; | 179 info.percent_complete = progress; |
| 181 | 180 |
| 182 scoped_ptr<base::ListValue> args( | 181 scoped_ptr<base::ListValue> args( |
| 183 image_writer_api::OnWriteError::Create(info, error_message)); | 182 image_writer_api::OnWriteError::Create(info, error_message)); |
| 184 scoped_ptr<Event> event(new Event( | 183 scoped_ptr<Event> event(new Event( |
| 185 image_writer_api::OnWriteError::kEventName, args.Pass())); | 184 image_writer_api::OnWriteError::kEventName, args.Pass())); |
| 186 | 185 |
| 187 ExtensionSystem::Get(profile_)->event_router()-> | 186 EventRouter::Get(profile_) |
| 188 DispatchEventToExtension(extension_id, event.Pass()); | 187 ->DispatchEventToExtension(extension_id, event.Pass()); |
| 189 | 188 |
| 190 DeleteOperation(extension_id); | 189 DeleteOperation(extension_id); |
| 191 } | 190 } |
| 192 | 191 |
| 193 Operation* OperationManager::GetOperation(const ExtensionId& extension_id) { | 192 Operation* OperationManager::GetOperation(const ExtensionId& extension_id) { |
| 194 OperationMap::iterator existing_operation = operations_.find(extension_id); | 193 OperationMap::iterator existing_operation = operations_.find(extension_id); |
| 195 | 194 |
| 196 if (existing_operation == operations_.end()) | 195 if (existing_operation == operations_.end()) |
| 197 return NULL; | 196 return NULL; |
| 198 return existing_operation->second.get(); | 197 return existing_operation->second.get(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 g_factory = LAZY_INSTANCE_INITIALIZER; | 245 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 247 | 246 |
| 248 BrowserContextKeyedAPIFactory<OperationManager>* | 247 BrowserContextKeyedAPIFactory<OperationManager>* |
| 249 OperationManager::GetFactoryInstance() { | 248 OperationManager::GetFactoryInstance() { |
| 250 return g_factory.Pointer(); | 249 return g_factory.Pointer(); |
| 251 } | 250 } |
| 252 | 251 |
| 253 | 252 |
| 254 } // namespace image_writer | 253 } // namespace image_writer |
| 255 } // namespace extensions | 254 } // namespace extensions |
| OLD | NEW |