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

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

Issue 10270018: gdata: Add GDataFileSystem::GetFileInfoByPathAsync(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 7 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>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/chromeos/chromeos_version.h" 14 #include "base/chromeos/chromeos_version.h"
15 #include "base/eintr_wrapper.h" 15 #include "base/eintr_wrapper.h"
16 #include "base/file_util.h" 16 #include "base/file_util.h"
17 #include "base/json/json_file_value_serializer.h" 17 #include "base/json/json_file_value_serializer.h"
18 #include "base/json/json_reader.h" 18 #include "base/json/json_reader.h"
19 #include "base/json/json_writer.h" 19 #include "base/json/json_writer.h"
20 #include "base/message_loop.h" 20 #include "base/message_loop.h"
21 #include "base/message_loop_proxy.h" 21 #include "base/message_loop_proxy.h"
22 #include "base/metrics/histogram.h" 22 #include "base/metrics/histogram.h"
23 #include "base/platform_file.h" 23 #include "base/platform_file.h"
24 #include "base/sys_info.h" 24 #include "base/sys_info.h"
25 #include "base/threading/platform_thread.h" 25 #include "base/threading/platform_thread.h"
26 #include "base/threading/sequenced_worker_pool.h" 26 #include "base/threading/sequenced_worker_pool.h"
27 #include "base/threading/thread_restrictions.h" 27 #include "base/threading/thread_restrictions.h"
28 #include "base/synchronization/waitable_event.h" 28 #include "base/synchronization/waitable_event.h"
29 #include "base/values.h" 29 #include "base/values.h"
30 #include "chrome/browser/chromeos/gdata/gdata.pb.h"
30 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" 31 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h"
31 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" 32 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h"
32 #include "chrome/browser/chromeos/gdata/gdata_protocol_handler.h" 33 #include "chrome/browser/chromeos/gdata/gdata_protocol_handler.h"
33 #include "chrome/browser/chromeos/gdata/gdata_sync_client.h" 34 #include "chrome/browser/chromeos/gdata/gdata_sync_client.h"
34 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" 35 #include "chrome/browser/chromeos/gdata/gdata_system_service.h"
35 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h" 36 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h"
36 #include "chrome/browser/chromeos/gdata/gdata_util.h" 37 #include "chrome/browser/chromeos/gdata/gdata_util.h"
37 #include "chrome/browser/prefs/pref_service.h" 38 #include "chrome/browser/prefs/pref_service.h"
38 #include "chrome/browser/profiles/profile.h" 39 #include "chrome/browser/profiles/profile.h"
39 #include "chrome/common/chrome_constants.h" 40 #include "chrome/common/chrome_constants.h"
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 // Ditto for SetMountedStateCallback. 802 // Ditto for SetMountedStateCallback.
802 void RelaySetMountedStateCallback( 803 void RelaySetMountedStateCallback(
803 scoped_refptr<base::MessageLoopProxy> relay_proxy, 804 scoped_refptr<base::MessageLoopProxy> relay_proxy,
804 const SetMountedStateCallback& callback, 805 const SetMountedStateCallback& callback,
805 base::PlatformFileError error, 806 base::PlatformFileError error,
806 const FilePath& file_path) { 807 const FilePath& file_path) {
807 relay_proxy->PostTask(FROM_HERE, 808 relay_proxy->PostTask(FROM_HERE,
808 base::Bind(callback, error, file_path)); 809 base::Bind(callback, error, file_path));
809 } 810 }
810 811
812 // Ditto for GetFileInfoCallback.
813 void RelayGetFileInfoCallback(
814 scoped_refptr<base::MessageLoopProxy> relay_proxy,
815 const GetFileInfoCallback& callback,
816 base::PlatformFileError error,
817 scoped_ptr<GDataFileProto> file_proto) {
818 relay_proxy->PostTask(
819 FROM_HERE,
820 base::Bind(callback, error, base::Passed(&file_proto)));
821 }
822
811 } // namespace 823 } // namespace
812 824
813 // GDataFileProperties struct implementation. 825 // GDataFileProperties struct implementation.
814 826
815 GDataFileProperties::GDataFileProperties() : is_hosted_document(false) { 827 GDataFileProperties::GDataFileProperties() : is_hosted_document(false) {
816 } 828 }
817 829
818 GDataFileProperties::~GDataFileProperties() { 830 GDataFileProperties::~GDataFileProperties() {
819 } 831 }
820 832
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 } 2109 }
2098 2110
2099 void GDataFileSystem::ResumeUpload( 2111 void GDataFileSystem::ResumeUpload(
2100 const ResumeUploadParams& params, 2112 const ResumeUploadParams& params,
2101 const ResumeFileUploadCallback& callback) { 2113 const ResumeFileUploadCallback& callback) {
2102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2103 2115
2104 documents_service_->ResumeUpload(params, callback); 2116 documents_service_->ResumeUpload(params, callback);
2105 } 2117 }
2106 2118
2119 void GDataFileSystem::GetFileInfoByPathAsync(
2120 const FilePath& file_path,
2121 const GetFileInfoCallback& callback) {
2122 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
2123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2124 const bool posted = BrowserThread::PostTask(
2125 BrowserThread::UI,
2126 FROM_HERE,
2127 base::Bind(&GDataFileSystem::GetFileInfoByPathAsync,
2128 ui_weak_ptr_,
2129 file_path,
2130 base::Bind(&RelayGetFileInfoCallback,
2131 base::MessageLoopProxy::current(),
2132 callback)));
2133 DCHECK(posted);
2134 return;
2135 }
2136
2137 GetFileInfoByPathAsyncOnUIThread(file_path, callback);
2138 }
2139
2140 void GDataFileSystem::GetFileInfoByPathAsyncOnUIThread(
2141 const FilePath& file_path,
2142 const GetFileInfoCallback& callback) {
2143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2144
2145 FindEntryByPathAsyncOnUIThread(
2146 file_path,
2147 base::Bind(&GDataFileSystem::OnEntryFound,
2148 ui_weak_ptr_,
2149 callback));
2150 }
2151
2152 void GDataFileSystem::OnEntryFound(const GetFileInfoCallback& callback,
2153 base::PlatformFileError error,
2154 const FilePath& directory_path,
2155 GDataEntry* entry) {
2156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2157
2158 if (error != base::PLATFORM_FILE_OK) {
2159 if (!callback.is_null())
2160 callback.Run(error, scoped_ptr<GDataFileProto>());
2161 return;
2162 }
2163
2164 GDataFile* file = entry->AsGDataFile();
2165 if (!file) {
2166 if (!callback.is_null())
2167 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND,
2168 scoped_ptr<GDataFileProto>());
2169 return;
2170 }
2171
2172 scoped_ptr<GDataFileProto> file_proto(new GDataFileProto);
2173 file->ToProto(file_proto.get());
2174
2175 if (!callback.is_null())
2176 callback.Run(base::PLATFORM_FILE_OK, file_proto.Pass());
2177 }
2178
2107 bool GDataFileSystem::GetFileInfoByPath( 2179 bool GDataFileSystem::GetFileInfoByPath(
2108 const FilePath& file_path, GDataFileProperties* properties) { 2180 const FilePath& file_path, GDataFileProperties* properties) {
2109 DCHECK(properties); 2181 DCHECK(properties);
2110 base::AutoLock lock(lock_); 2182 base::AutoLock lock(lock_);
2111 GDataEntry* entry = GetGDataEntryByPath(file_path); 2183 GDataEntry* entry = GetGDataEntryByPath(file_path);
2112 if (!entry) 2184 if (!entry)
2113 return false; 2185 return false;
2114 2186
2115 properties->file_info = entry->file_info(); 2187 properties->file_info = entry->file_info();
2116 properties->resource_id = entry->resource_id(); 2188 properties->resource_id = entry->resource_id();
(...skipping 2455 matching lines...) Expand 10 before | Expand all | Expand 10 after
4572 pref_registrar_->Init(profile_->GetPrefs()); 4644 pref_registrar_->Init(profile_->GetPrefs());
4573 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 4645 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
4574 } 4646 }
4575 4647
4576 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 4648 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
4577 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 4649 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
4578 global_free_disk_getter_for_testing = getter; 4650 global_free_disk_getter_for_testing = getter;
4579 } 4651 }
4580 4652
4581 } // namespace gdata 4653 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698