| Index: chrome/browser/chromeos/file_system_provider/throttled_file_system.h
|
| diff --git a/chrome/browser/chromeos/file_system_provider/fake_provided_file_system.h b/chrome/browser/chromeos/file_system_provider/throttled_file_system.h
|
| similarity index 54%
|
| copy from chrome/browser/chromeos/file_system_provider/fake_provided_file_system.h
|
| copy to chrome/browser/chromeos/file_system_provider/throttled_file_system.h
|
| index ccaf2523c949b0dc2c02a7aeca34937cda2925af..2866c9ff666864d6f283b81f6dc6d1d6c6ac7f42 100644
|
| --- a/chrome/browser/chromeos/file_system_provider/fake_provided_file_system.h
|
| +++ b/chrome/browser/chromeos/file_system_provider/throttled_file_system.h
|
| @@ -1,90 +1,55 @@
|
| -// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTEM_H_
|
| -#define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTEM_H_
|
| +#ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_THROTTLED_FILE_SYSTEM_H_
|
| +#define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_THROTTLED_FILE_SYSTEM_H_
|
|
|
| -#include <map>
|
| +#include <set>
|
| #include <string>
|
| -#include <vector>
|
|
|
| -#include "base/callback.h"
|
| -#include "base/files/file.h"
|
| -#include "base/memory/linked_ptr.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| #include "base/memory/weak_ptr.h"
|
| -#include "base/observer_list.h"
|
| -#include "base/task/cancelable_task_tracker.h"
|
| +#include "chrome/browser/chromeos/file_system_provider/abort_callback.h"
|
| +#include "chrome/browser/chromeos/file_system_provider/provided_file_system.h"
|
| #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
|
| #include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
|
| #include "chrome/browser/chromeos/file_system_provider/provided_file_system_observer.h"
|
| -#include "chrome/browser/chromeos/file_system_provider/watcher.h"
|
| #include "storage/browser/fileapi/async_file_util.h"
|
| #include "storage/browser/fileapi/watcher_manager.h"
|
| #include "url/gurl.h"
|
|
|
| class Profile;
|
|
|
| -namespace base {
|
| -class Time;
|
| -} // namespace base
|
| -
|
| namespace net {
|
| class IOBuffer;
|
| } // namespace net
|
|
|
| +namespace base {
|
| +class FilePath;
|
| +} // namespace base
|
| +
|
| namespace chromeos {
|
| namespace file_system_provider {
|
|
|
| +class Queue;
|
| class RequestManager;
|
|
|
| -// Path of a sample fake file, which is added to the fake file system by
|
| -// default.
|
| -extern const base::FilePath::CharType kFakeFilePath[];
|
| -
|
| -// Represents a file or a directory on a fake file system.
|
| -struct FakeEntry {
|
| - FakeEntry();
|
| - FakeEntry(scoped_ptr<EntryMetadata> metadata, const std::string& contents);
|
| - ~FakeEntry();
|
| -
|
| - scoped_ptr<EntryMetadata> metadata;
|
| - std::string contents;
|
| -
|
| - private:
|
| - DISALLOW_COPY_AND_ASSIGN(FakeEntry);
|
| -};
|
| -
|
| -// Fake provided file system implementation. Does not communicate with target
|
| -// extensions. Used for unit tests.
|
| -class FakeProvidedFileSystem : public ProvidedFileSystemInterface {
|
| +// Decorates ProvidedFileSystemInterface with throttling capabilities.
|
| +class ThrottledFileSystem : public ProvidedFileSystemInterface {
|
| public:
|
| - explicit FakeProvidedFileSystem(
|
| - const ProvidedFileSystemInfo& file_system_info);
|
| - virtual ~FakeProvidedFileSystem();
|
| -
|
| - // Adds a fake entry to the fake file system.
|
| - void AddEntry(const base::FilePath& entry_path,
|
| - bool is_directory,
|
| - const std::string& name,
|
| - int64 size,
|
| - base::Time modification_time,
|
| - std::string mime_type,
|
| - std::string contents);
|
| -
|
| - // Fetches a pointer to a fake entry registered in the fake file system. If
|
| - // not found, then returns NULL. The returned pointes is owned by
|
| - // FakeProvidedFileSystem.
|
| - const FakeEntry* GetEntry(const base::FilePath& entry_path) const;
|
| + explicit ThrottledFileSystem(
|
| + scoped_ptr<ProvidedFileSystemInterface> file_system);
|
| + virtual ~ThrottledFileSystem();
|
|
|
| // ProvidedFileSystemInterface overrides.
|
| virtual AbortCallback RequestUnmount(
|
| const storage::AsyncFileUtil::StatusCallback& callback) override;
|
| virtual AbortCallback GetMetadata(
|
| const base::FilePath& entry_path,
|
| - ProvidedFileSystemInterface::MetadataFieldMask fields,
|
| - const ProvidedFileSystemInterface::GetMetadataCallback& callback)
|
| - override;
|
| + MetadataFieldMask fields,
|
| + const GetMetadataCallback& callback) override;
|
| virtual AbortCallback ReadDirectory(
|
| const base::FilePath& directory_path,
|
| const storage::AsyncFileUtil::ReadDirectoryCallback& callback) override;
|
| @@ -156,44 +121,30 @@ class FakeProvidedFileSystem : public ProvidedFileSystemInterface {
|
| const storage::AsyncFileUtil::StatusCallback& callback) override;
|
| virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() override;
|
|
|
| - // Factory callback, to be used in Service::SetFileSystemFactory(). The
|
| - // |event_router| argument can be NULL.
|
| - static ProvidedFileSystemInterface* Create(
|
| - Profile* profile,
|
| - const ProvidedFileSystemInfo& file_system_info);
|
| -
|
| private:
|
| - typedef std::map<base::FilePath, linked_ptr<FakeEntry> > Entries;
|
| - typedef std::map<int, base::FilePath> OpenedFilesMap;
|
| -
|
| - // Utility function for posting a task which can be aborted by calling the
|
| - // returned callback.
|
| - AbortCallback PostAbortableTask(const base::Closure& callback);
|
| -
|
| - // Aborts a request. |task_id| refers to a posted callback returning a
|
| - // response for the operation, which will be cancelled, hence not called.
|
| - void Abort(int task_id,
|
| - const storage::AsyncFileUtil::StatusCallback& callback);
|
| -
|
| - // Aborts a request. |task_ids| refers to a vector of posted callbacks
|
| - // returning a response for the operation, which will be cancelled, hence not
|
| - // called.
|
| - void AbortMany(const std::vector<int>& task_ids,
|
| - const storage::AsyncFileUtil::StatusCallback& callback);
|
| -
|
| - ProvidedFileSystemInfo file_system_info_;
|
| - Entries entries_;
|
| - OpenedFilesMap opened_files_;
|
| - int last_file_handle_;
|
| - base::CancelableTaskTracker tracker_;
|
| - ObserverList<ProvidedFileSystemObserver> observers_;
|
| - Watchers watchers_;
|
| -
|
| - base::WeakPtrFactory<FakeProvidedFileSystem> weak_ptr_factory_;
|
| - DISALLOW_COPY_AND_ASSIGN(FakeProvidedFileSystem);
|
| + // Called when opening a file is completed with either a success or an error.
|
| + void OnOpenFileCompleted(int queue_token,
|
| + const OpenFileCallback& callback,
|
| + int file_handle,
|
| + base::File::Error result);
|
| +
|
| + // Called when closing a file is completed with either a success or an error.
|
| + void OnCloseFileCompleted(
|
| + int file_handle,
|
| + const storage::AsyncFileUtil::StatusCallback& callback,
|
| + base::File::Error result);
|
| +
|
| + scoped_ptr<ProvidedFileSystemInterface> file_system_;
|
| + scoped_ptr<Queue> open_queue_;
|
| +
|
| + // Map from file handles to open queue tokens.
|
| + std::map<int, int> opened_files_;
|
| +
|
| + base::WeakPtrFactory<ThrottledFileSystem> weak_ptr_factory_;
|
| + DISALLOW_COPY_AND_ASSIGN(ThrottledFileSystem);
|
| };
|
|
|
| } // namespace file_system_provider
|
| } // namespace chromeos
|
|
|
| -#endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTEM_H_
|
| +#endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_THROTTLED_FILE_SYSTEM_H_
|
|
|