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

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

Issue 125273006: Revert of Resubmit of imageWriterPrivate.destroyPartitions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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"
9 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" 8 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h"
10 #include "chrome/browser/extensions/api/image_writer_private/operation.h" 9 #include "chrome/browser/extensions/api/image_writer_private/operation.h"
11 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h " 10 #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" 11 #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" 12 #include "chrome/browser/extensions/api/image_writer_private/write_from_url_oper ation.h"
14 #include "chrome/browser/extensions/event_router_forwarder.h" 13 #include "chrome/browser/extensions/event_router_forwarder.h"
15 #include "chrome/browser/extensions/extension_host.h" 14 #include "chrome/browser/extensions/extension_host.h"
16 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/extension_system.h" 16 #include "chrome/browser/extensions/extension_system.h"
18 #include "chrome/browser/extensions/extension_system_factory.h" 17 #include "chrome/browser/extensions/extension_system_factory.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } 56 }
58 57
59 void OperationManager::StartWriteFromUrl( 58 void OperationManager::StartWriteFromUrl(
60 const ExtensionId& extension_id, 59 const ExtensionId& extension_id,
61 GURL url, 60 GURL url,
62 content::RenderViewHost* rvh, 61 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& storage_unit_id,
66 const Operation::StartWriteCallback& callback) { 65 const Operation::StartWriteCallback& callback) {
66
67 OperationMap::iterator existing_operation = operations_.find(extension_id); 67 OperationMap::iterator existing_operation = operations_.find(extension_id);
68 68
69 if (existing_operation != operations_.end()) { 69 if (existing_operation != operations_.end()) {
70 return callback.Run(false, error::kOperationAlreadyInProgress); 70 return callback.Run(false, error::kOperationAlreadyInProgress);
71 } 71 }
72 72
73 scoped_refptr<Operation> operation( 73 scoped_refptr<Operation> operation(
74 new WriteFromUrlOperation(weak_factory_.GetWeakPtr(), 74 new WriteFromUrlOperation(weak_factory_.GetWeakPtr(),
75 extension_id, 75 extension_id,
76 rvh, 76 rvh,
77 url, 77 url,
78 hash, 78 hash,
79 saveImageAsDownload, 79 saveImageAsDownload,
80 storage_unit_id)); 80 storage_unit_id));
81
81 operations_[extension_id] = operation; 82 operations_[extension_id] = operation;
83
82 BrowserThread::PostTask(BrowserThread::FILE, 84 BrowserThread::PostTask(BrowserThread::FILE,
83 FROM_HERE, 85 FROM_HERE,
84 base::Bind(&Operation::Start, operation)); 86 base::Bind(&Operation::Start,
87 operation.get()));
88
85 callback.Run(true, ""); 89 callback.Run(true, "");
86 } 90 }
87 91
88 void OperationManager::StartWriteFromFile( 92 void OperationManager::StartWriteFromFile(
89 const ExtensionId& extension_id, 93 const ExtensionId& extension_id,
90 const base::FilePath& path, 94 const base::FilePath& path,
91 const std::string& storage_unit_id, 95 const std::string& storage_unit_id,
92 const Operation::StartWriteCallback& callback) { 96 const Operation::StartWriteCallback& callback) {
93 OperationMap::iterator existing_operation = operations_.find(extension_id); 97 OperationMap::iterator existing_operation = operations_.find(extension_id);
94 98
95 if (existing_operation != operations_.end()) { 99 if (existing_operation != operations_.end()) {
96 return callback.Run(false, error::kOperationAlreadyInProgress); 100 return callback.Run(false, error::kOperationAlreadyInProgress);
97 } 101 }
98 102
99 scoped_refptr<Operation> operation( 103 scoped_refptr<Operation> operation(
100 new WriteFromFileOperation(weak_factory_.GetWeakPtr(), 104 new WriteFromFileOperation(weak_factory_.GetWeakPtr(),
101 extension_id, 105 extension_id,
102 path, 106 path,
103 storage_unit_id)); 107 storage_unit_id));
108
104 operations_[extension_id] = operation; 109 operations_[extension_id] = operation;
110
105 BrowserThread::PostTask(BrowserThread::FILE, 111 BrowserThread::PostTask(BrowserThread::FILE,
106 FROM_HERE, 112 FROM_HERE,
107 base::Bind(&Operation::Start, operation)); 113 base::Bind(&Operation::Start,
114 operation.get()));
115
108 callback.Run(true, ""); 116 callback.Run(true, "");
109 } 117 }
110 118
111 void OperationManager::CancelWrite( 119 void OperationManager::CancelWrite(
112 const ExtensionId& extension_id, 120 const ExtensionId& extension_id,
113 const Operation::CancelWriteCallback& callback) { 121 const Operation::CancelWriteCallback& callback) {
114 Operation* existing_operation = GetOperation(extension_id); 122 Operation* existing_operation = GetOperation(extension_id);
115 123
116 if (existing_operation == NULL) { 124 if (existing_operation == NULL) {
117 callback.Run(false, error::kNoOperationInProgress); 125 callback.Run(false, error::kNoOperationInProgress);
118 } else { 126 } else {
119 BrowserThread::PostTask(BrowserThread::FILE, 127 BrowserThread::PostTask(BrowserThread::FILE,
120 FROM_HERE, 128 FROM_HERE,
121 base::Bind(&Operation::Cancel, existing_operation)); 129 base::Bind(&Operation::Cancel, existing_operation));
122 DeleteOperation(extension_id); 130 DeleteOperation(extension_id);
123 callback.Run(true, ""); 131 callback.Run(true, "");
124 } 132 }
125 } 133 }
126 134
127 void OperationManager::DestroyPartitions(
128 const ExtensionId& extension_id,
129 const std::string& storage_unit_id,
130 const Operation::StartWriteCallback& callback) {
131 OperationMap::iterator existing_operation = operations_.find(extension_id);
132
133 if (existing_operation != operations_.end()) {
134 return callback.Run(false, error::kOperationAlreadyInProgress);
135 }
136
137 scoped_refptr<Operation> operation(
138 new DestroyPartitionsOperation(weak_factory_.GetWeakPtr(),
139 extension_id,
140 storage_unit_id));
141 operations_[extension_id] = operation;
142 BrowserThread::PostTask(BrowserThread::FILE,
143 FROM_HERE,
144 base::Bind(&Operation::Start, operation));
145 callback.Run(true, "");
146 }
147
148 void OperationManager::OnProgress(const ExtensionId& extension_id, 135 void OperationManager::OnProgress(const ExtensionId& extension_id,
149 image_writer_api::Stage stage, 136 image_writer_api::Stage stage,
150 int progress) { 137 int progress) {
151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
152 DVLOG(2) << "progress - " << stage << " at " << progress << "%"; 139 DVLOG(2) << "progress - " << stage << " at " << progress << "%";
153 140
154 image_writer_api::ProgressInfo info; 141 image_writer_api::ProgressInfo info;
155 info.stage = stage; 142 info.stage = stage;
156 info.percent_complete = progress; 143 info.percent_complete = progress;
157 144
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 g_factory = LAZY_INSTANCE_INITIALIZER; 245 g_factory = LAZY_INSTANCE_INITIALIZER;
259 246
260 ProfileKeyedAPIFactory<OperationManager>* 247 ProfileKeyedAPIFactory<OperationManager>*
261 OperationManager::GetFactoryInstance() { 248 OperationManager::GetFactoryInstance() {
262 return &g_factory.Get(); 249 return &g_factory.Get();
263 } 250 }
264 251
265 252
266 } // namespace image_writer 253 } // namespace image_writer
267 } // namespace extensions 254 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698