Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / directory_loader.h
blob7e5afbfdd7cf056ba1a138816c72c71eae3779e5
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 "base/threading/thread_checker.h"
19 #include "chrome/browser/chromeos/drive/file_system_interface.h"
20 #include "components/drive/file_errors.h"
21 #include "google_apis/drive/drive_api_error_codes.h"
22 #include "google_apis/drive/drive_common_callbacks.h"
24 namespace base {
25 class SequencedTaskRunner;
26 } // namespace base
28 namespace google_apis {
29 class AboutResource;
30 } // namespace google_apis
32 namespace drive {
34 class EventLogger;
35 class JobScheduler;
36 class ResourceEntry;
38 namespace internal {
40 class AboutResourceLoader;
41 class ChangeList;
42 class ChangeListLoaderObserver;
43 class DirectoryFetchInfo;
44 class LoaderController;
45 class ResourceMetadata;
47 // DirectoryLoader is used to load directory contents.
48 class DirectoryLoader {
49 public:
50 DirectoryLoader(EventLogger* logger,
51 base::SequencedTaskRunner* blocking_task_runner,
52 ResourceMetadata* resource_metadata,
53 JobScheduler* scheduler,
54 AboutResourceLoader* about_resource_loader,
55 LoaderController* apply_task_controller);
56 ~DirectoryLoader();
58 // Adds and removes the observer.
59 void AddObserver(ChangeListLoaderObserver* observer);
60 void RemoveObserver(ChangeListLoaderObserver* observer);
62 // Reads the directory contents.
63 // |entries_callback| can be null.
64 // |completion_callback| must not be null.
65 void ReadDirectory(const base::FilePath& directory_path,
66 const ReadDirectoryEntriesCallback& entries_callback,
67 const FileOperationCallback& completion_callback);
69 private:
70 class FeedFetcher;
71 struct ReadDirectoryCallbackState;
73 // Part of ReadDirectory().
74 void ReadDirectoryAfterGetEntry(
75 const base::FilePath& directory_path,
76 const ReadDirectoryEntriesCallback& entries_callback,
77 const FileOperationCallback& completion_callback,
78 bool should_try_loading_parent,
79 const ResourceEntry* entry,
80 FileError error);
81 void ReadDirectoryAfterLoadParent(
82 const base::FilePath& directory_path,
83 const ReadDirectoryEntriesCallback& entries_callback,
84 const FileOperationCallback& completion_callback,
85 FileError error);
86 void ReadDirectoryAfterGetAboutResource(
87 const std::string& local_id,
88 google_apis::DriveApiErrorCode status,
89 scoped_ptr<google_apis::AboutResource> about_resource);
90 void ReadDirectoryAfterCheckLocalState(
91 scoped_ptr<google_apis::AboutResource> about_resource,
92 const std::string& local_id,
93 const ResourceEntry* entry,
94 const int64* local_changestamp,
95 FileError error);
97 // Part of ReadDirectory().
98 // This function should be called when the directory load is complete.
99 // Flushes the callbacks waiting for the directory to be loaded.
100 void OnDirectoryLoadComplete(const std::string& local_id, FileError error);
101 void OnDirectoryLoadCompleteAfterRead(const std::string& local_id,
102 const ResourceEntryVector* entries,
103 FileError error);
105 // Sends |entries| to the callbacks.
106 void SendEntries(const std::string& local_id,
107 const ResourceEntryVector& entries);
109 // ================= Implementation for directory loading =================
110 // Loads the directory contents from server, and updates the local metadata.
111 // Runs |callback| when it is finished.
112 void LoadDirectoryFromServer(const DirectoryFetchInfo& directory_fetch_info);
114 // Part of LoadDirectoryFromServer() for a normal directory.
115 void LoadDirectoryFromServerAfterLoad(
116 const DirectoryFetchInfo& directory_fetch_info,
117 FeedFetcher* fetcher,
118 FileError error);
120 // Part of LoadDirectoryFromServer().
121 void LoadDirectoryFromServerAfterUpdateChangestamp(
122 const DirectoryFetchInfo& directory_fetch_info,
123 const base::FilePath* directory_path,
124 FileError error);
126 EventLogger* logger_; // Not owned.
127 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
128 ResourceMetadata* resource_metadata_; // Not owned.
129 JobScheduler* scheduler_; // Not owned.
130 AboutResourceLoader* about_resource_loader_; // Not owned.
131 LoaderController* loader_controller_; // Not owned.
132 base::ObserverList<ChangeListLoaderObserver> observers_;
133 typedef std::map<std::string, std::vector<ReadDirectoryCallbackState> >
134 LoadCallbackMap;
135 LoadCallbackMap pending_load_callback_;
137 // Set of the running feed fetcher for the fast fetch.
138 std::set<FeedFetcher*> fast_fetch_feed_fetcher_set_;
140 base::ThreadChecker thread_checker_;
142 // Note: This should remain the last member so it'll be destroyed and
143 // invalidate its weak pointers before any other members are destroyed.
144 base::WeakPtrFactory<DirectoryLoader> weak_ptr_factory_;
145 DISALLOW_COPY_AND_ASSIGN(DirectoryLoader);
148 } // namespace internal
149 } // namespace drive
151 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DIRECTORY_LOADER_H_