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

Side by Side Diff: chrome/browser/media_galleries/chromeos/mtp_device_delegate_impl_chromeos.cc

Issue 2606563002: Remove base::ScopedPtrHashMap from chrome/browser/media_galleries/. (Closed)
Patch Set: rev Created 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/chromeos/mtp_device_delegate_impl_chrom eos.h" 5 #include "chrome/browser/media_galleries/chromeos/mtp_device_delegate_impl_chrom eos.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <limits> 12 #include <limits>
13 #include <unordered_map>
13 #include <utility> 14 #include <utility>
14 #include <vector> 15 #include <vector>
15 16
16 #include "base/bind.h" 17 #include "base/bind.h"
17 #include "base/files/file_util.h" 18 #include "base/files/file_util.h"
18 #include "base/macros.h" 19 #include "base/macros.h"
19 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
20 #include "base/numerics/safe_conversions.h" 21 #include "base/numerics/safe_conversions.h"
21 #include "base/posix/eintr_wrapper.h" 22 #include "base/posix/eintr_wrapper.h"
22 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 bool DeleteChild(uint32_t file_id); 397 bool DeleteChild(uint32_t file_id);
397 398
398 bool HasChildren() const; 399 bool HasChildren() const;
399 400
400 uint32_t file_id() const { return file_id_; } 401 uint32_t file_id() const { return file_id_; }
401 const std::string& file_name() const { return file_name_; } 402 const std::string& file_name() const { return file_name_; }
402 MTPFileNode* parent() { return parent_; } 403 MTPFileNode* parent() { return parent_; }
403 404
404 private: 405 private:
405 // Container for holding a node's children. 406 // Container for holding a node's children.
406 typedef base::ScopedPtrHashMap<std::string, std::unique_ptr<MTPFileNode>> 407 using ChildNodes =
407 ChildNodes; 408 std::unordered_map<std::string, std::unique_ptr<MTPFileNode>>;
408 409
409 const uint32_t file_id_; 410 const uint32_t file_id_;
410 const std::string file_name_; 411 const std::string file_name_;
411 412
412 ChildNodes children_; 413 ChildNodes children_;
413 MTPFileNode* const parent_; 414 MTPFileNode* const parent_;
414 FileIdToMTPFileNodeMap* file_id_to_node_map_; 415 FileIdToMTPFileNodeMap* file_id_to_node_map_;
415 416
416 DISALLOW_COPY_AND_ASSIGN(MTPFileNode); 417 DISALLOW_COPY_AND_ASSIGN(MTPFileNode);
417 }; 418 };
(...skipping 16 matching lines...) Expand all
434 MTPDeviceDelegateImplLinux::MTPFileNode::~MTPFileNode() { 435 MTPDeviceDelegateImplLinux::MTPFileNode::~MTPFileNode() {
435 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 436 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
436 size_t erased = file_id_to_node_map_->erase(file_id_); 437 size_t erased = file_id_to_node_map_->erase(file_id_);
437 DCHECK_EQ(1U, erased); 438 DCHECK_EQ(1U, erased);
438 } 439 }
439 440
440 const MTPDeviceDelegateImplLinux::MTPFileNode* 441 const MTPDeviceDelegateImplLinux::MTPFileNode*
441 MTPDeviceDelegateImplLinux::MTPFileNode::GetChild( 442 MTPDeviceDelegateImplLinux::MTPFileNode::GetChild(
442 const std::string& name) const { 443 const std::string& name) const {
443 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 444 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
444 return children_.get(name); 445 auto it = children_.find(name);
446 if (it == children_.end())
447 return nullptr;
448 return it->second.get();
445 } 449 }
446 450
447 void MTPDeviceDelegateImplLinux::MTPFileNode::EnsureChildExists( 451 void MTPDeviceDelegateImplLinux::MTPFileNode::EnsureChildExists(
448 const std::string& name, 452 const std::string& name,
449 uint32_t id) { 453 uint32_t id) {
450 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 454 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
451 const MTPFileNode* child = GetChild(name); 455 const MTPFileNode* child = GetChild(name);
452 if (child && child->file_id() == id) 456 if (child && child->file_id() == id)
453 return; 457 return;
454 458
455 children_.set(name, base::WrapUnique(new MTPFileNode(id, name, this, 459 children_[name] =
456 file_id_to_node_map_))); 460 base::MakeUnique<MTPFileNode>(id, name, this, file_id_to_node_map_);
457 } 461 }
458 462
459 void MTPDeviceDelegateImplLinux::MTPFileNode::ClearNonexistentChildren( 463 void MTPDeviceDelegateImplLinux::MTPFileNode::ClearNonexistentChildren(
460 const std::set<std::string>& children_to_keep) { 464 const std::set<std::string>& children_to_keep) {
461 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 465 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
462 std::set<std::string> children_to_erase; 466 std::vector<std::string> children_to_erase;
463 for (ChildNodes::const_iterator it = children_.begin(); 467 for (const auto& child : children_) {
464 it != children_.end(); ++it) { 468 if (base::ContainsKey(children_to_keep, child.first))
465 if (base::ContainsKey(children_to_keep, it->first))
466 continue; 469 continue;
467 children_to_erase.insert(it->first); 470 children_to_erase.push_back(child.first);
468 } 471 }
469 for (std::set<std::string>::iterator it = children_to_erase.begin(); 472 for (const auto& child : children_to_erase)
470 it != children_to_erase.end(); ++it) { 473 children_.erase(child);
471 children_.take_and_erase(*it);
472 }
473 } 474 }
474 475
475 bool MTPDeviceDelegateImplLinux::MTPFileNode::DeleteChild(uint32_t file_id) { 476 bool MTPDeviceDelegateImplLinux::MTPFileNode::DeleteChild(uint32_t file_id) {
476 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 477 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
477 for (ChildNodes::iterator it = children_.begin(); 478 for (auto it = children_.begin(); it != children_.end(); ++it) {
478 it != children_.end(); ++it) {
479 if (it->second->file_id() == file_id) { 479 if (it->second->file_id() == file_id) {
480 DCHECK(!it->second->HasChildren()); 480 DCHECK(!it->second->HasChildren());
481 children_.erase(it); 481 children_.erase(it);
482 return true; 482 return true;
483 } 483 }
484 } 484 }
485 return false; 485 return false;
486 } 486 }
487 487
488 bool MTPDeviceDelegateImplLinux::MTPFileNode::HasChildren() const { 488 bool MTPDeviceDelegateImplLinux::MTPFileNode::HasChildren() const {
(...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 } 1891 }
1892 } 1892 }
1893 1893
1894 void CreateMTPDeviceAsyncDelegate( 1894 void CreateMTPDeviceAsyncDelegate(
1895 const std::string& device_location, 1895 const std::string& device_location,
1896 const bool read_only, 1896 const bool read_only,
1897 const CreateMTPDeviceAsyncDelegateCallback& callback) { 1897 const CreateMTPDeviceAsyncDelegateCallback& callback) {
1898 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1898 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1899 callback.Run(new MTPDeviceDelegateImplLinux(device_location, read_only)); 1899 callback.Run(new MTPDeviceDelegateImplLinux(device_location, read_only));
1900 } 1900 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698