Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / file_system / open_file_operation.h
blob19c8af7d83925c9f3da35bd28b460cc5476b6f7d
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPEN_FILE_OPERATION_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPEN_FILE_OPERATION_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread_checker.h"
15 #include "chrome/browser/chromeos/drive/file_system_interface.h"
16 #include "components/drive/file_errors.h"
18 namespace base {
19 class FilePath;
20 class ScopedClosureRunner;
21 class SequencedTaskRunner;
22 } // namespace base
24 namespace drive {
26 class JobScheduler;
27 class ResourceEntry;
29 namespace internal {
30 class ResourceMetadata;
31 class FileCache;
32 } // namespace internal
34 namespace file_system {
36 class CreateFileOperation;
37 class DownloadOperation;
38 class OperationDelegate;
40 class OpenFileOperation {
41 public:
42 OpenFileOperation(base::SequencedTaskRunner* blocking_task_runner,
43 OperationDelegate* delegate,
44 JobScheduler* scheduler,
45 internal::ResourceMetadata* metadata,
46 internal::FileCache* cache,
47 const base::FilePath& temporary_file_directory);
48 ~OpenFileOperation();
50 // Opens the file at |file_path|.
51 // If the file is not actually downloaded, this method starts
52 // to download it to the cache, and then runs |callback| upon the
53 // completion with the path to the local cache file.
54 // See also the definition of OpenMode for its meaning.
55 // If |mime_type| is non empty and the file is created by this OpenFile()
56 // call, the mime type is used as the file's property.
57 // |callback| must not be null.
58 void OpenFile(const base::FilePath& file_path,
59 OpenMode open_mode,
60 const std::string& mime_type,
61 const OpenFileCallback& callback);
63 private:
64 // Part of OpenFile(). Called after file creation is completed.
65 void OpenFileAfterCreateFile(const base::FilePath& file_path,
66 const OpenFileCallback& callback,
67 FileError error);
69 // Part of OpenFile(). Called after file downloading is completed.
70 void OpenFileAfterFileDownloaded(const OpenFileCallback& callback,
71 FileError error,
72 const base::FilePath& local_file_path,
73 scoped_ptr<ResourceEntry> entry);
75 // Part of OpenFile(). Called after opening the cache file.
76 void OpenFileAfterOpenForWrite(
77 const base::FilePath& local_file_path,
78 const std::string& local_id,
79 const OpenFileCallback& callback,
80 scoped_ptr<base::ScopedClosureRunner>* file_closer,
81 FileError error);
83 // Closes the file with |local_id|.
84 void CloseFile(const std::string& local_id,
85 scoped_ptr<base::ScopedClosureRunner> file_closer);
87 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
88 OperationDelegate* delegate_;
89 internal::FileCache* cache_;
91 scoped_ptr<CreateFileOperation> create_file_operation_;
92 scoped_ptr<DownloadOperation> download_operation_;
94 // The map from local id for an opened file to the number how many times
95 // the file is opened.
96 std::map<std::string, int> open_files_;
98 base::ThreadChecker thread_checker_;
100 // Note: This should remain the last member so it'll be destroyed and
101 // invalidate its weak pointers before any other members are destroyed.
102 base::WeakPtrFactory<OpenFileOperation> weak_ptr_factory_;
103 DISALLOW_COPY_AND_ASSIGN(OpenFileOperation);
106 } // namespace file_system
107 } // namespace drive
109 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPEN_FILE_OPERATION_H_