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

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

Issue 149313003: Significantly cleans up the ImageWriter Operation class and subclasses. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes compilation errors. Created 6 years, 10 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 "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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 BrowserThread::PostTask(BrowserThread::FILE, 52 BrowserThread::PostTask(BrowserThread::FILE,
53 FROM_HERE, 53 FROM_HERE,
54 base::Bind(&Operation::Abort, 54 base::Bind(&Operation::Abort,
55 iter->second)); 55 iter->second));
56 } 56 }
57 } 57 }
58 58
59 void OperationManager::StartWriteFromUrl( 59 void OperationManager::StartWriteFromUrl(
60 const ExtensionId& extension_id, 60 const ExtensionId& extension_id,
61 GURL url, 61 GURL url,
62 content::RenderViewHost* rvh,
63 const std::string& hash, 62 const std::string& hash,
64 bool saveImageAsDownload, 63 bool saveImageAsDownload,
65 const std::string& storage_unit_id, 64 const std::string& device_path,
66 const Operation::StartWriteCallback& callback) { 65 const Operation::StartWriteCallback& callback) {
67 OperationMap::iterator existing_operation = operations_.find(extension_id); 66 OperationMap::iterator existing_operation = operations_.find(extension_id);
68 67
69 if (existing_operation != operations_.end()) { 68 if (existing_operation != operations_.end()) {
70 return callback.Run(false, error::kOperationAlreadyInProgress); 69 return callback.Run(false, error::kOperationAlreadyInProgress);
71 } 70 }
72 71
73 scoped_refptr<Operation> operation( 72 scoped_refptr<Operation> operation(
74 new WriteFromUrlOperation(weak_factory_.GetWeakPtr(), 73 new WriteFromUrlOperation(weak_factory_.GetWeakPtr(),
75 extension_id, 74 extension_id,
76 rvh, 75 profile_->GetRequestContext(),
77 url, 76 url,
78 hash, 77 hash,
79 saveImageAsDownload, 78 saveImageAsDownload,
80 storage_unit_id)); 79 device_path));
81 operations_[extension_id] = operation; 80 operations_[extension_id] = operation;
82 BrowserThread::PostTask(BrowserThread::FILE, 81 BrowserThread::PostTask(BrowserThread::FILE,
83 FROM_HERE, 82 FROM_HERE,
84 base::Bind(&Operation::Start, operation)); 83 base::Bind(&Operation::Start, operation));
85 callback.Run(true, ""); 84 callback.Run(true, "");
86 } 85 }
87 86
88 void OperationManager::StartWriteFromFile( 87 void OperationManager::StartWriteFromFile(
89 const ExtensionId& extension_id, 88 const ExtensionId& extension_id,
90 const base::FilePath& path, 89 const base::FilePath& path,
91 const std::string& storage_unit_id, 90 const std::string& device_path,
92 const Operation::StartWriteCallback& callback) { 91 const Operation::StartWriteCallback& callback) {
93 OperationMap::iterator existing_operation = operations_.find(extension_id); 92 OperationMap::iterator existing_operation = operations_.find(extension_id);
94 93
95 if (existing_operation != operations_.end()) { 94 if (existing_operation != operations_.end()) {
96 return callback.Run(false, error::kOperationAlreadyInProgress); 95 return callback.Run(false, error::kOperationAlreadyInProgress);
97 } 96 }
98 97
99 scoped_refptr<Operation> operation( 98 scoped_refptr<Operation> operation(
100 new WriteFromFileOperation(weak_factory_.GetWeakPtr(), 99 new WriteFromFileOperation(weak_factory_.GetWeakPtr(),
101 extension_id, 100 extension_id,
102 path, 101 path,
103 storage_unit_id)); 102 device_path));
104 operations_[extension_id] = operation; 103 operations_[extension_id] = operation;
105 BrowserThread::PostTask(BrowserThread::FILE, 104 BrowserThread::PostTask(BrowserThread::FILE,
106 FROM_HERE, 105 FROM_HERE,
107 base::Bind(&Operation::Start, operation)); 106 base::Bind(&Operation::Start, operation));
108 callback.Run(true, ""); 107 callback.Run(true, "");
109 } 108 }
110 109
111 void OperationManager::CancelWrite( 110 void OperationManager::CancelWrite(
112 const ExtensionId& extension_id, 111 const ExtensionId& extension_id,
113 const Operation::CancelWriteCallback& callback) { 112 const Operation::CancelWriteCallback& callback) {
114 Operation* existing_operation = GetOperation(extension_id); 113 Operation* existing_operation = GetOperation(extension_id);
115 114
116 if (existing_operation == NULL) { 115 if (existing_operation == NULL) {
117 callback.Run(false, error::kNoOperationInProgress); 116 callback.Run(false, error::kNoOperationInProgress);
118 } else { 117 } else {
119 BrowserThread::PostTask(BrowserThread::FILE, 118 BrowserThread::PostTask(BrowserThread::FILE,
120 FROM_HERE, 119 FROM_HERE,
121 base::Bind(&Operation::Cancel, existing_operation)); 120 base::Bind(&Operation::Cancel, existing_operation));
122 DeleteOperation(extension_id); 121 DeleteOperation(extension_id);
123 callback.Run(true, ""); 122 callback.Run(true, "");
124 } 123 }
125 } 124 }
126 125
127 void OperationManager::DestroyPartitions( 126 void OperationManager::DestroyPartitions(
128 const ExtensionId& extension_id, 127 const ExtensionId& extension_id,
129 const std::string& storage_unit_id, 128 const std::string& device_path,
130 const Operation::StartWriteCallback& callback) { 129 const Operation::StartWriteCallback& callback) {
131 OperationMap::iterator existing_operation = operations_.find(extension_id); 130 OperationMap::iterator existing_operation = operations_.find(extension_id);
132 131
133 if (existing_operation != operations_.end()) { 132 if (existing_operation != operations_.end()) {
134 return callback.Run(false, error::kOperationAlreadyInProgress); 133 return callback.Run(false, error::kOperationAlreadyInProgress);
135 } 134 }
136 135
137 scoped_refptr<Operation> operation( 136 scoped_refptr<Operation> operation(
138 new DestroyPartitionsOperation(weak_factory_.GetWeakPtr(), 137 new DestroyPartitionsOperation(weak_factory_.GetWeakPtr(),
139 extension_id, 138 extension_id,
140 storage_unit_id)); 139 device_path));
141 operations_[extension_id] = operation; 140 operations_[extension_id] = operation;
142 BrowserThread::PostTask(BrowserThread::FILE, 141 BrowserThread::PostTask(BrowserThread::FILE,
143 FROM_HERE, 142 FROM_HERE,
144 base::Bind(&Operation::Start, operation)); 143 base::Bind(&Operation::Start, operation));
145 callback.Run(true, ""); 144 callback.Run(true, "");
146 } 145 }
147 146
148 void OperationManager::OnProgress(const ExtensionId& extension_id, 147 void OperationManager::OnProgress(const ExtensionId& extension_id,
149 image_writer_api::Stage stage, 148 image_writer_api::Stage stage,
150 int progress) { 149 int progress) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 g_factory = LAZY_INSTANCE_INITIALIZER; 256 g_factory = LAZY_INSTANCE_INITIALIZER;
258 257
259 ProfileKeyedAPIFactory<OperationManager>* 258 ProfileKeyedAPIFactory<OperationManager>*
260 OperationManager::GetFactoryInstance() { 259 OperationManager::GetFactoryInstance() {
261 return g_factory.Pointer(); 260 return g_factory.Pointer();
262 } 261 }
263 262
264 263
265 } // namespace image_writer 264 } // namespace image_writer
266 } // namespace extensions 265 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698