| 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_file_system_interface.h" | 16 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" |
| 16 #include "chrome/browser/chromeos/drive/drive_file_system_observer.h" | 17 #include "chrome/browser/chromeos/drive/drive_file_system_observer.h" |
| 17 #include "chrome/browser/chromeos/drive/drive_sync_client_observer.h" | 18 #include "chrome/browser/chromeos/drive/drive_sync_client_observer.h" |
| 18 #include "chrome/browser/google_apis/gdata_errorcode.h" | 19 #include "chrome/browser/google_apis/gdata_errorcode.h" |
| 19 | 20 |
| 20 class FilePath; | 21 class FilePath; |
| 21 | 22 |
| 22 namespace drive { | 23 namespace drive { |
| 23 | 24 |
| 24 class DriveEntryProto; | |
| 25 class DriveFileSystemInterface; | 25 class DriveFileSystemInterface; |
| 26 | 26 |
| 27 // The parameters for DrivePrefetcher construction. | 27 // The parameters for DrivePrefetcher construction. |
| 28 struct DrivePrefetcherOptions { | 28 struct DrivePrefetcherOptions { |
| 29 DrivePrefetcherOptions(); // Sets the default values. | 29 DrivePrefetcherOptions(); // Sets the default values. |
| 30 | 30 |
| 31 int initial_prefetch_count; | 31 int initial_prefetch_count; |
| 32 int64 prefetch_file_size_limit; | 32 int64 prefetch_file_size_limit; |
| 33 }; | 33 }; |
| 34 | 34 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // Helper methods to traverse over the file system. | 72 // Helper methods to traverse over the file system. |
| 73 void VisitFile(const DriveEntryProto& entry); | 73 void VisitFile(const DriveEntryProto& entry); |
| 74 void VisitDirectory(const FilePath& directory_path); | 74 void VisitDirectory(const FilePath& directory_path); |
| 75 void OnReadDirectory(const FilePath& directory_path, | 75 void OnReadDirectory(const FilePath& directory_path, |
| 76 DriveFileError error, | 76 DriveFileError error, |
| 77 bool hide_hosted_documents, | 77 bool hide_hosted_documents, |
| 78 scoped_ptr<DriveEntryProtoVector> entries); | 78 scoped_ptr<DriveEntryProtoVector> entries); |
| 79 void OnReadDirectoryFinished(); | 79 void OnReadDirectoryFinished(); |
| 80 | 80 |
| 81 // Keeps the kNumberOfLatestFilesToKeepInCache latest files in the filesystem. | 81 // Keeps the kNumberOfLatestFilesToKeepInCache latest files in the filesystem. |
| 82 typedef std::set<std::pair<int64, std::string> > LatestFileSet; | 82 typedef bool (*PrefetchPriorityComparator)(const DriveEntryProto&, |
| 83 const DriveEntryProto&); |
| 84 typedef std::set<DriveEntryProto, PrefetchPriorityComparator> LatestFileSet; |
| 83 LatestFileSet latest_files_; | 85 LatestFileSet latest_files_; |
| 84 | 86 |
| 85 // The queue of files to fetch. Files with higher priority comes front. | 87 // The queue of files to fetch. Files with higher priority comes front. |
| 86 std::deque<std::string> queue_; | 88 std::deque<std::string> queue_; |
| 87 | 89 |
| 88 // Number of in-flight |ExecuteOnePrefetch| calls that has not finished yet. | 90 // Number of in-flight |ExecuteOnePrefetch| calls that has not finished yet. |
| 89 int number_of_inflight_prefetches_; | 91 int number_of_inflight_prefetches_; |
| 90 | 92 |
| 91 // Number of in-flight |VisitDirectory| calls that has not finished yet. | 93 // Number of in-flight |VisitDirectory| calls that has not finished yet. |
| 92 int number_of_inflight_traversals_; | 94 int number_of_inflight_traversals_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 107 | 109 |
| 108 // Note: This should remain the last member so it'll be destroyed and | 110 // Note: This should remain the last member so it'll be destroyed and |
| 109 // invalidate its weak pointers before any other members are destroyed. | 111 // invalidate its weak pointers before any other members are destroyed. |
| 110 base::WeakPtrFactory<DrivePrefetcher> weak_ptr_factory_; | 112 base::WeakPtrFactory<DrivePrefetcher> weak_ptr_factory_; |
| 111 DISALLOW_COPY_AND_ASSIGN(DrivePrefetcher); | 113 DISALLOW_COPY_AND_ASSIGN(DrivePrefetcher); |
| 112 }; | 114 }; |
| 113 | 115 |
| 114 } // namespace drive | 116 } // namespace drive |
| 115 | 117 |
| 116 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_PREFETCHER_H_ | 118 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_PREFETCHER_H_ |
| OLD | NEW |