Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: chrome/browser/extensions/api/image_writer_private/operation_manager.cc

Issue 2825963003: Rewrite base::Bind to base::BindOnce with base_bind_rewriters in //chrome/browser/extensions (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 " 5 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h "
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 content::Source<Profile>(profile)); 53 content::Source<Profile>(profile));
54 } 54 }
55 55
56 OperationManager::~OperationManager() { 56 OperationManager::~OperationManager() {
57 } 57 }
58 58
59 void OperationManager::Shutdown() { 59 void OperationManager::Shutdown() {
60 for (OperationMap::iterator iter = operations_.begin(); 60 for (OperationMap::iterator iter = operations_.begin();
61 iter != operations_.end(); 61 iter != operations_.end();
62 iter++) { 62 iter++) {
63 BrowserThread::PostTask(BrowserThread::FILE, 63 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
64 FROM_HERE, 64 base::BindOnce(&Operation::Abort, iter->second));
65 base::Bind(&Operation::Abort,
66 iter->second));
67 } 65 }
68 } 66 }
69 67
70 void OperationManager::StartWriteFromUrl( 68 void OperationManager::StartWriteFromUrl(
71 const ExtensionId& extension_id, 69 const ExtensionId& extension_id,
72 GURL url, 70 GURL url,
73 const std::string& hash, 71 const std::string& hash,
74 const std::string& device_path, 72 const std::string& device_path,
75 const Operation::StartWriteCallback& callback) { 73 const Operation::StartWriteCallback& callback) {
76 #if defined(OS_CHROMEOS) 74 #if defined(OS_CHROMEOS)
(...skipping 10 matching lines...) Expand all
87 scoped_refptr<Operation> operation(new WriteFromUrlOperation( 85 scoped_refptr<Operation> operation(new WriteFromUrlOperation(
88 weak_factory_.GetWeakPtr(), 86 weak_factory_.GetWeakPtr(),
89 extension_id, 87 extension_id,
90 content::BrowserContext::GetDefaultStoragePartition(browser_context_)-> 88 content::BrowserContext::GetDefaultStoragePartition(browser_context_)->
91 GetURLRequestContext(), 89 GetURLRequestContext(),
92 url, 90 url,
93 hash, 91 hash,
94 device_path, 92 device_path,
95 GetAssociatedDownloadFolder())); 93 GetAssociatedDownloadFolder()));
96 operations_[extension_id] = operation; 94 operations_[extension_id] = operation;
97 BrowserThread::PostTask(BrowserThread::FILE, 95 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
98 FROM_HERE, 96 base::BindOnce(&Operation::Start, operation));
99 base::Bind(&Operation::Start, operation));
100 callback.Run(true, ""); 97 callback.Run(true, "");
101 } 98 }
102 99
103 void OperationManager::StartWriteFromFile( 100 void OperationManager::StartWriteFromFile(
104 const ExtensionId& extension_id, 101 const ExtensionId& extension_id,
105 const base::FilePath& path, 102 const base::FilePath& path,
106 const std::string& device_path, 103 const std::string& device_path,
107 const Operation::StartWriteCallback& callback) { 104 const Operation::StartWriteCallback& callback) {
108 #if defined(OS_CHROMEOS) 105 #if defined(OS_CHROMEOS)
109 // Chrome OS can only support a single operation at a time. 106 // Chrome OS can only support a single operation at a time.
110 if (operations_.size() > 0) { 107 if (operations_.size() > 0) {
111 #else 108 #else
112 OperationMap::iterator existing_operation = operations_.find(extension_id); 109 OperationMap::iterator existing_operation = operations_.find(extension_id);
113 110
114 if (existing_operation != operations_.end()) { 111 if (existing_operation != operations_.end()) {
115 #endif 112 #endif
116 return callback.Run(false, error::kOperationAlreadyInProgress); 113 return callback.Run(false, error::kOperationAlreadyInProgress);
117 } 114 }
118 115
119 scoped_refptr<Operation> operation(new WriteFromFileOperation( 116 scoped_refptr<Operation> operation(new WriteFromFileOperation(
120 weak_factory_.GetWeakPtr(), extension_id, path, device_path, 117 weak_factory_.GetWeakPtr(), extension_id, path, device_path,
121 GetAssociatedDownloadFolder())); 118 GetAssociatedDownloadFolder()));
122 operations_[extension_id] = operation; 119 operations_[extension_id] = operation;
123 BrowserThread::PostTask(BrowserThread::FILE, 120 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
124 FROM_HERE, 121 base::BindOnce(&Operation::Start, operation));
125 base::Bind(&Operation::Start, operation));
126 callback.Run(true, ""); 122 callback.Run(true, "");
127 } 123 }
128 124
129 void OperationManager::CancelWrite( 125 void OperationManager::CancelWrite(
130 const ExtensionId& extension_id, 126 const ExtensionId& extension_id,
131 const Operation::CancelWriteCallback& callback) { 127 const Operation::CancelWriteCallback& callback) {
132 Operation* existing_operation = GetOperation(extension_id); 128 Operation* existing_operation = GetOperation(extension_id);
133 129
134 if (existing_operation == NULL) { 130 if (existing_operation == NULL) {
135 callback.Run(false, error::kNoOperationInProgress); 131 callback.Run(false, error::kNoOperationInProgress);
136 } else { 132 } else {
137 BrowserThread::PostTask(BrowserThread::FILE, 133 BrowserThread::PostTask(
138 FROM_HERE, 134 BrowserThread::FILE, FROM_HERE,
139 base::Bind(&Operation::Cancel, existing_operation)); 135 base::BindOnce(&Operation::Cancel, existing_operation));
140 DeleteOperation(extension_id); 136 DeleteOperation(extension_id);
141 callback.Run(true, ""); 137 callback.Run(true, "");
142 } 138 }
143 } 139 }
144 140
145 void OperationManager::DestroyPartitions( 141 void OperationManager::DestroyPartitions(
146 const ExtensionId& extension_id, 142 const ExtensionId& extension_id,
147 const std::string& device_path, 143 const std::string& device_path,
148 const Operation::StartWriteCallback& callback) { 144 const Operation::StartWriteCallback& callback) {
149 OperationMap::iterator existing_operation = operations_.find(extension_id); 145 OperationMap::iterator existing_operation = operations_.find(extension_id);
150 146
151 if (existing_operation != operations_.end()) { 147 if (existing_operation != operations_.end()) {
152 return callback.Run(false, error::kOperationAlreadyInProgress); 148 return callback.Run(false, error::kOperationAlreadyInProgress);
153 } 149 }
154 150
155 scoped_refptr<Operation> operation(new DestroyPartitionsOperation( 151 scoped_refptr<Operation> operation(new DestroyPartitionsOperation(
156 weak_factory_.GetWeakPtr(), extension_id, device_path, 152 weak_factory_.GetWeakPtr(), extension_id, device_path,
157 GetAssociatedDownloadFolder())); 153 GetAssociatedDownloadFolder()));
158 operations_[extension_id] = operation; 154 operations_[extension_id] = operation;
159 BrowserThread::PostTask(BrowserThread::FILE, 155 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
160 FROM_HERE, 156 base::BindOnce(&Operation::Start, operation));
161 base::Bind(&Operation::Start, operation));
162 callback.Run(true, ""); 157 callback.Run(true, "");
163 } 158 }
164 159
165 void OperationManager::OnProgress(const ExtensionId& extension_id, 160 void OperationManager::OnProgress(const ExtensionId& extension_id,
166 image_writer_api::Stage stage, 161 image_writer_api::Stage stage,
167 int progress) { 162 int progress) {
168 DCHECK_CURRENTLY_ON(BrowserThread::UI); 163 DCHECK_CURRENTLY_ON(BrowserThread::UI);
169 164
170 image_writer_api::ProgressInfo info; 165 image_writer_api::ProgressInfo info;
171 info.stage = stage; 166 info.stage = stage;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 DestructorAtExit g_factory = LAZY_INSTANCE_INITIALIZER; 276 DestructorAtExit g_factory = LAZY_INSTANCE_INITIALIZER;
282 277
283 BrowserContextKeyedAPIFactory<OperationManager>* 278 BrowserContextKeyedAPIFactory<OperationManager>*
284 OperationManager::GetFactoryInstance() { 279 OperationManager::GetFactoryInstance() {
285 return g_factory.Pointer(); 280 return g_factory.Pointer();
286 } 281 }
287 282
288 283
289 } // namespace image_writer 284 } // namespace image_writer
290 } // namespace extensions 285 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698