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

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

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

Powered by Google App Engine
This is Rietveld 408576698