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