Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10207022: gdata: Simplify InitiateUpload() and ResumeUpload() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1870 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 cache_paths_.push_back(root_path.Append(kGDataCacheTmpDocumentsDir)); 1881 cache_paths_.push_back(root_path.Append(kGDataCacheTmpDocumentsDir));
1882 } 1882 }
1883 1883
1884 void GDataFileSystem::InitiateUpload( 1884 void GDataFileSystem::InitiateUpload(
1885 const std::string& file_name, 1885 const std::string& file_name,
1886 const std::string& content_type, 1886 const std::string& content_type,
1887 int64 content_length, 1887 int64 content_length,
1888 const FilePath& destination_directory, 1888 const FilePath& destination_directory,
1889 const FilePath& virtual_path, 1889 const FilePath& virtual_path,
1890 const InitiateUploadCallback& callback) { 1890 const InitiateUploadCallback& callback) {
1891 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1892
1891 GURL destination_directory_url = 1893 GURL destination_directory_url =
1892 GetUploadUrlForDirectory(destination_directory); 1894 GetUploadUrlForDirectory(destination_directory);
1893 1895
1894 if (destination_directory_url.is_empty()) { 1896 if (destination_directory_url.is_empty()) {
1895 if (!callback.is_null()) { 1897 if (!callback.is_null()) {
1896 MessageLoop::current()->PostTask( 1898 MessageLoop::current()->PostTask(
achuithb 2012/04/24 23:46:14 Is there a reason to PostTask here instead of runn
satorux1 2012/04/24 23:54:19 In async functions, we usually run a callback thro
1897 FROM_HERE, 1899 FROM_HERE,
1898 base::Bind(callback, 1900 base::Bind(callback,
1899 HTTP_BAD_REQUEST, GURL())); 1901 HTTP_BAD_REQUEST, GURL()));
1900 } 1902 }
1901 return; 1903 return;
1902 } 1904 }
1903 1905
1904 documents_service_->InitiateUpload( 1906 documents_service_->InitiateUpload(
1905 InitiateUploadParams(file_name, 1907 InitiateUploadParams(file_name,
1906 content_type, 1908 content_type,
1907 content_length, 1909 content_length,
1908 destination_directory_url, 1910 destination_directory_url,
1909 virtual_path), 1911 virtual_path),
1910 base::Bind(&GDataFileSystem::OnUploadLocationReceived, 1912 callback);
1911 GetWeakPtrForCurrentThread(),
1912 callback,
1913 // MessageLoopProxy is used to run |callback| on the
1914 // thread where this function was called.
1915 base::MessageLoopProxy::current()));
1916 }
1917
1918 void GDataFileSystem::OnUploadLocationReceived(
1919 const InitiateUploadCallback& callback,
1920 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
1921 GDataErrorCode code,
1922 const GURL& upload_location) {
1923
1924 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1925 if (!callback.is_null()) {
1926 message_loop_proxy->PostTask(FROM_HERE, base::Bind(callback, code,
1927 upload_location));
1928 }
1929 } 1913 }
1930 1914
1931 void GDataFileSystem::ResumeUpload( 1915 void GDataFileSystem::ResumeUpload(
1932 const ResumeUploadParams& params, 1916 const ResumeUploadParams& params,
1933 const ResumeFileUploadCallback& callback) { 1917 const ResumeFileUploadCallback& callback) {
1934 documents_service_->ResumeUpload( 1918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1935 params,
1936 base::Bind(&GDataFileSystem::OnResumeUpload,
1937 GetWeakPtrForCurrentThread(),
1938 base::MessageLoopProxy::current(),
1939 callback));
1940 }
1941 1919
1942 void GDataFileSystem::OnResumeUpload( 1920 documents_service_->ResumeUpload(params, callback);
1943 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
1944 const ResumeFileUploadCallback& callback,
1945 const ResumeUploadResponse& response,
1946 scoped_ptr<DocumentEntry> new_entry) {
1947 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1948 if (!callback.is_null())
1949 message_loop_proxy->PostTask(FROM_HERE,
1950 base::Bind(callback, response, base::Passed(&new_entry)));
1951 } 1921 }
1952 1922
1953 void GDataFileSystem::UnsafeFindEntryByPath( 1923 void GDataFileSystem::UnsafeFindEntryByPath(
1954 const FilePath& file_path, 1924 const FilePath& file_path,
1955 FindEntryDelegate* delegate) { 1925 FindEntryDelegate* delegate) {
1956 DCHECK(delegate); 1926 DCHECK(delegate);
1957 lock_.AssertAcquired(); 1927 lock_.AssertAcquired();
1958 1928
1959 std::vector<FilePath::StringType> components; 1929 std::vector<FilePath::StringType> components;
1960 file_path.GetComponents(&components); 1930 file_path.GetComponents(&components);
(...skipping 2436 matching lines...) Expand 10 before | Expand all | Expand 10 after
4397 pref_registrar_->Init(profile_->GetPrefs()); 4367 pref_registrar_->Init(profile_->GetPrefs());
4398 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 4368 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
4399 } 4369 }
4400 4370
4401 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 4371 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
4402 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 4372 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
4403 global_free_disk_getter_for_testing = getter; 4373 global_free_disk_getter_for_testing = getter;
4404 } 4374 }
4405 4375
4406 } // namespace gdata 4376 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698