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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 iter->second)); | 57 iter->second)); |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 void OperationManager::StartWriteFromUrl( | 61 void OperationManager::StartWriteFromUrl( |
62 const ExtensionId& extension_id, | 62 const ExtensionId& extension_id, |
63 GURL url, | 63 GURL url, |
64 const std::string& hash, | 64 const std::string& hash, |
65 const std::string& device_path, | 65 const std::string& device_path, |
66 const Operation::StartWriteCallback& callback) { | 66 const Operation::StartWriteCallback& callback) { |
| 67 #if defined(OS_CHROMEOS) |
| 68 // Chrome OS can only support a single operation at a time. |
| 69 if (operations_.size() > 0) { |
| 70 #else |
67 OperationMap::iterator existing_operation = operations_.find(extension_id); | 71 OperationMap::iterator existing_operation = operations_.find(extension_id); |
68 | 72 |
69 if (existing_operation != operations_.end()) { | 73 if (existing_operation != operations_.end()) { |
| 74 #endif |
70 return callback.Run(false, error::kOperationAlreadyInProgress); | 75 return callback.Run(false, error::kOperationAlreadyInProgress); |
71 } | 76 } |
72 | 77 |
73 scoped_refptr<Operation> operation( | 78 scoped_refptr<Operation> operation( |
74 new WriteFromUrlOperation(weak_factory_.GetWeakPtr(), | 79 new WriteFromUrlOperation(weak_factory_.GetWeakPtr(), |
75 extension_id, | 80 extension_id, |
76 browser_context_->GetRequestContext(), | 81 browser_context_->GetRequestContext(), |
77 url, | 82 url, |
78 hash, | 83 hash, |
79 device_path)); | 84 device_path)); |
80 operations_[extension_id] = operation; | 85 operations_[extension_id] = operation; |
81 BrowserThread::PostTask(BrowserThread::FILE, | 86 BrowserThread::PostTask(BrowserThread::FILE, |
82 FROM_HERE, | 87 FROM_HERE, |
83 base::Bind(&Operation::Start, operation)); | 88 base::Bind(&Operation::Start, operation)); |
84 callback.Run(true, ""); | 89 callback.Run(true, ""); |
85 } | 90 } |
86 | 91 |
87 void OperationManager::StartWriteFromFile( | 92 void OperationManager::StartWriteFromFile( |
88 const ExtensionId& extension_id, | 93 const ExtensionId& extension_id, |
89 const base::FilePath& path, | 94 const base::FilePath& path, |
90 const std::string& device_path, | 95 const std::string& device_path, |
91 const Operation::StartWriteCallback& callback) { | 96 const Operation::StartWriteCallback& callback) { |
| 97 #if defined(OS_CHROMEOS) |
| 98 // Chrome OS can only support a single operation at a time. |
| 99 if (operations_.size() > 0) { |
| 100 #else |
92 OperationMap::iterator existing_operation = operations_.find(extension_id); | 101 OperationMap::iterator existing_operation = operations_.find(extension_id); |
93 | 102 |
94 if (existing_operation != operations_.end()) { | 103 if (existing_operation != operations_.end()) { |
| 104 #endif |
95 return callback.Run(false, error::kOperationAlreadyInProgress); | 105 return callback.Run(false, error::kOperationAlreadyInProgress); |
96 } | 106 } |
97 | 107 |
98 scoped_refptr<Operation> operation(new WriteFromFileOperation( | 108 scoped_refptr<Operation> operation(new WriteFromFileOperation( |
99 weak_factory_.GetWeakPtr(), extension_id, path, device_path)); | 109 weak_factory_.GetWeakPtr(), extension_id, path, device_path)); |
100 operations_[extension_id] = operation; | 110 operations_[extension_id] = operation; |
101 BrowserThread::PostTask(BrowserThread::FILE, | 111 BrowserThread::PostTask(BrowserThread::FILE, |
102 FROM_HERE, | 112 FROM_HERE, |
103 base::Bind(&Operation::Start, operation)); | 113 base::Bind(&Operation::Start, operation)); |
104 callback.Run(true, ""); | 114 callback.Run(true, ""); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 g_factory = LAZY_INSTANCE_INITIALIZER; | 258 g_factory = LAZY_INSTANCE_INITIALIZER; |
249 | 259 |
250 BrowserContextKeyedAPIFactory<OperationManager>* | 260 BrowserContextKeyedAPIFactory<OperationManager>* |
251 OperationManager::GetFactoryInstance() { | 261 OperationManager::GetFactoryInstance() { |
252 return g_factory.Pointer(); | 262 return g_factory.Pointer(); |
253 } | 263 } |
254 | 264 |
255 | 265 |
256 } // namespace image_writer | 266 } // namespace image_writer |
257 } // namespace extensions | 267 } // namespace extensions |
OLD | NEW |