Commit a50a4194 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Modernize MTPDeviceDelegateImplLinux code.

- Change CachedPathToId() to return base::Optional.
- Use more C++11 features.
- Use more early returns and mark things const when it makes sense.

Change-Id: I8f8cc6d5aac232d526b18abf6eea347a3161ee5d
Reviewed-on: https://chromium-review.googlesource.com/1193930Reviewed-by: default avatarAnand Mistry <amistry@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587357}
parent 199f6e37
......@@ -11,6 +11,8 @@
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "base/callback.h"
#include "base/containers/circular_deque.h"
......@@ -18,6 +20,7 @@
#include "base/location.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "chrome/browser/media_galleries/chromeos/mtp_device_task_helper.h"
#include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h"
#include "content/public/browser/browser_thread.h"
......@@ -456,27 +459,26 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate {
// Fills the file cache using the results from NextUncachedPathComponent().
void FillFileCache(const base::FilePath& uncached_path);
// Given a full path, if it exists in the cache, writes the file's id to |id|
// and return true.
bool CachedPathToId(const base::FilePath& path, uint32_t* id) const;
// Given a full path, if it exists in the cache, return the id.
base::Optional<uint32_t> CachedPathToId(const base::FilePath& path) const;
// Evict the cache of |id|.
void EvictCachedPathToId(const uint32_t id);
void EvictCachedPathToId(uint32_t id);
// MTP device initialization state.
InitializationState init_state_;
InitializationState init_state_ = UNINITIALIZED;
// Used to make sure only one task is in progress at any time.
// Otherwise the browser will try to send too many requests at once and
// overload the device.
bool task_in_progress_;
bool task_in_progress_ = false;
// Registered file system device path. This path does not
// correspond to a real device path (e.g. "/usb:2,2:81282").
const base::FilePath device_path_;
// MTP device storage name (e.g. "usb:2,2:81282").
std::string storage_name_;
const std::string storage_name_;
// Mode for opening storage.
const bool read_only_;
......@@ -505,7 +507,7 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate {
// The root node of a tree-structure that caches the directory structure of
// the MTP device.
std::unique_ptr<MTPFileNode> root_node_;
const std::unique_ptr<MTPFileNode> root_node_;
// A list of child nodes encountered while a ReadDirectory operation, which
// can return results over multiple callbacks, is in progress.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment