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 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 const int kGDataUpdateCheckIntervalInSec = 5; | 50 const int kGDataUpdateCheckIntervalInSec = 5; |
51 #else | 51 #else |
52 const int kGDataUpdateCheckIntervalInSec = 60; | 52 const int kGDataUpdateCheckIntervalInSec = 60; |
53 #endif | 53 #endif |
54 | 54 |
55 //================================ Helper functions ============================ | 55 //================================ Helper functions ============================ |
56 | 56 |
57 // Runs GetFileCallback with pointers dereferenced. | 57 // Runs GetFileCallback with pointers dereferenced. |
58 // Used for PostTaskAndReply(). | 58 // Used for PostTaskAndReply(). |
59 void RunGetFileCallbackHelper(const GetFileCallback& callback, | 59 void RunGetFileCallbackHelper(const GetFileCallback& callback, |
60 GDataFileError* error, | 60 DriveFileError* error, |
61 FilePath* file_path, | 61 FilePath* file_path, |
62 std::string* mime_type, | 62 std::string* mime_type, |
63 DriveFileType* file_type) { | 63 DriveFileType* file_type) { |
64 DCHECK(error); | 64 DCHECK(error); |
65 DCHECK(file_path); | 65 DCHECK(file_path); |
66 DCHECK(mime_type); | 66 DCHECK(mime_type); |
67 DCHECK(file_type); | 67 DCHECK(file_type); |
68 | 68 |
69 if (!callback.is_null()) | 69 if (!callback.is_null()) |
70 callback.Run(*error, *file_path, *mime_type, *file_type); | 70 callback.Run(*error, *file_path, *mime_type, *file_type); |
71 } | 71 } |
72 | 72 |
73 // Ditto for FileOperationCallback | 73 // Ditto for FileOperationCallback |
74 void RunFileOperationCallbackHelper( | 74 void RunFileOperationCallbackHelper( |
75 const FileOperationCallback& callback, | 75 const FileOperationCallback& callback, |
76 GDataFileError* error) { | 76 DriveFileError* error) { |
77 DCHECK(error); | 77 DCHECK(error); |
78 | 78 |
79 if (!callback.is_null()) | 79 if (!callback.is_null()) |
80 callback.Run(*error); | 80 callback.Run(*error); |
81 } | 81 } |
82 | 82 |
83 // Callback for cache file operations invoked by AddUploadedFileOnUIThread. | 83 // Callback for cache file operations invoked by AddUploadedFileOnUIThread. |
84 void OnCacheUpdatedForAddUploadedFile( | 84 void OnCacheUpdatedForAddUploadedFile( |
85 const base::Closure& callback, | 85 const base::Closure& callback, |
86 GDataFileError /* error */, | 86 DriveFileError /* error */, |
87 const std::string& /* resource_id */, | 87 const std::string& /* resource_id */, |
88 const std::string& /* md5 */) { | 88 const std::string& /* md5 */) { |
89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
90 if (!callback.is_null()) | 90 if (!callback.is_null()) |
91 callback.Run(); | 91 callback.Run(); |
92 } | 92 } |
93 | 93 |
94 // Helper function called upon completion of AddUploadFile invoked by | 94 // Helper function called upon completion of AddUploadFile invoked by |
95 // OnTransferCompleted. | 95 // OnTransferCompleted. |
96 void OnAddUploadFileCompleted( | 96 void OnAddUploadFileCompleted( |
97 const FileOperationCallback& callback, | 97 const FileOperationCallback& callback, |
98 GDataFileError error) { | 98 DriveFileError error) { |
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
100 if (!callback.is_null()) | 100 if (!callback.is_null()) |
101 callback.Run(error); | 101 callback.Run(error); |
102 } | 102 } |
103 | 103 |
104 // The class to wait for the initial load of root feed and runs the callback | 104 // The class to wait for the initial load of root feed and runs the callback |
105 // after the initialization. | 105 // after the initialization. |
106 class InitialLoadObserver : public GDataFileSystemInterface::Observer { | 106 class InitialLoadObserver : public GDataFileSystemInterface::Observer { |
107 public: | 107 public: |
108 InitialLoadObserver(GDataFileSystemInterface* file_system, | 108 InitialLoadObserver(GDataFileSystemInterface* file_system, |
109 const base::Closure& callback) | 109 const base::Closure& callback) |
110 : file_system_(file_system), callback_(callback) {} | 110 : file_system_(file_system), callback_(callback) {} |
111 | 111 |
112 virtual void OnInitialLoadFinished() OVERRIDE { | 112 virtual void OnInitialLoadFinished() OVERRIDE { |
113 if (!callback_.is_null()) | 113 if (!callback_.is_null()) |
114 base::MessageLoopProxy::current()->PostTask(FROM_HERE, callback_); | 114 base::MessageLoopProxy::current()->PostTask(FROM_HERE, callback_); |
115 file_system_->RemoveObserver(this); | 115 file_system_->RemoveObserver(this); |
116 base::MessageLoopProxy::current()->DeleteSoon(FROM_HERE, this); | 116 base::MessageLoopProxy::current()->DeleteSoon(FROM_HERE, this); |
117 } | 117 } |
118 | 118 |
119 private: | 119 private: |
120 GDataFileSystemInterface* file_system_; | 120 GDataFileSystemInterface* file_system_; |
121 base::Closure callback_; | 121 base::Closure callback_; |
122 }; | 122 }; |
123 | 123 |
124 // Gets the file size of |local_file|. | 124 // Gets the file size of |local_file|. |
125 void GetLocalFileSizeOnBlockingPool(const FilePath& local_file, | 125 void GetLocalFileSizeOnBlockingPool(const FilePath& local_file, |
126 GDataFileError* error, | 126 DriveFileError* error, |
127 int64* file_size) { | 127 int64* file_size) { |
128 DCHECK(error); | 128 DCHECK(error); |
129 DCHECK(file_size); | 129 DCHECK(file_size); |
130 | 130 |
131 *file_size = 0; | 131 *file_size = 0; |
132 *error = file_util::GetFileSize(local_file, file_size) ? | 132 *error = file_util::GetFileSize(local_file, file_size) ? |
133 GDATA_FILE_OK : | 133 DRIVE_FILE_OK : |
134 GDATA_FILE_ERROR_NOT_FOUND; | 134 DRIVE_FILE_ERROR_NOT_FOUND; |
135 } | 135 } |
136 | 136 |
137 // Gets the file size and the content type of |local_file|. | 137 // Gets the file size and the content type of |local_file|. |
138 void GetLocalFileInfoOnBlockingPool( | 138 void GetLocalFileInfoOnBlockingPool( |
139 const FilePath& local_file, | 139 const FilePath& local_file, |
140 GDataFileError* error, | 140 DriveFileError* error, |
141 int64* file_size, | 141 int64* file_size, |
142 std::string* content_type) { | 142 std::string* content_type) { |
143 DCHECK(error); | 143 DCHECK(error); |
144 DCHECK(file_size); | 144 DCHECK(file_size); |
145 DCHECK(content_type); | 145 DCHECK(content_type); |
146 | 146 |
147 if (!net::GetMimeTypeFromExtension(local_file.Extension(), content_type)) | 147 if (!net::GetMimeTypeFromExtension(local_file.Extension(), content_type)) |
148 *content_type = kMimeTypeOctetStream; | 148 *content_type = kMimeTypeOctetStream; |
149 | 149 |
150 *file_size = 0; | 150 *file_size = 0; |
151 *error = file_util::GetFileSize(local_file, file_size) ? | 151 *error = file_util::GetFileSize(local_file, file_size) ? |
152 GDATA_FILE_OK : | 152 DRIVE_FILE_OK : |
153 GDATA_FILE_ERROR_NOT_FOUND; | 153 DRIVE_FILE_ERROR_NOT_FOUND; |
154 } | 154 } |
155 | 155 |
156 // Checks if a local file at |local_file_path| is a JSON file referencing a | 156 // Checks if a local file at |local_file_path| is a JSON file referencing a |
157 // hosted document on blocking pool, and if so, gets the resource ID of the | 157 // hosted document on blocking pool, and if so, gets the resource ID of the |
158 // document. | 158 // document. |
159 void GetDocumentResourceIdOnBlockingPool( | 159 void GetDocumentResourceIdOnBlockingPool( |
160 const FilePath& local_file_path, | 160 const FilePath& local_file_path, |
161 std::string* resource_id) { | 161 std::string* resource_id) { |
162 DCHECK(resource_id); | 162 DCHECK(resource_id); |
163 | 163 |
164 if (DocumentEntry::HasHostedDocumentExtension(local_file_path)) { | 164 if (DocumentEntry::HasHostedDocumentExtension(local_file_path)) { |
165 std::string error; | 165 std::string error; |
166 DictionaryValue* dict_value = NULL; | 166 DictionaryValue* dict_value = NULL; |
167 JSONFileValueSerializer serializer(local_file_path); | 167 JSONFileValueSerializer serializer(local_file_path); |
168 scoped_ptr<Value> value(serializer.Deserialize(NULL, &error)); | 168 scoped_ptr<Value> value(serializer.Deserialize(NULL, &error)); |
169 if (value.get() && value->GetAsDictionary(&dict_value)) | 169 if (value.get() && value->GetAsDictionary(&dict_value)) |
170 dict_value->GetString("resource_id", resource_id); | 170 dict_value->GetString("resource_id", resource_id); |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 // Creates a temporary JSON file representing a document with |edit_url| | 174 // Creates a temporary JSON file representing a document with |edit_url| |
175 // and |resource_id| under |document_dir| on blocking pool. | 175 // and |resource_id| under |document_dir| on blocking pool. |
176 void CreateDocumentJsonFileOnBlockingPool( | 176 void CreateDocumentJsonFileOnBlockingPool( |
177 const FilePath& document_dir, | 177 const FilePath& document_dir, |
178 const GURL& edit_url, | 178 const GURL& edit_url, |
179 const std::string& resource_id, | 179 const std::string& resource_id, |
180 GDataFileError* error, | 180 DriveFileError* error, |
181 FilePath* temp_file_path, | 181 FilePath* temp_file_path, |
182 std::string* mime_type, | 182 std::string* mime_type, |
183 DriveFileType* file_type) { | 183 DriveFileType* file_type) { |
184 DCHECK(error); | 184 DCHECK(error); |
185 DCHECK(temp_file_path); | 185 DCHECK(temp_file_path); |
186 DCHECK(mime_type); | 186 DCHECK(mime_type); |
187 DCHECK(file_type); | 187 DCHECK(file_type); |
188 | 188 |
189 *error = GDATA_FILE_ERROR_FAILED; | 189 *error = DRIVE_FILE_ERROR_FAILED; |
190 | 190 |
191 if (file_util::CreateTemporaryFileInDir(document_dir, temp_file_path)) { | 191 if (file_util::CreateTemporaryFileInDir(document_dir, temp_file_path)) { |
192 std::string document_content = base::StringPrintf( | 192 std::string document_content = base::StringPrintf( |
193 "{\"url\": \"%s\", \"resource_id\": \"%s\"}", | 193 "{\"url\": \"%s\", \"resource_id\": \"%s\"}", |
194 edit_url.spec().c_str(), resource_id.c_str()); | 194 edit_url.spec().c_str(), resource_id.c_str()); |
195 int document_size = static_cast<int>(document_content.size()); | 195 int document_size = static_cast<int>(document_content.size()); |
196 if (file_util::WriteFile(*temp_file_path, document_content.data(), | 196 if (file_util::WriteFile(*temp_file_path, document_content.data(), |
197 document_size) == document_size) { | 197 document_size) == document_size) { |
198 *error = GDATA_FILE_OK; | 198 *error = DRIVE_FILE_OK; |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 *mime_type = kMimeTypeJson; | 202 *mime_type = kMimeTypeJson; |
203 *file_type = HOSTED_DOCUMENT; | 203 *file_type = HOSTED_DOCUMENT; |
204 if (*error != GDATA_FILE_OK) | 204 if (*error != DRIVE_FILE_OK) |
205 temp_file_path->clear(); | 205 temp_file_path->clear(); |
206 } | 206 } |
207 | 207 |
208 // Gets the information of the file at local path |path|. The information is | 208 // Gets the information of the file at local path |path|. The information is |
209 // filled in |file_info|, and if it fails |result| will be assigned false. | 209 // filled in |file_info|, and if it fails |result| will be assigned false. |
210 void GetFileInfoOnBlockingPool(const FilePath& path, | 210 void GetFileInfoOnBlockingPool(const FilePath& path, |
211 base::PlatformFileInfo* file_info, | 211 base::PlatformFileInfo* file_info, |
212 bool* result) { | 212 bool* result) { |
213 *result = file_util::GetFileInfo(path, file_info); | 213 *result = file_util::GetFileInfo(path, file_info); |
214 } | 214 } |
215 | 215 |
216 // Copies a file from |src_file_path| to |dest_file_path| on the local | 216 // Copies a file from |src_file_path| to |dest_file_path| on the local |
217 // file system using file_util::CopyFile. |error| is set to | 217 // file system using file_util::CopyFile. |error| is set to |
218 // GDATA_FILE_OK on success or GDATA_FILE_ERROR_FAILED | 218 // DRIVE_FILE_OK on success or DRIVE_FILE_ERROR_FAILED |
219 // otherwise. | 219 // otherwise. |
220 void CopyLocalFileOnBlockingPool( | 220 void CopyLocalFileOnBlockingPool( |
221 const FilePath& src_file_path, | 221 const FilePath& src_file_path, |
222 const FilePath& dest_file_path, | 222 const FilePath& dest_file_path, |
223 GDataFileError* error) { | 223 DriveFileError* error) { |
224 DCHECK(error); | 224 DCHECK(error); |
225 | 225 |
226 *error = file_util::CopyFile(src_file_path, dest_file_path) ? | 226 *error = file_util::CopyFile(src_file_path, dest_file_path) ? |
227 GDATA_FILE_OK : GDATA_FILE_ERROR_FAILED; | 227 DRIVE_FILE_OK : DRIVE_FILE_ERROR_FAILED; |
228 } | 228 } |
229 | 229 |
230 // Callback for GetEntryByResourceIdAsync. | 230 // Callback for GetEntryByResourceIdAsync. |
231 // Adds |entry| to |results|. Runs |callback| with |results| when | 231 // Adds |entry| to |results|. Runs |callback| with |results| when |
232 // |run_callback| is true. When |entry| is not present in our local file system | 232 // |run_callback| is true. When |entry| is not present in our local file system |
233 // snapshot, it is not added to |results|. Instead, |entry_skipped_callback| is | 233 // snapshot, it is not added to |results|. Instead, |entry_skipped_callback| is |
234 // called. | 234 // called. |
235 void AddEntryToSearchResults( | 235 void AddEntryToSearchResults( |
236 std::vector<SearchResultInfo>* results, | 236 std::vector<SearchResultInfo>* results, |
237 const SearchCallback& callback, | 237 const SearchCallback& callback, |
238 const base::Closure& entry_skipped_callback, | 238 const base::Closure& entry_skipped_callback, |
239 GDataFileError error, | 239 DriveFileError error, |
240 bool run_callback, | 240 bool run_callback, |
241 const GURL& next_feed, | 241 const GURL& next_feed, |
242 DriveEntry* entry) { | 242 DriveEntry* entry) { |
243 // If a result is not present in our local file system snapshot, invoke | 243 // If a result is not present in our local file system snapshot, invoke |
244 // |entry_skipped_callback| and refreshes the snapshot with delta feed. | 244 // |entry_skipped_callback| and refreshes the snapshot with delta feed. |
245 // For example, this may happen if the entry has recently been added to the | 245 // For example, this may happen if the entry has recently been added to the |
246 // drive (and we still haven't received its delta feed). | 246 // drive (and we still haven't received its delta feed). |
247 if (entry) { | 247 if (entry) { |
248 const bool is_directory = entry->AsDriveDirectory() != NULL; | 248 const bool is_directory = entry->AsDriveDirectory() != NULL; |
249 results->push_back(SearchResultInfo(entry->GetFilePath(), is_directory)); | 249 results->push_back(SearchResultInfo(entry->GetFilePath(), is_directory)); |
250 } else { | 250 } else { |
251 if (!entry_skipped_callback.is_null()) | 251 if (!entry_skipped_callback.is_null()) |
252 entry_skipped_callback.Run(); | 252 entry_skipped_callback.Run(); |
253 } | 253 } |
254 | 254 |
255 if (run_callback) { | 255 if (run_callback) { |
256 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results); | 256 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results); |
257 if (!callback.is_null()) | 257 if (!callback.is_null()) |
258 callback.Run(error, next_feed, result_vec.Pass()); | 258 callback.Run(error, next_feed, result_vec.Pass()); |
259 } | 259 } |
260 } | 260 } |
261 | 261 |
262 // Helper function for binding |path| to GetEntryInfoWithFilePathCallback and | 262 // Helper function for binding |path| to GetEntryInfoWithFilePathCallback and |
263 // create GetEntryInfoCallback. | 263 // create GetEntryInfoCallback. |
264 void RunGetEntryInfoWithFilePathCallback( | 264 void RunGetEntryInfoWithFilePathCallback( |
265 const GetEntryInfoWithFilePathCallback& callback, | 265 const GetEntryInfoWithFilePathCallback& callback, |
266 const FilePath& path, | 266 const FilePath& path, |
267 GDataFileError error, | 267 DriveFileError error, |
268 scoped_ptr<DriveEntryProto> entry_proto) { | 268 scoped_ptr<DriveEntryProto> entry_proto) { |
269 if (!callback.is_null()) | 269 if (!callback.is_null()) |
270 callback.Run(error, path, entry_proto.Pass()); | 270 callback.Run(error, path, entry_proto.Pass()); |
271 } | 271 } |
272 | 272 |
273 } // namespace | 273 } // namespace |
274 | 274 |
275 // GDataFileSystem::CreateDirectoryParams struct implementation. | 275 // GDataFileSystem::CreateDirectoryParams struct implementation. |
276 struct GDataFileSystem::CreateDirectoryParams { | 276 struct GDataFileSystem::CreateDirectoryParams { |
277 CreateDirectoryParams(const FilePath& created_directory_path, | 277 CreateDirectoryParams(const FilePath& created_directory_path, |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 feed_loader_->ReloadFromServerIfNeeded( | 459 feed_loader_->ReloadFromServerIfNeeded( |
460 initial_origin, | 460 initial_origin, |
461 resource_metadata_->largest_changestamp(), | 461 resource_metadata_->largest_changestamp(), |
462 base::Bind(&GDataFileSystem::OnUpdateChecked, | 462 base::Bind(&GDataFileSystem::OnUpdateChecked, |
463 ui_weak_ptr_, | 463 ui_weak_ptr_, |
464 initial_origin)); | 464 initial_origin)); |
465 } | 465 } |
466 } | 466 } |
467 | 467 |
468 void GDataFileSystem::OnUpdateChecked(ContentOrigin initial_origin, | 468 void GDataFileSystem::OnUpdateChecked(ContentOrigin initial_origin, |
469 GDataFileError error) { | 469 DriveFileError error) { |
470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
471 | 471 |
472 if (error != GDATA_FILE_OK) | 472 if (error != DRIVE_FILE_OK) |
473 resource_metadata_->set_origin(initial_origin); | 473 resource_metadata_->set_origin(initial_origin); |
474 } | 474 } |
475 | 475 |
476 GDataFileSystem::~GDataFileSystem() { | 476 GDataFileSystem::~GDataFileSystem() { |
477 // This should be called from UI thread, from GDataSystemService shutdown. | 477 // This should be called from UI thread, from GDataSystemService shutdown. |
478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
479 | 479 |
480 feed_loader_->RemoveObserver(this); | 480 feed_loader_->RemoveObserver(this); |
481 | 481 |
482 // Cancel all the in-flight operations. | 482 // Cancel all the in-flight operations. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 DCHECK(!callback.is_null()); | 553 DCHECK(!callback.is_null()); |
554 | 554 |
555 if (entry) { | 555 if (entry) { |
556 scoped_ptr<DriveEntryProto> entry_proto(new DriveEntryProto); | 556 scoped_ptr<DriveEntryProto> entry_proto(new DriveEntryProto); |
557 entry->ToProtoFull(entry_proto.get()); | 557 entry->ToProtoFull(entry_proto.get()); |
558 CheckLocalModificationAndRun( | 558 CheckLocalModificationAndRun( |
559 entry_proto.Pass(), | 559 entry_proto.Pass(), |
560 base::Bind(&RunGetEntryInfoWithFilePathCallback, | 560 base::Bind(&RunGetEntryInfoWithFilePathCallback, |
561 callback, entry->GetFilePath())); | 561 callback, entry->GetFilePath())); |
562 } else { | 562 } else { |
563 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, | 563 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, |
564 FilePath(), | 564 FilePath(), |
565 scoped_ptr<DriveEntryProto>()); | 565 scoped_ptr<DriveEntryProto>()); |
566 } | 566 } |
567 } | 567 } |
568 | 568 |
569 void GDataFileSystem::LoadFeedIfNeeded(const FileOperationCallback& callback) { | 569 void GDataFileSystem::LoadFeedIfNeeded(const FileOperationCallback& callback) { |
570 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 570 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
571 DCHECK(!callback.is_null()); | 571 DCHECK(!callback.is_null()); |
572 | 572 |
573 if (resource_metadata_->origin() == INITIALIZING) { | 573 if (resource_metadata_->origin() == INITIALIZING) { |
574 // If root feed is not initialized but the initialization process has | 574 // If root feed is not initialized but the initialization process has |
575 // already started, add an observer to execute the remaining task after | 575 // already started, add an observer to execute the remaining task after |
576 // the end of the initialization. | 576 // the end of the initialization. |
577 AddObserver(new InitialLoadObserver(this, | 577 AddObserver(new InitialLoadObserver(this, |
578 base::Bind(callback, GDATA_FILE_OK))); | 578 base::Bind(callback, DRIVE_FILE_OK))); |
579 return; | 579 return; |
580 } else if (resource_metadata_->origin() == UNINITIALIZED) { | 580 } else if (resource_metadata_->origin() == UNINITIALIZED) { |
581 // Load root feed from this disk cache. Upon completion, kick off server | 581 // Load root feed from this disk cache. Upon completion, kick off server |
582 // fetching. | 582 // fetching. |
583 resource_metadata_->set_origin(INITIALIZING); | 583 resource_metadata_->set_origin(INITIALIZING); |
584 feed_loader_->LoadFromCache( | 584 feed_loader_->LoadFromCache( |
585 true, // should_load_from_server | 585 true, // should_load_from_server |
586 base::Bind(&GDataFileSystem::NotifyInitialLoadFinishedAndRun, | 586 base::Bind(&GDataFileSystem::NotifyInitialLoadFinishedAndRun, |
587 ui_weak_ptr_, | 587 ui_weak_ptr_, |
588 callback)); | 588 callback)); |
589 return; | 589 return; |
590 } | 590 } |
591 | 591 |
592 // The feed has already been loaded, so we have nothing to do, but post a | 592 // The feed has already been loaded, so we have nothing to do, but post a |
593 // task to the same thread, rather than calling it here, as | 593 // task to the same thread, rather than calling it here, as |
594 // LoadFeedIfNeeded() is asynchronous. | 594 // LoadFeedIfNeeded() is asynchronous. |
595 base::MessageLoopProxy::current()->PostTask( | 595 base::MessageLoopProxy::current()->PostTask( |
596 FROM_HERE, | 596 FROM_HERE, |
597 base::Bind(callback, GDATA_FILE_OK)); | 597 base::Bind(callback, DRIVE_FILE_OK)); |
598 } | 598 } |
599 | 599 |
600 void GDataFileSystem::TransferFileFromRemoteToLocal( | 600 void GDataFileSystem::TransferFileFromRemoteToLocal( |
601 const FilePath& remote_src_file_path, | 601 const FilePath& remote_src_file_path, |
602 const FilePath& local_dest_file_path, | 602 const FilePath& local_dest_file_path, |
603 const FileOperationCallback& callback) { | 603 const FileOperationCallback& callback) { |
604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
605 DCHECK(!callback.is_null()); | 605 DCHECK(!callback.is_null()); |
606 | 606 |
607 GetFileByPath(remote_src_file_path, | 607 GetFileByPath(remote_src_file_path, |
(...skipping 19 matching lines...) Expand all Loading... |
627 ui_weak_ptr_, | 627 ui_weak_ptr_, |
628 local_src_file_path, | 628 local_src_file_path, |
629 remote_dest_file_path, | 629 remote_dest_file_path, |
630 callback)); | 630 callback)); |
631 } | 631 } |
632 | 632 |
633 void GDataFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo( | 633 void GDataFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo( |
634 const FilePath& local_src_file_path, | 634 const FilePath& local_src_file_path, |
635 const FilePath& remote_dest_file_path, | 635 const FilePath& remote_dest_file_path, |
636 const FileOperationCallback& callback, | 636 const FileOperationCallback& callback, |
637 GDataFileError error, | 637 DriveFileError error, |
638 scoped_ptr<DriveEntryProto> entry_proto) { | 638 scoped_ptr<DriveEntryProto> entry_proto) { |
639 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 639 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
640 DCHECK(!callback.is_null()); | 640 DCHECK(!callback.is_null()); |
641 | 641 |
642 if (error != GDATA_FILE_OK) { | 642 if (error != DRIVE_FILE_OK) { |
643 callback.Run(error); | 643 callback.Run(error); |
644 return; | 644 return; |
645 } | 645 } |
646 | 646 |
647 DCHECK(entry_proto.get()); | 647 DCHECK(entry_proto.get()); |
648 if (!entry_proto->file_info().is_directory()) { | 648 if (!entry_proto->file_info().is_directory()) { |
649 // The parent of |remote_dest_file_path| is not a directory. | 649 // The parent of |remote_dest_file_path| is not a directory. |
650 callback.Run(GDATA_FILE_ERROR_NOT_A_DIRECTORY); | 650 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY); |
651 return; | 651 return; |
652 } | 652 } |
653 | 653 |
654 std::string* resource_id = new std::string; | 654 std::string* resource_id = new std::string; |
655 util::PostBlockingPoolSequencedTaskAndReply( | 655 util::PostBlockingPoolSequencedTaskAndReply( |
656 FROM_HERE, | 656 FROM_HERE, |
657 blocking_task_runner_, | 657 blocking_task_runner_, |
658 base::Bind(&GetDocumentResourceIdOnBlockingPool, | 658 base::Bind(&GetDocumentResourceIdOnBlockingPool, |
659 local_src_file_path, | 659 local_src_file_path, |
660 resource_id), | 660 resource_id), |
(...skipping 30 matching lines...) Expand all Loading... |
691 remote_dest_file_path.BaseName().RemoveExtension().value(), | 691 remote_dest_file_path.BaseName().RemoveExtension().value(), |
692 callback); | 692 callback); |
693 } | 693 } |
694 | 694 |
695 void GDataFileSystem::TransferRegularFile( | 695 void GDataFileSystem::TransferRegularFile( |
696 const FilePath& local_file_path, | 696 const FilePath& local_file_path, |
697 const FilePath& remote_dest_file_path, | 697 const FilePath& remote_dest_file_path, |
698 const FileOperationCallback& callback) { | 698 const FileOperationCallback& callback) { |
699 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 699 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
700 | 700 |
701 GDataFileError* error = | 701 DriveFileError* error = |
702 new GDataFileError(GDATA_FILE_OK); | 702 new DriveFileError(DRIVE_FILE_OK); |
703 int64* file_size = new int64; | 703 int64* file_size = new int64; |
704 std::string* content_type = new std::string; | 704 std::string* content_type = new std::string; |
705 util::PostBlockingPoolSequencedTaskAndReply( | 705 util::PostBlockingPoolSequencedTaskAndReply( |
706 FROM_HERE, | 706 FROM_HERE, |
707 blocking_task_runner_, | 707 blocking_task_runner_, |
708 base::Bind(&GetLocalFileInfoOnBlockingPool, | 708 base::Bind(&GetLocalFileInfoOnBlockingPool, |
709 local_file_path, | 709 local_file_path, |
710 error, | 710 error, |
711 file_size, | 711 file_size, |
712 content_type), | 712 content_type), |
713 base::Bind(&GDataFileSystem::StartFileUploadOnUIThread, | 713 base::Bind(&GDataFileSystem::StartFileUploadOnUIThread, |
714 ui_weak_ptr_, | 714 ui_weak_ptr_, |
715 StartFileUploadParams(local_file_path, | 715 StartFileUploadParams(local_file_path, |
716 remote_dest_file_path, | 716 remote_dest_file_path, |
717 callback), | 717 callback), |
718 base::Owned(error), | 718 base::Owned(error), |
719 base::Owned(file_size), | 719 base::Owned(file_size), |
720 base::Owned(content_type))); | 720 base::Owned(content_type))); |
721 } | 721 } |
722 | 722 |
723 void GDataFileSystem::StartFileUploadOnUIThread( | 723 void GDataFileSystem::StartFileUploadOnUIThread( |
724 const StartFileUploadParams& params, | 724 const StartFileUploadParams& params, |
725 GDataFileError* error, | 725 DriveFileError* error, |
726 int64* file_size, | 726 int64* file_size, |
727 std::string* content_type) { | 727 std::string* content_type) { |
728 // This method needs to run on the UI thread as required by | 728 // This method needs to run on the UI thread as required by |
729 // GDataUploader::UploadNewFile(). | 729 // GDataUploader::UploadNewFile(). |
730 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 730 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
731 DCHECK(error); | 731 DCHECK(error); |
732 DCHECK(file_size); | 732 DCHECK(file_size); |
733 DCHECK(content_type); | 733 DCHECK(content_type); |
734 | 734 |
735 if (*error != GDATA_FILE_OK) { | 735 if (*error != DRIVE_FILE_OK) { |
736 if (!params.callback.is_null()) | 736 if (!params.callback.is_null()) |
737 params.callback.Run(*error); | 737 params.callback.Run(*error); |
738 | 738 |
739 return; | 739 return; |
740 } | 740 } |
741 | 741 |
742 // Make sure the destination directory exists. | 742 // Make sure the destination directory exists. |
743 resource_metadata_->GetEntryInfoByPath( | 743 resource_metadata_->GetEntryInfoByPath( |
744 params.remote_file_path.DirName(), | 744 params.remote_file_path.DirName(), |
745 base::Bind( | 745 base::Bind( |
746 &GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo, | 746 &GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo, |
747 ui_weak_ptr_, | 747 ui_weak_ptr_, |
748 params, | 748 params, |
749 *file_size, | 749 *file_size, |
750 *content_type)); | 750 *content_type)); |
751 } | 751 } |
752 | 752 |
753 void GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo( | 753 void GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo( |
754 const StartFileUploadParams& params, | 754 const StartFileUploadParams& params, |
755 int64 file_size, | 755 int64 file_size, |
756 std::string content_type, | 756 std::string content_type, |
757 GDataFileError error, | 757 DriveFileError error, |
758 scoped_ptr<DriveEntryProto> entry_proto) { | 758 scoped_ptr<DriveEntryProto> entry_proto) { |
759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
760 | 760 |
761 if (entry_proto.get() && !entry_proto->file_info().is_directory()) | 761 if (entry_proto.get() && !entry_proto->file_info().is_directory()) |
762 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; | 762 error = DRIVE_FILE_ERROR_NOT_A_DIRECTORY; |
763 | 763 |
764 if (error != GDATA_FILE_OK) { | 764 if (error != DRIVE_FILE_OK) { |
765 if (!params.callback.is_null()) | 765 if (!params.callback.is_null()) |
766 params.callback.Run(error); | 766 params.callback.Run(error); |
767 return; | 767 return; |
768 } | 768 } |
769 DCHECK(entry_proto.get()); | 769 DCHECK(entry_proto.get()); |
770 | 770 |
771 // Fill in values of UploadFileInfo. | 771 // Fill in values of UploadFileInfo. |
772 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo); | 772 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo); |
773 upload_file_info->file_path = params.local_file_path; | 773 upload_file_info->file_path = params.local_file_path; |
774 upload_file_info->file_size = file_size; | 774 upload_file_info->file_size = file_size; |
775 upload_file_info->gdata_path = params.remote_file_path; | 775 upload_file_info->gdata_path = params.remote_file_path; |
776 // Use the file name as the title. | 776 // Use the file name as the title. |
777 upload_file_info->title = params.remote_file_path.BaseName().value(); | 777 upload_file_info->title = params.remote_file_path.BaseName().value(); |
778 upload_file_info->content_length = file_size; | 778 upload_file_info->content_length = file_size; |
779 upload_file_info->all_bytes_present = true; | 779 upload_file_info->all_bytes_present = true; |
780 upload_file_info->content_type = content_type; | 780 upload_file_info->content_type = content_type; |
781 upload_file_info->initial_upload_location = GURL(entry_proto->upload_url()); | 781 upload_file_info->initial_upload_location = GURL(entry_proto->upload_url()); |
782 upload_file_info->upload_mode = UPLOAD_NEW_FILE; | 782 upload_file_info->upload_mode = UPLOAD_NEW_FILE; |
783 | 783 |
784 upload_file_info->completion_callback = | 784 upload_file_info->completion_callback = |
785 base::Bind(&GDataFileSystem::OnTransferCompleted, | 785 base::Bind(&GDataFileSystem::OnTransferCompleted, |
786 ui_weak_ptr_, | 786 ui_weak_ptr_, |
787 params.callback); | 787 params.callback); |
788 | 788 |
789 uploader_->UploadNewFile(upload_file_info.Pass()); | 789 uploader_->UploadNewFile(upload_file_info.Pass()); |
790 } | 790 } |
791 | 791 |
792 void GDataFileSystem::OnTransferCompleted( | 792 void GDataFileSystem::OnTransferCompleted( |
793 const FileOperationCallback& callback, | 793 const FileOperationCallback& callback, |
794 GDataFileError error, | 794 DriveFileError error, |
795 scoped_ptr<UploadFileInfo> upload_file_info) { | 795 scoped_ptr<UploadFileInfo> upload_file_info) { |
796 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 796 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
797 DCHECK(upload_file_info.get()); | 797 DCHECK(upload_file_info.get()); |
798 | 798 |
799 if (error == GDATA_FILE_OK && upload_file_info->entry.get()) { | 799 if (error == DRIVE_FILE_OK && upload_file_info->entry.get()) { |
800 AddUploadedFile(UPLOAD_NEW_FILE, | 800 AddUploadedFile(UPLOAD_NEW_FILE, |
801 upload_file_info->gdata_path.DirName(), | 801 upload_file_info->gdata_path.DirName(), |
802 upload_file_info->entry.Pass(), | 802 upload_file_info->entry.Pass(), |
803 upload_file_info->file_path, | 803 upload_file_info->file_path, |
804 DriveCache::FILE_OPERATION_COPY, | 804 DriveCache::FILE_OPERATION_COPY, |
805 base::Bind(&OnAddUploadFileCompleted, callback, error)); | 805 base::Bind(&OnAddUploadFileCompleted, callback, error)); |
806 } else if (!callback.is_null()) { | 806 } else if (!callback.is_null()) { |
807 callback.Run(error); | 807 callback.Run(error); |
808 } | 808 } |
809 } | 809 } |
(...skipping 28 matching lines...) Expand all Loading... |
838 } | 838 } |
839 | 839 |
840 void GDataFileSystem::CopyOnUIThreadAfterGetEntryInfoPair( | 840 void GDataFileSystem::CopyOnUIThreadAfterGetEntryInfoPair( |
841 const FilePath& dest_file_path, | 841 const FilePath& dest_file_path, |
842 const FileOperationCallback& callback, | 842 const FileOperationCallback& callback, |
843 scoped_ptr<EntryInfoPairResult> result) { | 843 scoped_ptr<EntryInfoPairResult> result) { |
844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
845 DCHECK(!callback.is_null()); | 845 DCHECK(!callback.is_null()); |
846 DCHECK(result.get()); | 846 DCHECK(result.get()); |
847 | 847 |
848 if (result->first.error != GDATA_FILE_OK) { | 848 if (result->first.error != DRIVE_FILE_OK) { |
849 callback.Run(result->first.error); | 849 callback.Run(result->first.error); |
850 return; | 850 return; |
851 } else if (result->second.error != GDATA_FILE_OK) { | 851 } else if (result->second.error != DRIVE_FILE_OK) { |
852 callback.Run(result->second.error); | 852 callback.Run(result->second.error); |
853 return; | 853 return; |
854 } | 854 } |
855 | 855 |
856 scoped_ptr<DriveEntryProto> src_file_proto = result->first.proto.Pass(); | 856 scoped_ptr<DriveEntryProto> src_file_proto = result->first.proto.Pass(); |
857 scoped_ptr<DriveEntryProto> dest_parent_proto = result->second.proto.Pass(); | 857 scoped_ptr<DriveEntryProto> dest_parent_proto = result->second.proto.Pass(); |
858 | 858 |
859 if (!dest_parent_proto->file_info().is_directory()) { | 859 if (!dest_parent_proto->file_info().is_directory()) { |
860 callback.Run(GDATA_FILE_ERROR_NOT_A_DIRECTORY); | 860 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY); |
861 return; | 861 return; |
862 } else if (src_file_proto->file_info().is_directory()) { | 862 } else if (src_file_proto->file_info().is_directory()) { |
863 // TODO(kochi): Implement copy for directories. In the interim, | 863 // TODO(kochi): Implement copy for directories. In the interim, |
864 // we handle recursive directory copy in the file manager. | 864 // we handle recursive directory copy in the file manager. |
865 // crbug.com/141596 | 865 // crbug.com/141596 |
866 callback.Run(GDATA_FILE_ERROR_INVALID_OPERATION); | 866 callback.Run(DRIVE_FILE_ERROR_INVALID_OPERATION); |
867 return; | 867 return; |
868 } | 868 } |
869 | 869 |
870 if (src_file_proto->file_specific_info().is_hosted_document()) { | 870 if (src_file_proto->file_specific_info().is_hosted_document()) { |
871 CopyDocumentToDirectory(dest_file_path.DirName(), | 871 CopyDocumentToDirectory(dest_file_path.DirName(), |
872 src_file_proto->resource_id(), | 872 src_file_proto->resource_id(), |
873 // Drop the document extension, which should not be | 873 // Drop the document extension, which should not be |
874 // in the document title. | 874 // in the document title. |
875 dest_file_path.BaseName().RemoveExtension().value(), | 875 dest_file_path.BaseName().RemoveExtension().value(), |
876 callback); | 876 callback); |
877 return; | 877 return; |
878 } | 878 } |
879 | 879 |
880 // TODO(kochi): Reimplement this once the server API supports | 880 // TODO(kochi): Reimplement this once the server API supports |
881 // copying of regular files directly on the server side. crbug.com/138273 | 881 // copying of regular files directly on the server side. crbug.com/138273 |
882 const FilePath& src_file_path = result->first.path; | 882 const FilePath& src_file_path = result->first.path; |
883 GetFileByPath(src_file_path, | 883 GetFileByPath(src_file_path, |
884 base::Bind(&GDataFileSystem::OnGetFileCompleteForCopy, | 884 base::Bind(&GDataFileSystem::OnGetFileCompleteForCopy, |
885 ui_weak_ptr_, | 885 ui_weak_ptr_, |
886 dest_file_path, | 886 dest_file_path, |
887 callback), | 887 callback), |
888 GetContentCallback()); | 888 GetContentCallback()); |
889 } | 889 } |
890 | 890 |
891 void GDataFileSystem::OnGetFileCompleteForCopy( | 891 void GDataFileSystem::OnGetFileCompleteForCopy( |
892 const FilePath& remote_dest_file_path, | 892 const FilePath& remote_dest_file_path, |
893 const FileOperationCallback& callback, | 893 const FileOperationCallback& callback, |
894 GDataFileError error, | 894 DriveFileError error, |
895 const FilePath& local_file_path, | 895 const FilePath& local_file_path, |
896 const std::string& unused_mime_type, | 896 const std::string& unused_mime_type, |
897 DriveFileType file_type) { | 897 DriveFileType file_type) { |
898 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 898 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
899 DCHECK(!callback.is_null()); | 899 DCHECK(!callback.is_null()); |
900 | 900 |
901 if (error != GDATA_FILE_OK) { | 901 if (error != DRIVE_FILE_OK) { |
902 callback.Run(error); | 902 callback.Run(error); |
903 return; | 903 return; |
904 } | 904 } |
905 | 905 |
906 // This callback is only triggered for a regular file via Copy(). | 906 // This callback is only triggered for a regular file via Copy(). |
907 DCHECK_EQ(REGULAR_FILE, file_type); | 907 DCHECK_EQ(REGULAR_FILE, file_type); |
908 TransferRegularFile(local_file_path, remote_dest_file_path, callback); | 908 TransferRegularFile(local_file_path, remote_dest_file_path, callback); |
909 } | 909 } |
910 | 910 |
911 void GDataFileSystem::OnGetFileCompleteForTransferFile( | 911 void GDataFileSystem::OnGetFileCompleteForTransferFile( |
912 const FilePath& local_dest_file_path, | 912 const FilePath& local_dest_file_path, |
913 const FileOperationCallback& callback, | 913 const FileOperationCallback& callback, |
914 GDataFileError error, | 914 DriveFileError error, |
915 const FilePath& local_file_path, | 915 const FilePath& local_file_path, |
916 const std::string& unused_mime_type, | 916 const std::string& unused_mime_type, |
917 DriveFileType file_type) { | 917 DriveFileType file_type) { |
918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
919 DCHECK(!callback.is_null()); | 919 DCHECK(!callback.is_null()); |
920 | 920 |
921 if (error != GDATA_FILE_OK) { | 921 if (error != DRIVE_FILE_OK) { |
922 callback.Run(error); | 922 callback.Run(error); |
923 return; | 923 return; |
924 } | 924 } |
925 | 925 |
926 // GetFileByPath downloads the file from gdata to a local cache, which is then | 926 // GetFileByPath downloads the file from gdata to a local cache, which is then |
927 // copied to the actual destination path on the local file system using | 927 // copied to the actual destination path on the local file system using |
928 // CopyLocalFileOnBlockingPool. | 928 // CopyLocalFileOnBlockingPool. |
929 GDataFileError* copy_file_error = | 929 DriveFileError* copy_file_error = |
930 new GDataFileError(GDATA_FILE_OK); | 930 new DriveFileError(DRIVE_FILE_OK); |
931 util::PostBlockingPoolSequencedTaskAndReply( | 931 util::PostBlockingPoolSequencedTaskAndReply( |
932 FROM_HERE, | 932 FROM_HERE, |
933 blocking_task_runner_, | 933 blocking_task_runner_, |
934 base::Bind(&CopyLocalFileOnBlockingPool, | 934 base::Bind(&CopyLocalFileOnBlockingPool, |
935 local_file_path, | 935 local_file_path, |
936 local_dest_file_path, | 936 local_dest_file_path, |
937 copy_file_error), | 937 copy_file_error), |
938 base::Bind(&RunFileOperationCallbackHelper, | 938 base::Bind(&RunFileOperationCallbackHelper, |
939 callback, | 939 callback, |
940 base::Owned(copy_file_error))); | 940 base::Owned(copy_file_error))); |
(...skipping 15 matching lines...) Expand all Loading... |
956 } | 956 } |
957 | 957 |
958 void GDataFileSystem::Rename(const FilePath& file_path, | 958 void GDataFileSystem::Rename(const FilePath& file_path, |
959 const FilePath::StringType& new_name, | 959 const FilePath::StringType& new_name, |
960 const FileMoveCallback& callback) { | 960 const FileMoveCallback& callback) { |
961 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 961 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
962 DCHECK(!callback.is_null()); | 962 DCHECK(!callback.is_null()); |
963 | 963 |
964 // It is a no-op if the file is renamed to the same name. | 964 // It is a no-op if the file is renamed to the same name. |
965 if (file_path.BaseName().value() == new_name) { | 965 if (file_path.BaseName().value() == new_name) { |
966 callback.Run(GDATA_FILE_OK, file_path); | 966 callback.Run(DRIVE_FILE_OK, file_path); |
967 return; | 967 return; |
968 } | 968 } |
969 | 969 |
970 // Get the edit URL of an entry at |file_path|. | 970 // Get the edit URL of an entry at |file_path|. |
971 resource_metadata_->GetEntryInfoByPath( | 971 resource_metadata_->GetEntryInfoByPath( |
972 file_path, | 972 file_path, |
973 base::Bind( | 973 base::Bind( |
974 &GDataFileSystem::RenameAfterGetEntryInfo, | 974 &GDataFileSystem::RenameAfterGetEntryInfo, |
975 ui_weak_ptr_, | 975 ui_weak_ptr_, |
976 file_path, | 976 file_path, |
977 new_name, | 977 new_name, |
978 callback)); | 978 callback)); |
979 } | 979 } |
980 | 980 |
981 void GDataFileSystem::RenameAfterGetEntryInfo( | 981 void GDataFileSystem::RenameAfterGetEntryInfo( |
982 const FilePath& file_path, | 982 const FilePath& file_path, |
983 const FilePath::StringType& new_name, | 983 const FilePath::StringType& new_name, |
984 const FileMoveCallback& callback, | 984 const FileMoveCallback& callback, |
985 GDataFileError error, | 985 DriveFileError error, |
986 scoped_ptr<DriveEntryProto> entry_proto) { | 986 scoped_ptr<DriveEntryProto> entry_proto) { |
987 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 987 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
988 | 988 |
989 if (error != GDATA_FILE_OK) { | 989 if (error != DRIVE_FILE_OK) { |
990 if (!callback.is_null()) | 990 if (!callback.is_null()) |
991 callback.Run(error, file_path); | 991 callback.Run(error, file_path); |
992 return; | 992 return; |
993 } | 993 } |
994 DCHECK(entry_proto.get()); | 994 DCHECK(entry_proto.get()); |
995 | 995 |
996 // Drop the .g<something> extension from |new_name| if the file being | 996 // Drop the .g<something> extension from |new_name| if the file being |
997 // renamed is a hosted document and |new_name| has the same .g<something> | 997 // renamed is a hosted document and |new_name| has the same .g<something> |
998 // extension as the file. | 998 // extension as the file. |
999 FilePath::StringType file_name = new_name; | 999 FilePath::StringType file_name = new_name; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 } | 1046 } |
1047 | 1047 |
1048 void GDataFileSystem::MoveOnUIThreadAfterGetEntryInfoPair( | 1048 void GDataFileSystem::MoveOnUIThreadAfterGetEntryInfoPair( |
1049 const FilePath& dest_file_path, | 1049 const FilePath& dest_file_path, |
1050 const FileOperationCallback& callback, | 1050 const FileOperationCallback& callback, |
1051 scoped_ptr<EntryInfoPairResult> result) { | 1051 scoped_ptr<EntryInfoPairResult> result) { |
1052 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1052 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1053 DCHECK(!callback.is_null()); | 1053 DCHECK(!callback.is_null()); |
1054 DCHECK(result.get()); | 1054 DCHECK(result.get()); |
1055 | 1055 |
1056 if (result->first.error != GDATA_FILE_OK) { | 1056 if (result->first.error != DRIVE_FILE_OK) { |
1057 callback.Run(result->first.error); | 1057 callback.Run(result->first.error); |
1058 return; | 1058 return; |
1059 } else if (result->second.error != GDATA_FILE_OK) { | 1059 } else if (result->second.error != DRIVE_FILE_OK) { |
1060 callback.Run(result->second.error); | 1060 callback.Run(result->second.error); |
1061 return; | 1061 return; |
1062 } | 1062 } |
1063 | 1063 |
1064 scoped_ptr<DriveEntryProto> dest_parent_proto = result->second.proto.Pass(); | 1064 scoped_ptr<DriveEntryProto> dest_parent_proto = result->second.proto.Pass(); |
1065 if (!dest_parent_proto->file_info().is_directory()) { | 1065 if (!dest_parent_proto->file_info().is_directory()) { |
1066 callback.Run(GDATA_FILE_ERROR_NOT_A_DIRECTORY); | 1066 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY); |
1067 return; | 1067 return; |
1068 } | 1068 } |
1069 | 1069 |
1070 // If the file/directory is moved to the same directory, just rename it. | 1070 // If the file/directory is moved to the same directory, just rename it. |
1071 const FilePath& src_file_path = result->first.path; | 1071 const FilePath& src_file_path = result->first.path; |
1072 const FilePath& dest_parent_path = result->second.path; | 1072 const FilePath& dest_parent_path = result->second.path; |
1073 if (src_file_path.DirName() == dest_parent_path) { | 1073 if (src_file_path.DirName() == dest_parent_path) { |
1074 FileMoveCallback final_file_path_update_callback = | 1074 FileMoveCallback final_file_path_update_callback = |
1075 base::Bind(&GDataFileSystem::OnFilePathUpdated, | 1075 base::Bind(&GDataFileSystem::OnFilePathUpdated, |
1076 ui_weak_ptr_, | 1076 ui_weak_ptr_, |
(...skipping 24 matching lines...) Expand all Loading... |
1101 ui_weak_ptr_, | 1101 ui_weak_ptr_, |
1102 add_file_to_directory_callback); | 1102 add_file_to_directory_callback); |
1103 | 1103 |
1104 Rename(src_file_path, dest_file_path.BaseName().value(), | 1104 Rename(src_file_path, dest_file_path.BaseName().value(), |
1105 remove_file_from_directory_callback); | 1105 remove_file_from_directory_callback); |
1106 } | 1106 } |
1107 | 1107 |
1108 void GDataFileSystem::MoveEntryFromRootDirectory( | 1108 void GDataFileSystem::MoveEntryFromRootDirectory( |
1109 const FilePath& dir_path, | 1109 const FilePath& dir_path, |
1110 const FileOperationCallback& callback, | 1110 const FileOperationCallback& callback, |
1111 GDataFileError error, | 1111 DriveFileError error, |
1112 const FilePath& file_path) { | 1112 const FilePath& file_path) { |
1113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1114 DCHECK(!callback.is_null()); | 1114 DCHECK(!callback.is_null()); |
1115 DCHECK_EQ(kDriveRootDirectory, file_path.DirName().value()); | 1115 DCHECK_EQ(kDriveRootDirectory, file_path.DirName().value()); |
1116 | 1116 |
1117 // Return if there is an error or |dir_path| is the root directory. | 1117 // Return if there is an error or |dir_path| is the root directory. |
1118 if (error != GDATA_FILE_OK || dir_path == FilePath(kDriveRootDirectory)) { | 1118 if (error != DRIVE_FILE_OK || dir_path == FilePath(kDriveRootDirectory)) { |
1119 callback.Run(error); | 1119 callback.Run(error); |
1120 return; | 1120 return; |
1121 } | 1121 } |
1122 | 1122 |
1123 resource_metadata_->GetEntryInfoPairByPaths( | 1123 resource_metadata_->GetEntryInfoPairByPaths( |
1124 file_path, | 1124 file_path, |
1125 dir_path, | 1125 dir_path, |
1126 base::Bind( | 1126 base::Bind( |
1127 &GDataFileSystem::MoveEntryFromRootDirectoryAfterGetEntryInfoPair, | 1127 &GDataFileSystem::MoveEntryFromRootDirectoryAfterGetEntryInfoPair, |
1128 ui_weak_ptr_, | 1128 ui_weak_ptr_, |
1129 callback)); | 1129 callback)); |
1130 } | 1130 } |
1131 | 1131 |
1132 void GDataFileSystem::MoveEntryFromRootDirectoryAfterGetEntryInfoPair( | 1132 void GDataFileSystem::MoveEntryFromRootDirectoryAfterGetEntryInfoPair( |
1133 const FileOperationCallback& callback, | 1133 const FileOperationCallback& callback, |
1134 scoped_ptr<EntryInfoPairResult> result) { | 1134 scoped_ptr<EntryInfoPairResult> result) { |
1135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1136 DCHECK(!callback.is_null()); | 1136 DCHECK(!callback.is_null()); |
1137 DCHECK(result.get()); | 1137 DCHECK(result.get()); |
1138 | 1138 |
1139 if (result->first.error != GDATA_FILE_OK) { | 1139 if (result->first.error != DRIVE_FILE_OK) { |
1140 callback.Run(result->first.error); | 1140 callback.Run(result->first.error); |
1141 return; | 1141 return; |
1142 } else if (result->second.error != GDATA_FILE_OK) { | 1142 } else if (result->second.error != DRIVE_FILE_OK) { |
1143 callback.Run(result->second.error); | 1143 callback.Run(result->second.error); |
1144 return; | 1144 return; |
1145 } | 1145 } |
1146 | 1146 |
1147 scoped_ptr<DriveEntryProto> src_proto = result->first.proto.Pass(); | 1147 scoped_ptr<DriveEntryProto> src_proto = result->first.proto.Pass(); |
1148 scoped_ptr<DriveEntryProto> dir_proto = result->second.proto.Pass(); | 1148 scoped_ptr<DriveEntryProto> dir_proto = result->second.proto.Pass(); |
1149 | 1149 |
1150 if (!dir_proto->file_info().is_directory()) { | 1150 if (!dir_proto->file_info().is_directory()) { |
1151 callback.Run(GDATA_FILE_ERROR_NOT_A_DIRECTORY); | 1151 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY); |
1152 return; | 1152 return; |
1153 } | 1153 } |
1154 | 1154 |
1155 const FilePath& file_path = result->first.path; | 1155 const FilePath& file_path = result->first.path; |
1156 const FilePath& dir_path = result->second.path; | 1156 const FilePath& dir_path = result->second.path; |
1157 drive_service_->AddResourceToDirectory( | 1157 drive_service_->AddResourceToDirectory( |
1158 GURL(dir_proto->content_url()), | 1158 GURL(dir_proto->content_url()), |
1159 GURL(src_proto->edit_url()), | 1159 GURL(src_proto->edit_url()), |
1160 base::Bind(&GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted, | 1160 base::Bind(&GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted, |
1161 ui_weak_ptr_, | 1161 ui_weak_ptr_, |
1162 callback, | 1162 callback, |
1163 file_path, | 1163 file_path, |
1164 dir_path)); | 1164 dir_path)); |
1165 } | 1165 } |
1166 | 1166 |
1167 void GDataFileSystem::RemoveEntryFromNonRootDirectory( | 1167 void GDataFileSystem::RemoveEntryFromNonRootDirectory( |
1168 const FileMoveCallback& callback, | 1168 const FileMoveCallback& callback, |
1169 GDataFileError error, | 1169 DriveFileError error, |
1170 const FilePath& file_path) { | 1170 const FilePath& file_path) { |
1171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1172 DCHECK(!callback.is_null()); | 1172 DCHECK(!callback.is_null()); |
1173 | 1173 |
1174 const FilePath dir_path = file_path.DirName(); | 1174 const FilePath dir_path = file_path.DirName(); |
1175 // Return if there is an error or |dir_path| is the root directory. | 1175 // Return if there is an error or |dir_path| is the root directory. |
1176 if (error != GDATA_FILE_OK || dir_path == FilePath(kDriveRootDirectory)) { | 1176 if (error != DRIVE_FILE_OK || dir_path == FilePath(kDriveRootDirectory)) { |
1177 callback.Run(error, file_path); | 1177 callback.Run(error, file_path); |
1178 return; | 1178 return; |
1179 } | 1179 } |
1180 | 1180 |
1181 resource_metadata_->GetEntryInfoPairByPaths( | 1181 resource_metadata_->GetEntryInfoPairByPaths( |
1182 file_path, | 1182 file_path, |
1183 dir_path, | 1183 dir_path, |
1184 base::Bind( | 1184 base::Bind( |
1185 &GDataFileSystem::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair, | 1185 &GDataFileSystem::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair, |
1186 ui_weak_ptr_, | 1186 ui_weak_ptr_, |
1187 callback)); | 1187 callback)); |
1188 } | 1188 } |
1189 | 1189 |
1190 void GDataFileSystem::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair( | 1190 void GDataFileSystem::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair( |
1191 const FileMoveCallback& callback, | 1191 const FileMoveCallback& callback, |
1192 scoped_ptr<EntryInfoPairResult> result) { | 1192 scoped_ptr<EntryInfoPairResult> result) { |
1193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1194 DCHECK(!callback.is_null()); | 1194 DCHECK(!callback.is_null()); |
1195 DCHECK(result.get()); | 1195 DCHECK(result.get()); |
1196 | 1196 |
1197 const FilePath& file_path = result->first.path; | 1197 const FilePath& file_path = result->first.path; |
1198 const FilePath& dir_path = result->second.path; | 1198 const FilePath& dir_path = result->second.path; |
1199 if (result->first.error != GDATA_FILE_OK) { | 1199 if (result->first.error != DRIVE_FILE_OK) { |
1200 callback.Run(result->first.error, file_path); | 1200 callback.Run(result->first.error, file_path); |
1201 return; | 1201 return; |
1202 } else if (result->second.error != GDATA_FILE_OK) { | 1202 } else if (result->second.error != DRIVE_FILE_OK) { |
1203 callback.Run(result->second.error, file_path); | 1203 callback.Run(result->second.error, file_path); |
1204 return; | 1204 return; |
1205 } | 1205 } |
1206 | 1206 |
1207 scoped_ptr<DriveEntryProto> entry_proto = result->first.proto.Pass(); | 1207 scoped_ptr<DriveEntryProto> entry_proto = result->first.proto.Pass(); |
1208 scoped_ptr<DriveEntryProto> dir_proto = result->second.proto.Pass(); | 1208 scoped_ptr<DriveEntryProto> dir_proto = result->second.proto.Pass(); |
1209 | 1209 |
1210 if (!dir_proto->file_info().is_directory()) { | 1210 if (!dir_proto->file_info().is_directory()) { |
1211 callback.Run(GDATA_FILE_ERROR_NOT_A_DIRECTORY, file_path); | 1211 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, file_path); |
1212 return; | 1212 return; |
1213 } | 1213 } |
1214 | 1214 |
1215 drive_service_->RemoveResourceFromDirectory( | 1215 drive_service_->RemoveResourceFromDirectory( |
1216 GURL(dir_proto->content_url()), | 1216 GURL(dir_proto->content_url()), |
1217 GURL(entry_proto->edit_url()), | 1217 GURL(entry_proto->edit_url()), |
1218 entry_proto->resource_id(), | 1218 entry_proto->resource_id(), |
1219 base::Bind(&GDataFileSystem::MoveEntryToRootDirectoryLocally, | 1219 base::Bind(&GDataFileSystem::MoveEntryToRootDirectoryLocally, |
1220 ui_weak_ptr_, | 1220 ui_weak_ptr_, |
1221 callback, | 1221 callback, |
(...skipping 27 matching lines...) Expand all Loading... |
1249 ui_weak_ptr_, | 1249 ui_weak_ptr_, |
1250 file_path, | 1250 file_path, |
1251 is_recursive, | 1251 is_recursive, |
1252 callback)); | 1252 callback)); |
1253 } | 1253 } |
1254 | 1254 |
1255 void GDataFileSystem::RemoveOnUIThreadAfterGetEntryInfo( | 1255 void GDataFileSystem::RemoveOnUIThreadAfterGetEntryInfo( |
1256 const FilePath& file_path, | 1256 const FilePath& file_path, |
1257 bool /* is_recursive */, | 1257 bool /* is_recursive */, |
1258 const FileOperationCallback& callback, | 1258 const FileOperationCallback& callback, |
1259 GDataFileError error, | 1259 DriveFileError error, |
1260 scoped_ptr<DriveEntryProto> entry_proto) { | 1260 scoped_ptr<DriveEntryProto> entry_proto) { |
1261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1262 | 1262 |
1263 if (error != GDATA_FILE_OK) { | 1263 if (error != DRIVE_FILE_OK) { |
1264 if (!callback.is_null()) { | 1264 if (!callback.is_null()) { |
1265 base::MessageLoopProxy::current()->PostTask( | 1265 base::MessageLoopProxy::current()->PostTask( |
1266 FROM_HERE, base::Bind(callback, error)); | 1266 FROM_HERE, base::Bind(callback, error)); |
1267 } | 1267 } |
1268 return; | 1268 return; |
1269 } | 1269 } |
1270 | 1270 |
1271 DCHECK(entry_proto.get()); | 1271 DCHECK(entry_proto.get()); |
1272 drive_service_->DeleteDocument( | 1272 drive_service_->DeleteDocument( |
1273 GURL(entry_proto->edit_url()), | 1273 GURL(entry_proto->edit_url()), |
(...skipping 29 matching lines...) Expand all Loading... |
1303 FilePath first_missing_path; | 1303 FilePath first_missing_path; |
1304 GURL last_parent_dir_url; | 1304 GURL last_parent_dir_url; |
1305 FindMissingDirectoryResult result = | 1305 FindMissingDirectoryResult result = |
1306 FindFirstMissingParentDirectory(directory_path, | 1306 FindFirstMissingParentDirectory(directory_path, |
1307 &last_parent_dir_url, | 1307 &last_parent_dir_url, |
1308 &first_missing_path); | 1308 &first_missing_path); |
1309 switch (result) { | 1309 switch (result) { |
1310 case FOUND_INVALID: { | 1310 case FOUND_INVALID: { |
1311 if (!callback.is_null()) { | 1311 if (!callback.is_null()) { |
1312 MessageLoop::current()->PostTask(FROM_HERE, | 1312 MessageLoop::current()->PostTask(FROM_HERE, |
1313 base::Bind(callback, GDATA_FILE_ERROR_NOT_FOUND)); | 1313 base::Bind(callback, DRIVE_FILE_ERROR_NOT_FOUND)); |
1314 } | 1314 } |
1315 | 1315 |
1316 return; | 1316 return; |
1317 } | 1317 } |
1318 case DIRECTORY_ALREADY_PRESENT: { | 1318 case DIRECTORY_ALREADY_PRESENT: { |
1319 if (!callback.is_null()) { | 1319 if (!callback.is_null()) { |
1320 MessageLoop::current()->PostTask(FROM_HERE, | 1320 MessageLoop::current()->PostTask(FROM_HERE, |
1321 base::Bind(callback, | 1321 base::Bind(callback, |
1322 is_exclusive ? GDATA_FILE_ERROR_EXISTS : | 1322 is_exclusive ? DRIVE_FILE_ERROR_EXISTS : |
1323 GDATA_FILE_OK)); | 1323 DRIVE_FILE_OK)); |
1324 } | 1324 } |
1325 | 1325 |
1326 return; | 1326 return; |
1327 } | 1327 } |
1328 case FOUND_MISSING: { | 1328 case FOUND_MISSING: { |
1329 // There is a missing folder to be created here, move on with the rest of | 1329 // There is a missing folder to be created here, move on with the rest of |
1330 // this function. | 1330 // this function. |
1331 break; | 1331 break; |
1332 } | 1332 } |
1333 default: { | 1333 default: { |
1334 NOTREACHED(); | 1334 NOTREACHED(); |
1335 break; | 1335 break; |
1336 } | 1336 } |
1337 } | 1337 } |
1338 | 1338 |
1339 // Do we have a parent directory here as well? We can't then create target | 1339 // Do we have a parent directory here as well? We can't then create target |
1340 // directory if this is not a recursive operation. | 1340 // directory if this is not a recursive operation. |
1341 if (directory_path != first_missing_path && !is_recursive) { | 1341 if (directory_path != first_missing_path && !is_recursive) { |
1342 if (!callback.is_null()) { | 1342 if (!callback.is_null()) { |
1343 MessageLoop::current()->PostTask(FROM_HERE, | 1343 MessageLoop::current()->PostTask(FROM_HERE, |
1344 base::Bind(callback, GDATA_FILE_ERROR_NOT_FOUND)); | 1344 base::Bind(callback, DRIVE_FILE_ERROR_NOT_FOUND)); |
1345 } | 1345 } |
1346 return; | 1346 return; |
1347 } | 1347 } |
1348 | 1348 |
1349 drive_service_->CreateDirectory( | 1349 drive_service_->CreateDirectory( |
1350 last_parent_dir_url, | 1350 last_parent_dir_url, |
1351 first_missing_path.BaseName().value(), | 1351 first_missing_path.BaseName().value(), |
1352 base::Bind(&GDataFileSystem::OnCreateDirectoryCompleted, | 1352 base::Bind(&GDataFileSystem::OnCreateDirectoryCompleted, |
1353 ui_weak_ptr_, | 1353 ui_weak_ptr_, |
1354 CreateDirectoryParams( | 1354 CreateDirectoryParams( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 ui_weak_ptr_, | 1387 ui_weak_ptr_, |
1388 file_path, | 1388 file_path, |
1389 is_exclusive, | 1389 is_exclusive, |
1390 callback)); | 1390 callback)); |
1391 } | 1391 } |
1392 | 1392 |
1393 void GDataFileSystem::OnGetEntryInfoForCreateFile( | 1393 void GDataFileSystem::OnGetEntryInfoForCreateFile( |
1394 const FilePath& file_path, | 1394 const FilePath& file_path, |
1395 bool is_exclusive, | 1395 bool is_exclusive, |
1396 const FileOperationCallback& callback, | 1396 const FileOperationCallback& callback, |
1397 GDataFileError result, | 1397 DriveFileError result, |
1398 scoped_ptr<DriveEntryProto> entry_proto) { | 1398 scoped_ptr<DriveEntryProto> entry_proto) { |
1399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1400 DCHECK(!callback.is_null()); | 1400 DCHECK(!callback.is_null()); |
1401 | 1401 |
1402 // The |file_path| is invalid. It is an error. | 1402 // The |file_path| is invalid. It is an error. |
1403 if (result != GDATA_FILE_ERROR_NOT_FOUND && | 1403 if (result != DRIVE_FILE_ERROR_NOT_FOUND && |
1404 result != GDATA_FILE_OK) { | 1404 result != DRIVE_FILE_OK) { |
1405 callback.Run(result); | 1405 callback.Run(result); |
1406 return; | 1406 return; |
1407 } | 1407 } |
1408 | 1408 |
1409 // An entry already exists at |file_path|. | 1409 // An entry already exists at |file_path|. |
1410 if (result == GDATA_FILE_OK) { | 1410 if (result == DRIVE_FILE_OK) { |
1411 DCHECK(entry_proto.get()); | 1411 DCHECK(entry_proto.get()); |
1412 // If an exclusive mode is requested, or the entry is not a regular file, | 1412 // If an exclusive mode is requested, or the entry is not a regular file, |
1413 // it is an error. | 1413 // it is an error. |
1414 if (is_exclusive || | 1414 if (is_exclusive || |
1415 entry_proto->file_info().is_directory() || | 1415 entry_proto->file_info().is_directory() || |
1416 entry_proto->file_specific_info().is_hosted_document()) { | 1416 entry_proto->file_specific_info().is_hosted_document()) { |
1417 callback.Run(GDATA_FILE_ERROR_EXISTS); | 1417 callback.Run(DRIVE_FILE_ERROR_EXISTS); |
1418 return; | 1418 return; |
1419 } | 1419 } |
1420 | 1420 |
1421 // Otherwise nothing more to do. Succeeded. | 1421 // Otherwise nothing more to do. Succeeded. |
1422 callback.Run(GDATA_FILE_OK); | 1422 callback.Run(DRIVE_FILE_OK); |
1423 return; | 1423 return; |
1424 } | 1424 } |
1425 | 1425 |
1426 // No entry found at |file_path|. Let's create a brand new file. | 1426 // No entry found at |file_path|. Let's create a brand new file. |
1427 // For now, it is implemented by uploading an empty file (/dev/null). | 1427 // For now, it is implemented by uploading an empty file (/dev/null). |
1428 // TODO(kinaba): http://crbug.com/135143. Implement in a nicer way. | 1428 // TODO(kinaba): http://crbug.com/135143. Implement in a nicer way. |
1429 TransferRegularFile(FilePath(kEmptyFilePath), file_path, callback); | 1429 TransferRegularFile(FilePath(kEmptyFilePath), file_path, callback); |
1430 } | 1430 } |
1431 | 1431 |
1432 void GDataFileSystem::GetFileByPath( | 1432 void GDataFileSystem::GetFileByPath( |
(...skipping 22 matching lines...) Expand all Loading... |
1455 ui_weak_ptr_, | 1455 ui_weak_ptr_, |
1456 file_path, | 1456 file_path, |
1457 CreateRelayCallback(get_file_callback), | 1457 CreateRelayCallback(get_file_callback), |
1458 CreateRelayCallback(get_content_callback))); | 1458 CreateRelayCallback(get_content_callback))); |
1459 } | 1459 } |
1460 | 1460 |
1461 void GDataFileSystem::OnGetEntryInfoCompleteForGetFileByPath( | 1461 void GDataFileSystem::OnGetEntryInfoCompleteForGetFileByPath( |
1462 const FilePath& file_path, | 1462 const FilePath& file_path, |
1463 const GetFileCallback& get_file_callback, | 1463 const GetFileCallback& get_file_callback, |
1464 const GetContentCallback& get_content_callback, | 1464 const GetContentCallback& get_content_callback, |
1465 GDataFileError error, | 1465 DriveFileError error, |
1466 scoped_ptr<DriveEntryProto> entry_proto) { | 1466 scoped_ptr<DriveEntryProto> entry_proto) { |
1467 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1467 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1468 | 1468 |
1469 // If |error| == PLATFORM_FILE_OK then |entry_proto| must be valid. | 1469 // If |error| == PLATFORM_FILE_OK then |entry_proto| must be valid. |
1470 DCHECK(error != GDATA_FILE_OK || | 1470 DCHECK(error != DRIVE_FILE_OK || |
1471 (entry_proto.get() && !entry_proto->resource_id().empty())); | 1471 (entry_proto.get() && !entry_proto->resource_id().empty())); |
1472 GetResolvedFileByPath(file_path, | 1472 GetResolvedFileByPath(file_path, |
1473 get_file_callback, | 1473 get_file_callback, |
1474 get_content_callback, | 1474 get_content_callback, |
1475 error, | 1475 error, |
1476 entry_proto.get()); | 1476 entry_proto.get()); |
1477 } | 1477 } |
1478 | 1478 |
1479 void GDataFileSystem::GetResolvedFileByPath( | 1479 void GDataFileSystem::GetResolvedFileByPath( |
1480 const FilePath& file_path, | 1480 const FilePath& file_path, |
1481 const GetFileCallback& get_file_callback, | 1481 const GetFileCallback& get_file_callback, |
1482 const GetContentCallback& get_content_callback, | 1482 const GetContentCallback& get_content_callback, |
1483 GDataFileError error, | 1483 DriveFileError error, |
1484 const DriveEntryProto* entry_proto) { | 1484 const DriveEntryProto* entry_proto) { |
1485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1486 | 1486 |
1487 if (entry_proto && !entry_proto->has_file_specific_info()) | 1487 if (entry_proto && !entry_proto->has_file_specific_info()) |
1488 error = GDATA_FILE_ERROR_NOT_FOUND; | 1488 error = DRIVE_FILE_ERROR_NOT_FOUND; |
1489 | 1489 |
1490 if (error != GDATA_FILE_OK) { | 1490 if (error != DRIVE_FILE_OK) { |
1491 if (!get_file_callback.is_null()) { | 1491 if (!get_file_callback.is_null()) { |
1492 MessageLoop::current()->PostTask( | 1492 MessageLoop::current()->PostTask( |
1493 FROM_HERE, | 1493 FROM_HERE, |
1494 base::Bind(get_file_callback, | 1494 base::Bind(get_file_callback, |
1495 GDATA_FILE_ERROR_NOT_FOUND, | 1495 DRIVE_FILE_ERROR_NOT_FOUND, |
1496 FilePath(), | 1496 FilePath(), |
1497 std::string(), | 1497 std::string(), |
1498 REGULAR_FILE)); | 1498 REGULAR_FILE)); |
1499 } | 1499 } |
1500 return; | 1500 return; |
1501 } | 1501 } |
1502 | 1502 |
1503 // For a hosted document, we create a special JSON file to represent the | 1503 // For a hosted document, we create a special JSON file to represent the |
1504 // document instead of fetching the document content in one of the exported | 1504 // document instead of fetching the document content in one of the exported |
1505 // formats. The JSON file contains the edit URL and resource ID of the | 1505 // formats. The JSON file contains the edit URL and resource ID of the |
1506 // document. | 1506 // document. |
1507 if (entry_proto->file_specific_info().is_hosted_document()) { | 1507 if (entry_proto->file_specific_info().is_hosted_document()) { |
1508 GDataFileError* error = | 1508 DriveFileError* error = |
1509 new GDataFileError(GDATA_FILE_OK); | 1509 new DriveFileError(DRIVE_FILE_OK); |
1510 FilePath* temp_file_path = new FilePath; | 1510 FilePath* temp_file_path = new FilePath; |
1511 std::string* mime_type = new std::string; | 1511 std::string* mime_type = new std::string; |
1512 DriveFileType* file_type = new DriveFileType(REGULAR_FILE); | 1512 DriveFileType* file_type = new DriveFileType(REGULAR_FILE); |
1513 util::PostBlockingPoolSequencedTaskAndReply( | 1513 util::PostBlockingPoolSequencedTaskAndReply( |
1514 FROM_HERE, | 1514 FROM_HERE, |
1515 blocking_task_runner_, | 1515 blocking_task_runner_, |
1516 base::Bind(&CreateDocumentJsonFileOnBlockingPool, | 1516 base::Bind(&CreateDocumentJsonFileOnBlockingPool, |
1517 cache_->GetCacheDirectoryPath( | 1517 cache_->GetCacheDirectoryPath( |
1518 DriveCache::CACHE_TYPE_TMP_DOCUMENTS), | 1518 DriveCache::CACHE_TYPE_TMP_DOCUMENTS), |
1519 GURL(entry_proto->file_specific_info().alternate_url()), | 1519 GURL(entry_proto->file_specific_info().alternate_url()), |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1594 file_path = file->GetFilePath(); | 1594 file_path = file->GetFilePath(); |
1595 } | 1595 } |
1596 | 1596 |
1597 // Report an error immediately if the file for the resource ID is not | 1597 // Report an error immediately if the file for the resource ID is not |
1598 // found. | 1598 // found. |
1599 if (file_path.empty()) { | 1599 if (file_path.empty()) { |
1600 if (!get_file_callback.is_null()) { | 1600 if (!get_file_callback.is_null()) { |
1601 base::MessageLoopProxy::current()->PostTask( | 1601 base::MessageLoopProxy::current()->PostTask( |
1602 FROM_HERE, | 1602 FROM_HERE, |
1603 base::Bind(get_file_callback, | 1603 base::Bind(get_file_callback, |
1604 GDATA_FILE_ERROR_NOT_FOUND, | 1604 DRIVE_FILE_ERROR_NOT_FOUND, |
1605 FilePath(), | 1605 FilePath(), |
1606 std::string(), | 1606 std::string(), |
1607 REGULAR_FILE)); | 1607 REGULAR_FILE)); |
1608 } | 1608 } |
1609 return; | 1609 return; |
1610 } | 1610 } |
1611 | 1611 |
1612 GetFileByPath(file_path, get_file_callback, get_content_callback); | 1612 GetFileByPath(file_path, get_file_callback, get_content_callback); |
1613 } | 1613 } |
1614 | 1614 |
1615 void GDataFileSystem::OnGetFileFromCache(const GetFileFromCacheParams& params, | 1615 void GDataFileSystem::OnGetFileFromCache(const GetFileFromCacheParams& params, |
1616 GDataFileError error, | 1616 DriveFileError error, |
1617 const std::string& resource_id, | 1617 const std::string& resource_id, |
1618 const std::string& md5, | 1618 const std::string& md5, |
1619 const FilePath& cache_file_path) { | 1619 const FilePath& cache_file_path) { |
1620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1621 | 1621 |
1622 // Have we found the file in cache? If so, return it back to the caller. | 1622 // Have we found the file in cache? If so, return it back to the caller. |
1623 if (error == GDATA_FILE_OK) { | 1623 if (error == DRIVE_FILE_OK) { |
1624 if (!params.get_file_callback.is_null()) { | 1624 if (!params.get_file_callback.is_null()) { |
1625 params.get_file_callback.Run(error, | 1625 params.get_file_callback.Run(error, |
1626 cache_file_path, | 1626 cache_file_path, |
1627 params.mime_type, | 1627 params.mime_type, |
1628 REGULAR_FILE); | 1628 REGULAR_FILE); |
1629 } | 1629 } |
1630 return; | 1630 return; |
1631 } | 1631 } |
1632 | 1632 |
1633 // If cache file is not found, try to download the file from the server | 1633 // If cache file is not found, try to download the file from the server |
(...skipping 21 matching lines...) Expand all Loading... |
1655 params.get_file_callback, | 1655 params.get_file_callback, |
1656 params.get_content_callback))); | 1656 params.get_content_callback))); |
1657 } | 1657 } |
1658 | 1658 |
1659 void GDataFileSystem::OnGetDocumentEntry(const FilePath& cache_file_path, | 1659 void GDataFileSystem::OnGetDocumentEntry(const FilePath& cache_file_path, |
1660 const GetFileFromCacheParams& params, | 1660 const GetFileFromCacheParams& params, |
1661 GDataErrorCode status, | 1661 GDataErrorCode status, |
1662 scoped_ptr<base::Value> data) { | 1662 scoped_ptr<base::Value> data) { |
1663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1664 | 1664 |
1665 GDataFileError error = util::GDataToGDataFileError(status); | 1665 DriveFileError error = util::GDataToDriveFileError(status); |
1666 | 1666 |
1667 scoped_ptr<DriveEntry> fresh_entry; | 1667 scoped_ptr<DriveEntry> fresh_entry; |
1668 if (error == GDATA_FILE_OK) { | 1668 if (error == DRIVE_FILE_OK) { |
1669 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); | 1669 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); |
1670 if (doc_entry.get()) | 1670 if (doc_entry.get()) |
1671 fresh_entry.reset(resource_metadata_->FromDocumentEntry(*doc_entry)); | 1671 fresh_entry.reset(resource_metadata_->FromDocumentEntry(*doc_entry)); |
1672 if (!fresh_entry.get() || !fresh_entry->AsDriveFile()) { | 1672 if (!fresh_entry.get() || !fresh_entry->AsDriveFile()) { |
1673 LOG(ERROR) << "Got invalid entry from server for " << params.resource_id; | 1673 LOG(ERROR) << "Got invalid entry from server for " << params.resource_id; |
1674 error = GDATA_FILE_ERROR_FAILED; | 1674 error = DRIVE_FILE_ERROR_FAILED; |
1675 } | 1675 } |
1676 } | 1676 } |
1677 | 1677 |
1678 if (error != GDATA_FILE_OK) { | 1678 if (error != DRIVE_FILE_OK) { |
1679 if (!params.get_file_callback.is_null()) { | 1679 if (!params.get_file_callback.is_null()) { |
1680 params.get_file_callback.Run(error, | 1680 params.get_file_callback.Run(error, |
1681 cache_file_path, | 1681 cache_file_path, |
1682 params.mime_type, | 1682 params.mime_type, |
1683 REGULAR_FILE); | 1683 REGULAR_FILE); |
1684 } | 1684 } |
1685 return; | 1685 return; |
1686 } | 1686 } |
1687 | 1687 |
1688 GURL content_url = fresh_entry->content_url(); | 1688 GURL content_url = fresh_entry->content_url(); |
(...skipping 23 matching lines...) Expand all Loading... |
1712 void GDataFileSystem::StartDownloadFileIfEnoughSpace( | 1712 void GDataFileSystem::StartDownloadFileIfEnoughSpace( |
1713 const GetFileFromCacheParams& params, | 1713 const GetFileFromCacheParams& params, |
1714 const GURL& content_url, | 1714 const GURL& content_url, |
1715 const FilePath& cache_file_path, | 1715 const FilePath& cache_file_path, |
1716 bool* has_enough_space) { | 1716 bool* has_enough_space) { |
1717 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1717 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1718 | 1718 |
1719 if (!*has_enough_space) { | 1719 if (!*has_enough_space) { |
1720 // If no enough space, return PLATFORM_FILE_ERROR_NO_SPACE. | 1720 // If no enough space, return PLATFORM_FILE_ERROR_NO_SPACE. |
1721 if (!params.get_file_callback.is_null()) { | 1721 if (!params.get_file_callback.is_null()) { |
1722 params.get_file_callback.Run(GDATA_FILE_ERROR_NO_SPACE, | 1722 params.get_file_callback.Run(DRIVE_FILE_ERROR_NO_SPACE, |
1723 cache_file_path, | 1723 cache_file_path, |
1724 params.mime_type, | 1724 params.mime_type, |
1725 REGULAR_FILE); | 1725 REGULAR_FILE); |
1726 } | 1726 } |
1727 return; | 1727 return; |
1728 } | 1728 } |
1729 | 1729 |
1730 // We have enough disk space. Start downloading the file. | 1730 // We have enough disk space. Start downloading the file. |
1731 drive_service_->DownloadFile( | 1731 drive_service_->DownloadFile( |
1732 params.virtual_file_path, | 1732 params.virtual_file_path, |
(...skipping 27 matching lines...) Expand all Loading... |
1760 LoadFeedIfNeeded( | 1760 LoadFeedIfNeeded( |
1761 base::Bind(&GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterLoad, | 1761 base::Bind(&GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterLoad, |
1762 ui_weak_ptr_, | 1762 ui_weak_ptr_, |
1763 file_path, | 1763 file_path, |
1764 callback)); | 1764 callback)); |
1765 } | 1765 } |
1766 | 1766 |
1767 void GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterLoad( | 1767 void GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterLoad( |
1768 const FilePath& file_path, | 1768 const FilePath& file_path, |
1769 const GetEntryInfoCallback& callback, | 1769 const GetEntryInfoCallback& callback, |
1770 GDataFileError error) { | 1770 DriveFileError error) { |
1771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1772 DCHECK(!callback.is_null()); | 1772 DCHECK(!callback.is_null()); |
1773 | 1773 |
1774 if (error != GDATA_FILE_OK) { | 1774 if (error != DRIVE_FILE_OK) { |
1775 callback.Run(error, scoped_ptr<DriveEntryProto>()); | 1775 callback.Run(error, scoped_ptr<DriveEntryProto>()); |
1776 return; | 1776 return; |
1777 } | 1777 } |
1778 | 1778 |
1779 resource_metadata_->GetEntryInfoByPath( | 1779 resource_metadata_->GetEntryInfoByPath( |
1780 file_path, | 1780 file_path, |
1781 base::Bind(&GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterGetEntry, | 1781 base::Bind(&GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterGetEntry, |
1782 ui_weak_ptr_, | 1782 ui_weak_ptr_, |
1783 callback)); | 1783 callback)); |
1784 } | 1784 } |
1785 | 1785 |
1786 void GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterGetEntry( | 1786 void GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterGetEntry( |
1787 const GetEntryInfoCallback& callback, | 1787 const GetEntryInfoCallback& callback, |
1788 GDataFileError error, | 1788 DriveFileError error, |
1789 scoped_ptr<DriveEntryProto> entry_proto) { | 1789 scoped_ptr<DriveEntryProto> entry_proto) { |
1790 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1790 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1791 DCHECK(!callback.is_null()); | 1791 DCHECK(!callback.is_null()); |
1792 | 1792 |
1793 if (error != GDATA_FILE_OK) { | 1793 if (error != DRIVE_FILE_OK) { |
1794 callback.Run(error, scoped_ptr<DriveEntryProto>()); | 1794 callback.Run(error, scoped_ptr<DriveEntryProto>()); |
1795 return; | 1795 return; |
1796 } | 1796 } |
1797 DCHECK(entry_proto.get()); | 1797 DCHECK(entry_proto.get()); |
1798 | 1798 |
1799 CheckLocalModificationAndRun(entry_proto.Pass(), callback); | 1799 CheckLocalModificationAndRun(entry_proto.Pass(), callback); |
1800 } | 1800 } |
1801 | 1801 |
1802 void GDataFileSystem::ReadDirectoryByPath( | 1802 void GDataFileSystem::ReadDirectoryByPath( |
1803 const FilePath& file_path, | 1803 const FilePath& file_path, |
(...skipping 18 matching lines...) Expand all Loading... |
1822 LoadFeedIfNeeded( | 1822 LoadFeedIfNeeded( |
1823 base::Bind(&GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterLoad, | 1823 base::Bind(&GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterLoad, |
1824 ui_weak_ptr_, | 1824 ui_weak_ptr_, |
1825 file_path, | 1825 file_path, |
1826 callback)); | 1826 callback)); |
1827 } | 1827 } |
1828 | 1828 |
1829 void GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterLoad( | 1829 void GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterLoad( |
1830 const FilePath& file_path, | 1830 const FilePath& file_path, |
1831 const ReadDirectoryWithSettingCallback& callback, | 1831 const ReadDirectoryWithSettingCallback& callback, |
1832 GDataFileError error) { | 1832 DriveFileError error) { |
1833 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1833 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1834 DCHECK(!callback.is_null()); | 1834 DCHECK(!callback.is_null()); |
1835 | 1835 |
1836 if (error != GDATA_FILE_OK) { | 1836 if (error != DRIVE_FILE_OK) { |
1837 callback.Run(error, | 1837 callback.Run(error, |
1838 hide_hosted_docs_, | 1838 hide_hosted_docs_, |
1839 scoped_ptr<DriveEntryProtoVector>()); | 1839 scoped_ptr<DriveEntryProtoVector>()); |
1840 return; | 1840 return; |
1841 } | 1841 } |
1842 | 1842 |
1843 resource_metadata_->ReadDirectoryByPath( | 1843 resource_metadata_->ReadDirectoryByPath( |
1844 file_path, | 1844 file_path, |
1845 base::Bind(&GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterRead, | 1845 base::Bind(&GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterRead, |
1846 ui_weak_ptr_, | 1846 ui_weak_ptr_, |
1847 callback)); | 1847 callback)); |
1848 } | 1848 } |
1849 | 1849 |
1850 void GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterRead( | 1850 void GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterRead( |
1851 const ReadDirectoryWithSettingCallback& callback, | 1851 const ReadDirectoryWithSettingCallback& callback, |
1852 GDataFileError error, | 1852 DriveFileError error, |
1853 scoped_ptr<DriveEntryProtoVector> entries) { | 1853 scoped_ptr<DriveEntryProtoVector> entries) { |
1854 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1854 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1855 DCHECK(!callback.is_null()); | 1855 DCHECK(!callback.is_null()); |
1856 | 1856 |
1857 if (error != GDATA_FILE_OK) { | 1857 if (error != DRIVE_FILE_OK) { |
1858 callback.Run(error, | 1858 callback.Run(error, |
1859 hide_hosted_docs_, | 1859 hide_hosted_docs_, |
1860 scoped_ptr<DriveEntryProtoVector>()); | 1860 scoped_ptr<DriveEntryProtoVector>()); |
1861 return; | 1861 return; |
1862 } | 1862 } |
1863 DCHECK(entries.get()); // This is valid for emptry directories too. | 1863 DCHECK(entries.get()); // This is valid for emptry directories too. |
1864 | 1864 |
1865 callback.Run(GDATA_FILE_OK, hide_hosted_docs_, entries.Pass()); | 1865 callback.Run(DRIVE_FILE_OK, hide_hosted_docs_, entries.Pass()); |
1866 } | 1866 } |
1867 | 1867 |
1868 void GDataFileSystem::RequestDirectoryRefresh(const FilePath& file_path) { | 1868 void GDataFileSystem::RequestDirectoryRefresh(const FilePath& file_path) { |
1869 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1869 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1870 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1870 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1871 RunTaskOnUIThread( | 1871 RunTaskOnUIThread( |
1872 base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread, | 1872 base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread, |
1873 ui_weak_ptr_, | 1873 ui_weak_ptr_, |
1874 file_path)); | 1874 file_path)); |
1875 } | 1875 } |
1876 | 1876 |
1877 void GDataFileSystem::RequestDirectoryRefreshOnUIThread( | 1877 void GDataFileSystem::RequestDirectoryRefreshOnUIThread( |
1878 const FilePath& file_path) { | 1878 const FilePath& file_path) { |
1879 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1879 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1880 | 1880 |
1881 // Make sure the destination directory exists. | 1881 // Make sure the destination directory exists. |
1882 resource_metadata_->GetEntryInfoByPath( | 1882 resource_metadata_->GetEntryInfoByPath( |
1883 file_path, | 1883 file_path, |
1884 base::Bind( | 1884 base::Bind( |
1885 &GDataFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo, | 1885 &GDataFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo, |
1886 ui_weak_ptr_, | 1886 ui_weak_ptr_, |
1887 file_path)); | 1887 file_path)); |
1888 } | 1888 } |
1889 | 1889 |
1890 void GDataFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo( | 1890 void GDataFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo( |
1891 const FilePath& file_path, | 1891 const FilePath& file_path, |
1892 GDataFileError error, | 1892 DriveFileError error, |
1893 scoped_ptr<DriveEntryProto> entry_proto) { | 1893 scoped_ptr<DriveEntryProto> entry_proto) { |
1894 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1894 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1895 | 1895 |
1896 if (error != GDATA_FILE_OK || | 1896 if (error != DRIVE_FILE_OK || |
1897 !entry_proto->file_info().is_directory()) { | 1897 !entry_proto->file_info().is_directory()) { |
1898 LOG(ERROR) << "Directory entry not found: " << file_path.value(); | 1898 LOG(ERROR) << "Directory entry not found: " << file_path.value(); |
1899 return; | 1899 return; |
1900 } | 1900 } |
1901 | 1901 |
1902 feed_loader_->LoadDirectoryFromServer( | 1902 feed_loader_->LoadDirectoryFromServer( |
1903 resource_metadata_->origin(), | 1903 resource_metadata_->origin(), |
1904 entry_proto->resource_id(), | 1904 entry_proto->resource_id(), |
1905 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh, | 1905 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh, |
1906 ui_weak_ptr_, | 1906 ui_weak_ptr_, |
1907 file_path)); | 1907 file_path)); |
1908 } | 1908 } |
1909 | 1909 |
1910 void GDataFileSystem::OnRequestDirectoryRefresh( | 1910 void GDataFileSystem::OnRequestDirectoryRefresh( |
1911 const FilePath& directory_path, | 1911 const FilePath& directory_path, |
1912 GetDocumentsParams* params, | 1912 GetDocumentsParams* params, |
1913 GDataFileError error) { | 1913 DriveFileError error) { |
1914 DCHECK(params); | 1914 DCHECK(params); |
1915 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1915 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1916 | 1916 |
1917 if (error != GDATA_FILE_OK) { | 1917 if (error != DRIVE_FILE_OK) { |
1918 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value() | 1918 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value() |
1919 << ": " << error; | 1919 << ": " << error; |
1920 return; | 1920 return; |
1921 } | 1921 } |
1922 | 1922 |
1923 int64 unused_delta_feed_changestamp = 0; | 1923 int64 unused_delta_feed_changestamp = 0; |
1924 FeedToFileResourceMapUmaStats unused_uma_stats; | 1924 FeedToFileResourceMapUmaStats unused_uma_stats; |
1925 FileResourceIdMap file_map; | 1925 FileResourceIdMap file_map; |
1926 GDataWapiFeedProcessor feed_processor(resource_metadata_.get()); | 1926 GDataWapiFeedProcessor feed_processor(resource_metadata_.get()); |
1927 error = feed_processor.FeedToFileResourceMap( | 1927 error = feed_processor.FeedToFileResourceMap( |
1928 *params->feed_list, | 1928 *params->feed_list, |
1929 &file_map, | 1929 &file_map, |
1930 &unused_delta_feed_changestamp, | 1930 &unused_delta_feed_changestamp, |
1931 &unused_uma_stats); | 1931 &unused_uma_stats); |
1932 if (error != GDATA_FILE_OK) { | 1932 if (error != DRIVE_FILE_OK) { |
1933 LOG(ERROR) << "Failed to convert feed: " << directory_path.value() | 1933 LOG(ERROR) << "Failed to convert feed: " << directory_path.value() |
1934 << ": " << error; | 1934 << ": " << error; |
1935 return; | 1935 return; |
1936 } | 1936 } |
1937 | 1937 |
1938 resource_metadata_->RefreshDirectory( | 1938 resource_metadata_->RefreshDirectory( |
1939 params->directory_resource_id, | 1939 params->directory_resource_id, |
1940 file_map, | 1940 file_map, |
1941 base::Bind(&GDataFileSystem::OnDirectoryChangeFileMoveCallback, | 1941 base::Bind(&GDataFileSystem::OnDirectoryChangeFileMoveCallback, |
1942 ui_weak_ptr_)); | 1942 ui_weak_ptr_)); |
(...skipping 23 matching lines...) Expand all Loading... |
1966 // UpdateFileByResourceIdOnUIThread(). crbug.com/143873 | 1966 // UpdateFileByResourceIdOnUIThread(). crbug.com/143873 |
1967 resource_metadata_->GetEntryInfoByResourceId( | 1967 resource_metadata_->GetEntryInfoByResourceId( |
1968 resource_id, | 1968 resource_id, |
1969 base::Bind(&GDataFileSystem::UpdateFileByEntryInfo, | 1969 base::Bind(&GDataFileSystem::UpdateFileByEntryInfo, |
1970 ui_weak_ptr_, | 1970 ui_weak_ptr_, |
1971 callback)); | 1971 callback)); |
1972 } | 1972 } |
1973 | 1973 |
1974 void GDataFileSystem::UpdateFileByEntryInfo( | 1974 void GDataFileSystem::UpdateFileByEntryInfo( |
1975 const FileOperationCallback& callback, | 1975 const FileOperationCallback& callback, |
1976 GDataFileError error, | 1976 DriveFileError error, |
1977 const FilePath& /* dive_file_path */, | 1977 const FilePath& /* dive_file_path */, |
1978 scoped_ptr<DriveEntryProto> entry_proto) { | 1978 scoped_ptr<DriveEntryProto> entry_proto) { |
1979 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1979 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1980 DCHECK(!callback.is_null()); | 1980 DCHECK(!callback.is_null()); |
1981 | 1981 |
1982 if (error != GDATA_FILE_OK) { | 1982 if (error != DRIVE_FILE_OK) { |
1983 callback.Run(error); | 1983 callback.Run(error); |
1984 return; | 1984 return; |
1985 } | 1985 } |
1986 | 1986 |
1987 DCHECK(entry_proto.get()); | 1987 DCHECK(entry_proto.get()); |
1988 if (entry_proto->file_info().is_directory()) { | 1988 if (entry_proto->file_info().is_directory()) { |
1989 callback.Run(GDATA_FILE_ERROR_NOT_FOUND); | 1989 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND); |
1990 return; | 1990 return; |
1991 } | 1991 } |
1992 | 1992 |
1993 cache_->GetFileOnUIThread( | 1993 cache_->GetFileOnUIThread( |
1994 entry_proto->resource_id(), | 1994 entry_proto->resource_id(), |
1995 entry_proto->file_specific_info().file_md5(), | 1995 entry_proto->file_specific_info().file_md5(), |
1996 base::Bind(&GDataFileSystem::OnGetFileCompleteForUpdateFile, | 1996 base::Bind(&GDataFileSystem::OnGetFileCompleteForUpdateFile, |
1997 ui_weak_ptr_, | 1997 ui_weak_ptr_, |
1998 callback)); | 1998 callback)); |
1999 } | 1999 } |
2000 | 2000 |
2001 void GDataFileSystem::OnGetFileCompleteForUpdateFile( | 2001 void GDataFileSystem::OnGetFileCompleteForUpdateFile( |
2002 const FileOperationCallback& callback, | 2002 const FileOperationCallback& callback, |
2003 GDataFileError error, | 2003 DriveFileError error, |
2004 const std::string& resource_id, | 2004 const std::string& resource_id, |
2005 const std::string& /* md5 */, | 2005 const std::string& /* md5 */, |
2006 const FilePath& cache_file_path) { | 2006 const FilePath& cache_file_path) { |
2007 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2007 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2008 DCHECK(!callback.is_null()); | 2008 DCHECK(!callback.is_null()); |
2009 | 2009 |
2010 if (error != GDATA_FILE_OK) { | 2010 if (error != DRIVE_FILE_OK) { |
2011 callback.Run(error); | 2011 callback.Run(error); |
2012 return; | 2012 return; |
2013 } | 2013 } |
2014 | 2014 |
2015 // Gets the size of the cache file. Since the file is locally modified, the | 2015 // Gets the size of the cache file. Since the file is locally modified, the |
2016 // file size information stored in DriveEntry is not correct. | 2016 // file size information stored in DriveEntry is not correct. |
2017 GDataFileError* get_size_error = new GDataFileError(GDATA_FILE_ERROR_FAILED); | 2017 DriveFileError* get_size_error = new DriveFileError(DRIVE_FILE_ERROR_FAILED); |
2018 int64* file_size = new int64(-1); | 2018 int64* file_size = new int64(-1); |
2019 util::PostBlockingPoolSequencedTaskAndReply( | 2019 util::PostBlockingPoolSequencedTaskAndReply( |
2020 FROM_HERE, | 2020 FROM_HERE, |
2021 blocking_task_runner_, | 2021 blocking_task_runner_, |
2022 base::Bind(&GetLocalFileSizeOnBlockingPool, | 2022 base::Bind(&GetLocalFileSizeOnBlockingPool, |
2023 cache_file_path, | 2023 cache_file_path, |
2024 get_size_error, | 2024 get_size_error, |
2025 file_size), | 2025 file_size), |
2026 base::Bind(&GDataFileSystem::OnGetFileSizeCompleteForUpdateFile, | 2026 base::Bind(&GDataFileSystem::OnGetFileSizeCompleteForUpdateFile, |
2027 ui_weak_ptr_, | 2027 ui_weak_ptr_, |
2028 callback, | 2028 callback, |
2029 resource_id, | 2029 resource_id, |
2030 cache_file_path, | 2030 cache_file_path, |
2031 base::Owned(get_size_error), | 2031 base::Owned(get_size_error), |
2032 base::Owned(file_size))); | 2032 base::Owned(file_size))); |
2033 } | 2033 } |
2034 | 2034 |
2035 void GDataFileSystem::OnGetFileSizeCompleteForUpdateFile( | 2035 void GDataFileSystem::OnGetFileSizeCompleteForUpdateFile( |
2036 const FileOperationCallback& callback, | 2036 const FileOperationCallback& callback, |
2037 const std::string& resource_id, | 2037 const std::string& resource_id, |
2038 const FilePath& cache_file_path, | 2038 const FilePath& cache_file_path, |
2039 GDataFileError* error, | 2039 DriveFileError* error, |
2040 int64* file_size) { | 2040 int64* file_size) { |
2041 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2041 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2042 DCHECK(!callback.is_null()); | 2042 DCHECK(!callback.is_null()); |
2043 | 2043 |
2044 if (*error != GDATA_FILE_OK) { | 2044 if (*error != DRIVE_FILE_OK) { |
2045 callback.Run(*error); | 2045 callback.Run(*error); |
2046 return; | 2046 return; |
2047 } | 2047 } |
2048 | 2048 |
2049 // TODO(satorux): GetEntryInfoByResourceId() is called twice for | 2049 // TODO(satorux): GetEntryInfoByResourceId() is called twice for |
2050 // UpdateFileByResourceIdOnUIThread(). crbug.com/143873 | 2050 // UpdateFileByResourceIdOnUIThread(). crbug.com/143873 |
2051 resource_metadata_->GetEntryInfoByResourceId( | 2051 resource_metadata_->GetEntryInfoByResourceId( |
2052 resource_id, | 2052 resource_id, |
2053 base::Bind(&GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry, | 2053 base::Bind(&GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry, |
2054 ui_weak_ptr_, | 2054 ui_weak_ptr_, |
2055 callback, | 2055 callback, |
2056 *file_size, | 2056 *file_size, |
2057 cache_file_path)); | 2057 cache_file_path)); |
2058 } | 2058 } |
2059 | 2059 |
2060 void GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry( | 2060 void GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry( |
2061 const FileOperationCallback& callback, | 2061 const FileOperationCallback& callback, |
2062 int64 file_size, | 2062 int64 file_size, |
2063 const FilePath& cache_file_path, | 2063 const FilePath& cache_file_path, |
2064 GDataFileError error, | 2064 DriveFileError error, |
2065 const FilePath& drive_file_path, | 2065 const FilePath& drive_file_path, |
2066 scoped_ptr<DriveEntryProto> entry_proto) { | 2066 scoped_ptr<DriveEntryProto> entry_proto) { |
2067 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2067 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2068 DCHECK(!callback.is_null()); | 2068 DCHECK(!callback.is_null()); |
2069 | 2069 |
2070 if (error != GDATA_FILE_OK) { | 2070 if (error != DRIVE_FILE_OK) { |
2071 callback.Run(error); | 2071 callback.Run(error); |
2072 return; | 2072 return; |
2073 } | 2073 } |
2074 | 2074 |
2075 DCHECK(entry_proto.get()); | 2075 DCHECK(entry_proto.get()); |
2076 if (entry_proto->file_info().is_directory()) { | 2076 if (entry_proto->file_info().is_directory()) { |
2077 callback.Run(GDATA_FILE_ERROR_NOT_FOUND); | 2077 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND); |
2078 return; | 2078 return; |
2079 } | 2079 } |
2080 | 2080 |
2081 uploader_->UploadExistingFile( | 2081 uploader_->UploadExistingFile( |
2082 GURL(entry_proto->upload_url()), | 2082 GURL(entry_proto->upload_url()), |
2083 drive_file_path, | 2083 drive_file_path, |
2084 cache_file_path, | 2084 cache_file_path, |
2085 file_size, | 2085 file_size, |
2086 entry_proto->file_specific_info().content_mime_type(), | 2086 entry_proto->file_specific_info().content_mime_type(), |
2087 base::Bind(&GDataFileSystem::OnUpdatedFileUploaded, | 2087 base::Bind(&GDataFileSystem::OnUpdatedFileUploaded, |
2088 ui_weak_ptr_, | 2088 ui_weak_ptr_, |
2089 callback)); | 2089 callback)); |
2090 } | 2090 } |
2091 | 2091 |
2092 void GDataFileSystem::OnUpdatedFileUploaded( | 2092 void GDataFileSystem::OnUpdatedFileUploaded( |
2093 const FileOperationCallback& callback, | 2093 const FileOperationCallback& callback, |
2094 GDataFileError error, | 2094 DriveFileError error, |
2095 scoped_ptr<UploadFileInfo> upload_file_info) { | 2095 scoped_ptr<UploadFileInfo> upload_file_info) { |
2096 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2096 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2097 DCHECK(upload_file_info.get()); | 2097 DCHECK(upload_file_info.get()); |
2098 | 2098 |
2099 if (error != GDATA_FILE_OK) { | 2099 if (error != DRIVE_FILE_OK) { |
2100 if (!callback.is_null()) | 2100 if (!callback.is_null()) |
2101 callback.Run(error); | 2101 callback.Run(error); |
2102 return; | 2102 return; |
2103 } | 2103 } |
2104 | 2104 |
2105 AddUploadedFile(UPLOAD_EXISTING_FILE, | 2105 AddUploadedFile(UPLOAD_EXISTING_FILE, |
2106 upload_file_info->gdata_path.DirName(), | 2106 upload_file_info->gdata_path.DirName(), |
2107 upload_file_info->entry.Pass(), | 2107 upload_file_info->entry.Pass(), |
2108 upload_file_info->file_path, | 2108 upload_file_info->file_path, |
2109 DriveCache::FILE_OPERATION_MOVE, | 2109 DriveCache::FILE_OPERATION_MOVE, |
(...skipping 24 matching lines...) Expand all Loading... |
2134 callback)); | 2134 callback)); |
2135 } | 2135 } |
2136 | 2136 |
2137 void GDataFileSystem::OnGetAvailableSpace( | 2137 void GDataFileSystem::OnGetAvailableSpace( |
2138 const GetAvailableSpaceCallback& callback, | 2138 const GetAvailableSpaceCallback& callback, |
2139 GDataErrorCode status, | 2139 GDataErrorCode status, |
2140 scoped_ptr<base::Value> data) { | 2140 scoped_ptr<base::Value> data) { |
2141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2142 DCHECK(!callback.is_null()); | 2142 DCHECK(!callback.is_null()); |
2143 | 2143 |
2144 GDataFileError error = util::GDataToGDataFileError(status); | 2144 DriveFileError error = util::GDataToDriveFileError(status); |
2145 if (error != GDATA_FILE_OK) { | 2145 if (error != DRIVE_FILE_OK) { |
2146 callback.Run(error, -1, -1); | 2146 callback.Run(error, -1, -1); |
2147 return; | 2147 return; |
2148 } | 2148 } |
2149 | 2149 |
2150 scoped_ptr<AccountMetadataFeed> feed; | 2150 scoped_ptr<AccountMetadataFeed> feed; |
2151 if (data.get()) | 2151 if (data.get()) |
2152 feed = AccountMetadataFeed::CreateFrom(*data); | 2152 feed = AccountMetadataFeed::CreateFrom(*data); |
2153 if (!feed.get()) { | 2153 if (!feed.get()) { |
2154 callback.Run(GDATA_FILE_ERROR_FAILED, -1, -1); | 2154 callback.Run(DRIVE_FILE_ERROR_FAILED, -1, -1); |
2155 return; | 2155 return; |
2156 } | 2156 } |
2157 | 2157 |
2158 callback.Run(GDATA_FILE_OK, | 2158 callback.Run(DRIVE_FILE_OK, |
2159 feed->quota_bytes_total(), | 2159 feed->quota_bytes_total(), |
2160 feed->quota_bytes_used()); | 2160 feed->quota_bytes_used()); |
2161 } | 2161 } |
2162 | 2162 |
2163 void GDataFileSystem::OnGetAboutResource( | 2163 void GDataFileSystem::OnGetAboutResource( |
2164 const GetAvailableSpaceCallback& callback, | 2164 const GetAvailableSpaceCallback& callback, |
2165 GDataErrorCode status, | 2165 GDataErrorCode status, |
2166 scoped_ptr<base::Value> resource_json) { | 2166 scoped_ptr<base::Value> resource_json) { |
2167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2168 DCHECK(!callback.is_null()); | 2168 DCHECK(!callback.is_null()); |
2169 | 2169 |
2170 GDataFileError error = util::GDataToGDataFileError(status); | 2170 DriveFileError error = util::GDataToDriveFileError(status); |
2171 if (error != GDATA_FILE_OK) { | 2171 if (error != DRIVE_FILE_OK) { |
2172 callback.Run(error, -1, -1); | 2172 callback.Run(error, -1, -1); |
2173 return; | 2173 return; |
2174 } | 2174 } |
2175 | 2175 |
2176 scoped_ptr<AboutResource> about; | 2176 scoped_ptr<AboutResource> about; |
2177 if (resource_json.get()) | 2177 if (resource_json.get()) |
2178 about = AboutResource::CreateFrom(*resource_json); | 2178 about = AboutResource::CreateFrom(*resource_json); |
2179 | 2179 |
2180 if (!about.get()) { | 2180 if (!about.get()) { |
2181 callback.Run(GDATA_FILE_ERROR_FAILED, -1, -1); | 2181 callback.Run(DRIVE_FILE_ERROR_FAILED, -1, -1); |
2182 return; | 2182 return; |
2183 } | 2183 } |
2184 | 2184 |
2185 callback.Run(GDATA_FILE_OK, | 2185 callback.Run(DRIVE_FILE_OK, |
2186 about->quota_bytes_total(), | 2186 about->quota_bytes_total(), |
2187 about->quota_bytes_used()); | 2187 about->quota_bytes_used()); |
2188 } | 2188 } |
2189 | 2189 |
2190 void GDataFileSystem::OnCreateDirectoryCompleted( | 2190 void GDataFileSystem::OnCreateDirectoryCompleted( |
2191 const CreateDirectoryParams& params, | 2191 const CreateDirectoryParams& params, |
2192 GDataErrorCode status, | 2192 GDataErrorCode status, |
2193 scoped_ptr<base::Value> data) { | 2193 scoped_ptr<base::Value> data) { |
2194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2195 | 2195 |
2196 GDataFileError error = util::GDataToGDataFileError(status); | 2196 DriveFileError error = util::GDataToDriveFileError(status); |
2197 if (error != GDATA_FILE_OK) { | 2197 if (error != DRIVE_FILE_OK) { |
2198 if (!params.callback.is_null()) | 2198 if (!params.callback.is_null()) |
2199 params.callback.Run(error); | 2199 params.callback.Run(error); |
2200 | 2200 |
2201 return; | 2201 return; |
2202 } | 2202 } |
2203 | 2203 |
2204 base::DictionaryValue* dict_value = NULL; | 2204 base::DictionaryValue* dict_value = NULL; |
2205 base::Value* created_entry = NULL; | 2205 base::Value* created_entry = NULL; |
2206 if (data.get() && data->GetAsDictionary(&dict_value) && dict_value) | 2206 if (data.get() && data->GetAsDictionary(&dict_value) && dict_value) |
2207 dict_value->Get("entry", &created_entry); | 2207 dict_value->Get("entry", &created_entry); |
2208 error = AddNewDirectory(params.created_directory_path.DirName(), | 2208 error = AddNewDirectory(params.created_directory_path.DirName(), |
2209 created_entry); | 2209 created_entry); |
2210 | 2210 |
2211 if (error != GDATA_FILE_OK) { | 2211 if (error != DRIVE_FILE_OK) { |
2212 if (!params.callback.is_null()) | 2212 if (!params.callback.is_null()) |
2213 params.callback.Run(error); | 2213 params.callback.Run(error); |
2214 | 2214 |
2215 return; | 2215 return; |
2216 } | 2216 } |
2217 | 2217 |
2218 // Not done yet with recursive directory creation? | 2218 // Not done yet with recursive directory creation? |
2219 if (params.target_directory_path != params.created_directory_path && | 2219 if (params.target_directory_path != params.created_directory_path && |
2220 params.is_recursive) { | 2220 params.is_recursive) { |
2221 CreateDirectory(params.target_directory_path, | 2221 CreateDirectory(params.target_directory_path, |
2222 params.is_exclusive, | 2222 params.is_exclusive, |
2223 params.is_recursive, | 2223 params.is_recursive, |
2224 params.callback); | 2224 params.callback); |
2225 return; | 2225 return; |
2226 } | 2226 } |
2227 | 2227 |
2228 if (!params.callback.is_null()) { | 2228 if (!params.callback.is_null()) { |
2229 // Finally done with the create request. | 2229 // Finally done with the create request. |
2230 params.callback.Run(GDATA_FILE_OK); | 2230 params.callback.Run(DRIVE_FILE_OK); |
2231 } | 2231 } |
2232 } | 2232 } |
2233 | 2233 |
2234 void GDataFileSystem::OnSearch(const SearchCallback& callback, | 2234 void GDataFileSystem::OnSearch(const SearchCallback& callback, |
2235 GetDocumentsParams* params, | 2235 GetDocumentsParams* params, |
2236 GDataFileError error) { | 2236 DriveFileError error) { |
2237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2238 | 2238 |
2239 if (error != GDATA_FILE_OK) { | 2239 if (error != DRIVE_FILE_OK) { |
2240 if (!callback.is_null()) | 2240 if (!callback.is_null()) |
2241 callback.Run(error, GURL(), scoped_ptr<std::vector<SearchResultInfo> >()); | 2241 callback.Run(error, GURL(), scoped_ptr<std::vector<SearchResultInfo> >()); |
2242 return; | 2242 return; |
2243 } | 2243 } |
2244 | 2244 |
2245 // The search results will be returned using virtual directory. | 2245 // The search results will be returned using virtual directory. |
2246 // The directory is not really part of the file system, so it has no parent or | 2246 // The directory is not really part of the file system, so it has no parent or |
2247 // root. | 2247 // root. |
2248 std::vector<SearchResultInfo>* results(new std::vector<SearchResultInfo>()); | 2248 std::vector<SearchResultInfo>* results(new std::vector<SearchResultInfo>()); |
2249 | 2249 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2345 } | 2345 } |
2346 | 2346 |
2347 void GDataFileSystem::LoadRootFeedFromCacheForTesting() { | 2347 void GDataFileSystem::LoadRootFeedFromCacheForTesting() { |
2348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2349 | 2349 |
2350 feed_loader_->LoadFromCache( | 2350 feed_loader_->LoadFromCache( |
2351 false, // should_load_from_server. | 2351 false, // should_load_from_server. |
2352 FileOperationCallback()); | 2352 FileOperationCallback()); |
2353 } | 2353 } |
2354 | 2354 |
2355 GDataFileError GDataFileSystem::UpdateFromFeedForTesting( | 2355 DriveFileError GDataFileSystem::UpdateFromFeedForTesting( |
2356 const std::vector<DocumentFeed*>& feed_list, | 2356 const std::vector<DocumentFeed*>& feed_list, |
2357 int64 start_changestamp, | 2357 int64 start_changestamp, |
2358 int64 root_feed_changestamp) { | 2358 int64 root_feed_changestamp) { |
2359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2360 | 2360 |
2361 return feed_loader_->UpdateFromFeed(feed_list, | 2361 return feed_loader_->UpdateFromFeed(feed_list, |
2362 start_changestamp, | 2362 start_changestamp, |
2363 root_feed_changestamp); | 2363 root_feed_changestamp); |
2364 } | 2364 } |
2365 | 2365 |
2366 void GDataFileSystem::OnFilePathUpdated(const FileOperationCallback& callback, | 2366 void GDataFileSystem::OnFilePathUpdated(const FileOperationCallback& callback, |
2367 GDataFileError error, | 2367 DriveFileError error, |
2368 const FilePath& /* file_path */) { | 2368 const FilePath& /* file_path */) { |
2369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2370 if (!callback.is_null()) | 2370 if (!callback.is_null()) |
2371 callback.Run(error); | 2371 callback.Run(error); |
2372 } | 2372 } |
2373 | 2373 |
2374 void GDataFileSystem::OnCopyDocumentCompleted( | 2374 void GDataFileSystem::OnCopyDocumentCompleted( |
2375 const FilePath& dir_path, | 2375 const FilePath& dir_path, |
2376 const FileOperationCallback& callback, | 2376 const FileOperationCallback& callback, |
2377 GDataErrorCode status, | 2377 GDataErrorCode status, |
2378 scoped_ptr<base::Value> data) { | 2378 scoped_ptr<base::Value> data) { |
2379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2380 DCHECK(!callback.is_null()); | 2380 DCHECK(!callback.is_null()); |
2381 | 2381 |
2382 GDataFileError error = util::GDataToGDataFileError(status); | 2382 DriveFileError error = util::GDataToDriveFileError(status); |
2383 if (error != GDATA_FILE_OK) { | 2383 if (error != DRIVE_FILE_OK) { |
2384 callback.Run(error); | 2384 callback.Run(error); |
2385 return; | 2385 return; |
2386 } | 2386 } |
2387 | 2387 |
2388 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); | 2388 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); |
2389 if (!doc_entry.get()) { | 2389 if (!doc_entry.get()) { |
2390 callback.Run(GDATA_FILE_ERROR_FAILED); | 2390 callback.Run(DRIVE_FILE_ERROR_FAILED); |
2391 return; | 2391 return; |
2392 } | 2392 } |
2393 | 2393 |
2394 DriveEntry* entry = resource_metadata_->FromDocumentEntry(*doc_entry); | 2394 DriveEntry* entry = resource_metadata_->FromDocumentEntry(*doc_entry); |
2395 if (!entry) { | 2395 if (!entry) { |
2396 callback.Run(GDATA_FILE_ERROR_FAILED); | 2396 callback.Run(DRIVE_FILE_ERROR_FAILED); |
2397 return; | 2397 return; |
2398 } | 2398 } |
2399 | 2399 |
2400 // |entry| was added in the root directory on the server, so we should | 2400 // |entry| was added in the root directory on the server, so we should |
2401 // first add it to |root_| to mirror the state and then move it to the | 2401 // first add it to |root_| to mirror the state and then move it to the |
2402 // destination directory by MoveEntryFromRootDirectory(). | 2402 // destination directory by MoveEntryFromRootDirectory(). |
2403 resource_metadata_->AddEntryToDirectory( | 2403 resource_metadata_->AddEntryToDirectory( |
2404 resource_metadata_->root(), | 2404 resource_metadata_->root(), |
2405 entry, | 2405 entry, |
2406 base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory, | 2406 base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory, |
2407 ui_weak_ptr_, | 2407 ui_weak_ptr_, |
2408 dir_path, | 2408 dir_path, |
2409 callback)); | 2409 callback)); |
2410 } | 2410 } |
2411 | 2411 |
2412 void GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted( | 2412 void GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted( |
2413 const FileOperationCallback& callback, | 2413 const FileOperationCallback& callback, |
2414 const FilePath& file_path, | 2414 const FilePath& file_path, |
2415 const FilePath& dir_path, | 2415 const FilePath& dir_path, |
2416 GDataErrorCode status, | 2416 GDataErrorCode status, |
2417 const GURL& document_url) { | 2417 const GURL& document_url) { |
2418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2419 DCHECK(!callback.is_null()); | 2419 DCHECK(!callback.is_null()); |
2420 | 2420 |
2421 GDataFileError error = util::GDataToGDataFileError(status); | 2421 DriveFileError error = util::GDataToDriveFileError(status); |
2422 if (error == GDATA_FILE_OK) { | 2422 if (error == DRIVE_FILE_OK) { |
2423 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path); | 2423 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path); |
2424 if (entry) { | 2424 if (entry) { |
2425 DCHECK_EQ(resource_metadata_->root(), entry->parent()); | 2425 DCHECK_EQ(resource_metadata_->root(), entry->parent()); |
2426 resource_metadata_->MoveEntryToDirectory( | 2426 resource_metadata_->MoveEntryToDirectory( |
2427 dir_path, | 2427 dir_path, |
2428 entry, | 2428 entry, |
2429 base::Bind( | 2429 base::Bind( |
2430 &GDataFileSystem::NotifyAndRunFileOperationCallback, | 2430 &GDataFileSystem::NotifyAndRunFileOperationCallback, |
2431 ui_weak_ptr_, | 2431 ui_weak_ptr_, |
2432 callback)); | 2432 callback)); |
2433 return; | 2433 return; |
2434 } else { | 2434 } else { |
2435 error = GDATA_FILE_ERROR_NOT_FOUND; | 2435 error = DRIVE_FILE_ERROR_NOT_FOUND; |
2436 } | 2436 } |
2437 } | 2437 } |
2438 | 2438 |
2439 callback.Run(error); | 2439 callback.Run(error); |
2440 } | 2440 } |
2441 | 2441 |
2442 void GDataFileSystem::OnRemovedDocument( | 2442 void GDataFileSystem::OnRemovedDocument( |
2443 const FileOperationCallback& callback, | 2443 const FileOperationCallback& callback, |
2444 const FilePath& file_path, | 2444 const FilePath& file_path, |
2445 GDataErrorCode status, | 2445 GDataErrorCode status, |
2446 const GURL& document_url) { | 2446 const GURL& document_url) { |
2447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2448 | 2448 |
2449 GDataFileError error = util::GDataToGDataFileError(status); | 2449 DriveFileError error = util::GDataToDriveFileError(status); |
2450 | 2450 |
2451 if (error == GDATA_FILE_OK) | 2451 if (error == DRIVE_FILE_OK) |
2452 error = RemoveEntryAndCacheLocally(file_path); | 2452 error = RemoveEntryAndCacheLocally(file_path); |
2453 | 2453 |
2454 if (!callback.is_null()) { | 2454 if (!callback.is_null()) { |
2455 callback.Run(error); | 2455 callback.Run(error); |
2456 } | 2456 } |
2457 } | 2457 } |
2458 | 2458 |
2459 void GDataFileSystem::OnFileDownloaded( | 2459 void GDataFileSystem::OnFileDownloaded( |
2460 const GetFileFromCacheParams& params, | 2460 const GetFileFromCacheParams& params, |
2461 GDataErrorCode status, | 2461 GDataErrorCode status, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2513 } | 2513 } |
2514 | 2514 |
2515 void GDataFileSystem::OnFileDownloadedAndSpaceChecked( | 2515 void GDataFileSystem::OnFileDownloadedAndSpaceChecked( |
2516 const GetFileFromCacheParams& params, | 2516 const GetFileFromCacheParams& params, |
2517 GDataErrorCode status, | 2517 GDataErrorCode status, |
2518 const GURL& content_url, | 2518 const GURL& content_url, |
2519 const FilePath& downloaded_file_path, | 2519 const FilePath& downloaded_file_path, |
2520 bool* has_enough_space) { | 2520 bool* has_enough_space) { |
2521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2522 | 2522 |
2523 GDataFileError error = util::GDataToGDataFileError(status); | 2523 DriveFileError error = util::GDataToDriveFileError(status); |
2524 | 2524 |
2525 // Make sure that downloaded file is properly stored in cache. We don't have | 2525 // Make sure that downloaded file is properly stored in cache. We don't have |
2526 // to wait for this operation to finish since the user can already use the | 2526 // to wait for this operation to finish since the user can already use the |
2527 // downloaded file. | 2527 // downloaded file. |
2528 if (error == GDATA_FILE_OK) { | 2528 if (error == DRIVE_FILE_OK) { |
2529 if (*has_enough_space) { | 2529 if (*has_enough_space) { |
2530 cache_->StoreOnUIThread( | 2530 cache_->StoreOnUIThread( |
2531 params.resource_id, | 2531 params.resource_id, |
2532 params.md5, | 2532 params.md5, |
2533 downloaded_file_path, | 2533 downloaded_file_path, |
2534 DriveCache::FILE_OPERATION_MOVE, | 2534 DriveCache::FILE_OPERATION_MOVE, |
2535 base::Bind(&GDataFileSystem::OnDownloadStoredToCache, | 2535 base::Bind(&GDataFileSystem::OnDownloadStoredToCache, |
2536 ui_weak_ptr_)); | 2536 ui_weak_ptr_)); |
2537 } else { | 2537 } else { |
2538 // If we don't have enough space, remove the downloaded file, and | 2538 // If we don't have enough space, remove the downloaded file, and |
2539 // report "no space" error. | 2539 // report "no space" error. |
2540 util::PostBlockingPoolSequencedTask( | 2540 util::PostBlockingPoolSequencedTask( |
2541 FROM_HERE, | 2541 FROM_HERE, |
2542 blocking_task_runner_, | 2542 blocking_task_runner_, |
2543 base::Bind(base::IgnoreResult(&file_util::Delete), | 2543 base::Bind(base::IgnoreResult(&file_util::Delete), |
2544 downloaded_file_path, | 2544 downloaded_file_path, |
2545 false /* recursive*/)); | 2545 false /* recursive*/)); |
2546 error = GDATA_FILE_ERROR_NO_SPACE; | 2546 error = DRIVE_FILE_ERROR_NO_SPACE; |
2547 } | 2547 } |
2548 } | 2548 } |
2549 | 2549 |
2550 if (!params.get_file_callback.is_null()) { | 2550 if (!params.get_file_callback.is_null()) { |
2551 params.get_file_callback.Run(error, | 2551 params.get_file_callback.Run(error, |
2552 downloaded_file_path, | 2552 downloaded_file_path, |
2553 params.mime_type, | 2553 params.mime_type, |
2554 REGULAR_FILE); | 2554 REGULAR_FILE); |
2555 } | 2555 } |
2556 } | 2556 } |
2557 | 2557 |
2558 void GDataFileSystem::OnDownloadStoredToCache(GDataFileError error, | 2558 void GDataFileSystem::OnDownloadStoredToCache(DriveFileError error, |
2559 const std::string& resource_id, | 2559 const std::string& resource_id, |
2560 const std::string& md5) { | 2560 const std::string& md5) { |
2561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2562 // Nothing much to do here for now. | 2562 // Nothing much to do here for now. |
2563 } | 2563 } |
2564 | 2564 |
2565 void GDataFileSystem::RenameEntryLocally( | 2565 void GDataFileSystem::RenameEntryLocally( |
2566 const FilePath& file_path, | 2566 const FilePath& file_path, |
2567 const FilePath::StringType& new_name, | 2567 const FilePath::StringType& new_name, |
2568 const FileMoveCallback& callback, | 2568 const FileMoveCallback& callback, |
2569 GDataErrorCode status, | 2569 GDataErrorCode status, |
2570 const GURL& document_url) { | 2570 const GURL& document_url) { |
2571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2572 | 2572 |
2573 const GDataFileError error = util::GDataToGDataFileError(status); | 2573 const DriveFileError error = util::GDataToDriveFileError(status); |
2574 if (error != GDATA_FILE_OK) { | 2574 if (error != DRIVE_FILE_OK) { |
2575 if (!callback.is_null()) | 2575 if (!callback.is_null()) |
2576 callback.Run(error, FilePath()); | 2576 callback.Run(error, FilePath()); |
2577 return; | 2577 return; |
2578 } | 2578 } |
2579 | 2579 |
2580 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path); | 2580 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path); |
2581 if (!entry) { | 2581 if (!entry) { |
2582 if (!callback.is_null()) | 2582 if (!callback.is_null()) |
2583 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath()); | 2583 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, FilePath()); |
2584 return; | 2584 return; |
2585 } | 2585 } |
2586 | 2586 |
2587 DCHECK(entry->parent()); | 2587 DCHECK(entry->parent()); |
2588 entry->set_title(new_name); | 2588 entry->set_title(new_name); |
2589 // After changing the title of the entry, call MoveEntryToDirectory() to | 2589 // After changing the title of the entry, call MoveEntryToDirectory() to |
2590 // remove the entry from its parent directory and then add it back in order to | 2590 // remove the entry from its parent directory and then add it back in order to |
2591 // go through the file name de-duplication. | 2591 // go through the file name de-duplication. |
2592 // TODO(achuith/satorux/zel): This code is fragile. The title has been | 2592 // TODO(achuith/satorux/zel): This code is fragile. The title has been |
2593 // changed, but not the file_name. MoveEntryToDirectory calls RemoveChild to | 2593 // changed, but not the file_name. MoveEntryToDirectory calls RemoveChild to |
2594 // remove the child based on the old file_name, and then re-adds the child by | 2594 // remove the child based on the old file_name, and then re-adds the child by |
2595 // first assigning the new title to file_name. http://crbug.com/30157 | 2595 // first assigning the new title to file_name. http://crbug.com/30157 |
2596 resource_metadata_->MoveEntryToDirectory( | 2596 resource_metadata_->MoveEntryToDirectory( |
2597 entry->parent()->GetFilePath(), | 2597 entry->parent()->GetFilePath(), |
2598 entry, | 2598 entry, |
2599 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, | 2599 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, |
2600 ui_weak_ptr_, | 2600 ui_weak_ptr_, |
2601 callback)); | 2601 callback)); |
2602 } | 2602 } |
2603 | 2603 |
2604 void GDataFileSystem::MoveEntryToRootDirectoryLocally( | 2604 void GDataFileSystem::MoveEntryToRootDirectoryLocally( |
2605 const FileMoveCallback& callback, | 2605 const FileMoveCallback& callback, |
2606 const FilePath& file_path, | 2606 const FilePath& file_path, |
2607 const FilePath& dir_path, | 2607 const FilePath& dir_path, |
2608 GDataErrorCode status, | 2608 GDataErrorCode status, |
2609 const GURL& document_url) { | 2609 const GURL& document_url) { |
2610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2611 DCHECK(!callback.is_null()); | 2611 DCHECK(!callback.is_null()); |
2612 | 2612 |
2613 const GDataFileError error = util::GDataToGDataFileError(status); | 2613 const DriveFileError error = util::GDataToDriveFileError(status); |
2614 if (error != GDATA_FILE_OK) { | 2614 if (error != DRIVE_FILE_OK) { |
2615 callback.Run(error, FilePath()); | 2615 callback.Run(error, FilePath()); |
2616 return; | 2616 return; |
2617 } | 2617 } |
2618 | 2618 |
2619 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path); | 2619 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path); |
2620 if (!entry) { | 2620 if (!entry) { |
2621 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath()); | 2621 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, FilePath()); |
2622 return; | 2622 return; |
2623 } | 2623 } |
2624 | 2624 |
2625 resource_metadata_->MoveEntryToDirectory( | 2625 resource_metadata_->MoveEntryToDirectory( |
2626 resource_metadata_->root()->GetFilePath(), | 2626 resource_metadata_->root()->GetFilePath(), |
2627 entry, | 2627 entry, |
2628 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, | 2628 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, |
2629 ui_weak_ptr_, | 2629 ui_weak_ptr_, |
2630 callback)); | 2630 callback)); |
2631 } | 2631 } |
2632 | 2632 |
2633 void GDataFileSystem::NotifyAndRunFileMoveCallback( | 2633 void GDataFileSystem::NotifyAndRunFileMoveCallback( |
2634 const FileMoveCallback& callback, | 2634 const FileMoveCallback& callback, |
2635 GDataFileError error, | 2635 DriveFileError error, |
2636 const FilePath& moved_file_path) { | 2636 const FilePath& moved_file_path) { |
2637 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2637 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2638 | 2638 |
2639 if (error == GDATA_FILE_OK) | 2639 if (error == DRIVE_FILE_OK) |
2640 OnDirectoryChanged(moved_file_path.DirName()); | 2640 OnDirectoryChanged(moved_file_path.DirName()); |
2641 | 2641 |
2642 if (!callback.is_null()) | 2642 if (!callback.is_null()) |
2643 callback.Run(error, moved_file_path); | 2643 callback.Run(error, moved_file_path); |
2644 } | 2644 } |
2645 | 2645 |
2646 void GDataFileSystem::NotifyAndRunFileOperationCallback( | 2646 void GDataFileSystem::NotifyAndRunFileOperationCallback( |
2647 const FileOperationCallback& callback, | 2647 const FileOperationCallback& callback, |
2648 GDataFileError error, | 2648 DriveFileError error, |
2649 const FilePath& moved_file_path) { | 2649 const FilePath& moved_file_path) { |
2650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2651 DCHECK(!callback.is_null()); | 2651 DCHECK(!callback.is_null()); |
2652 | 2652 |
2653 if (error == GDATA_FILE_OK) | 2653 if (error == DRIVE_FILE_OK) |
2654 OnDirectoryChanged(moved_file_path.DirName()); | 2654 OnDirectoryChanged(moved_file_path.DirName()); |
2655 | 2655 |
2656 callback.Run(error); | 2656 callback.Run(error); |
2657 } | 2657 } |
2658 | 2658 |
2659 void GDataFileSystem::OnDirectoryChangeFileMoveCallback( | 2659 void GDataFileSystem::OnDirectoryChangeFileMoveCallback( |
2660 GDataFileError error, | 2660 DriveFileError error, |
2661 const FilePath& directory_path) { | 2661 const FilePath& directory_path) { |
2662 if (error == GDATA_FILE_OK) | 2662 if (error == DRIVE_FILE_OK) |
2663 OnDirectoryChanged(directory_path); | 2663 OnDirectoryChanged(directory_path); |
2664 } | 2664 } |
2665 | 2665 |
2666 GDataFileError GDataFileSystem::RemoveEntryAndCacheLocally( | 2666 DriveFileError GDataFileSystem::RemoveEntryAndCacheLocally( |
2667 const FilePath& file_path) { | 2667 const FilePath& file_path) { |
2668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2669 | 2669 |
2670 std::string resource_id; | 2670 std::string resource_id; |
2671 GDataFileError error = RemoveEntryLocally(file_path, &resource_id); | 2671 DriveFileError error = RemoveEntryLocally(file_path, &resource_id); |
2672 if (error != GDATA_FILE_OK) | 2672 if (error != DRIVE_FILE_OK) |
2673 return error; | 2673 return error; |
2674 | 2674 |
2675 // If resource_id is not empty, remove its corresponding file from cache. | 2675 // If resource_id is not empty, remove its corresponding file from cache. |
2676 if (!resource_id.empty()) | 2676 if (!resource_id.empty()) |
2677 cache_->RemoveOnUIThread(resource_id, CacheOperationCallback()); | 2677 cache_->RemoveOnUIThread(resource_id, CacheOperationCallback()); |
2678 | 2678 |
2679 return GDATA_FILE_OK; | 2679 return DRIVE_FILE_OK; |
2680 } | 2680 } |
2681 | 2681 |
2682 void GDataFileSystem::RemoveStaleEntryOnUpload( | 2682 void GDataFileSystem::RemoveStaleEntryOnUpload( |
2683 const std::string& resource_id, | 2683 const std::string& resource_id, |
2684 DriveDirectory* parent_dir, | 2684 DriveDirectory* parent_dir, |
2685 const FileMoveCallback& callback, | 2685 const FileMoveCallback& callback, |
2686 DriveEntry* existing_entry) { | 2686 DriveEntry* existing_entry) { |
2687 if (existing_entry && | 2687 if (existing_entry && |
2688 // This should always match, but just in case. | 2688 // This should always match, but just in case. |
2689 existing_entry->parent() == parent_dir) { | 2689 existing_entry->parent() == parent_dir) { |
2690 resource_metadata_->RemoveEntryFromParent(existing_entry, callback); | 2690 resource_metadata_->RemoveEntryFromParent(existing_entry, callback); |
2691 } else { | 2691 } else { |
2692 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath()); | 2692 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, FilePath()); |
2693 LOG(ERROR) << "Entry for the existing file not found: " << resource_id; | 2693 LOG(ERROR) << "Entry for the existing file not found: " << resource_id; |
2694 } | 2694 } |
2695 } | 2695 } |
2696 | 2696 |
2697 void GDataFileSystem::NotifyFileSystemMounted() { | 2697 void GDataFileSystem::NotifyFileSystemMounted() { |
2698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2699 | 2699 |
2700 DVLOG(1) << "File System is mounted"; | 2700 DVLOG(1) << "File System is mounted"; |
2701 // Notify the observers that the file system is mounted. | 2701 // Notify the observers that the file system is mounted. |
2702 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2702 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
2703 OnFileSystemMounted()); | 2703 OnFileSystemMounted()); |
2704 } | 2704 } |
2705 | 2705 |
2706 void GDataFileSystem::NotifyFileSystemToBeUnmounted() { | 2706 void GDataFileSystem::NotifyFileSystemToBeUnmounted() { |
2707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2708 | 2708 |
2709 DVLOG(1) << "File System is to be unmounted"; | 2709 DVLOG(1) << "File System is to be unmounted"; |
2710 // Notify the observers that the file system is being unmounted. | 2710 // Notify the observers that the file system is being unmounted. |
2711 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2711 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
2712 OnFileSystemBeingUnmounted()); | 2712 OnFileSystemBeingUnmounted()); |
2713 } | 2713 } |
2714 | 2714 |
2715 void GDataFileSystem::NotifyInitialLoadFinishedAndRun( | 2715 void GDataFileSystem::NotifyInitialLoadFinishedAndRun( |
2716 const FileOperationCallback& callback, | 2716 const FileOperationCallback& callback, |
2717 GDataFileError error) { | 2717 DriveFileError error) { |
2718 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2718 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2719 DCHECK(!callback.is_null()); | 2719 DCHECK(!callback.is_null()); |
2720 | 2720 |
2721 // Notify the observers that root directory has been initialized. | 2721 // Notify the observers that root directory has been initialized. |
2722 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2722 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
2723 OnInitialLoadFinished()); | 2723 OnInitialLoadFinished()); |
2724 | 2724 |
2725 callback.Run(error); | 2725 callback.Run(error); |
2726 } | 2726 } |
2727 | 2727 |
2728 GDataFileError GDataFileSystem::AddNewDirectory( | 2728 DriveFileError GDataFileSystem::AddNewDirectory( |
2729 const FilePath& directory_path, base::Value* entry_value) { | 2729 const FilePath& directory_path, base::Value* entry_value) { |
2730 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2730 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2731 | 2731 |
2732 if (!entry_value) | 2732 if (!entry_value) |
2733 return GDATA_FILE_ERROR_FAILED; | 2733 return DRIVE_FILE_ERROR_FAILED; |
2734 | 2734 |
2735 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value)); | 2735 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value)); |
2736 | 2736 |
2737 if (!doc_entry.get()) | 2737 if (!doc_entry.get()) |
2738 return GDATA_FILE_ERROR_FAILED; | 2738 return DRIVE_FILE_ERROR_FAILED; |
2739 | 2739 |
2740 // Find parent directory element within the cached file system snapshot. | 2740 // Find parent directory element within the cached file system snapshot. |
2741 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(directory_path); | 2741 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(directory_path); |
2742 if (!entry) | 2742 if (!entry) |
2743 return GDATA_FILE_ERROR_FAILED; | 2743 return DRIVE_FILE_ERROR_FAILED; |
2744 | 2744 |
2745 // Check if parent is a directory since in theory since this is a callback | 2745 // Check if parent is a directory since in theory since this is a callback |
2746 // something could in the meantime have nuked the parent dir and created a | 2746 // something could in the meantime have nuked the parent dir and created a |
2747 // file with the exact same name. | 2747 // file with the exact same name. |
2748 DriveDirectory* parent_dir = entry->AsDriveDirectory(); | 2748 DriveDirectory* parent_dir = entry->AsDriveDirectory(); |
2749 if (!parent_dir) | 2749 if (!parent_dir) |
2750 return GDATA_FILE_ERROR_FAILED; | 2750 return DRIVE_FILE_ERROR_FAILED; |
2751 | 2751 |
2752 DriveEntry* new_entry = | 2752 DriveEntry* new_entry = |
2753 resource_metadata_->FromDocumentEntry(*doc_entry); | 2753 resource_metadata_->FromDocumentEntry(*doc_entry); |
2754 if (!new_entry) | 2754 if (!new_entry) |
2755 return GDATA_FILE_ERROR_FAILED; | 2755 return DRIVE_FILE_ERROR_FAILED; |
2756 | 2756 |
2757 resource_metadata_->AddEntryToDirectory( | 2757 resource_metadata_->AddEntryToDirectory( |
2758 parent_dir, | 2758 parent_dir, |
2759 new_entry, | 2759 new_entry, |
2760 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, | 2760 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, |
2761 ui_weak_ptr_, | 2761 ui_weak_ptr_, |
2762 FileMoveCallback())); | 2762 FileMoveCallback())); |
2763 return GDATA_FILE_OK; | 2763 return DRIVE_FILE_OK; |
2764 } | 2764 } |
2765 | 2765 |
2766 GDataFileSystem::FindMissingDirectoryResult | 2766 GDataFileSystem::FindMissingDirectoryResult |
2767 GDataFileSystem::FindFirstMissingParentDirectory( | 2767 GDataFileSystem::FindFirstMissingParentDirectory( |
2768 const FilePath& directory_path, | 2768 const FilePath& directory_path, |
2769 GURL* last_dir_content_url, | 2769 GURL* last_dir_content_url, |
2770 FilePath* first_missing_parent_path) { | 2770 FilePath* first_missing_parent_path) { |
2771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2772 | 2772 |
2773 // Let's find which how deep is the existing directory structure and | 2773 // Let's find which how deep is the existing directory structure and |
(...skipping 15 matching lines...) Expand all Loading... |
2789 return FOUND_INVALID; | 2789 return FOUND_INVALID; |
2790 } | 2790 } |
2791 } else { | 2791 } else { |
2792 *first_missing_parent_path = current_path; | 2792 *first_missing_parent_path = current_path; |
2793 return FOUND_MISSING; | 2793 return FOUND_MISSING; |
2794 } | 2794 } |
2795 } | 2795 } |
2796 return DIRECTORY_ALREADY_PRESENT; | 2796 return DIRECTORY_ALREADY_PRESENT; |
2797 } | 2797 } |
2798 | 2798 |
2799 GDataFileError GDataFileSystem::RemoveEntryLocally( | 2799 DriveFileError GDataFileSystem::RemoveEntryLocally( |
2800 const FilePath& file_path, std::string* resource_id) { | 2800 const FilePath& file_path, std::string* resource_id) { |
2801 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2801 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2802 | 2802 |
2803 resource_id->clear(); | 2803 resource_id->clear(); |
2804 | 2804 |
2805 // Find directory element within the cached file system snapshot. | 2805 // Find directory element within the cached file system snapshot. |
2806 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path); | 2806 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path); |
2807 | 2807 |
2808 if (!entry) | 2808 if (!entry) |
2809 return GDATA_FILE_ERROR_NOT_FOUND; | 2809 return DRIVE_FILE_ERROR_NOT_FOUND; |
2810 | 2810 |
2811 // You can't remove root element. | 2811 // You can't remove root element. |
2812 if (!entry->parent()) | 2812 if (!entry->parent()) |
2813 return GDATA_FILE_ERROR_ACCESS_DENIED; | 2813 return DRIVE_FILE_ERROR_ACCESS_DENIED; |
2814 | 2814 |
2815 // If it's a file (only files have resource id), get its resource id so that | 2815 // If it's a file (only files have resource id), get its resource id so that |
2816 // we can remove it after releasing the auto lock. | 2816 // we can remove it after releasing the auto lock. |
2817 if (entry->AsDriveFile()) | 2817 if (entry->AsDriveFile()) |
2818 *resource_id = entry->AsDriveFile()->resource_id(); | 2818 *resource_id = entry->AsDriveFile()->resource_id(); |
2819 | 2819 |
2820 resource_metadata_->RemoveEntryFromParent( | 2820 resource_metadata_->RemoveEntryFromParent( |
2821 entry, | 2821 entry, |
2822 base::Bind(&GDataFileSystem::OnDirectoryChangeFileMoveCallback, | 2822 base::Bind(&GDataFileSystem::OnDirectoryChangeFileMoveCallback, |
2823 ui_weak_ptr_)); | 2823 ui_weak_ptr_)); |
2824 return GDATA_FILE_OK; | 2824 return DRIVE_FILE_OK; |
2825 } | 2825 } |
2826 | 2826 |
2827 void GDataFileSystem::AddUploadedFile( | 2827 void GDataFileSystem::AddUploadedFile( |
2828 UploadMode upload_mode, | 2828 UploadMode upload_mode, |
2829 const FilePath& virtual_dir_path, | 2829 const FilePath& virtual_dir_path, |
2830 scoped_ptr<DocumentEntry> entry, | 2830 scoped_ptr<DocumentEntry> entry, |
2831 const FilePath& file_content_path, | 2831 const FilePath& file_content_path, |
2832 DriveCache::FileOperationType cache_operation, | 2832 DriveCache::FileOperationType cache_operation, |
2833 const base::Closure& callback) { | 2833 const base::Closure& callback) { |
2834 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2834 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2895 if (upload_mode == UPLOAD_EXISTING_FILE) { | 2895 if (upload_mode == UPLOAD_EXISTING_FILE) { |
2896 // Remove an existing entry, which should be present. | 2896 // Remove an existing entry, which should be present. |
2897 resource_metadata_->GetEntryByResourceIdAsync( | 2897 resource_metadata_->GetEntryByResourceIdAsync( |
2898 resource_id, | 2898 resource_id, |
2899 base::Bind(&GDataFileSystem::RemoveStaleEntryOnUpload, | 2899 base::Bind(&GDataFileSystem::RemoveStaleEntryOnUpload, |
2900 ui_weak_ptr_, | 2900 ui_weak_ptr_, |
2901 resource_id, | 2901 resource_id, |
2902 parent_dir, | 2902 parent_dir, |
2903 file_move_callback)); | 2903 file_move_callback)); |
2904 } else { | 2904 } else { |
2905 file_move_callback.Run(GDATA_FILE_OK, FilePath()); | 2905 file_move_callback.Run(DRIVE_FILE_OK, FilePath()); |
2906 } | 2906 } |
2907 } | 2907 } |
2908 | 2908 |
2909 void GDataFileSystem::ContinueAddUploadedFile( | 2909 void GDataFileSystem::ContinueAddUploadedFile( |
2910 AddUploadedFileParams* params, | 2910 AddUploadedFileParams* params, |
2911 GDataFileError error, | 2911 DriveFileError error, |
2912 const FilePath& file_path) { | 2912 const FilePath& file_path) { |
2913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2914 DCHECK_EQ(GDATA_FILE_OK, error); | 2914 DCHECK_EQ(DRIVE_FILE_OK, error); |
2915 DCHECK(params->new_entry.get()); | 2915 DCHECK(params->new_entry.get()); |
2916 DriveFile* file = params->new_entry->AsDriveFile(); | 2916 DriveFile* file = params->new_entry->AsDriveFile(); |
2917 DCHECK(file); | 2917 DCHECK(file); |
2918 | 2918 |
2919 params->resource_id = file->resource_id(); | 2919 params->resource_id = file->resource_id(); |
2920 params->md5 = file->file_md5(); | 2920 params->md5 = file->file_md5(); |
2921 resource_metadata_->AddEntryToDirectory( | 2921 resource_metadata_->AddEntryToDirectory( |
2922 params->parent_dir, | 2922 params->parent_dir, |
2923 params->new_entry.release(), | 2923 params->new_entry.release(), |
2924 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, | 2924 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, |
2925 ui_weak_ptr_, | 2925 ui_weak_ptr_, |
2926 base::Bind(&GDataFileSystem::AddUploadedFileToCache, | 2926 base::Bind(&GDataFileSystem::AddUploadedFileToCache, |
2927 ui_weak_ptr_, | 2927 ui_weak_ptr_, |
2928 base::Owned(params)))); | 2928 base::Owned(params)))); |
2929 } | 2929 } |
2930 | 2930 |
2931 void GDataFileSystem::AddUploadedFileToCache( | 2931 void GDataFileSystem::AddUploadedFileToCache( |
2932 AddUploadedFileParams* params, | 2932 AddUploadedFileParams* params, |
2933 GDataFileError error, | 2933 DriveFileError error, |
2934 const FilePath& file_path) { | 2934 const FilePath& file_path) { |
2935 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2935 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2936 | 2936 |
2937 if (params->upload_mode == UPLOAD_NEW_FILE) { | 2937 if (params->upload_mode == UPLOAD_NEW_FILE) { |
2938 // Add the file to the cache if we have uploaded a new file. | 2938 // Add the file to the cache if we have uploaded a new file. |
2939 cache_->StoreOnUIThread(params->resource_id, | 2939 cache_->StoreOnUIThread(params->resource_id, |
2940 params->md5, | 2940 params->md5, |
2941 params->file_content_path, | 2941 params->file_content_path, |
2942 params->cache_operation, | 2942 params->cache_operation, |
2943 base::Bind(&OnCacheUpdatedForAddUploadedFile, | 2943 base::Bind(&OnCacheUpdatedForAddUploadedFile, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3059 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3059 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3060 | 3060 |
3061 // If the file is already opened, it cannot be opened again before closed. | 3061 // If the file is already opened, it cannot be opened again before closed. |
3062 // This is for avoiding simultaneous modification to the file, and moreover | 3062 // This is for avoiding simultaneous modification to the file, and moreover |
3063 // to avoid an inconsistent cache state (suppose an operation sequence like | 3063 // to avoid an inconsistent cache state (suppose an operation sequence like |
3064 // Open->Open->modify->Close->modify->Close; the second modify may not be | 3064 // Open->Open->modify->Close->modify->Close; the second modify may not be |
3065 // synchronized to the server since it is already Closed on the cache). | 3065 // synchronized to the server since it is already Closed on the cache). |
3066 if (open_files_.find(file_path) != open_files_.end()) { | 3066 if (open_files_.find(file_path) != open_files_.end()) { |
3067 MessageLoop::current()->PostTask( | 3067 MessageLoop::current()->PostTask( |
3068 FROM_HERE, | 3068 FROM_HERE, |
3069 base::Bind(callback, GDATA_FILE_ERROR_IN_USE, FilePath())); | 3069 base::Bind(callback, DRIVE_FILE_ERROR_IN_USE, FilePath())); |
3070 return; | 3070 return; |
3071 } | 3071 } |
3072 open_files_.insert(file_path); | 3072 open_files_.insert(file_path); |
3073 | 3073 |
3074 resource_metadata_->GetEntryInfoByPath( | 3074 resource_metadata_->GetEntryInfoByPath( |
3075 file_path, | 3075 file_path, |
3076 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForOpenFile, | 3076 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForOpenFile, |
3077 ui_weak_ptr_, | 3077 ui_weak_ptr_, |
3078 file_path, | 3078 file_path, |
3079 base::Bind(&GDataFileSystem::OnOpenFileFinished, | 3079 base::Bind(&GDataFileSystem::OnOpenFileFinished, |
3080 ui_weak_ptr_, | 3080 ui_weak_ptr_, |
3081 file_path, | 3081 file_path, |
3082 callback))); | 3082 callback))); |
3083 } | 3083 } |
3084 | 3084 |
3085 void GDataFileSystem::OnGetEntryInfoCompleteForOpenFile( | 3085 void GDataFileSystem::OnGetEntryInfoCompleteForOpenFile( |
3086 const FilePath& file_path, | 3086 const FilePath& file_path, |
3087 const OpenFileCallback& callback, | 3087 const OpenFileCallback& callback, |
3088 GDataFileError error, | 3088 DriveFileError error, |
3089 scoped_ptr<DriveEntryProto> entry_proto) { | 3089 scoped_ptr<DriveEntryProto> entry_proto) { |
3090 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3090 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3091 | 3091 |
3092 if (entry_proto.get() && !entry_proto->has_file_specific_info()) | 3092 if (entry_proto.get() && !entry_proto->has_file_specific_info()) |
3093 error = GDATA_FILE_ERROR_NOT_FOUND; | 3093 error = DRIVE_FILE_ERROR_NOT_FOUND; |
3094 | 3094 |
3095 if (error == GDATA_FILE_OK) { | 3095 if (error == DRIVE_FILE_OK) { |
3096 if (entry_proto->file_specific_info().file_md5().empty() || | 3096 if (entry_proto->file_specific_info().file_md5().empty() || |
3097 entry_proto->file_specific_info().is_hosted_document()) { | 3097 entry_proto->file_specific_info().is_hosted_document()) { |
3098 // No support for opening a directory or hosted document. | 3098 // No support for opening a directory or hosted document. |
3099 error = GDATA_FILE_ERROR_INVALID_OPERATION; | 3099 error = DRIVE_FILE_ERROR_INVALID_OPERATION; |
3100 } | 3100 } |
3101 } | 3101 } |
3102 | 3102 |
3103 if (error != GDATA_FILE_OK) { | 3103 if (error != DRIVE_FILE_OK) { |
3104 if (!callback.is_null()) | 3104 if (!callback.is_null()) |
3105 callback.Run(error, FilePath()); | 3105 callback.Run(error, FilePath()); |
3106 return; | 3106 return; |
3107 } | 3107 } |
3108 | 3108 |
3109 DCHECK(!entry_proto->resource_id().empty()); | 3109 DCHECK(!entry_proto->resource_id().empty()); |
3110 GetResolvedFileByPath( | 3110 GetResolvedFileByPath( |
3111 file_path, | 3111 file_path, |
3112 base::Bind(&GDataFileSystem::OnGetFileCompleteForOpenFile, | 3112 base::Bind(&GDataFileSystem::OnGetFileCompleteForOpenFile, |
3113 ui_weak_ptr_, | 3113 ui_weak_ptr_, |
3114 callback, | 3114 callback, |
3115 GetFileCompleteForOpenParams( | 3115 GetFileCompleteForOpenParams( |
3116 entry_proto->resource_id(), | 3116 entry_proto->resource_id(), |
3117 entry_proto->file_specific_info().file_md5())), | 3117 entry_proto->file_specific_info().file_md5())), |
3118 GetContentCallback(), | 3118 GetContentCallback(), |
3119 error, | 3119 error, |
3120 entry_proto.get()); | 3120 entry_proto.get()); |
3121 } | 3121 } |
3122 | 3122 |
3123 void GDataFileSystem::OnGetFileCompleteForOpenFile( | 3123 void GDataFileSystem::OnGetFileCompleteForOpenFile( |
3124 const OpenFileCallback& callback, | 3124 const OpenFileCallback& callback, |
3125 const GetFileCompleteForOpenParams& entry_proto, | 3125 const GetFileCompleteForOpenParams& entry_proto, |
3126 GDataFileError error, | 3126 DriveFileError error, |
3127 const FilePath& file_path, | 3127 const FilePath& file_path, |
3128 const std::string& mime_type, | 3128 const std::string& mime_type, |
3129 DriveFileType file_type) { | 3129 DriveFileType file_type) { |
3130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3131 | 3131 |
3132 if (error != GDATA_FILE_OK) { | 3132 if (error != DRIVE_FILE_OK) { |
3133 if (!callback.is_null()) | 3133 if (!callback.is_null()) |
3134 callback.Run(error, FilePath()); | 3134 callback.Run(error, FilePath()); |
3135 return; | 3135 return; |
3136 } | 3136 } |
3137 | 3137 |
3138 // OpenFileOnUIThread ensures that the file is a regular file. | 3138 // OpenFileOnUIThread ensures that the file is a regular file. |
3139 DCHECK_EQ(REGULAR_FILE, file_type); | 3139 DCHECK_EQ(REGULAR_FILE, file_type); |
3140 | 3140 |
3141 cache_->MarkDirtyOnUIThread( | 3141 cache_->MarkDirtyOnUIThread( |
3142 entry_proto.resource_id, | 3142 entry_proto.resource_id, |
3143 entry_proto.md5, | 3143 entry_proto.md5, |
3144 base::Bind(&GDataFileSystem::OnMarkDirtyInCacheCompleteForOpenFile, | 3144 base::Bind(&GDataFileSystem::OnMarkDirtyInCacheCompleteForOpenFile, |
3145 ui_weak_ptr_, | 3145 ui_weak_ptr_, |
3146 callback)); | 3146 callback)); |
3147 } | 3147 } |
3148 | 3148 |
3149 void GDataFileSystem::OnMarkDirtyInCacheCompleteForOpenFile( | 3149 void GDataFileSystem::OnMarkDirtyInCacheCompleteForOpenFile( |
3150 const OpenFileCallback& callback, | 3150 const OpenFileCallback& callback, |
3151 GDataFileError error, | 3151 DriveFileError error, |
3152 const std::string& resource_id, | 3152 const std::string& resource_id, |
3153 const std::string& md5, | 3153 const std::string& md5, |
3154 const FilePath& cache_file_path) { | 3154 const FilePath& cache_file_path) { |
3155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3156 | 3156 |
3157 if (!callback.is_null()) | 3157 if (!callback.is_null()) |
3158 callback.Run(error, cache_file_path); | 3158 callback.Run(error, cache_file_path); |
3159 } | 3159 } |
3160 | 3160 |
3161 void GDataFileSystem::OnOpenFileFinished(const FilePath& file_path, | 3161 void GDataFileSystem::OnOpenFileFinished(const FilePath& file_path, |
3162 const OpenFileCallback& callback, | 3162 const OpenFileCallback& callback, |
3163 GDataFileError result, | 3163 DriveFileError result, |
3164 const FilePath& cache_file_path) { | 3164 const FilePath& cache_file_path) { |
3165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3166 | 3166 |
3167 // All the invocation of |callback| from operations initiated from OpenFile | 3167 // All the invocation of |callback| from operations initiated from OpenFile |
3168 // must go through here. Removes the |file_path| from the remembered set when | 3168 // must go through here. Removes the |file_path| from the remembered set when |
3169 // the file was not successfully opened. | 3169 // the file was not successfully opened. |
3170 if (result != GDATA_FILE_OK) | 3170 if (result != DRIVE_FILE_OK) |
3171 open_files_.erase(file_path); | 3171 open_files_.erase(file_path); |
3172 | 3172 |
3173 if (!callback.is_null()) | 3173 if (!callback.is_null()) |
3174 callback.Run(result, cache_file_path); | 3174 callback.Run(result, cache_file_path); |
3175 } | 3175 } |
3176 | 3176 |
3177 void GDataFileSystem::CloseFile(const FilePath& file_path, | 3177 void GDataFileSystem::CloseFile(const FilePath& file_path, |
3178 const FileOperationCallback& callback) { | 3178 const FileOperationCallback& callback) { |
3179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 3179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
3180 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 3180 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
3181 DCHECK(!callback.is_null()); | 3181 DCHECK(!callback.is_null()); |
3182 | 3182 |
3183 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CloseFileOnUIThread, | 3183 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CloseFileOnUIThread, |
3184 ui_weak_ptr_, | 3184 ui_weak_ptr_, |
3185 file_path, | 3185 file_path, |
3186 CreateRelayCallback(callback))); | 3186 CreateRelayCallback(callback))); |
3187 } | 3187 } |
3188 | 3188 |
3189 void GDataFileSystem::CloseFileOnUIThread( | 3189 void GDataFileSystem::CloseFileOnUIThread( |
3190 const FilePath& file_path, | 3190 const FilePath& file_path, |
3191 const FileOperationCallback& callback) { | 3191 const FileOperationCallback& callback) { |
3192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3193 DCHECK(!callback.is_null()); | 3193 DCHECK(!callback.is_null()); |
3194 | 3194 |
3195 if (open_files_.find(file_path) == open_files_.end()) { | 3195 if (open_files_.find(file_path) == open_files_.end()) { |
3196 // The file is not being opened. | 3196 // The file is not being opened. |
3197 MessageLoop::current()->PostTask( | 3197 MessageLoop::current()->PostTask( |
3198 FROM_HERE, | 3198 FROM_HERE, |
3199 base::Bind(callback, GDATA_FILE_ERROR_NOT_FOUND)); | 3199 base::Bind(callback, DRIVE_FILE_ERROR_NOT_FOUND)); |
3200 return; | 3200 return; |
3201 } | 3201 } |
3202 | 3202 |
3203 // Step 1 of CloseFile: Get resource_id and md5 for |file_path|. | 3203 // Step 1 of CloseFile: Get resource_id and md5 for |file_path|. |
3204 resource_metadata_->GetEntryInfoByPath( | 3204 resource_metadata_->GetEntryInfoByPath( |
3205 file_path, | 3205 file_path, |
3206 base::Bind(&GDataFileSystem::CloseFileOnUIThreadAfterGetEntryInfo, | 3206 base::Bind(&GDataFileSystem::CloseFileOnUIThreadAfterGetEntryInfo, |
3207 ui_weak_ptr_, | 3207 ui_weak_ptr_, |
3208 file_path, | 3208 file_path, |
3209 base::Bind(&GDataFileSystem::CloseFileOnUIThreadFinalize, | 3209 base::Bind(&GDataFileSystem::CloseFileOnUIThreadFinalize, |
3210 ui_weak_ptr_, | 3210 ui_weak_ptr_, |
3211 file_path, | 3211 file_path, |
3212 callback))); | 3212 callback))); |
3213 } | 3213 } |
3214 | 3214 |
3215 void GDataFileSystem::CloseFileOnUIThreadAfterGetEntryInfo( | 3215 void GDataFileSystem::CloseFileOnUIThreadAfterGetEntryInfo( |
3216 const FilePath& file_path, | 3216 const FilePath& file_path, |
3217 const FileOperationCallback& callback, | 3217 const FileOperationCallback& callback, |
3218 GDataFileError error, | 3218 DriveFileError error, |
3219 scoped_ptr<DriveEntryProto> entry_proto) { | 3219 scoped_ptr<DriveEntryProto> entry_proto) { |
3220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3221 DCHECK(!callback.is_null()); | 3221 DCHECK(!callback.is_null()); |
3222 | 3222 |
3223 if (entry_proto.get() && !entry_proto->has_file_specific_info()) | 3223 if (entry_proto.get() && !entry_proto->has_file_specific_info()) |
3224 error = GDATA_FILE_ERROR_NOT_FOUND; | 3224 error = DRIVE_FILE_ERROR_NOT_FOUND; |
3225 | 3225 |
3226 if (error != GDATA_FILE_OK) { | 3226 if (error != DRIVE_FILE_OK) { |
3227 callback.Run(error); | 3227 callback.Run(error); |
3228 return; | 3228 return; |
3229 } | 3229 } |
3230 | 3230 |
3231 // Step 2 of CloseFile: Commit the modification in cache. This will trigger | 3231 // Step 2 of CloseFile: Commit the modification in cache. This will trigger |
3232 // background upload. | 3232 // background upload. |
3233 // TODO(benchan,kinaba): Call ClearDirtyInCache instead of CommitDirtyInCache | 3233 // TODO(benchan,kinaba): Call ClearDirtyInCache instead of CommitDirtyInCache |
3234 // if the file has not been modified. Come up with a way to detect the | 3234 // if the file has not been modified. Come up with a way to detect the |
3235 // intactness effectively, or provide a method for user to declare it when | 3235 // intactness effectively, or provide a method for user to declare it when |
3236 // calling CloseFile(). | 3236 // calling CloseFile(). |
3237 cache_->CommitDirtyOnUIThread( | 3237 cache_->CommitDirtyOnUIThread( |
3238 entry_proto->resource_id(), | 3238 entry_proto->resource_id(), |
3239 entry_proto->file_specific_info().file_md5(), | 3239 entry_proto->file_specific_info().file_md5(), |
3240 base::Bind(&GDataFileSystem::CloseFileOnUIThreadAfterCommitDirtyInCache, | 3240 base::Bind(&GDataFileSystem::CloseFileOnUIThreadAfterCommitDirtyInCache, |
3241 ui_weak_ptr_, | 3241 ui_weak_ptr_, |
3242 callback)); | 3242 callback)); |
3243 } | 3243 } |
3244 | 3244 |
3245 void GDataFileSystem::CloseFileOnUIThreadAfterCommitDirtyInCache( | 3245 void GDataFileSystem::CloseFileOnUIThreadAfterCommitDirtyInCache( |
3246 const FileOperationCallback& callback, | 3246 const FileOperationCallback& callback, |
3247 GDataFileError error, | 3247 DriveFileError error, |
3248 const std::string& /* resource_id */, | 3248 const std::string& /* resource_id */, |
3249 const std::string& /* md5 */) { | 3249 const std::string& /* md5 */) { |
3250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3251 DCHECK(!callback.is_null()); | 3251 DCHECK(!callback.is_null()); |
3252 | 3252 |
3253 callback.Run(error); | 3253 callback.Run(error); |
3254 } | 3254 } |
3255 | 3255 |
3256 void GDataFileSystem::CloseFileOnUIThreadFinalize( | 3256 void GDataFileSystem::CloseFileOnUIThreadFinalize( |
3257 const FilePath& file_path, | 3257 const FilePath& file_path, |
3258 const FileOperationCallback& callback, | 3258 const FileOperationCallback& callback, |
3259 GDataFileError result) { | 3259 DriveFileError result) { |
3260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3261 DCHECK(!callback.is_null()); | 3261 DCHECK(!callback.is_null()); |
3262 | 3262 |
3263 // Step 3 of CloseFile. | 3263 // Step 3 of CloseFile. |
3264 // All the invocation of |callback| from operations initiated from CloseFile | 3264 // All the invocation of |callback| from operations initiated from CloseFile |
3265 // must go through here. Removes the |file_path| from the remembered set so | 3265 // must go through here. Removes the |file_path| from the remembered set so |
3266 // that subsequent operations can open the file again. | 3266 // that subsequent operations can open the file again. |
3267 open_files_.erase(file_path); | 3267 open_files_.erase(file_path); |
3268 | 3268 |
3269 // Then invokes the user-supplied callback function. | 3269 // Then invokes the user-supplied callback function. |
3270 callback.Run(result); | 3270 callback.Run(result); |
3271 } | 3271 } |
3272 | 3272 |
3273 void GDataFileSystem::CheckLocalModificationAndRun( | 3273 void GDataFileSystem::CheckLocalModificationAndRun( |
3274 scoped_ptr<DriveEntryProto> entry_proto, | 3274 scoped_ptr<DriveEntryProto> entry_proto, |
3275 const GetEntryInfoCallback& callback) { | 3275 const GetEntryInfoCallback& callback) { |
3276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3277 DCHECK(entry_proto.get()); | 3277 DCHECK(entry_proto.get()); |
3278 DCHECK(!callback.is_null()); | 3278 DCHECK(!callback.is_null()); |
3279 | 3279 |
3280 // For entries that will never be cached, use the original entry info as is. | 3280 // For entries that will never be cached, use the original entry info as is. |
3281 if (!entry_proto->has_file_specific_info() || | 3281 if (!entry_proto->has_file_specific_info() || |
3282 entry_proto->file_specific_info().is_hosted_document()) { | 3282 entry_proto->file_specific_info().is_hosted_document()) { |
3283 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3283 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
3284 return; | 3284 return; |
3285 } | 3285 } |
3286 | 3286 |
3287 // Checks if the file is cached and modified locally. | 3287 // Checks if the file is cached and modified locally. |
3288 const std::string resource_id = entry_proto->resource_id(); | 3288 const std::string resource_id = entry_proto->resource_id(); |
3289 const std::string md5 = entry_proto->file_specific_info().file_md5(); | 3289 const std::string md5 = entry_proto->file_specific_info().file_md5(); |
3290 cache_->GetCacheEntryOnUIThread( | 3290 cache_->GetCacheEntryOnUIThread( |
3291 resource_id, | 3291 resource_id, |
3292 md5, | 3292 md5, |
3293 base::Bind( | 3293 base::Bind( |
3294 &GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry, | 3294 &GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry, |
3295 ui_weak_ptr_, base::Passed(&entry_proto), callback)); | 3295 ui_weak_ptr_, base::Passed(&entry_proto), callback)); |
3296 } | 3296 } |
3297 | 3297 |
3298 void GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry( | 3298 void GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry( |
3299 scoped_ptr<DriveEntryProto> entry_proto, | 3299 scoped_ptr<DriveEntryProto> entry_proto, |
3300 const GetEntryInfoCallback& callback, | 3300 const GetEntryInfoCallback& callback, |
3301 bool success, | 3301 bool success, |
3302 const DriveCacheEntry& cache_entry) { | 3302 const DriveCacheEntry& cache_entry) { |
3303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3304 DCHECK(!callback.is_null()); | 3304 DCHECK(!callback.is_null()); |
3305 | 3305 |
3306 // When no dirty cache is found, use the original entry info as is. | 3306 // When no dirty cache is found, use the original entry info as is. |
3307 if (!success || !cache_entry.is_dirty()) { | 3307 if (!success || !cache_entry.is_dirty()) { |
3308 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3308 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
3309 return; | 3309 return; |
3310 } | 3310 } |
3311 | 3311 |
3312 // Gets the cache file path. | 3312 // Gets the cache file path. |
3313 const std::string& resource_id = entry_proto->resource_id(); | 3313 const std::string& resource_id = entry_proto->resource_id(); |
3314 const std::string& md5 = entry_proto->file_specific_info().file_md5(); | 3314 const std::string& md5 = entry_proto->file_specific_info().file_md5(); |
3315 cache_->GetFileOnUIThread( | 3315 cache_->GetFileOnUIThread( |
3316 resource_id, | 3316 resource_id, |
3317 md5, | 3317 md5, |
3318 base::Bind( | 3318 base::Bind( |
3319 &GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheFile, | 3319 &GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheFile, |
3320 ui_weak_ptr_, base::Passed(&entry_proto), callback)); | 3320 ui_weak_ptr_, base::Passed(&entry_proto), callback)); |
3321 } | 3321 } |
3322 | 3322 |
3323 void GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheFile( | 3323 void GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheFile( |
3324 scoped_ptr<DriveEntryProto> entry_proto, | 3324 scoped_ptr<DriveEntryProto> entry_proto, |
3325 const GetEntryInfoCallback& callback, | 3325 const GetEntryInfoCallback& callback, |
3326 GDataFileError error, | 3326 DriveFileError error, |
3327 const std::string& resource_id, | 3327 const std::string& resource_id, |
3328 const std::string& md5, | 3328 const std::string& md5, |
3329 const FilePath& local_cache_path) { | 3329 const FilePath& local_cache_path) { |
3330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3331 DCHECK(!callback.is_null()); | 3331 DCHECK(!callback.is_null()); |
3332 | 3332 |
3333 // When no dirty cache is found, use the original entry info as is. | 3333 // When no dirty cache is found, use the original entry info as is. |
3334 if (error != GDATA_FILE_OK) { | 3334 if (error != DRIVE_FILE_OK) { |
3335 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3335 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
3336 return; | 3336 return; |
3337 } | 3337 } |
3338 | 3338 |
3339 // If the cache is dirty, obtain the file info from the cache file itself. | 3339 // If the cache is dirty, obtain the file info from the cache file itself. |
3340 base::PlatformFileInfo* file_info = new base::PlatformFileInfo; | 3340 base::PlatformFileInfo* file_info = new base::PlatformFileInfo; |
3341 bool* get_file_info_result = new bool(false); | 3341 bool* get_file_info_result = new bool(false); |
3342 util::PostBlockingPoolSequencedTaskAndReply( | 3342 util::PostBlockingPoolSequencedTaskAndReply( |
3343 FROM_HERE, | 3343 FROM_HERE, |
3344 blocking_task_runner_, | 3344 blocking_task_runner_, |
3345 base::Bind(&GetFileInfoOnBlockingPool, | 3345 base::Bind(&GetFileInfoOnBlockingPool, |
(...skipping 10 matching lines...) Expand all Loading... |
3356 | 3356 |
3357 void GDataFileSystem::CheckLocalModificationAndRunAfterGetFileInfo( | 3357 void GDataFileSystem::CheckLocalModificationAndRunAfterGetFileInfo( |
3358 scoped_ptr<DriveEntryProto> entry_proto, | 3358 scoped_ptr<DriveEntryProto> entry_proto, |
3359 const GetEntryInfoCallback& callback, | 3359 const GetEntryInfoCallback& callback, |
3360 base::PlatformFileInfo* file_info, | 3360 base::PlatformFileInfo* file_info, |
3361 bool* get_file_info_result) { | 3361 bool* get_file_info_result) { |
3362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3363 DCHECK(!callback.is_null()); | 3363 DCHECK(!callback.is_null()); |
3364 | 3364 |
3365 if (!*get_file_info_result) { | 3365 if (!*get_file_info_result) { |
3366 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, scoped_ptr<DriveEntryProto>()); | 3366 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, scoped_ptr<DriveEntryProto>()); |
3367 return; | 3367 return; |
3368 } | 3368 } |
3369 | 3369 |
3370 PlatformFileInfoProto entry_file_info; | 3370 PlatformFileInfoProto entry_file_info; |
3371 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3371 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
3372 *entry_proto->mutable_file_info() = entry_file_info; | 3372 *entry_proto->mutable_file_info() = entry_file_info; |
3373 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3373 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
3374 } | 3374 } |
3375 | 3375 |
3376 } // namespace gdata | 3376 } // namespace gdata |
OLD | NEW |