| 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 <errno.h> | 7 #include <errno.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 1873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1884 cache_paths_.push_back(root_path.Append(kGDataCacheTmpDocumentsDir)); | 1884 cache_paths_.push_back(root_path.Append(kGDataCacheTmpDocumentsDir)); |
| 1885 } | 1885 } |
| 1886 | 1886 |
| 1887 void GDataFileSystem::InitiateUpload( | 1887 void GDataFileSystem::InitiateUpload( |
| 1888 const std::string& file_name, | 1888 const std::string& file_name, |
| 1889 const std::string& content_type, | 1889 const std::string& content_type, |
| 1890 int64 content_length, | 1890 int64 content_length, |
| 1891 const FilePath& destination_directory, | 1891 const FilePath& destination_directory, |
| 1892 const FilePath& virtual_path, | 1892 const FilePath& virtual_path, |
| 1893 const InitiateUploadCallback& callback) { | 1893 const InitiateUploadCallback& callback) { |
| 1894 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1895 |
| 1894 GURL destination_directory_url = | 1896 GURL destination_directory_url = |
| 1895 GetUploadUrlForDirectory(destination_directory); | 1897 GetUploadUrlForDirectory(destination_directory); |
| 1896 | 1898 |
| 1897 if (destination_directory_url.is_empty()) { | 1899 if (destination_directory_url.is_empty()) { |
| 1898 if (!callback.is_null()) { | 1900 if (!callback.is_null()) { |
| 1899 MessageLoop::current()->PostTask( | 1901 MessageLoop::current()->PostTask( |
| 1900 FROM_HERE, | 1902 FROM_HERE, |
| 1901 base::Bind(callback, | 1903 base::Bind(callback, |
| 1902 HTTP_BAD_REQUEST, GURL())); | 1904 HTTP_BAD_REQUEST, GURL())); |
| 1903 } | 1905 } |
| 1904 return; | 1906 return; |
| 1905 } | 1907 } |
| 1906 | 1908 |
| 1907 documents_service_->InitiateUpload( | 1909 documents_service_->InitiateUpload( |
| 1908 InitiateUploadParams(file_name, | 1910 InitiateUploadParams(file_name, |
| 1909 content_type, | 1911 content_type, |
| 1910 content_length, | 1912 content_length, |
| 1911 destination_directory_url, | 1913 destination_directory_url, |
| 1912 virtual_path), | 1914 virtual_path), |
| 1913 base::Bind(&GDataFileSystem::OnUploadLocationReceived, | 1915 callback); |
| 1914 GetWeakPtrForCurrentThread(), | |
| 1915 callback, | |
| 1916 // MessageLoopProxy is used to run |callback| on the | |
| 1917 // thread where this function was called. | |
| 1918 base::MessageLoopProxy::current())); | |
| 1919 } | |
| 1920 | |
| 1921 void GDataFileSystem::OnUploadLocationReceived( | |
| 1922 const InitiateUploadCallback& callback, | |
| 1923 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | |
| 1924 GDataErrorCode code, | |
| 1925 const GURL& upload_location) { | |
| 1926 | |
| 1927 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1928 if (!callback.is_null()) { | |
| 1929 message_loop_proxy->PostTask(FROM_HERE, base::Bind(callback, code, | |
| 1930 upload_location)); | |
| 1931 } | |
| 1932 } | 1916 } |
| 1933 | 1917 |
| 1934 void GDataFileSystem::ResumeUpload( | 1918 void GDataFileSystem::ResumeUpload( |
| 1935 const ResumeUploadParams& params, | 1919 const ResumeUploadParams& params, |
| 1936 const ResumeFileUploadCallback& callback) { | 1920 const ResumeFileUploadCallback& callback) { |
| 1937 documents_service_->ResumeUpload( | 1921 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1938 params, | |
| 1939 base::Bind(&GDataFileSystem::OnResumeUpload, | |
| 1940 GetWeakPtrForCurrentThread(), | |
| 1941 base::MessageLoopProxy::current(), | |
| 1942 callback)); | |
| 1943 } | |
| 1944 | 1922 |
| 1945 void GDataFileSystem::OnResumeUpload( | 1923 documents_service_->ResumeUpload(params, callback); |
| 1946 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | |
| 1947 const ResumeFileUploadCallback& callback, | |
| 1948 const ResumeUploadResponse& response, | |
| 1949 scoped_ptr<DocumentEntry> new_entry) { | |
| 1950 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1951 if (!callback.is_null()) | |
| 1952 message_loop_proxy->PostTask(FROM_HERE, | |
| 1953 base::Bind(callback, response, base::Passed(&new_entry))); | |
| 1954 } | 1924 } |
| 1955 | 1925 |
| 1956 void GDataFileSystem::UnsafeFindEntryByPath( | 1926 void GDataFileSystem::UnsafeFindEntryByPath( |
| 1957 const FilePath& file_path, | 1927 const FilePath& file_path, |
| 1958 FindEntryDelegate* delegate) { | 1928 FindEntryDelegate* delegate) { |
| 1959 DCHECK(delegate); | 1929 DCHECK(delegate); |
| 1960 lock_.AssertAcquired(); | 1930 lock_.AssertAcquired(); |
| 1961 | 1931 |
| 1962 std::vector<FilePath::StringType> components; | 1932 std::vector<FilePath::StringType> components; |
| 1963 file_path.GetComponents(&components); | 1933 file_path.GetComponents(&components); |
| (...skipping 2436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4400 pref_registrar_->Init(profile_->GetPrefs()); | 4370 pref_registrar_->Init(profile_->GetPrefs()); |
| 4401 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 4371 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
| 4402 } | 4372 } |
| 4403 | 4373 |
| 4404 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 4374 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
| 4405 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 4375 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
| 4406 global_free_disk_getter_for_testing = getter; | 4376 global_free_disk_getter_for_testing = getter; |
| 4407 } | 4377 } |
| 4408 | 4378 |
| 4409 } // namespace gdata | 4379 } // namespace gdata |
| OLD | NEW |