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_GDATA_GDATA_FILE_SYSTEM_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
20 #include "base/platform_file.h" | 20 #include "base/platform_file.h" |
21 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
| 22 #include "chrome/browser/chromeos/gdata/find_entry_delegate.h" |
22 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" | 23 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" |
23 #include "chrome/browser/chromeos/gdata/gdata_files.h" | 24 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
24 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" | 25 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" |
25 #include "chrome/browser/chromeos/gdata/gdata_params.h" | 26 #include "chrome/browser/chromeos/gdata/gdata_params.h" |
26 #include "chrome/browser/chromeos/gdata/gdata_parser.h" | 27 #include "chrome/browser/chromeos/gdata/gdata_parser.h" |
27 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" | 28 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" |
28 #include "chrome/browser/prefs/pref_change_registrar.h" | 29 #include "chrome/browser/prefs/pref_change_registrar.h" |
29 #include "chrome/browser/profiles/profile_keyed_service.h" | 30 #include "chrome/browser/profiles/profile_keyed_service.h" |
30 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 31 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
31 #include "content/public/browser/notification_observer.h" | 32 #include "content/public/browser/notification_observer.h" |
(...skipping 20 matching lines...) Expand all Loading... |
52 const std::string& resource_id, | 53 const std::string& resource_id, |
53 const std::string& md5)> CacheOperationCallback; | 54 const std::string& md5)> CacheOperationCallback; |
54 | 55 |
55 // Callback for GetFileFromCache. | 56 // Callback for GetFileFromCache. |
56 typedef base::Callback<void(base::PlatformFileError error, | 57 typedef base::Callback<void(base::PlatformFileError error, |
57 const std::string& resource_id, | 58 const std::string& resource_id, |
58 const std::string& md5, | 59 const std::string& md5, |
59 const FilePath& cache_file_path)> | 60 const FilePath& cache_file_path)> |
60 GetFileFromCacheCallback; | 61 GetFileFromCacheCallback; |
61 | 62 |
62 // Used to get result of file search. Please note that |file| is a live | |
63 // object provided to this callback under lock. It must not be used outside | |
64 // of the callback method. This callback can be invoked on different thread | |
65 // than one that started FileFileByPath() request. | |
66 typedef base::Callback<void(base::PlatformFileError error, | |
67 const FilePath& directory_path, | |
68 GDataEntry* entry)> | |
69 FindEntryCallback; | |
70 | |
71 // Used to get files from the file system. | 63 // Used to get files from the file system. |
72 typedef base::Callback<void(base::PlatformFileError error, | 64 typedef base::Callback<void(base::PlatformFileError error, |
73 const FilePath& file_path, | 65 const FilePath& file_path, |
74 const std::string& mime_type, | 66 const std::string& mime_type, |
75 GDataFileType file_type)> | 67 GDataFileType file_type)> |
76 GetFileCallback; | 68 GetFileCallback; |
77 | 69 |
78 // Callback for SetMountedState. | 70 // Callback for SetMountedState. |
79 typedef base::Callback<void(base::PlatformFileError error, | 71 typedef base::Callback<void(base::PlatformFileError error, |
80 const FilePath& file_path)> | 72 const FilePath& file_path)> |
(...skipping 17 matching lines...) Expand all Loading... |
98 | 90 |
99 // Used by GDataFileSystem::GetDocumentResourceIdOnIOThreadPool to return | 91 // Used by GDataFileSystem::GetDocumentResourceIdOnIOThreadPool to return |
100 // the resource ID read from a document JSON file on the local file system. | 92 // the resource ID read from a document JSON file on the local file system. |
101 typedef base::Callback<void(const std::string& resource_id)> | 93 typedef base::Callback<void(const std::string& resource_id)> |
102 GetDocumentResourceIdCallback; | 94 GetDocumentResourceIdCallback; |
103 | 95 |
104 // Callback for GetCacheState operation. | 96 // Callback for GetCacheState operation. |
105 typedef base::Callback<void(base::PlatformFileError error, | 97 typedef base::Callback<void(base::PlatformFileError error, |
106 int cache_state)> GetCacheStateCallback; | 98 int cache_state)> GetCacheStateCallback; |
107 | 99 |
108 // Delegate class used to deal with results synchronous read-only search | |
109 // over virtual file system. | |
110 class FindEntryDelegate { | |
111 public: | |
112 virtual ~FindEntryDelegate(); | |
113 | |
114 // Called when FindEntryByPathSync() completes search. | |
115 virtual void OnDone(base::PlatformFileError error, | |
116 const FilePath& directory_path, | |
117 GDataEntry* entry) = 0; | |
118 }; | |
119 | |
120 // Delegate used to find a directory element for file system updates. | |
121 class ReadOnlyFindEntryDelegate : public FindEntryDelegate { | |
122 public: | |
123 ReadOnlyFindEntryDelegate(); | |
124 | |
125 // Returns found entry. | |
126 GDataEntry* entry() { return entry_; } | |
127 | |
128 private: | |
129 // FindEntryDelegate overrides. | |
130 virtual void OnDone(base::PlatformFileError error, | |
131 const FilePath& directory_path, | |
132 GDataEntry* entry) OVERRIDE; | |
133 | |
134 // Entry that was found. | |
135 GDataEntry* entry_; | |
136 }; | |
137 | |
138 // Helper structure used for extracting key properties from GDataFile object. | 100 // Helper structure used for extracting key properties from GDataFile object. |
139 struct GDataFileProperties { | 101 struct GDataFileProperties { |
140 GDataFileProperties(); | 102 GDataFileProperties(); |
141 ~GDataFileProperties(); | 103 ~GDataFileProperties(); |
142 | 104 |
143 base::PlatformFileInfo file_info; | 105 base::PlatformFileInfo file_info; |
144 std::string resource_id; | 106 std::string resource_id; |
145 std::string file_md5; | 107 std::string file_md5; |
146 std::string mime_type; | 108 std::string mime_type; |
147 GURL content_url; | 109 GURL content_url; |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 const FilePath& virtual_path, | 557 const FilePath& virtual_path, |
596 const InitiateUploadCallback& callback); | 558 const InitiateUploadCallback& callback); |
597 | 559 |
598 // Resumes upload operation for chunk of file defined in |params.. | 560 // Resumes upload operation for chunk of file defined in |params.. |
599 // | 561 // |
600 // Can be called from *UI* thread. |callback| is run on the calling thread. | 562 // Can be called from *UI* thread. |callback| is run on the calling thread. |
601 // TODO(satorux,achuith): Remove this: crosbug.com/29943 | 563 // TODO(satorux,achuith): Remove this: crosbug.com/29943 |
602 void ResumeUpload(const ResumeUploadParams& params, | 564 void ResumeUpload(const ResumeUploadParams& params, |
603 const ResumeFileUploadCallback& callback); | 565 const ResumeFileUploadCallback& callback); |
604 | 566 |
605 // Unsafe (unlocked) version of FindEntryByPathSync method. | |
606 void UnsafeFindEntryByPath(const FilePath& file_path, | |
607 FindEntryDelegate* delegate); | |
608 | |
609 // Converts document feed from gdata service into DirectoryInfo. On failure, | 567 // Converts document feed from gdata service into DirectoryInfo. On failure, |
610 // returns NULL and fills in |error| with an appropriate value. | 568 // returns NULL and fills in |error| with an appropriate value. |
611 GDataDirectory* ParseGDataFeed(GDataErrorCode status, | 569 GDataDirectory* ParseGDataFeed(GDataErrorCode status, |
612 base::Value* data, | 570 base::Value* data, |
613 base::PlatformFileError *error); | 571 base::PlatformFileError *error); |
614 | 572 |
615 // Initiates transfer of |local_file_path| with |resource_id| to | 573 // Initiates transfer of |local_file_path| with |resource_id| to |
616 // |remote_dest_file_path|. |local_file_path| must be a file from the local | 574 // |remote_dest_file_path|. |local_file_path| must be a file from the local |
617 // file system, |remote_dest_file_path| is the virtual destination path within | 575 // file system, |remote_dest_file_path| is the virtual destination path within |
618 // gdata file system. If |resource_id| is a non-empty string, the transfer is | 576 // gdata file system. If |resource_id| is a non-empty string, the transfer is |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 }; | 1272 }; |
1315 | 1273 |
1316 // Sets the free disk space getter for testing. | 1274 // Sets the free disk space getter for testing. |
1317 // The existing getter is deleted. | 1275 // The existing getter is deleted. |
1318 void SetFreeDiskSpaceGetterForTesting( | 1276 void SetFreeDiskSpaceGetterForTesting( |
1319 FreeDiskSpaceGetterInterface* getter); | 1277 FreeDiskSpaceGetterInterface* getter); |
1320 | 1278 |
1321 } // namespace gdata | 1279 } // namespace gdata |
1322 | 1280 |
1323 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 1281 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
OLD | NEW |