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

Side by Side Diff: chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.cc

Issue 1492403002: Remove kuint32max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: http security header file Created 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.h" 5 #include "chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9
9 #include <algorithm> 10 #include <algorithm>
11 #include <limits>
10 #include <vector> 12 #include <vector>
11 13
12 #include "base/bind.h" 14 #include "base/bind.h"
13 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
14 #include "base/numerics/safe_conversions.h" 16 #include "base/numerics/safe_conversions.h"
15 #include "base/posix/eintr_wrapper.h" 17 #include "base/posix/eintr_wrapper.h"
16 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_split.h" 19 #include "base/strings/string_split.h"
18 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
19 #include "chrome/browser/media_galleries/linux/mtp_device_task_helper_map_servic e.h" 21 #include "chrome/browser/media_galleries/linux/mtp_device_task_helper_map_servic e.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // |storage_name| specifies the name of the storage device. 97 // |storage_name| specifies the name of the storage device.
96 // |read_only| specifies the mode of the storage device. 98 // |read_only| specifies the mode of the storage device.
97 // |parent_id| is an object id of the parent directory. 99 // |parent_id| is an object id of the parent directory.
98 // |directory_name| is name of the new directory. 100 // |directory_name| is name of the new directory.
99 // |success_callback| is called when the directory is created successfully. 101 // |success_callback| is called when the directory is created successfully.
100 // |error_callback| is called when it fails to create a directory. 102 // |error_callback| is called when it fails to create a directory.
101 // |success_callback| and |error_callback| runs on the IO thread. 103 // |success_callback| and |error_callback| runs on the IO thread.
102 void CreateDirectoryOnUIThread( 104 void CreateDirectoryOnUIThread(
103 const std::string& storage_name, 105 const std::string& storage_name,
104 const bool read_only, 106 const bool read_only,
105 const uint32 parent_id, 107 const uint32_t parent_id,
106 const std::string& directory_name, 108 const std::string& directory_name,
107 const MTPDeviceTaskHelper::CreateDirectorySuccessCallback& success_callback, 109 const MTPDeviceTaskHelper::CreateDirectorySuccessCallback& success_callback,
108 const MTPDeviceTaskHelper::ErrorCallback& error_callback) { 110 const MTPDeviceTaskHelper::ErrorCallback& error_callback) {
109 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 111 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
110 MTPDeviceTaskHelper* task_helper = 112 MTPDeviceTaskHelper* task_helper =
111 GetDeviceTaskHelperForStorage(storage_name, read_only); 113 GetDeviceTaskHelperForStorage(storage_name, read_only);
112 if (!task_helper) 114 if (!task_helper)
113 return; 115 return;
114 task_helper->CreateDirectory(parent_id, directory_name, success_callback, 116 task_helper->CreateDirectory(parent_id, directory_name, success_callback,
115 error_callback); 117 error_callback);
116 } 118 }
117 119
118 // Enumerates the |dir_id| directory file entries. 120 // Enumerates the |dir_id| directory file entries.
119 // 121 //
120 // Called on the UI thread to dispatch the request to the 122 // Called on the UI thread to dispatch the request to the
121 // MediaTransferProtocolManager. 123 // MediaTransferProtocolManager.
122 // 124 //
123 // |storage_name| specifies the name of the storage device. 125 // |storage_name| specifies the name of the storage device.
124 // |read_only| specifies the mode of the storage device. 126 // |read_only| specifies the mode of the storage device.
125 // |directory_id| is an id of a directory to read. 127 // |directory_id| is an id of a directory to read.
126 // |max_size| is a maximum size to read. Set 0 not to specify the maximum size. 128 // |max_size| is a maximum size to read. Set 0 not to specify the maximum size.
127 // |success_callback| is called when the ReadDirectory request succeeds. 129 // |success_callback| is called when the ReadDirectory request succeeds.
128 // |error_callback| is called when the ReadDirectory request fails. 130 // |error_callback| is called when the ReadDirectory request fails.
129 // |success_callback| and |error_callback| runs on the IO thread. 131 // |success_callback| and |error_callback| runs on the IO thread.
130 void ReadDirectoryOnUIThread( 132 void ReadDirectoryOnUIThread(
131 const std::string& storage_name, 133 const std::string& storage_name,
132 const bool read_only, 134 const bool read_only,
133 const uint32 directory_id, 135 const uint32_t directory_id,
134 const size_t max_size, 136 const size_t max_size,
135 const MTPDeviceTaskHelper::ReadDirectorySuccessCallback& success_callback, 137 const MTPDeviceTaskHelper::ReadDirectorySuccessCallback& success_callback,
136 const MTPDeviceTaskHelper::ErrorCallback& error_callback) { 138 const MTPDeviceTaskHelper::ErrorCallback& error_callback) {
137 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 139 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
138 MTPDeviceTaskHelper* task_helper = 140 MTPDeviceTaskHelper* task_helper =
139 GetDeviceTaskHelperForStorage(storage_name, read_only); 141 GetDeviceTaskHelperForStorage(storage_name, read_only);
140 if (!task_helper) 142 if (!task_helper)
141 return; 143 return;
142 task_helper->ReadDirectory(directory_id, max_size, success_callback, 144 task_helper->ReadDirectory(directory_id, max_size, success_callback,
143 error_callback); 145 error_callback);
144 } 146 }
145 147
146 // Gets the |file_path| details. 148 // Gets the |file_path| details.
147 // 149 //
148 // Called on the UI thread to dispatch the request to the 150 // Called on the UI thread to dispatch the request to the
149 // MediaTransferProtocolManager. 151 // MediaTransferProtocolManager.
150 // 152 //
151 // |storage_name| specifies the name of the storage device. 153 // |storage_name| specifies the name of the storage device.
152 // |read_only| specifies the mode of the storage device. 154 // |read_only| specifies the mode of the storage device.
153 // |success_callback| is called when the GetFileInfo request succeeds. 155 // |success_callback| is called when the GetFileInfo request succeeds.
154 // |error_callback| is called when the GetFileInfo request fails. 156 // |error_callback| is called when the GetFileInfo request fails.
155 // |success_callback| and |error_callback| runs on the IO thread. 157 // |success_callback| and |error_callback| runs on the IO thread.
156 void GetFileInfoOnUIThread( 158 void GetFileInfoOnUIThread(
157 const std::string& storage_name, 159 const std::string& storage_name,
158 const bool read_only, 160 const bool read_only,
159 uint32 file_id, 161 uint32_t file_id,
160 const MTPDeviceTaskHelper::GetFileInfoSuccessCallback& success_callback, 162 const MTPDeviceTaskHelper::GetFileInfoSuccessCallback& success_callback,
161 const MTPDeviceTaskHelper::ErrorCallback& error_callback) { 163 const MTPDeviceTaskHelper::ErrorCallback& error_callback) {
162 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 164 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
163 MTPDeviceTaskHelper* task_helper = 165 MTPDeviceTaskHelper* task_helper =
164 GetDeviceTaskHelperForStorage(storage_name, read_only); 166 GetDeviceTaskHelperForStorage(storage_name, read_only);
165 if (!task_helper) 167 if (!task_helper)
166 return; 168 return;
167 task_helper->GetFileInfo(file_id, success_callback, error_callback); 169 task_helper->GetFileInfo(file_id, success_callback, error_callback);
168 } 170 }
169 171
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // |storage_name| specifies the name of the storage device. 221 // |storage_name| specifies the name of the storage device.
220 // |read_only| specifies the mode of the storage device. 222 // |read_only| specifies the mode of the storage device.
221 // |object_id| is an id of object to be renamed. 223 // |object_id| is an id of object to be renamed.
222 // |new_name| is new name of the object. 224 // |new_name| is new name of the object.
223 // |success_callback| is called when the object is renamed successfully. 225 // |success_callback| is called when the object is renamed successfully.
224 // |error_callback| is called when it fails to rename the object. 226 // |error_callback| is called when it fails to rename the object.
225 // |success_callback| and |error_callback| runs on the IO thread. 227 // |success_callback| and |error_callback| runs on the IO thread.
226 void RenameObjectOnUIThread( 228 void RenameObjectOnUIThread(
227 const std::string& storage_name, 229 const std::string& storage_name,
228 const bool read_only, 230 const bool read_only,
229 const uint32 object_id, 231 const uint32_t object_id,
230 const std::string& new_name, 232 const std::string& new_name,
231 const MTPDeviceTaskHelper::RenameObjectSuccessCallback& success_callback, 233 const MTPDeviceTaskHelper::RenameObjectSuccessCallback& success_callback,
232 const MTPDeviceTaskHelper::ErrorCallback& error_callback) { 234 const MTPDeviceTaskHelper::ErrorCallback& error_callback) {
233 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 235 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
234 MTPDeviceTaskHelper* task_helper = 236 MTPDeviceTaskHelper* task_helper =
235 GetDeviceTaskHelperForStorage(storage_name, read_only); 237 GetDeviceTaskHelperForStorage(storage_name, read_only);
236 if (!task_helper) 238 if (!task_helper)
237 return; 239 return;
238 task_helper->RenameObject(object_id, new_name, success_callback, 240 task_helper->RenameObject(object_id, new_name, success_callback,
239 error_callback); 241 error_callback);
240 } 242 }
241 243
242 // Copies the file |source_file_descriptor| to |file_name| in |parent_id|. 244 // Copies the file |source_file_descriptor| to |file_name| in |parent_id|.
243 // 245 //
244 // |storage_name| specifies the name of the storage device. 246 // |storage_name| specifies the name of the storage device.
245 // |read_only| specifies the mode of the storage device. 247 // |read_only| specifies the mode of the storage device.
246 // |source_file_descriptor| file descriptor of source file. 248 // |source_file_descriptor| file descriptor of source file.
247 // |parent_id| object id of a target directory. 249 // |parent_id| object id of a target directory.
248 // |file_name| file name of a target file. 250 // |file_name| file name of a target file.
249 // |success_callback| is called when the file is copied successfully. 251 // |success_callback| is called when the file is copied successfully.
250 // |error_callback| is called when it fails to copy file. 252 // |error_callback| is called when it fails to copy file.
251 // Since this method does not close the file descriptor, callbacks are 253 // Since this method does not close the file descriptor, callbacks are
252 // responsible for closing it. 254 // responsible for closing it.
253 void CopyFileFromLocalOnUIThread( 255 void CopyFileFromLocalOnUIThread(
254 const std::string& storage_name, 256 const std::string& storage_name,
255 const bool read_only, 257 const bool read_only,
256 const int source_file_descriptor, 258 const int source_file_descriptor,
257 const uint32 parent_id, 259 const uint32_t parent_id,
258 const std::string& file_name, 260 const std::string& file_name,
259 const MTPDeviceTaskHelper::CopyFileFromLocalSuccessCallback& 261 const MTPDeviceTaskHelper::CopyFileFromLocalSuccessCallback&
260 success_callback, 262 success_callback,
261 const MTPDeviceTaskHelper::ErrorCallback& error_callback) { 263 const MTPDeviceTaskHelper::ErrorCallback& error_callback) {
262 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 264 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
263 MTPDeviceTaskHelper* task_helper = 265 MTPDeviceTaskHelper* task_helper =
264 GetDeviceTaskHelperForStorage(storage_name, read_only); 266 GetDeviceTaskHelperForStorage(storage_name, read_only);
265 if (!task_helper) 267 if (!task_helper)
266 return; 268 return;
267 task_helper->CopyFileFromLocal(storage_name, source_file_descriptor, 269 task_helper->CopyFileFromLocal(storage_name, source_file_descriptor,
268 parent_id, file_name, success_callback, 270 parent_id, file_name, success_callback,
269 error_callback); 271 error_callback);
270 } 272 }
271 273
272 // Deletes |object_id|. 274 // Deletes |object_id|.
273 // 275 //
274 // Called on the UI thread to dispatch the request to the 276 // Called on the UI thread to dispatch the request to the
275 // MediaTransferProtocolManager. 277 // MediaTransferProtocolManager.
276 // 278 //
277 // |storage_name| specifies the name of the storage device. 279 // |storage_name| specifies the name of the storage device.
278 // |read_only| specifies the mode of the storage device. 280 // |read_only| specifies the mode of the storage device.
279 // |object_id| is the object to be deleted. 281 // |object_id| is the object to be deleted.
280 // |success_callback| is called when the object is deleted successfully. 282 // |success_callback| is called when the object is deleted successfully.
281 // |error_callback| is called when it fails to delete the object. 283 // |error_callback| is called when it fails to delete the object.
282 // |success_callback| and |error_callback| runs on the IO thread. 284 // |success_callback| and |error_callback| runs on the IO thread.
283 void DeleteObjectOnUIThread( 285 void DeleteObjectOnUIThread(
284 const std::string storage_name, 286 const std::string storage_name,
285 const bool read_only, 287 const bool read_only,
286 const uint32 object_id, 288 const uint32_t object_id,
287 const MTPDeviceTaskHelper::DeleteObjectSuccessCallback success_callback, 289 const MTPDeviceTaskHelper::DeleteObjectSuccessCallback success_callback,
288 const MTPDeviceTaskHelper::ErrorCallback error_callback) { 290 const MTPDeviceTaskHelper::ErrorCallback error_callback) {
289 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 291 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
290 MTPDeviceTaskHelper* task_helper = 292 MTPDeviceTaskHelper* task_helper =
291 GetDeviceTaskHelperForStorage(storage_name, read_only); 293 GetDeviceTaskHelperForStorage(storage_name, read_only);
292 if (!task_helper) 294 if (!task_helper)
293 return; 295 return;
294 task_helper->DeleteObject(object_id, success_callback, error_callback); 296 task_helper->DeleteObject(object_id, success_callback, error_callback);
295 } 297 }
296 298
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 } 343 }
342 344
343 // Deletes a temporary file |file_path|. 345 // Deletes a temporary file |file_path|.
344 void DeleteTemporaryFile(const base::FilePath& file_path) { 346 void DeleteTemporaryFile(const base::FilePath& file_path) {
345 content::BrowserThread::PostBlockingPoolTask( 347 content::BrowserThread::PostBlockingPoolTask(
346 FROM_HERE, base::Bind(base::IgnoreResult(base::DeleteFile), file_path, 348 FROM_HERE, base::Bind(base::IgnoreResult(base::DeleteFile), file_path,
347 false /* not recursive*/)); 349 false /* not recursive*/));
348 } 350 }
349 351
350 // A fake callback to be passed as CopyFileProgressCallback. 352 // A fake callback to be passed as CopyFileProgressCallback.
351 void FakeCopyFileProgressCallback(int64 size) { 353 void FakeCopyFileProgressCallback(int64_t size) {}
352 }
353 354
354 } // namespace 355 } // namespace
355 356
356 MTPDeviceDelegateImplLinux::PendingTaskInfo::PendingTaskInfo( 357 MTPDeviceDelegateImplLinux::PendingTaskInfo::PendingTaskInfo(
357 const base::FilePath& path, 358 const base::FilePath& path,
358 content::BrowserThread::ID thread_id, 359 content::BrowserThread::ID thread_id,
359 const tracked_objects::Location& location, 360 const tracked_objects::Location& location,
360 const base::Closure& task) 361 const base::Closure& task)
361 : path(path), 362 : path(path),
362 thread_id(thread_id), 363 thread_id(thread_id),
363 location(location), 364 location(location),
364 task(task) { 365 task(task) {
365 } 366 }
366 367
367 MTPDeviceDelegateImplLinux::PendingTaskInfo::~PendingTaskInfo() { 368 MTPDeviceDelegateImplLinux::PendingTaskInfo::~PendingTaskInfo() {
368 } 369 }
369 370
370 // Represents a file on the MTP device. 371 // Represents a file on the MTP device.
371 // Lives on the IO thread. 372 // Lives on the IO thread.
372 class MTPDeviceDelegateImplLinux::MTPFileNode { 373 class MTPDeviceDelegateImplLinux::MTPFileNode {
373 public: 374 public:
374 MTPFileNode(uint32 file_id, 375 MTPFileNode(uint32_t file_id,
375 const std::string& file_name, 376 const std::string& file_name,
376 MTPFileNode* parent, 377 MTPFileNode* parent,
377 FileIdToMTPFileNodeMap* file_id_to_node_map); 378 FileIdToMTPFileNodeMap* file_id_to_node_map);
378 ~MTPFileNode(); 379 ~MTPFileNode();
379 380
380 const MTPFileNode* GetChild(const std::string& name) const; 381 const MTPFileNode* GetChild(const std::string& name) const;
381 382
382 void EnsureChildExists(const std::string& name, uint32 id); 383 void EnsureChildExists(const std::string& name, uint32_t id);
383 384
384 // Clears all the children, except those in |children_to_keep|. 385 // Clears all the children, except those in |children_to_keep|.
385 void ClearNonexistentChildren( 386 void ClearNonexistentChildren(
386 const std::set<std::string>& children_to_keep); 387 const std::set<std::string>& children_to_keep);
387 388
388 bool DeleteChild(uint32 file_id); 389 bool DeleteChild(uint32_t file_id);
389 390
390 bool HasChildren() const; 391 bool HasChildren() const;
391 392
392 uint32 file_id() const { return file_id_; } 393 uint32_t file_id() const { return file_id_; }
393 const std::string& file_name() const { return file_name_; } 394 const std::string& file_name() const { return file_name_; }
394 MTPFileNode* parent() { return parent_; } 395 MTPFileNode* parent() { return parent_; }
395 396
396 private: 397 private:
397 // Container for holding a node's children. 398 // Container for holding a node's children.
398 typedef base::ScopedPtrHashMap<std::string, scoped_ptr<MTPFileNode>> 399 typedef base::ScopedPtrHashMap<std::string, scoped_ptr<MTPFileNode>>
399 ChildNodes; 400 ChildNodes;
400 401
401 const uint32 file_id_; 402 const uint32_t file_id_;
402 const std::string file_name_; 403 const std::string file_name_;
403 404
404 ChildNodes children_; 405 ChildNodes children_;
405 MTPFileNode* const parent_; 406 MTPFileNode* const parent_;
406 FileIdToMTPFileNodeMap* file_id_to_node_map_; 407 FileIdToMTPFileNodeMap* file_id_to_node_map_;
407 408
408 DISALLOW_COPY_AND_ASSIGN(MTPFileNode); 409 DISALLOW_COPY_AND_ASSIGN(MTPFileNode);
409 }; 410 };
410 411
411 MTPDeviceDelegateImplLinux::MTPFileNode::MTPFileNode( 412 MTPDeviceDelegateImplLinux::MTPFileNode::MTPFileNode(
412 uint32 file_id, 413 uint32_t file_id,
413 const std::string& file_name, 414 const std::string& file_name,
414 MTPFileNode* parent, 415 MTPFileNode* parent,
415 FileIdToMTPFileNodeMap* file_id_to_node_map) 416 FileIdToMTPFileNodeMap* file_id_to_node_map)
416 : file_id_(file_id), 417 : file_id_(file_id),
417 file_name_(file_name), 418 file_name_(file_name),
418 parent_(parent), 419 parent_(parent),
419 file_id_to_node_map_(file_id_to_node_map) { 420 file_id_to_node_map_(file_id_to_node_map) {
420 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 421 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
421 DCHECK(file_id_to_node_map_); 422 DCHECK(file_id_to_node_map_);
422 DCHECK(!ContainsKey(*file_id_to_node_map_, file_id_)); 423 DCHECK(!ContainsKey(*file_id_to_node_map_, file_id_));
423 (*file_id_to_node_map_)[file_id_] = this; 424 (*file_id_to_node_map_)[file_id_] = this;
424 } 425 }
425 426
426 MTPDeviceDelegateImplLinux::MTPFileNode::~MTPFileNode() { 427 MTPDeviceDelegateImplLinux::MTPFileNode::~MTPFileNode() {
427 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 428 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
428 size_t erased = file_id_to_node_map_->erase(file_id_); 429 size_t erased = file_id_to_node_map_->erase(file_id_);
429 DCHECK_EQ(1U, erased); 430 DCHECK_EQ(1U, erased);
430 } 431 }
431 432
432 const MTPDeviceDelegateImplLinux::MTPFileNode* 433 const MTPDeviceDelegateImplLinux::MTPFileNode*
433 MTPDeviceDelegateImplLinux::MTPFileNode::GetChild( 434 MTPDeviceDelegateImplLinux::MTPFileNode::GetChild(
434 const std::string& name) const { 435 const std::string& name) const {
435 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 436 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
436 return children_.get(name); 437 return children_.get(name);
437 } 438 }
438 439
439 void MTPDeviceDelegateImplLinux::MTPFileNode::EnsureChildExists( 440 void MTPDeviceDelegateImplLinux::MTPFileNode::EnsureChildExists(
440 const std::string& name, 441 const std::string& name,
441 uint32 id) { 442 uint32_t id) {
442 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 443 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
443 const MTPFileNode* child = GetChild(name); 444 const MTPFileNode* child = GetChild(name);
444 if (child && child->file_id() == id) 445 if (child && child->file_id() == id)
445 return; 446 return;
446 447
447 children_.set( 448 children_.set(
448 name, 449 name,
449 make_scoped_ptr(new MTPFileNode(id, name, this, file_id_to_node_map_))); 450 make_scoped_ptr(new MTPFileNode(id, name, this, file_id_to_node_map_)));
450 } 451 }
451 452
452 void MTPDeviceDelegateImplLinux::MTPFileNode::ClearNonexistentChildren( 453 void MTPDeviceDelegateImplLinux::MTPFileNode::ClearNonexistentChildren(
453 const std::set<std::string>& children_to_keep) { 454 const std::set<std::string>& children_to_keep) {
454 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 455 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
455 std::set<std::string> children_to_erase; 456 std::set<std::string> children_to_erase;
456 for (ChildNodes::const_iterator it = children_.begin(); 457 for (ChildNodes::const_iterator it = children_.begin();
457 it != children_.end(); ++it) { 458 it != children_.end(); ++it) {
458 if (ContainsKey(children_to_keep, it->first)) 459 if (ContainsKey(children_to_keep, it->first))
459 continue; 460 continue;
460 children_to_erase.insert(it->first); 461 children_to_erase.insert(it->first);
461 } 462 }
462 for (std::set<std::string>::iterator it = children_to_erase.begin(); 463 for (std::set<std::string>::iterator it = children_to_erase.begin();
463 it != children_to_erase.end(); ++it) { 464 it != children_to_erase.end(); ++it) {
464 children_.take_and_erase(*it); 465 children_.take_and_erase(*it);
465 } 466 }
466 } 467 }
467 468
468 bool MTPDeviceDelegateImplLinux::MTPFileNode::DeleteChild(uint32 file_id) { 469 bool MTPDeviceDelegateImplLinux::MTPFileNode::DeleteChild(uint32_t file_id) {
469 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 470 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
470 for (ChildNodes::iterator it = children_.begin(); 471 for (ChildNodes::iterator it = children_.begin();
471 it != children_.end(); ++it) { 472 it != children_.end(); ++it) {
472 if (it->second->file_id() == file_id) { 473 if (it->second->file_id() == file_id) {
473 DCHECK(!it->second->HasChildren()); 474 DCHECK(!it->second->HasChildren());
474 children_.erase(it); 475 children_.erase(it);
475 return true; 476 return true;
476 } 477 }
477 } 478 }
478 return false; 479 return false;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 closure)); 609 closure));
609 } 610 }
610 611
611 bool MTPDeviceDelegateImplLinux::IsStreaming() { 612 bool MTPDeviceDelegateImplLinux::IsStreaming() {
612 return true; 613 return true;
613 } 614 }
614 615
615 void MTPDeviceDelegateImplLinux::ReadBytes( 616 void MTPDeviceDelegateImplLinux::ReadBytes(
616 const base::FilePath& device_file_path, 617 const base::FilePath& device_file_path,
617 const scoped_refptr<net::IOBuffer>& buf, 618 const scoped_refptr<net::IOBuffer>& buf,
618 int64 offset, 619 int64_t offset,
619 int buf_len, 620 int buf_len,
620 const ReadBytesSuccessCallback& success_callback, 621 const ReadBytesSuccessCallback& success_callback,
621 const ErrorCallback& error_callback) { 622 const ErrorCallback& error_callback) {
622 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 623 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
623 DCHECK(!device_file_path.empty()); 624 DCHECK(!device_file_path.empty());
624 base::Closure closure = 625 base::Closure closure =
625 base::Bind(&MTPDeviceDelegateImplLinux::ReadBytesInternal, 626 base::Bind(&MTPDeviceDelegateImplLinux::ReadBytesInternal,
626 weak_ptr_factory_.GetWeakPtr(), 627 weak_ptr_factory_.GetWeakPtr(),
627 device_file_path, 628 device_file_path,
628 buf, 629 buf,
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 read_only_)); 829 read_only_));
829 delete this; 830 delete this;
830 } 831 }
831 832
832 void MTPDeviceDelegateImplLinux::GetFileInfoInternal( 833 void MTPDeviceDelegateImplLinux::GetFileInfoInternal(
833 const base::FilePath& file_path, 834 const base::FilePath& file_path,
834 const GetFileInfoSuccessCallback& success_callback, 835 const GetFileInfoSuccessCallback& success_callback,
835 const ErrorCallback& error_callback) { 836 const ErrorCallback& error_callback) {
836 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 837 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
837 838
838 uint32 file_id; 839 uint32_t file_id;
839 if (CachedPathToId(file_path, &file_id)) { 840 if (CachedPathToId(file_path, &file_id)) {
840 GetFileInfoSuccessCallback success_callback_wrapper = 841 GetFileInfoSuccessCallback success_callback_wrapper =
841 base::Bind(&MTPDeviceDelegateImplLinux::OnDidGetFileInfo, 842 base::Bind(&MTPDeviceDelegateImplLinux::OnDidGetFileInfo,
842 weak_ptr_factory_.GetWeakPtr(), 843 weak_ptr_factory_.GetWeakPtr(),
843 success_callback); 844 success_callback);
844 ErrorCallback error_callback_wrapper = 845 ErrorCallback error_callback_wrapper =
845 base::Bind(&MTPDeviceDelegateImplLinux::HandleDeviceFileError, 846 base::Bind(&MTPDeviceDelegateImplLinux::HandleDeviceFileError,
846 weak_ptr_factory_.GetWeakPtr(), 847 weak_ptr_factory_.GetWeakPtr(),
847 error_callback, 848 error_callback,
848 file_id); 849 file_id);
(...skipping 22 matching lines...) Expand all
871 const ErrorCallback& error_callback) { 872 const ErrorCallback& error_callback) {
872 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 873 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
873 874
874 const base::FilePath current_component = components.back(); 875 const base::FilePath current_component = components.back();
875 std::vector<base::FilePath> other_components = components; 876 std::vector<base::FilePath> other_components = components;
876 other_components.pop_back(); 877 other_components.pop_back();
877 878
878 if (other_components.empty()) { 879 if (other_components.empty()) {
879 // Either we reached the last component in the recursive case, or this is 880 // Either we reached the last component in the recursive case, or this is
880 // the non-recursive case. 881 // the non-recursive case.
881 uint32 parent_id; 882 uint32_t parent_id;
882 if (CachedPathToId(current_component.DirName(), &parent_id)) { 883 if (CachedPathToId(current_component.DirName(), &parent_id)) {
883 const base::Closure closure = 884 const base::Closure closure =
884 base::Bind(&MTPDeviceDelegateImplLinux::CreateSingleDirectory, 885 base::Bind(&MTPDeviceDelegateImplLinux::CreateSingleDirectory,
885 weak_ptr_factory_.GetWeakPtr(), current_component, 886 weak_ptr_factory_.GetWeakPtr(), current_component,
886 exclusive, success_callback, error_callback); 887 exclusive, success_callback, error_callback);
887 EnsureInitAndRunTask(PendingTaskInfo( 888 EnsureInitAndRunTask(PendingTaskInfo(
888 base::FilePath(), content::BrowserThread::IO, FROM_HERE, closure)); 889 base::FilePath(), content::BrowserThread::IO, FROM_HERE, closure));
889 } else { 890 } else {
890 error_callback.Run(base::File::FILE_ERROR_NOT_FOUND); 891 error_callback.Run(base::File::FILE_ERROR_NOT_FOUND);
891 } 892 }
892 } else { 893 } else {
893 // Ensures that parent directories are created for recursive case. 894 // Ensures that parent directories are created for recursive case.
894 uint32 directory_id; 895 uint32_t directory_id;
895 if (CachedPathToId(current_component, &directory_id)) { 896 if (CachedPathToId(current_component, &directory_id)) {
896 // Parent directory |current_component| already exists, continue creating 897 // Parent directory |current_component| already exists, continue creating
897 // directories. 898 // directories.
898 const base::Closure closure = 899 const base::Closure closure =
899 base::Bind(&MTPDeviceDelegateImplLinux::CreateDirectoryInternal, 900 base::Bind(&MTPDeviceDelegateImplLinux::CreateDirectoryInternal,
900 weak_ptr_factory_.GetWeakPtr(), other_components, 901 weak_ptr_factory_.GetWeakPtr(), other_components,
901 exclusive, success_callback, error_callback); 902 exclusive, success_callback, error_callback);
902 EnsureInitAndRunTask(PendingTaskInfo( 903 EnsureInitAndRunTask(PendingTaskInfo(
903 base::FilePath(), content::BrowserThread::IO, FROM_HERE, closure)); 904 base::FilePath(), content::BrowserThread::IO, FROM_HERE, closure));
904 } else { 905 } else {
(...skipping 22 matching lines...) Expand all
927 928
928 PendingRequestDone(); 929 PendingRequestDone();
929 } 930 }
930 931
931 void MTPDeviceDelegateImplLinux::ReadDirectoryInternal( 932 void MTPDeviceDelegateImplLinux::ReadDirectoryInternal(
932 const base::FilePath& root, 933 const base::FilePath& root,
933 const ReadDirectorySuccessCallback& success_callback, 934 const ReadDirectorySuccessCallback& success_callback,
934 const ErrorCallback& error_callback) { 935 const ErrorCallback& error_callback) {
935 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 936 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
936 937
937 uint32 dir_id; 938 uint32_t dir_id;
938 if (CachedPathToId(root, &dir_id)) { 939 if (CachedPathToId(root, &dir_id)) {
939 GetFileInfoSuccessCallback success_callback_wrapper = 940 GetFileInfoSuccessCallback success_callback_wrapper =
940 base::Bind(&MTPDeviceDelegateImplLinux::OnDidGetFileInfoToReadDirectory, 941 base::Bind(&MTPDeviceDelegateImplLinux::OnDidGetFileInfoToReadDirectory,
941 weak_ptr_factory_.GetWeakPtr(), 942 weak_ptr_factory_.GetWeakPtr(),
942 dir_id, 943 dir_id,
943 success_callback, 944 success_callback,
944 error_callback); 945 error_callback);
945 ErrorCallback error_callback_wrapper = 946 ErrorCallback error_callback_wrapper =
946 base::Bind(&MTPDeviceDelegateImplLinux::HandleDeviceFileError, 947 base::Bind(&MTPDeviceDelegateImplLinux::HandleDeviceFileError,
947 weak_ptr_factory_.GetWeakPtr(), 948 weak_ptr_factory_.GetWeakPtr(),
(...skipping 15 matching lines...) Expand all
963 PendingRequestDone(); 964 PendingRequestDone();
964 } 965 }
965 966
966 void MTPDeviceDelegateImplLinux::CreateSnapshotFileInternal( 967 void MTPDeviceDelegateImplLinux::CreateSnapshotFileInternal(
967 const base::FilePath& device_file_path, 968 const base::FilePath& device_file_path,
968 const base::FilePath& local_path, 969 const base::FilePath& local_path,
969 const CreateSnapshotFileSuccessCallback& success_callback, 970 const CreateSnapshotFileSuccessCallback& success_callback,
970 const ErrorCallback& error_callback) { 971 const ErrorCallback& error_callback) {
971 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 972 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
972 973
973 uint32 file_id; 974 uint32_t file_id;
974 if (CachedPathToId(device_file_path, &file_id)) { 975 if (CachedPathToId(device_file_path, &file_id)) {
975 scoped_ptr<SnapshotRequestInfo> request_info( 976 scoped_ptr<SnapshotRequestInfo> request_info(
976 new SnapshotRequestInfo(file_id, 977 new SnapshotRequestInfo(file_id,
977 local_path, 978 local_path,
978 success_callback, 979 success_callback,
979 error_callback)); 980 error_callback));
980 GetFileInfoSuccessCallback success_callback_wrapper = 981 GetFileInfoSuccessCallback success_callback_wrapper =
981 base::Bind( 982 base::Bind(
982 &MTPDeviceDelegateImplLinux::OnDidGetFileInfoToCreateSnapshotFile, 983 &MTPDeviceDelegateImplLinux::OnDidGetFileInfoToCreateSnapshotFile,
983 weak_ptr_factory_.GetWeakPtr(), 984 weak_ptr_factory_.GetWeakPtr(),
(...skipping 14 matching lines...) Expand all
998 FROM_HERE, 999 FROM_HERE,
999 closure)); 1000 closure));
1000 } else { 1001 } else {
1001 error_callback.Run(base::File::FILE_ERROR_NOT_FOUND); 1002 error_callback.Run(base::File::FILE_ERROR_NOT_FOUND);
1002 } 1003 }
1003 PendingRequestDone(); 1004 PendingRequestDone();
1004 } 1005 }
1005 1006
1006 void MTPDeviceDelegateImplLinux::ReadBytesInternal( 1007 void MTPDeviceDelegateImplLinux::ReadBytesInternal(
1007 const base::FilePath& device_file_path, 1008 const base::FilePath& device_file_path,
1008 net::IOBuffer* buf, int64 offset, int buf_len, 1009 net::IOBuffer* buf,
1010 int64_t offset,
1011 int buf_len,
1009 const ReadBytesSuccessCallback& success_callback, 1012 const ReadBytesSuccessCallback& success_callback,
1010 const ErrorCallback& error_callback) { 1013 const ErrorCallback& error_callback) {
1011 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1014 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1012 1015
1013 uint32 file_id; 1016 uint32_t file_id;
1014 if (CachedPathToId(device_file_path, &file_id)) { 1017 if (CachedPathToId(device_file_path, &file_id)) {
1015 ReadBytesRequest request( 1018 ReadBytesRequest request(
1016 file_id, buf, offset, buf_len, 1019 file_id, buf, offset, buf_len,
1017 base::Bind(&MTPDeviceDelegateImplLinux::OnDidReadBytes, 1020 base::Bind(&MTPDeviceDelegateImplLinux::OnDidReadBytes,
1018 weak_ptr_factory_.GetWeakPtr(), 1021 weak_ptr_factory_.GetWeakPtr(),
1019 success_callback), 1022 success_callback),
1020 base::Bind(&MTPDeviceDelegateImplLinux::HandleDeviceFileError, 1023 base::Bind(&MTPDeviceDelegateImplLinux::HandleDeviceFileError,
1021 weak_ptr_factory_.GetWeakPtr(), 1024 weak_ptr_factory_.GetWeakPtr(),
1022 error_callback, 1025 error_callback,
1023 file_id)); 1026 file_id));
(...skipping 19 matching lines...) Expand all
1043 const base::File::Info& source_file_info) { 1046 const base::File::Info& source_file_info) {
1044 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1047 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1045 1048
1046 if (source_file_info.is_directory) { 1049 if (source_file_info.is_directory) {
1047 error_callback.Run(base::File::FILE_ERROR_NOT_A_FILE); 1050 error_callback.Run(base::File::FILE_ERROR_NOT_A_FILE);
1048 return; 1051 return;
1049 } 1052 }
1050 1053
1051 if (source_file_path.DirName() == device_file_path.DirName()) { 1054 if (source_file_path.DirName() == device_file_path.DirName()) {
1052 // If a file is moved in a same directory, rename the file. 1055 // If a file is moved in a same directory, rename the file.
1053 uint32 file_id; 1056 uint32_t file_id;
1054 if (CachedPathToId(source_file_path, &file_id)) { 1057 if (CachedPathToId(source_file_path, &file_id)) {
1055 const MTPDeviceTaskHelper::RenameObjectSuccessCallback 1058 const MTPDeviceTaskHelper::RenameObjectSuccessCallback
1056 success_callback_wrapper = base::Bind( 1059 success_callback_wrapper = base::Bind(
1057 &MTPDeviceDelegateImplLinux::OnDidMoveFileLocalWithRename, 1060 &MTPDeviceDelegateImplLinux::OnDidMoveFileLocalWithRename,
1058 weak_ptr_factory_.GetWeakPtr(), success_callback, 1061 weak_ptr_factory_.GetWeakPtr(), success_callback,
1059 source_file_path, file_id); 1062 source_file_path, file_id);
1060 const MTPDeviceTaskHelper::ErrorCallback error_callback_wrapper = 1063 const MTPDeviceTaskHelper::ErrorCallback error_callback_wrapper =
1061 base::Bind(&MTPDeviceDelegateImplLinux::HandleDeviceFileError, 1064 base::Bind(&MTPDeviceDelegateImplLinux::HandleDeviceFileError,
1062 weak_ptr_factory_.GetWeakPtr(), error_callback, file_id); 1065 weak_ptr_factory_.GetWeakPtr(), error_callback, file_id);
1063 const base::Closure closure = 1066 const base::Closure closure =
(...skipping 26 matching lines...) Expand all
1090 const ErrorCallback& error_callback, 1093 const ErrorCallback& error_callback,
1091 const std::pair<int, base::File::Error>& open_fd_result) { 1094 const std::pair<int, base::File::Error>& open_fd_result) {
1092 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1095 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1093 1096
1094 if (open_fd_result.second != base::File::FILE_OK) { 1097 if (open_fd_result.second != base::File::FILE_OK) {
1095 error_callback.Run(open_fd_result.second); 1098 error_callback.Run(open_fd_result.second);
1096 return; 1099 return;
1097 } 1100 }
1098 1101
1099 const int source_file_descriptor = open_fd_result.first; 1102 const int source_file_descriptor = open_fd_result.first;
1100 uint32 parent_id; 1103 uint32_t parent_id;
1101 if (CachedPathToId(device_file_path.DirName(), &parent_id)) { 1104 if (CachedPathToId(device_file_path.DirName(), &parent_id)) {
1102 CopyFileFromLocalSuccessCallback success_callback_wrapper = 1105 CopyFileFromLocalSuccessCallback success_callback_wrapper =
1103 base::Bind(&MTPDeviceDelegateImplLinux::OnDidCopyFileFromLocal, 1106 base::Bind(&MTPDeviceDelegateImplLinux::OnDidCopyFileFromLocal,
1104 weak_ptr_factory_.GetWeakPtr(), success_callback, 1107 weak_ptr_factory_.GetWeakPtr(), success_callback,
1105 device_file_path, source_file_descriptor); 1108 device_file_path, source_file_descriptor);
1106 1109
1107 ErrorCallback error_callback_wrapper = base::Bind( 1110 ErrorCallback error_callback_wrapper = base::Bind(
1108 &MTPDeviceDelegateImplLinux::HandleCopyFileFromLocalError, 1111 &MTPDeviceDelegateImplLinux::HandleCopyFileFromLocalError,
1109 weak_ptr_factory_.GetWeakPtr(), error_callback, source_file_descriptor); 1112 weak_ptr_factory_.GetWeakPtr(), error_callback, source_file_descriptor);
1110 1113
(...skipping 17 matching lines...) Expand all
1128 void MTPDeviceDelegateImplLinux::DeleteFileInternal( 1131 void MTPDeviceDelegateImplLinux::DeleteFileInternal(
1129 const base::FilePath& file_path, 1132 const base::FilePath& file_path,
1130 const DeleteFileSuccessCallback& success_callback, 1133 const DeleteFileSuccessCallback& success_callback,
1131 const ErrorCallback& error_callback, 1134 const ErrorCallback& error_callback,
1132 const base::File::Info& file_info) { 1135 const base::File::Info& file_info) {
1133 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1136 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1134 1137
1135 if (file_info.is_directory) { 1138 if (file_info.is_directory) {
1136 error_callback.Run(base::File::FILE_ERROR_NOT_A_FILE); 1139 error_callback.Run(base::File::FILE_ERROR_NOT_A_FILE);
1137 } else { 1140 } else {
1138 uint32 file_id; 1141 uint32_t file_id;
1139 if (CachedPathToId(file_path, &file_id)) 1142 if (CachedPathToId(file_path, &file_id))
1140 RunDeleteObjectOnUIThread(file_path, file_id, success_callback, 1143 RunDeleteObjectOnUIThread(file_path, file_id, success_callback,
1141 error_callback); 1144 error_callback);
1142 else 1145 else
1143 error_callback.Run(base::File::FILE_ERROR_NOT_FOUND); 1146 error_callback.Run(base::File::FILE_ERROR_NOT_FOUND);
1144 } 1147 }
1145 } 1148 }
1146 1149
1147 void MTPDeviceDelegateImplLinux::DeleteDirectoryInternal( 1150 void MTPDeviceDelegateImplLinux::DeleteDirectoryInternal(
1148 const base::FilePath& file_path, 1151 const base::FilePath& file_path,
1149 const DeleteDirectorySuccessCallback& success_callback, 1152 const DeleteDirectorySuccessCallback& success_callback,
1150 const ErrorCallback& error_callback, 1153 const ErrorCallback& error_callback,
1151 const base::File::Info& file_info) { 1154 const base::File::Info& file_info) {
1152 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1155 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1153 1156
1154 if (!file_info.is_directory) { 1157 if (!file_info.is_directory) {
1155 error_callback.Run(base::File::FILE_ERROR_NOT_A_DIRECTORY); 1158 error_callback.Run(base::File::FILE_ERROR_NOT_A_DIRECTORY);
1156 return; 1159 return;
1157 } 1160 }
1158 1161
1159 uint32 directory_id; 1162 uint32_t directory_id;
1160 if (!CachedPathToId(file_path, &directory_id)) { 1163 if (!CachedPathToId(file_path, &directory_id)) {
1161 error_callback.Run(base::File::FILE_ERROR_NOT_FOUND); 1164 error_callback.Run(base::File::FILE_ERROR_NOT_FOUND);
1162 return; 1165 return;
1163 } 1166 }
1164 1167
1165 // Checks the cache first. If it has children in cache, the directory cannot 1168 // Checks the cache first. If it has children in cache, the directory cannot
1166 // be empty. 1169 // be empty.
1167 FileIdToMTPFileNodeMap::const_iterator it = 1170 FileIdToMTPFileNodeMap::const_iterator it =
1168 file_id_to_node_map_.find(directory_id); 1171 file_id_to_node_map_.find(directory_id);
1169 if (it != file_id_to_node_map_.end() && it->second->HasChildren()) { 1172 if (it != file_id_to_node_map_.end() && it->second->HasChildren()) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 const base::Closure closure = 1230 const base::Closure closure =
1228 base::Bind(&MTPDeviceDelegateImplLinux::CreateDirectoryInternal, 1231 base::Bind(&MTPDeviceDelegateImplLinux::CreateDirectoryInternal,
1229 weak_ptr_factory_.GetWeakPtr(), components, exclusive, 1232 weak_ptr_factory_.GetWeakPtr(), components, exclusive,
1230 success_callback, error_callback); 1233 success_callback, error_callback);
1231 EnsureInitAndRunTask(PendingTaskInfo( 1234 EnsureInitAndRunTask(PendingTaskInfo(
1232 base::FilePath(), content::BrowserThread::IO, FROM_HERE, closure)); 1235 base::FilePath(), content::BrowserThread::IO, FROM_HERE, closure));
1233 } 1236 }
1234 1237
1235 void MTPDeviceDelegateImplLinux::OnDidReadDirectoryToDeleteDirectory( 1238 void MTPDeviceDelegateImplLinux::OnDidReadDirectoryToDeleteDirectory(
1236 const base::FilePath& directory_path, 1239 const base::FilePath& directory_path,
1237 const uint32 directory_id, 1240 const uint32_t directory_id,
1238 const DeleteDirectorySuccessCallback& success_callback, 1241 const DeleteDirectorySuccessCallback& success_callback,
1239 const ErrorCallback& error_callback, 1242 const ErrorCallback& error_callback,
1240 const MTPDeviceTaskHelper::MTPEntries& entries, 1243 const MTPDeviceTaskHelper::MTPEntries& entries,
1241 const bool has_more) { 1244 const bool has_more) {
1242 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1245 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1243 DCHECK(!has_more); 1246 DCHECK(!has_more);
1244 1247
1245 if (entries.size() > 0) { 1248 if (entries.size() > 0) {
1246 error_callback.Run(base::File::FILE_ERROR_NOT_EMPTY); 1249 error_callback.Run(base::File::FILE_ERROR_NOT_EMPTY);
1247 } else { 1250 } else {
1248 RunDeleteObjectOnUIThread(directory_path, directory_id, success_callback, 1251 RunDeleteObjectOnUIThread(directory_path, directory_id, success_callback,
1249 error_callback); 1252 error_callback);
1250 } 1253 }
1251 1254
1252 PendingRequestDone(); 1255 PendingRequestDone();
1253 } 1256 }
1254 1257
1255 void MTPDeviceDelegateImplLinux::RunDeleteObjectOnUIThread( 1258 void MTPDeviceDelegateImplLinux::RunDeleteObjectOnUIThread(
1256 const base::FilePath& object_path, 1259 const base::FilePath& object_path,
1257 const uint32 object_id, 1260 const uint32_t object_id,
1258 const DeleteObjectSuccessCallback& success_callback, 1261 const DeleteObjectSuccessCallback& success_callback,
1259 const ErrorCallback& error_callback) { 1262 const ErrorCallback& error_callback) {
1260 const MTPDeviceTaskHelper::DeleteObjectSuccessCallback 1263 const MTPDeviceTaskHelper::DeleteObjectSuccessCallback
1261 success_callback_wrapper = 1264 success_callback_wrapper =
1262 base::Bind(&MTPDeviceDelegateImplLinux::OnDidDeleteObject, 1265 base::Bind(&MTPDeviceDelegateImplLinux::OnDidDeleteObject,
1263 weak_ptr_factory_.GetWeakPtr(), object_path, object_id, 1266 weak_ptr_factory_.GetWeakPtr(), object_path, object_id,
1264 success_callback); 1267 success_callback);
1265 1268
1266 const MTPDeviceTaskHelper::ErrorCallback error_callback_wrapper = 1269 const MTPDeviceTaskHelper::ErrorCallback error_callback_wrapper =
1267 base::Bind(&MTPDeviceDelegateImplLinux::HandleDeleteFileOrDirectoryError, 1270 base::Bind(&MTPDeviceDelegateImplLinux::HandleDeleteFileOrDirectoryError,
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 const CreateDirectorySuccessCallback& success_callback, 1402 const CreateDirectorySuccessCallback& success_callback,
1400 const ErrorCallback& error_callback, 1403 const ErrorCallback& error_callback,
1401 const base::File::Error error) { 1404 const base::File::Error error) {
1402 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1405 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1403 1406
1404 if (error != base::File::FILE_ERROR_NOT_FOUND) { 1407 if (error != base::File::FILE_ERROR_NOT_FOUND) {
1405 error_callback.Run(base::File::FILE_ERROR_NOT_FOUND); 1408 error_callback.Run(base::File::FILE_ERROR_NOT_FOUND);
1406 return; 1409 return;
1407 } 1410 }
1408 1411
1409 uint32 parent_id; 1412 uint32_t parent_id;
1410 if (!CachedPathToId(directory_path.DirName(), &parent_id)) { 1413 if (!CachedPathToId(directory_path.DirName(), &parent_id)) {
1411 error_callback.Run(base::File::FILE_ERROR_NOT_FOUND); 1414 error_callback.Run(base::File::FILE_ERROR_NOT_FOUND);
1412 return; 1415 return;
1413 } 1416 }
1414 1417
1415 const MTPDeviceTaskHelper::CreateDirectorySuccessCallback 1418 const MTPDeviceTaskHelper::CreateDirectorySuccessCallback
1416 success_callback_wrapper = base::Bind( 1419 success_callback_wrapper = base::Bind(
1417 &MTPDeviceDelegateImplLinux::OnDidCreateSingleDirectory, 1420 &MTPDeviceDelegateImplLinux::OnDidCreateSingleDirectory,
1418 weak_ptr_factory_.GetWeakPtr(), directory_path, success_callback); 1421 weak_ptr_factory_.GetWeakPtr(), directory_path, success_callback);
1419 const MTPDeviceTaskHelper::ErrorCallback error_callback_wrapper = 1422 const MTPDeviceTaskHelper::ErrorCallback error_callback_wrapper =
1420 base::Bind(&MTPDeviceDelegateImplLinux::HandleDeviceFileError, 1423 base::Bind(&MTPDeviceDelegateImplLinux::HandleDeviceFileError,
1421 weak_ptr_factory_.GetWeakPtr(), error_callback, parent_id); 1424 weak_ptr_factory_.GetWeakPtr(), error_callback, parent_id);
1422 const base::Closure closure = 1425 const base::Closure closure =
1423 base::Bind(&CreateDirectoryOnUIThread, storage_name_, read_only_, 1426 base::Bind(&CreateDirectoryOnUIThread, storage_name_, read_only_,
1424 parent_id, directory_path.BaseName().value(), 1427 parent_id, directory_path.BaseName().value(),
1425 success_callback_wrapper, error_callback_wrapper); 1428 success_callback_wrapper, error_callback_wrapper);
1426 EnsureInitAndRunTask(PendingTaskInfo( 1429 EnsureInitAndRunTask(PendingTaskInfo(
1427 base::FilePath(), content::BrowserThread::UI, FROM_HERE, closure)); 1430 base::FilePath(), content::BrowserThread::UI, FROM_HERE, closure));
1428 } 1431 }
1429 1432
1430 void MTPDeviceDelegateImplLinux::OnDidGetFileInfoToReadDirectory( 1433 void MTPDeviceDelegateImplLinux::OnDidGetFileInfoToReadDirectory(
1431 uint32 dir_id, 1434 uint32_t dir_id,
1432 const ReadDirectorySuccessCallback& success_callback, 1435 const ReadDirectorySuccessCallback& success_callback,
1433 const ErrorCallback& error_callback, 1436 const ErrorCallback& error_callback,
1434 const base::File::Info& file_info) { 1437 const base::File::Info& file_info) {
1435 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1438 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1436 DCHECK(task_in_progress_); 1439 DCHECK(task_in_progress_);
1437 if (!file_info.is_directory) { 1440 if (!file_info.is_directory) {
1438 return HandleDeviceFileError(error_callback, 1441 return HandleDeviceFileError(error_callback,
1439 dir_id, 1442 dir_id,
1440 base::File::FILE_ERROR_NOT_A_DIRECTORY); 1443 base::File::FILE_ERROR_NOT_A_DIRECTORY);
1441 } 1444 }
(...skipping 13 matching lines...) Expand all
1455 void MTPDeviceDelegateImplLinux::OnDidGetFileInfoToCreateSnapshotFile( 1458 void MTPDeviceDelegateImplLinux::OnDidGetFileInfoToCreateSnapshotFile(
1456 scoped_ptr<SnapshotRequestInfo> snapshot_request_info, 1459 scoped_ptr<SnapshotRequestInfo> snapshot_request_info,
1457 const base::File::Info& file_info) { 1460 const base::File::Info& file_info) {
1458 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1461 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1459 DCHECK(!current_snapshot_request_info_.get()); 1462 DCHECK(!current_snapshot_request_info_.get());
1460 DCHECK(snapshot_request_info.get()); 1463 DCHECK(snapshot_request_info.get());
1461 DCHECK(task_in_progress_); 1464 DCHECK(task_in_progress_);
1462 base::File::Error error = base::File::FILE_OK; 1465 base::File::Error error = base::File::FILE_OK;
1463 if (file_info.is_directory) 1466 if (file_info.is_directory)
1464 error = base::File::FILE_ERROR_NOT_A_FILE; 1467 error = base::File::FILE_ERROR_NOT_A_FILE;
1465 else if (file_info.size < 0 || file_info.size > kuint32max) 1468 else if (file_info.size < 0 ||
1469 file_info.size > std::numeric_limits<uint32_t>::max())
1466 error = base::File::FILE_ERROR_FAILED; 1470 error = base::File::FILE_ERROR_FAILED;
1467 1471
1468 if (error != base::File::FILE_OK) 1472 if (error != base::File::FILE_OK)
1469 return HandleDeviceFileError(snapshot_request_info->error_callback, 1473 return HandleDeviceFileError(snapshot_request_info->error_callback,
1470 snapshot_request_info->file_id, 1474 snapshot_request_info->file_id,
1471 error); 1475 error);
1472 1476
1473 base::File::Info snapshot_file_info(file_info); 1477 base::File::Info snapshot_file_info(file_info);
1474 // Modify the last modified time to null. This prevents the time stamp 1478 // Modify the last modified time to null. This prevents the time stamp
1475 // verfication in LocalFileStreamReader. 1479 // verfication in LocalFileStreamReader.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 1557
1554 void MTPDeviceDelegateImplLinux::OnCreateParentDirectoryErrorToCreateDirectory( 1558 void MTPDeviceDelegateImplLinux::OnCreateParentDirectoryErrorToCreateDirectory(
1555 const ErrorCallback& callback, 1559 const ErrorCallback& callback,
1556 const base::File::Error error) { 1560 const base::File::Error error) {
1557 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1561 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1558 1562
1559 callback.Run(base::File::FILE_ERROR_FAILED); 1563 callback.Run(base::File::FILE_ERROR_FAILED);
1560 } 1564 }
1561 1565
1562 void MTPDeviceDelegateImplLinux::OnDidReadDirectory( 1566 void MTPDeviceDelegateImplLinux::OnDidReadDirectory(
1563 uint32 dir_id, 1567 uint32_t dir_id,
1564 const ReadDirectorySuccessCallback& success_callback, 1568 const ReadDirectorySuccessCallback& success_callback,
1565 const MTPDeviceTaskHelper::MTPEntries& mtp_entries, 1569 const MTPDeviceTaskHelper::MTPEntries& mtp_entries,
1566 bool has_more) { 1570 bool has_more) {
1567 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1571 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1568 1572
1569 FileIdToMTPFileNodeMap::iterator it = file_id_to_node_map_.find(dir_id); 1573 FileIdToMTPFileNodeMap::iterator it = file_id_to_node_map_.find(dir_id);
1570 DCHECK(it != file_id_to_node_map_.end()); 1574 DCHECK(it != file_id_to_node_map_.end());
1571 MTPFileNode* dir_node = it->second; 1575 MTPFileNode* dir_node = it->second;
1572 1576
1573 // Traverse the MTPFileNode tree to reconstuct the full path for |dir_id|. 1577 // Traverse the MTPFileNode tree to reconstuct the full path for |dir_id|.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 const base::FilePath& temporary_file_path) { 1714 const base::FilePath& temporary_file_path) {
1711 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1715 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1712 1716
1713 DeleteTemporaryFile(temporary_file_path); 1717 DeleteTemporaryFile(temporary_file_path);
1714 success_callback.Run(); 1718 success_callback.Run();
1715 } 1719 }
1716 1720
1717 void MTPDeviceDelegateImplLinux::OnDidMoveFileLocalWithRename( 1721 void MTPDeviceDelegateImplLinux::OnDidMoveFileLocalWithRename(
1718 const MoveFileLocalSuccessCallback& success_callback, 1722 const MoveFileLocalSuccessCallback& success_callback,
1719 const base::FilePath& source_file_path, 1723 const base::FilePath& source_file_path,
1720 const uint32 file_id) { 1724 const uint32_t file_id) {
1721 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1725 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1722 1726
1723 EvictCachedPathToId(file_id); 1727 EvictCachedPathToId(file_id);
1724 success_callback.Run(); 1728 success_callback.Run();
1725 NotifyFileChange(source_file_path, 1729 NotifyFileChange(source_file_path,
1726 storage::WatcherManager::ChangeType::DELETED); 1730 storage::WatcherManager::ChangeType::DELETED);
1727 NotifyFileChange(source_file_path.DirName(), 1731 NotifyFileChange(source_file_path.DirName(),
1728 storage::WatcherManager::ChangeType::CHANGED); 1732 storage::WatcherManager::ChangeType::CHANGED);
1729 PendingRequestDone(); 1733 PendingRequestDone();
1730 } 1734 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 1772
1769 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, 1773 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
1770 closure); 1774 closure);
1771 1775
1772 error_callback.Run(error); 1776 error_callback.Run(error);
1773 PendingRequestDone(); 1777 PendingRequestDone();
1774 } 1778 }
1775 1779
1776 void MTPDeviceDelegateImplLinux::OnDidDeleteObject( 1780 void MTPDeviceDelegateImplLinux::OnDidDeleteObject(
1777 const base::FilePath& object_path, 1781 const base::FilePath& object_path,
1778 const uint32 object_id, 1782 const uint32_t object_id,
1779 const DeleteObjectSuccessCallback success_callback) { 1783 const DeleteObjectSuccessCallback success_callback) {
1780 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1784 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1781 1785
1782 EvictCachedPathToId(object_id); 1786 EvictCachedPathToId(object_id);
1783 success_callback.Run(); 1787 success_callback.Run();
1784 NotifyFileChange(object_path, storage::WatcherManager::ChangeType::DELETED); 1788 NotifyFileChange(object_path, storage::WatcherManager::ChangeType::DELETED);
1785 NotifyFileChange(object_path.DirName(), 1789 NotifyFileChange(object_path.DirName(),
1786 storage::WatcherManager::ChangeType::CHANGED); 1790 storage::WatcherManager::ChangeType::CHANGED);
1787 PendingRequestDone(); 1791 PendingRequestDone();
1788 } 1792 }
1789 1793
1790 void MTPDeviceDelegateImplLinux::HandleDeleteFileOrDirectoryError( 1794 void MTPDeviceDelegateImplLinux::HandleDeleteFileOrDirectoryError(
1791 const ErrorCallback& error_callback, 1795 const ErrorCallback& error_callback,
1792 base::File::Error error) { 1796 base::File::Error error) {
1793 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1797 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1794 1798
1795 error_callback.Run(error); 1799 error_callback.Run(error);
1796 PendingRequestDone(); 1800 PendingRequestDone();
1797 } 1801 }
1798 1802
1799 void MTPDeviceDelegateImplLinux::HandleDeviceFileError( 1803 void MTPDeviceDelegateImplLinux::HandleDeviceFileError(
1800 const ErrorCallback& error_callback, 1804 const ErrorCallback& error_callback,
1801 uint32 file_id, 1805 uint32_t file_id,
1802 base::File::Error error) { 1806 base::File::Error error) {
1803 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1807 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1804 1808
1805 EvictCachedPathToId(file_id); 1809 EvictCachedPathToId(file_id);
1806 error_callback.Run(error); 1810 error_callback.Run(error);
1807 PendingRequestDone(); 1811 PendingRequestDone();
1808 } 1812 }
1809 1813
1810 base::FilePath MTPDeviceDelegateImplLinux::NextUncachedPathComponent( 1814 base::FilePath MTPDeviceDelegateImplLinux::NextUncachedPathComponent(
1811 const base::FilePath& path, 1815 const base::FilePath& path,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1848 ReadDirectorySuccessCallback success_callback = 1852 ReadDirectorySuccessCallback success_callback =
1849 base::Bind(&MTPDeviceDelegateImplLinux::OnDidFillFileCache, 1853 base::Bind(&MTPDeviceDelegateImplLinux::OnDidFillFileCache,
1850 weak_ptr_factory_.GetWeakPtr(), 1854 weak_ptr_factory_.GetWeakPtr(),
1851 uncached_path); 1855 uncached_path);
1852 ErrorCallback error_callback = 1856 ErrorCallback error_callback =
1853 base::Bind(&MTPDeviceDelegateImplLinux::OnFillFileCacheFailed, 1857 base::Bind(&MTPDeviceDelegateImplLinux::OnFillFileCacheFailed,
1854 weak_ptr_factory_.GetWeakPtr()); 1858 weak_ptr_factory_.GetWeakPtr());
1855 ReadDirectoryInternal(uncached_path, success_callback, error_callback); 1859 ReadDirectoryInternal(uncached_path, success_callback, error_callback);
1856 } 1860 }
1857 1861
1858
1859 bool MTPDeviceDelegateImplLinux::CachedPathToId(const base::FilePath& path, 1862 bool MTPDeviceDelegateImplLinux::CachedPathToId(const base::FilePath& path,
1860 uint32* id) const { 1863 uint32_t* id) const {
1861 DCHECK(id); 1864 DCHECK(id);
1862 1865
1863 std::string device_relpath = GetDeviceRelativePath(device_path_, path); 1866 std::string device_relpath = GetDeviceRelativePath(device_path_, path);
1864 if (device_relpath.empty()) 1867 if (device_relpath.empty())
1865 return false; 1868 return false;
1866 std::vector<std::string> device_relpath_components; 1869 std::vector<std::string> device_relpath_components;
1867 if (device_relpath != kRootPath) { 1870 if (device_relpath != kRootPath) {
1868 device_relpath_components = base::SplitString( 1871 device_relpath_components = base::SplitString(
1869 device_relpath, "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 1872 device_relpath, "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
1870 } 1873 }
1871 const MTPFileNode* current_node = root_node_.get(); 1874 const MTPFileNode* current_node = root_node_.get();
1872 for (size_t i = 0; i < device_relpath_components.size(); ++i) { 1875 for (size_t i = 0; i < device_relpath_components.size(); ++i) {
1873 current_node = current_node->GetChild(device_relpath_components[i]); 1876 current_node = current_node->GetChild(device_relpath_components[i]);
1874 if (!current_node) 1877 if (!current_node)
1875 return false; 1878 return false;
1876 } 1879 }
1877 *id = current_node->file_id(); 1880 *id = current_node->file_id();
1878 return true; 1881 return true;
1879 } 1882 }
1880 1883
1881 void MTPDeviceDelegateImplLinux::EvictCachedPathToId(const uint32 id) { 1884 void MTPDeviceDelegateImplLinux::EvictCachedPathToId(const uint32_t id) {
1882 FileIdToMTPFileNodeMap::iterator it = file_id_to_node_map_.find(id); 1885 FileIdToMTPFileNodeMap::iterator it = file_id_to_node_map_.find(id);
1883 if (it != file_id_to_node_map_.end()) { 1886 if (it != file_id_to_node_map_.end()) {
1884 DCHECK(!it->second->HasChildren()); 1887 DCHECK(!it->second->HasChildren());
1885 MTPFileNode* parent = it->second->parent(); 1888 MTPFileNode* parent = it->second->parent();
1886 if (parent) { 1889 if (parent) {
1887 const bool ret = parent->DeleteChild(id); 1890 const bool ret = parent->DeleteChild(id);
1888 DCHECK(ret); 1891 DCHECK(ret);
1889 } 1892 }
1890 } 1893 }
1891 } 1894 }
1892 1895
1893 void CreateMTPDeviceAsyncDelegate( 1896 void CreateMTPDeviceAsyncDelegate(
1894 const std::string& device_location, 1897 const std::string& device_location,
1895 const bool read_only, 1898 const bool read_only,
1896 const CreateMTPDeviceAsyncDelegateCallback& callback) { 1899 const CreateMTPDeviceAsyncDelegateCallback& callback) {
1897 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1900 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1898 callback.Run(new MTPDeviceDelegateImplLinux(device_location, read_only)); 1901 callback.Run(new MTPDeviceDelegateImplLinux(device_location, read_only));
1899 } 1902 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698