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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, |
62 const std::string& hash, | 63 const std::string& hash, |
63 const std::string& device_path, | 64 bool saveImageAsDownload, |
| 65 const std::string& storage_unit_id, |
64 const Operation::StartWriteCallback& callback) { | 66 const Operation::StartWriteCallback& callback) { |
65 OperationMap::iterator existing_operation = operations_.find(extension_id); | 67 OperationMap::iterator existing_operation = operations_.find(extension_id); |
66 | 68 |
67 if (existing_operation != operations_.end()) { | 69 if (existing_operation != operations_.end()) { |
68 return callback.Run(false, error::kOperationAlreadyInProgress); | 70 return callback.Run(false, error::kOperationAlreadyInProgress); |
69 } | 71 } |
70 | 72 |
71 scoped_refptr<Operation> operation( | 73 scoped_refptr<Operation> operation( |
72 new WriteFromUrlOperation(weak_factory_.GetWeakPtr(), | 74 new WriteFromUrlOperation(weak_factory_.GetWeakPtr(), |
73 extension_id, | 75 extension_id, |
74 profile_->GetRequestContext(), | 76 rvh, |
75 url, | 77 url, |
76 hash, | 78 hash, |
77 device_path)); | 79 saveImageAsDownload, |
| 80 storage_unit_id)); |
78 operations_[extension_id] = operation; | 81 operations_[extension_id] = operation; |
79 BrowserThread::PostTask(BrowserThread::FILE, | 82 BrowserThread::PostTask(BrowserThread::FILE, |
80 FROM_HERE, | 83 FROM_HERE, |
81 base::Bind(&Operation::Start, operation)); | 84 base::Bind(&Operation::Start, operation)); |
82 callback.Run(true, ""); | 85 callback.Run(true, ""); |
83 } | 86 } |
84 | 87 |
85 void OperationManager::StartWriteFromFile( | 88 void OperationManager::StartWriteFromFile( |
86 const ExtensionId& extension_id, | 89 const ExtensionId& extension_id, |
87 const base::FilePath& path, | 90 const base::FilePath& path, |
88 const std::string& device_path, | 91 const std::string& storage_unit_id, |
89 const Operation::StartWriteCallback& callback) { | 92 const Operation::StartWriteCallback& callback) { |
90 OperationMap::iterator existing_operation = operations_.find(extension_id); | 93 OperationMap::iterator existing_operation = operations_.find(extension_id); |
91 | 94 |
92 if (existing_operation != operations_.end()) { | 95 if (existing_operation != operations_.end()) { |
93 return callback.Run(false, error::kOperationAlreadyInProgress); | 96 return callback.Run(false, error::kOperationAlreadyInProgress); |
94 } | 97 } |
95 | 98 |
96 scoped_refptr<Operation> operation(new WriteFromFileOperation( | 99 scoped_refptr<Operation> operation( |
97 weak_factory_.GetWeakPtr(), extension_id, path, device_path)); | 100 new WriteFromFileOperation(weak_factory_.GetWeakPtr(), |
| 101 extension_id, |
| 102 path, |
| 103 storage_unit_id)); |
98 operations_[extension_id] = operation; | 104 operations_[extension_id] = operation; |
99 BrowserThread::PostTask(BrowserThread::FILE, | 105 BrowserThread::PostTask(BrowserThread::FILE, |
100 FROM_HERE, | 106 FROM_HERE, |
101 base::Bind(&Operation::Start, operation)); | 107 base::Bind(&Operation::Start, operation)); |
102 callback.Run(true, ""); | 108 callback.Run(true, ""); |
103 } | 109 } |
104 | 110 |
105 void OperationManager::CancelWrite( | 111 void OperationManager::CancelWrite( |
106 const ExtensionId& extension_id, | 112 const ExtensionId& extension_id, |
107 const Operation::CancelWriteCallback& callback) { | 113 const Operation::CancelWriteCallback& callback) { |
108 Operation* existing_operation = GetOperation(extension_id); | 114 Operation* existing_operation = GetOperation(extension_id); |
109 | 115 |
110 if (existing_operation == NULL) { | 116 if (existing_operation == NULL) { |
111 callback.Run(false, error::kNoOperationInProgress); | 117 callback.Run(false, error::kNoOperationInProgress); |
112 } else { | 118 } else { |
113 BrowserThread::PostTask(BrowserThread::FILE, | 119 BrowserThread::PostTask(BrowserThread::FILE, |
114 FROM_HERE, | 120 FROM_HERE, |
115 base::Bind(&Operation::Cancel, existing_operation)); | 121 base::Bind(&Operation::Cancel, existing_operation)); |
116 DeleteOperation(extension_id); | 122 DeleteOperation(extension_id); |
117 callback.Run(true, ""); | 123 callback.Run(true, ""); |
118 } | 124 } |
119 } | 125 } |
120 | 126 |
121 void OperationManager::DestroyPartitions( | 127 void OperationManager::DestroyPartitions( |
122 const ExtensionId& extension_id, | 128 const ExtensionId& extension_id, |
123 const std::string& device_path, | 129 const std::string& storage_unit_id, |
124 const Operation::StartWriteCallback& callback) { | 130 const Operation::StartWriteCallback& callback) { |
125 OperationMap::iterator existing_operation = operations_.find(extension_id); | 131 OperationMap::iterator existing_operation = operations_.find(extension_id); |
126 | 132 |
127 if (existing_operation != operations_.end()) { | 133 if (existing_operation != operations_.end()) { |
128 return callback.Run(false, error::kOperationAlreadyInProgress); | 134 return callback.Run(false, error::kOperationAlreadyInProgress); |
129 } | 135 } |
130 | 136 |
131 scoped_refptr<Operation> operation(new DestroyPartitionsOperation( | 137 scoped_refptr<Operation> operation( |
132 weak_factory_.GetWeakPtr(), extension_id, device_path)); | 138 new DestroyPartitionsOperation(weak_factory_.GetWeakPtr(), |
| 139 extension_id, |
| 140 storage_unit_id)); |
133 operations_[extension_id] = operation; | 141 operations_[extension_id] = operation; |
134 BrowserThread::PostTask(BrowserThread::FILE, | 142 BrowserThread::PostTask(BrowserThread::FILE, |
135 FROM_HERE, | 143 FROM_HERE, |
136 base::Bind(&Operation::Start, operation)); | 144 base::Bind(&Operation::Start, operation)); |
137 callback.Run(true, ""); | 145 callback.Run(true, ""); |
138 } | 146 } |
139 | 147 |
140 void OperationManager::OnProgress(const ExtensionId& extension_id, | 148 void OperationManager::OnProgress(const ExtensionId& extension_id, |
141 image_writer_api::Stage stage, | 149 image_writer_api::Stage stage, |
142 int progress) { | 150 int progress) { |
143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 152 DVLOG(2) << "progress - " << stage << " at " << progress << "%"; |
144 | 153 |
145 image_writer_api::ProgressInfo info; | 154 image_writer_api::ProgressInfo info; |
146 info.stage = stage; | 155 info.stage = stage; |
147 info.percent_complete = progress; | 156 info.percent_complete = progress; |
148 | 157 |
149 scoped_ptr<base::ListValue> args( | 158 scoped_ptr<base::ListValue> args( |
150 image_writer_api::OnWriteProgress::Create(info)); | 159 image_writer_api::OnWriteProgress::Create(info)); |
151 scoped_ptr<Event> event(new Event( | 160 scoped_ptr<Event> event(new Event( |
152 image_writer_api::OnWriteProgress::kEventName, args.Pass())); | 161 image_writer_api::OnWriteProgress::kEventName, args.Pass())); |
153 | 162 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 g_factory = LAZY_INSTANCE_INITIALIZER; | 257 g_factory = LAZY_INSTANCE_INITIALIZER; |
249 | 258 |
250 ProfileKeyedAPIFactory<OperationManager>* | 259 ProfileKeyedAPIFactory<OperationManager>* |
251 OperationManager::GetFactoryInstance() { | 260 OperationManager::GetFactoryInstance() { |
252 return g_factory.Pointer(); | 261 return g_factory.Pointer(); |
253 } | 262 } |
254 | 263 |
255 | 264 |
256 } // namespace image_writer | 265 } // namespace image_writer |
257 } // namespace extensions | 266 } // namespace extensions |
OLD | NEW |