OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_PREFETCHER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_PREFETCHER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_PREFETCHER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_PREFETCHER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <deque> | 9 #include <deque> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "chrome/browser/chromeos/drive/drive.pb.h" | 15 #include "chrome/browser/chromeos/drive/drive.pb.h" |
16 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" | 16 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" |
17 #include "chrome/browser/chromeos/drive/drive_file_system_observer.h" | 17 #include "chrome/browser/chromeos/drive/drive_file_system_observer.h" |
18 #include "chrome/browser/chromeos/drive/drive_sync_client_observer.h" | 18 #include "chrome/browser/chromeos/drive/drive_sync_client_observer.h" |
19 | 19 |
| 20 namespace base { |
20 class FilePath; | 21 class FilePath; |
| 22 } |
21 | 23 |
22 namespace drive { | 24 namespace drive { |
23 | 25 |
24 class EventLogger; | 26 class EventLogger; |
25 | 27 |
26 // The parameters for DrivePrefetcher construction. | 28 // The parameters for DrivePrefetcher construction. |
27 struct DrivePrefetcherOptions { | 29 struct DrivePrefetcherOptions { |
28 DrivePrefetcherOptions(); // Sets the default values. | 30 DrivePrefetcherOptions(); // Sets the default values. |
29 | 31 |
30 int initial_prefetch_count; | 32 int initial_prefetch_count; |
31 int64 prefetch_file_size_limit; | 33 int64 prefetch_file_size_limit; |
32 }; | 34 }; |
33 | 35 |
34 // DrivePrefetcher is used to observe and scan the Drive file system for | 36 // DrivePrefetcher is used to observe and scan the Drive file system for |
35 // maintaining the prioritized list of files to prefetch into the cache. | 37 // maintaining the prioritized list of files to prefetch into the cache. |
36 // | 38 // |
37 // All the methods (including ctor and dtor) must be called from UI thread. | 39 // All the methods (including ctor and dtor) must be called from UI thread. |
38 class DrivePrefetcher : public DriveFileSystemObserver, | 40 class DrivePrefetcher : public DriveFileSystemObserver, |
39 public DriveSyncClientObserver { | 41 public DriveSyncClientObserver { |
40 public: | 42 public: |
41 DrivePrefetcher(DriveFileSystemInterface* file_system, | 43 DrivePrefetcher(DriveFileSystemInterface* file_system, |
42 EventLogger* event_logger, | 44 EventLogger* event_logger, |
43 const DrivePrefetcherOptions& options); | 45 const DrivePrefetcherOptions& options); |
44 virtual ~DrivePrefetcher(); | 46 virtual ~DrivePrefetcher(); |
45 | 47 |
46 // DriveFileSystemObserver overrides. | 48 // DriveFileSystemObserver overrides. |
47 virtual void OnInitialLoadFinished(DriveFileError error) OVERRIDE; | 49 virtual void OnInitialLoadFinished(DriveFileError error) OVERRIDE; |
48 virtual void OnDirectoryChanged(const FilePath& directory_path) OVERRIDE; | 50 virtual void OnDirectoryChanged( |
| 51 const base::FilePath& directory_path) OVERRIDE; |
49 | 52 |
50 // DriveSyncClientObserver overrides. | 53 // DriveSyncClientObserver overrides. |
51 virtual void OnSyncTaskStarted() OVERRIDE; | 54 virtual void OnSyncTaskStarted() OVERRIDE; |
52 virtual void OnSyncClientStopped() OVERRIDE; | 55 virtual void OnSyncClientStopped() OVERRIDE; |
53 virtual void OnSyncClientIdle() OVERRIDE; | 56 virtual void OnSyncClientIdle() OVERRIDE; |
54 | 57 |
55 private: | 58 private: |
56 // Initializes the internal data to keep the prefetch priority among files. | 59 // Initializes the internal data to keep the prefetch priority among files. |
57 void DoFullScan(); | 60 void DoFullScan(); |
58 | 61 |
59 // Fetches the file with the highest prefetch priority. If prefetching is | 62 // Fetches the file with the highest prefetch priority. If prefetching is |
60 // currently suspended, do nothing. | 63 // currently suspended, do nothing. |
61 void DoPrefetch(); | 64 void DoPrefetch(); |
62 | 65 |
63 // Called when DoPrefetch is done. | 66 // Called when DoPrefetch is done. |
64 void OnPrefetchFinished(const std::string& resource_id, | 67 void OnPrefetchFinished(const std::string& resource_id, |
65 DriveFileError error, | 68 DriveFileError error, |
66 const FilePath& file_path, | 69 const base::FilePath& file_path, |
67 const std::string& mime_type, | 70 const std::string& mime_type, |
68 DriveFileType file_type); | 71 DriveFileType file_type); |
69 | 72 |
70 // Creates the |queue_| from the list of files with |latest_| timestamps. | 73 // Creates the |queue_| from the list of files with |latest_| timestamps. |
71 void ReconstructQueue(); | 74 void ReconstructQueue(); |
72 | 75 |
73 // Helper methods to traverse over the file system. | 76 // Helper methods to traverse over the file system. |
74 void VisitFile(const DriveEntryProto& entry); | 77 void VisitFile(const DriveEntryProto& entry); |
75 void VisitDirectory(const FilePath& directory_path); | 78 void VisitDirectory(const base::FilePath& directory_path); |
76 void OnReadDirectory(const FilePath& directory_path, | 79 void OnReadDirectory(const base::FilePath& directory_path, |
77 DriveFileError error, | 80 DriveFileError error, |
78 bool hide_hosted_documents, | 81 bool hide_hosted_documents, |
79 scoped_ptr<DriveEntryProtoVector> entries); | 82 scoped_ptr<DriveEntryProtoVector> entries); |
80 void OnReadDirectoryFinished(); | 83 void OnReadDirectoryFinished(); |
81 | 84 |
82 // Keeps the kNumberOfLatestFilesToKeepInCache latest files in the filesystem. | 85 // Keeps the kNumberOfLatestFilesToKeepInCache latest files in the filesystem. |
83 typedef bool (*PrefetchPriorityComparator)(const DriveEntryProto&, | 86 typedef bool (*PrefetchPriorityComparator)(const DriveEntryProto&, |
84 const DriveEntryProto&); | 87 const DriveEntryProto&); |
85 typedef std::set<DriveEntryProto, PrefetchPriorityComparator> LatestFileSet; | 88 typedef std::set<DriveEntryProto, PrefetchPriorityComparator> LatestFileSet; |
86 LatestFileSet latest_files_; | 89 LatestFileSet latest_files_; |
(...skipping 26 matching lines...) Expand all Loading... |
113 | 116 |
114 // Note: This should remain the last member so it'll be destroyed and | 117 // Note: This should remain the last member so it'll be destroyed and |
115 // invalidate its weak pointers before any other members are destroyed. | 118 // invalidate its weak pointers before any other members are destroyed. |
116 base::WeakPtrFactory<DrivePrefetcher> weak_ptr_factory_; | 119 base::WeakPtrFactory<DrivePrefetcher> weak_ptr_factory_; |
117 DISALLOW_COPY_AND_ASSIGN(DrivePrefetcher); | 120 DISALLOW_COPY_AND_ASSIGN(DrivePrefetcher); |
118 }; | 121 }; |
119 | 122 |
120 } // namespace drive | 123 } // namespace drive |
121 | 124 |
122 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_PREFETCHER_H_ | 125 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_PREFETCHER_H_ |
OLD | NEW |