Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / directory_loader.h
blob775d2e1e6e5167f32bbe111dc50efa238e93c25e
1 // Copyright 2014 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_DIRECTORY_LOADER_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DIRECTORY_LOADER_H_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
13 #include "base/callback.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/scoped_vector.h"
17 #include "base/observer_list.h"
18 #include "chrome/browser/chromeos/drive/file_errors.h"
19 #include "chrome/browser/chromeos/drive/file_system_interface.h"
20 #include "google_apis/drive/drive_api_error_codes.h"
21 #include "google_apis/drive/drive_common_callbacks.h"
23 namespace base {
24 class SequencedTaskRunner;
25 } // namespace base
27 namespace google_apis {
28 class AboutResource;
29 } // namespace google_apis
31 namespace drive {
33 class EventLogger;
34 class JobScheduler;
35 class ResourceEntry;
37 namespace internal {
39 class AboutResourceLoader;
40 class ChangeList;
41 class ChangeListLoaderObserver;
42 class DirectoryFetchInfo;
43 class LoaderController;
44 class ResourceMetadata;
46 // DirectoryLoader is used to load directory contents.
47 class DirectoryLoader {
48 public:
49 DirectoryLoader(EventLogger* logger,
50 base::SequencedTaskRunner* blocking_task_runner,
51 ResourceMetadata* resource_metadata,
52 JobScheduler* scheduler,
53 AboutResourceLoader* about_resource_loader,
54 LoaderController* apply_task_controller);
55 ~DirectoryLoader();
57 // Adds and removes the observer.
58 void AddObserver(ChangeListLoaderObserver* observer);
59 void RemoveObserver(ChangeListLoaderObserver* observer);
61 // Reads the directory contents.
62 // |entries_callback| can be null.
63 // |completion_callback| must not be null.
64 void ReadDirectory(const base::FilePath& directory_path,
65 const ReadDirectoryEntriesCallback& entries_callback,
66 const FileOperationCallback& completion_callback);
68 private:
69 class FeedFetcher;
70 struct ReadDirectoryCallbackState;
72 // Part of ReadDirectory().
73 void ReadDirectoryAfterGetEntry(
74 const base::FilePath& directory_path,
75 const ReadDirectoryEntriesCallback& entries_callback,
76 const FileOperationCallback& completion_callback,
77 bool should_try_loading_parent,
78 const ResourceEntry* entry,
79 FileError error);
80 void ReadDirectoryAfterLoadParent(
81 const base::FilePath& directory_path,
82 const ReadDirectoryEntriesCallback& entries_callback,
83 const FileOperationCallback& completion_callback,
84 FileError error);
85 void ReadDirectoryAfterGetAboutResource(
86 const std::string& local_id,
87 google_apis::DriveApiErrorCode status,
88 scoped_ptr<google_apis::AboutResource> about_resource);
89 void ReadDirectoryAfterCheckLocalState(
90 scoped_ptr<google_apis::AboutResource> about_resource,
91 const std::string& local_id,
92 const ResourceEntry* entry,
93 const int64* local_changestamp,
94 FileError error);
96 // Part of ReadDirectory().
97 // This function should be called when the directory load is complete.
98 // Flushes the callbacks waiting for the directory to be loaded.
99 void OnDirectoryLoadComplete(const std::string& local_id, FileError error);
100 void OnDirectoryLoadCompleteAfterRead(const std::string& local_id,
101 const ResourceEntryVector* entries,
102 FileError error);
104 // Sends |entries| to the callbacks.
105 void SendEntries(const std::string& local_id,
106 const ResourceEntryVector& entries);
108 // ================= Implementation for directory loading =================
109 // Loads the directory contents from server, and updates the local metadata.
110 // Runs |callback| when it is finished.
111 void LoadDirectoryFromServer(const DirectoryFetchInfo& directory_fetch_info);
113 // Part of LoadDirectoryFromServer() for a normal directory.
114 void LoadDirectoryFromServerAfterLoad(
115 const DirectoryFetchInfo& directory_fetch_info,
116 FeedFetcher* fetcher,
117 FileError error);
119 // Part of LoadDirectoryFromServer().
120 void LoadDirectoryFromServerAfterUpdateChangestamp(
121 const DirectoryFetchInfo& directory_fetch_info,
122 const base::FilePath* directory_path,
123 FileError error);
125 EventLogger* logger_; // Not owned.
126 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
127 ResourceMetadata* resource_metadata_; // Not owned.
128 JobScheduler* scheduler_; // Not owned.
129 AboutResourceLoader* about_resource_loader_; // Not owned.
130 LoaderController* loader_controller_; // Not owned.
131 ObserverList<ChangeListLoaderObserver> observers_;
132 typedef std::map<std::string, std::vector<ReadDirectoryCallbackState> >
133 LoadCallbackMap;
134 LoadCallbackMap pending_load_callback_;
136 // Set of the running feed fetcher for the fast fetch.
137 std::set<FeedFetcher*> fast_fetch_feed_fetcher_set_;
139 // Note: This should remain the last member so it'll be destroyed and
140 // invalidate its weak pointers before any other members are destroyed.
141 base::WeakPtrFactory<DirectoryLoader> weak_ptr_factory_;
142 DISALLOW_COPY_AND_ASSIGN(DirectoryLoader);
145 } // namespace internal
146 } // namespace drive
148 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DIRECTORY_LOADER_H_